Expand description
Alpaca market data stream (behind alpaca feature).
Alpaca market data connectors for US equities and crypto.
Connects to Alpaca’s market data WebSocket streams:
- IEX:
wss://stream.data.alpaca.markets/v2/iex(free, US equities) - SIP:
wss://stream.data.alpaca.markets/v2/sip(paid, consolidated tape) - Crypto:
wss://stream.data.alpaca.markets/v1beta3/crypto/us
§Testing Status
Tested locally, CI planned (free tier — paper trading allowed):
- Crypto streaming: trades and quotes (24/7)
- IEX equity streaming: trades and quotes (market hours only)
NOT tested (requires Algo Trader Plus subscription):
- SIP equity streaming — implemented but unverified against real endpoints
§Authentication
Alpaca requires authentication via AlpacaCredentials. Credentials can be:
- Loaded from environment variables via
AlpacaCredentials::from_env() - Provided explicitly via
AlpacaCredentials::new()
Auth message is sent immediately after WebSocket connection, before subscriptions.
§One connection per feed
Alpaca allows an account one market data connection per feed and refuses a second with
connection limit exceeded. Every stream an
AlpacaSubscriber and its clones open on a feed
shares one socket to it, so trades and quotes — any number of symbols, over any number of
subscribe calls — can stream together. Pass clones of one subscriber to every stream on the
account; see AlpacaSubscriber and
connection for the details.
§Example
use rustrade_data::exchange::alpaca::{AlpacaCredentials, AlpacaSubscriber, AlpacaIex};
use rustrade_data::streams::Streams;
use rustrade_data::subscription::trade::PublicTrades;
// Load credentials at construction time (fails fast if env vars missing)
let subscriber = AlpacaSubscriber::from_env()?;
let streams = Streams::<PublicTrades>::builder()
.subscribe(subscriber, [(AlpacaIex::default(), "AAPL", "USD", PublicTrades)])
.init()
.await?;§Connectors
AlpacaIex: Free IEX feed for US equitiesAlpacaSip: Paid consolidated SIP feed (untested — requires subscription)AlpacaCrypto: Crypto market data
§Supported Streams
PublicTrades: Real-time tradesQuotes: Real-time quotes — IEX’s own top of book on the IEX feed, the NBBO on SIP, Alpaca’s crypto venue on cryptoOrderBooksL1: the same quotes as a top of book, read from the samequoteschannel. This is the kindDynamicStreamsserves, since the engine’s market data carries a top of book rather than a quote. A side Alpaca publishes at a zero price has no quote and isNone.
§Subscription confirmation
Alpaca answers a subscribe with one frame naming every symbol the connection holds.
Initialisation does not return until every requested symbol has been named; if any is
still outstanding when the subscription timeout expires, the subscribe fails and names what was
missing. A partial subscription is therefore an error rather than a quietly reduced stream. The
AlpacaSubscriber confirms each subscribe on the
connection it shares.
A confirmed symbol is not a promise of prompt data. Alpaca’s crypto feed publishes a quote when top-of-book changes, so the delay before a given symbol first ticks is large and highly variable – 1s, 15s, 96s and 132s for four symbols confirmed on one connection in a single 300s window. Callers must not infer a failed subscription from silence, and must not use the first event as a readiness signal for any particular instrument.
Re-exports§
pub use reference::AlpacaStockSplit;pub use reference::CorporateActionsQuery;pub use rest::AlpacaRestClient;pub use rest::AlpacaRestError;
Modules§
- channel
- connection
- One WebSocket per feed, shared by every stream an
AlpacaSubscriberand its clones open on it. - market
- options
- Alpaca options market data client.
- quote
- reference
- Alpaca corporate-actions reference data (
GET /v1beta1/corporate-actions). - rest
- Shared Alpaca REST transport.
- stream
- The Alpaca market stream.
- subscription
- trade
Structs§
- Alpaca
- Generic Alpaca market data connector.
- Alpaca
Credentials - Credentials for authenticating to Alpaca market data WebSocket.
- Alpaca
Server Crypto - Crypto server.
- Alpaca
Server Iex - IEX server (free US equities feed).
- Alpaca
Server Sip - SIP server (paid consolidated US equities feed).
- Alpaca
Subscriber - Alpaca market data subscriber: authenticates, and shares one connection per feed among every stream it and its clones open.
Constants§
- WEBSOCKET_
URL_ CRYPTO - Crypto WebSocket URL.
- WEBSOCKET_
URL_ IEX - IEX WebSocket URL (free US equities feed).
- WEBSOCKET_
URL_ SIP - SIP WebSocket URL (paid consolidated US equities feed).
Type Aliases§
- Alpaca
Crypto - Alpaca crypto connector.
- Alpaca
Iex - Alpaca IEX equities connector (free feed).
- Alpaca
Sip - Alpaca SIP equities connector (paid feed, untested).