AlpacaOrderBook
Maintains live Alpaca crypto order books from the orderbook messages of
Alpaca's market-data stream, saves each pair's book to State and announces
each save on the pair's changed topic (openspec pubsub-topics, "Order
book"). Built on Virtufin.MarketData.DevKit.
| Property | Value |
|---|---|
| Project | Virtufin.Worker.AlpacaOrderBook |
| Base class | Virtufin.MarketData.DevKit.MarketDataWorkerBase |
| Engine | application/x-dotnet-dll |
| Input topic | act.exchange.alpaca.orderbook.update (raw frames from WebSocketManager) |
| Output topic | <world>.exchange.alpaca.orderbook.changed.<PAIR> |
| State key | <world>.exchange.alpaca.orderbook.<PAIR> |
| ce-type | com.virtufin.exchange.alpaca.orderbook.changed |
Behaviour
- Full book, then changes. After a subscribe Alpaca sends each pair's full
book (
"r": true), then level changes, where size 0 removes a level. A full book replaces the pair's book; changes before the first full book are skipped. - No snapshots, no gaps. Alpaca's stream has no update ids and nothing to resync against. After a reconnect or actor handoff the WebSocketManager's connection handshake logs in and subscribes again, and Alpaca resends the full book.
- Saved book.
{ bids, asks, last_update_id, updated_at }, best level first, each level[price, size]as decimal strings: the same shape as BinanceOrderBook's, so readers serve both venues.last_update_idcounts the messages applied. - Throttled. A pair's book is saved (and
changedpublished) at most once persaveintervalms; a full book always saves. One frame can carry several pairs: onechangedevent per saved pair. - Envelope.
exchange=alpaca,marketworld,marketuniverse,clocktype, andeventtime=ce-time= Alpaca's time (t) of the last applied message. - Ignored. Status messages (
success,subscription), errors, other stream types and untracked pairs.
Config (CreateWorker config, as extension attributes)
| Key | Default | Meaning |
|---|---|---|
currencypairs |
required | Comma-separated canonical pairs, e.g. BTC_USD,ETH_USD (Alpaca's BTC/USD) |
pricedecimals |
8 |
Decimals kept for prices (Alpaca's stream has no tick size) |
sizedecimals |
9 |
Decimals kept for sizes |
saveintervalms |
250 |
Minimum time between two saves of one pair's book; 0 saves every message |
stateservice |
workmanager |
State namespace of the books |
world |
act |
act or hyp.<name> |
venue |
alpaca |
Topic segment and exchange |
marketuniverse |
ALL |
marketuniverse extension |
clocktype |
wall for act, else historical |
clocktype extension |
Deploy
- Feed (WebSocketManager 0.7.0+): connect to
wss://stream.data.alpaca.markets/v1beta3/crypto/uswithauto_reconnect,publish_topic=act.exchange.alpaca.orderbook.updateand ahandshakewhose handler logs in and subscribes to the pairs'orderbooks. Alpaca allows one stream connection per account. - Worker:
AlpacaOrderBook/scripts/create_worker.py(one instance for all pairs), then start it. - Consume: subscribe to
act.exchange.alpaca.orderbook.changed.BTC_USDand read the book from State.
The alpaca-order-book-live.verso notebook in the examples repo runs all three,
including the handshake handler.