trader.news.archive module

News archive: fetch a span of history once, replay from it thereafter.

BarCache’s shape, for the same reason — one fetch, then a local read — but with the opposite failure policy on refresh. There is no tail to re-fetch and no refresh flag at all: an archived headline is evidence of what was published, and re-reading it later would either change nothing or quietly substitute a correction for the wording a stored decision was actually made on.

class trader.news.archive.NewsArchive(repository, provider)[source]

Bases: object

Ensures a time span is present locally, fetching only what is missing.

Parameters:
ensure(symbol, start, end)[source]

Return archived news for [start, end), fetching any uncovered span.

Raises:

MarketDataError – a fetch failed. Deliberately propagated: coverage is recorded only after a fetch returns, so a failure leaves the span missing and the next run retries it. Degrading quietly here would write a permanent hole that reads as “this symbol had no news”, which is the one thing coverage exists to make impossible.

Parameters:
  • symbol (str)

  • start (datetime)

  • end (datetime)

Return type:

list[NewsItem]

load(symbol, start, end)[source]

Read the archive without fetching anything.

What a replay uses. A replay that could reach the network would score the model against news fetched today rather than against the pinned archive, and would silently succeed while doing it.

Parameters:
  • symbol (str)

  • start (datetime)

  • end (datetime)

Return type:

list[NewsItem]

class trader.news.archive.NewsArchiveProvider(*args, **kwargs)[source]

Bases: Protocol

A news source that can answer for a past window.

Separate from NewsProvider because almost nothing can do this: yfinance offers roughly the last ten items per ticker and no history at all, which is the fact that made an archive table worth building in the first place.

get_news_between(symbol, start, end)[source]

Every archived item published in [start, end).

Parameters:
  • symbol (str)

  • start (datetime)

  • end (datetime)

Return type:

list[ArchivedNewsItem]