trader.daemon.schedule module

Turning the market clock into an action.

Pure: a MarketClock and a now in, a decision out. The loop does the sleeping, so every case here is an equality assertion in a test rather than a stopwatch.

class trader.daemon.schedule.MarketSchedule(config)[source]

Bases: object

Decides only the market-state wait.

Deliberately not the other two waits in this system: the gap between cycles of an open market belongs to the loop, and the delay after a failure belongs to Backoff. Three sleeps with three owners means no test has to work out which one produced a duration.

Parameters:

config (DaemonConfig)

next_action(clock, now)[source]

Run now if the market is open, otherwise wait for the open.

Branches on is_open rather than comparing now against the timestamps: while the market is open, next_open is tomorrow’s session, so inferring the state from the timestamps would read an open market as one that opens in 20 hours.

Parameters:
Return type:

RunNow | SleepFor

class trader.daemon.schedule.RunNow[source]

Bases: object

Run a cycle immediately.

class trader.daemon.schedule.SleepFor(seconds, reason)[source]

Bases: object

Wait, and say why in terms an operator can check against a clock.

Parameters:
  • seconds (float)

  • reason (str)

seconds: float
reason: str