trader.marketdata.seed_import module¶
Converts third-party historical bar exports into domain Bars (issue #41).
trader seed-bars reads these functions’ output through the same BarRepository.save_bars path YFinanceProvider/BarCache write through, so an imported bar is indistinguishable in shape from a live-fetched one — only CachedBar.source tells them apart, per that column’s own docstring in trader/persistence/models.py.
Built and tested against synthetic fixtures, not the real dataset. The motivating find (../backtesting: 264MB of Feather-cached OHLCV across 21 tickers, plus a 145MB Interactive Brokers 1-minute SPY export) was not reachable from the checkout this was built in. Every parsing decision below is therefore pinned against the documented shape from issue #41 and this module’s own tests, not against a real file. Anyone pointing this at the real data for the first time should expect to adjust _TIMESTAMP_CANDIDATES/ _CLOSE_CANDIDATES/the IB date-format list below to match what the files actually contain, and to widen the fixtures in tests/marketdata/test_seed_import.py once a real sample is available.
Two independent parsers, deliberately not unified behind one “detect the format” entry point: the two source files come from two different vendors with two different shapes (yfinance’s Open/High/Low/Close/Volume columns and a pandas-native timestamp vs. Interactive Brokers’ date/open/…/average/barCount columns and an exchange-local string timestamp), and guessing which one a file is would be exactly the kind of silent misinterpretation _to_decimal already refuses to do for a bare float. The caller (trader seed-bars –format …) states the format; nothing here sniffs it.
- trader.marketdata.seed_import.SOURCE_IBKR_SEED = 'ibkr_seed'¶
Tags a row imported from an Interactive Brokers historical-data export (barCount/average columns are IB’s own fingerprint, per issue #41) — a different vendor with different adjustment/aggregation conventions than yfinance. source is what stops this silently sharing an unlabelled series with SOURCE_YFINANCE_SEED rows or a live fetch; the three must stay distinguishable from each other, not just seed-vs-live.
- trader.marketdata.seed_import.SOURCE_YFINANCE_SEED = 'yfinance_seed'¶
Tags a row imported from the 21-ticker Feather cache — built, per issue #41, by the source repo’s own download.py calling yfinance directly, so it is directly comparable to what YFinanceProvider fetches live, just years deeper. Still tagged, never left source=None: None means “this app fetched it live”, and a seeded row did not, regardless of how similar the vendor is.
- trader.marketdata.seed_import.load_feather_bars(path, symbol)[source]¶
Parse one of ../backtesting's cached yfinance Feather files into Bars.
Documented shape (issue #41): one Feather file per ticker per interval, written by the source repo’s own download.py from yfinance.download()/Ticker.history() output — columns named Open/High/Low/Close`[/`Adj Close]/Volume, with the timestamp surviving reset_index() as a Date/Datetime column (or, if it was not reset, still present as the frame’s own DatetimeIndex).
- Raises:
MarketDataError – the file cannot be read, a required column cannot be found, or a value cannot be converted — never a raw pandas/pyarrow exception or a silently wrong Bar.
- Parameters:
path (Path)
symbol (str)
- Return type:
list[Bar]
- trader.marketdata.seed_import.load_ibkr_csv_bars(path, symbol, *, tz='America/New_York')[source]¶
Parse an Interactive Brokers historical-data CSV export into Bars.
Documented shape (issue #41): date,open,high,low,close,volume,average, barCount (column order not assumed — read by name), one file per symbol, timestamps in the contract’s exchange-local time with no embedded zone (tz supplies it; see _parse_ibkr_timestamp). average/barCount (or wap in place of average) are IB’s own fingerprint per issue #41 and are read only to fail loudly if genuinely absent from both names — see below — never stored, since CachedBar has no field for either.
The fingerprint check is soft on average/wap specifically (a stripped export might omit it) but the presence of at least one recognisable volume-or-count column beyond plain OHLCV is not required either; this function accepts a bare date,open,high,low,close,volume file too, so a trimmed export is not refused for missing metadata nobody asked this importer to store.
- Raises:
MarketDataError – the file cannot be read, a required OHLCV column cannot be found, or a value cannot be converted.
- Parameters:
path (Path)
symbol (str)
tz (str)
- Return type:
list[Bar]