Documentation update
This commit is contained in:
+11
-12
@@ -2,7 +2,7 @@
|
||||
|
||||
## Initial Goal
|
||||
|
||||
Create a Python module/tool that fetches daily candlestick data from the IBKR API for a specific ticker and date range.
|
||||
Create a Python module/tool that fetches daily candlestick data from the Alpaca Market Data API for a specific ticker and date range.
|
||||
|
||||
The intended example workflow is:
|
||||
|
||||
@@ -14,41 +14,40 @@ The intended example workflow is:
|
||||
|
||||
## Current Implementation
|
||||
|
||||
The first implementation is intentionally small:
|
||||
The current implementation is intentionally small:
|
||||
|
||||
- ticker passed as a required command line argument;
|
||||
- end date passed with `--end-date YYYYMMDD`, defaulting to yesterday;
|
||||
- end date can also be derived with `--end-date-from-parquet`;
|
||||
- duration passed with `--duration`, defaulting to `1 W`;
|
||||
- hard-coded IBKR Gateway target: `127.0.0.1:4002`;
|
||||
- uses the IBKR API through `ib_insync`;
|
||||
- prints fetched candles as CSV-like rows;
|
||||
- uses the Alpaca Market Data API through `alpaca-py`;
|
||||
- reads credentials from `--api-key` / `--secret-key`, `ALPACA_API_KEY` / `ALPACA_SECRET_KEY`, or `.env`;
|
||||
- writes candles to a symbol-named Parquet file;
|
||||
- appends to an existing symbol file and keeps one row per date.
|
||||
|
||||
Run it with:
|
||||
|
||||
```sh
|
||||
mise exec -- uv run python src/trading_bot/data/fetch_ibkr_daily.py SPY
|
||||
mise exec -- uv run python src/trading_bot/data/fetch_alpaca_daily.py SPY
|
||||
```
|
||||
|
||||
To override the requested range:
|
||||
|
||||
```sh
|
||||
mise exec -- uv run python src/trading_bot/data/fetch_ibkr_daily.py SPY --end-date 20250605 --duration "1 M"
|
||||
mise exec -- uv run python src/trading_bot/data/fetch_alpaca_daily.py SPY --end-date 20250605 --duration "1 M"
|
||||
```
|
||||
|
||||
To fetch backward from the oldest date already stored in the symbol file:
|
||||
|
||||
```sh
|
||||
mise exec -- uv run python src/trading_bot/data/fetch_ibkr_daily.py SPY --end-date-from-parquet
|
||||
mise exec -- uv run python src/trading_bot/data/fetch_alpaca_daily.py SPY --end-date-from-parquet
|
||||
```
|
||||
|
||||
`--end-date` and `--end-date-from-parquet` cannot be used together. If the symbol Parquet file does not exist or has no rows, `--end-date-from-parquet` uses today's US/Eastern date.
|
||||
|
||||
This expects a local IBKR Gateway session to be running and accepting API connections on `127.0.0.1:4002`.
|
||||
This expects Alpaca API credentials to be available via CLI arguments, environment variables, or `.env`.
|
||||
|
||||
By default, output is written to `data/ibkr/daily/SPY.parquet`. Use `--output-dir` to choose another directory.
|
||||
By default, output is written to `data/alpaca/daily/SPY.parquet`. Use `--output-dir` to choose another directory.
|
||||
|
||||
Manual test instructions are in [manual-test/README.md](manual-test/README.md).
|
||||
|
||||
@@ -78,5 +77,5 @@ Candidate output schema:
|
||||
Open decisions:
|
||||
|
||||
- how to handle adjusted versus unadjusted prices;
|
||||
- how to handle missing sessions and IBKR pacing limits;
|
||||
- whether to use `ib_insync` long term or a lower-level IBKR client wrapper.
|
||||
- how to handle missing sessions, market holidays, and Alpaca API rate limits;
|
||||
- whether to add explicit feed selection, adjustment settings, or data entitlement checks.
|
||||
|
||||
Reference in New Issue
Block a user