# Historical warehouse

**Storage:** SQLite file (ADR-003)  
**Default path:** `C:\Users\akfai\Downloads\Cursor Project\TradingBite-Platform\data\tradingbite-warehouse.sqlite`  
**Git:** `/data/` is gitignored — never commit datasets.

## Uniqueness

Primary key: `(source, symbol, timeframe, timestamp_ms)`  
UTC bar **open** time in `timestamp_iso` + indexed `timestamp_ms`.

## UTC

All stored timestamps are **UTC** (OANDA v20 candle `time`).

## Volume

`volume_type = tick` for OANDA FX (not exchange real volume).

## CLI

**WHEN:** After `OANDA_API_TOKEN` is set in `.env`.

**WHERE:** `C:\Users\akfai\Downloads\Cursor Project\TradingBite-Platform`

```powershell
cd "C:\Users\akfai\Downloads\Cursor Project\TradingBite-Platform"
npm run warehouse:import:test
npm run warehouse:import:year
npm run warehouse:backup
```

## Query API (server)

`GET /api/warehouse/candles?symbol=EUR_USD&timeframe=M15&count=100`

Response includes `"dataSource": "TRADINGBITE_WAREHOUSE"`.

## Chart

Toolbar **Data → Warehouse** (EUR/USD M15 only in Phase E).  
**OANDA Live** unchanged via `/api/candles`.

## Backup / restore

- **Backup:** copies DB to `data/backups/tradingbite-warehouse-<stamp>.sqlite`
- **Restore:** `restoreWarehouseDb(path)` in `lib/warehouse/backup.ts` (see tests)

Verify row count via `dataset_meta` after restore.
