Skip to content

AlpacaTrades

Turns Alpaca crypto trade frames into the public trade tape, published as world-scoped market data on the trade topics of the openspec pubsub-topics spec ("Public trade tape"). The same canonical contract as BinanceTrades, so a consumer does not care which venue produced the tape.

Property Value
Project Virtufin.Worker.AlpacaTrades
Worker type alpacatradetape
Base class Virtufin.MarketData.DevKit.MarketDataWorkerBase
Engine application/x-dotnet-dll
Input topic act.exchange.alpaca.trade.update (raw frames from WebSocketManager)
Output topic <world>.exchange.alpaca.trade.executed.<PAIR>
ce-type com.virtufin.exchange.alpaca.trade.executed
Payload { trade_id, price, qty, side, trade_time }

Behaviour

  • Trades only. Only messages with T == "t" are published; Alpaca's success/subscription status messages, errors and other channels are skipped without an error event.
  • Arrays, several pairs per frame. Alpaca batches messages as a JSON array; one frame can carry trades for several symbols. Each is published on its own pair's topic.
  • Once per trade. The last trade id per pair is remembered, so a redelivered or replayed frame is dropped. Alpaca's i is per symbol, so per-pair dedupe is correct.
  • Side. tks names the aggressor: B → buy, S → sell.
  • Envelope. exchange=alpaca, marketworld, marketuniverse, clocktype, eventtime = ce-time = the trade time (t, nanoseconds); no scenario extensions.

Config (CreateWorker config, as extension attributes)

Key Default Meaning
currencypairs required Comma-separated canonical pairs, e.g. BTC_USD,ETH_USD (maps Alpaca's BTC/USD back to BTC_USD)
world act act or hyp.<name> (topic prefix and marketworld)
venue alpaca Topic segment and exchange
marketuniverse ALL marketuniverse extension
clocktype wall for act, else historical clocktype extension

Deploy

  1. Trade feed (WebSocketManager, no worker): one connection to Alpaca's crypto stream with a handshake that logs in and subscribes to {"action":"subscribe","trades":["BTC/USD",…]} -- AlpacaHandshake with channels: trades (or an in-notebook handler). The frames go to act.exchange.alpaca.trade.update; no routing is needed, because the worker reads each message's S.
  2. Worker: scripts/create_worker.py with this config (one instance covers every pair; extra instances need disjoint currencypairs lists).

Trades are the highest-rate market data in the system; anything folding them should set publishintervalms/saveintervalms (see the indicator workers).