Live records (Databento-style)¶
brisk live also serves its feed to other programs on this computer, as the records the
cloud API returns. briskapi.Live is shaped like Databento's live client and needs no key or
sign-in: only the feed signs in to your broker.
brisk live --site sbi # records, uploads and serves XTKS.BRISK until you stop it (--site demo: the demo, XTKS.BRISKDEMO)
import briskapi
live = briskapi.Live() # finds the feed running on this computer
live.subscribe(dataset="XTKS.BRISK", schema="imbalance", symbols=["7203", "6758"])
live.subscribe(dataset="XTKS.BRISK", schema="trades", symbols=["7203"], start=0) # the day so far, then live
live.subscribe(dataset="XTKS.BRISK", schema="ohlcv-1m", symbols=["7203"]) # each minute's bar as it ends
for record in live: # or live.add_callback(fn); live.start(); live.block_for_close()
print(record.schema, record.symbol, record.ts_event)
- Schemas:
trades,mbp-10,imbalance,definition,brisk-quotesand the OHLCV barsohlcv-1stoohlcv-1d, with the same columns and values asHistoricalreturns for the same session.Livebuilds its bars from the trades it receives, by the cloud's rules. - Bars come as soon as their interval ends, by the feed's clock: when a later batch is
stamped past the end, or when this computer's clock, less the delay measured from BRiSK to this
session (the largest of the last 10 seconds), passes it. A trade that arrives after its own
bar has ended goes into the next bar still open (the cloud places it by its own time), so
every trade counts and bars come in order. A bar is given only if the
session saw its whole span within the trading sessions: with
start, from the feed's start; without, the bars that begin after it subscribed. - Where a session starts: with the day's definitions, then each update as it arrives.
start(a time, a date, UTC nanoseconds, or 0 for everything the feed has) first replays the feed's trading day from then: the feed has the day from when it started, plus the day's trades its snapshot restored.snapshot=Truebeginsmbp-10,imbalanceorbrisk-quoteswith each security's current quote (flags32). - Records are dicts, also readable as attributes (
record.price), withrecord.schema. They come in the order the feed receives its batches; within a batch, inHistorical's order.add_callback(fn, exception_callback)andadd_stream(path)(JSON lines; Databento writes DBN) take them too.block_for_close(timeout)waits for the session's end, andstop()ends it. Subscribe before or afterstart(): a later subscription gets its own replay or snapshot, and its symbols from then on. A session's subscriptions share one dataset.symbology_mapmapsinstrument_idto the code. - The fast lane: a broker feed records the whole market, which at the opening auction can
fall seconds behind the stream on a slower computer. A session that subscribes to its own
symbols, without
start, gets them on the fast lane: read as each frame arrives, ahead of the recording, with the same records. The lane takes about 500 symbols per worker it has (a quarter of the feed's).ALL_SYMBOLS, astartreplay, or symbols beyond what it takes come at the recording's pace instead; a session whose later subscription no longer fits moves there without missing or repeating a record. - Only this computer: the feed listens on 127.0.0.1 and admits a session only with the key
it keeps, with its port, in an owner-only file (
~/.config/brisk/gateway/XTKS.BRISK.json), whichLive()reads. Nothing it serves leaves your computer. A session that falls more than 1 GB behind is dropped rather than slowing the feed or its recording. - Serving:
brisk liveserves unless you pass--no-gateway; one feed per dataset at a time. In Python, passgateway=Truetobriskapi.connect().