L1 book snapshots include the best bid and ask, price and size, for a given market.
async for snap in client.subscribe_l1_book_stream(
symbols=["BTC Crypto/USD"],
venue="COINBASE"
):
print(snap)
import { L1BookSnapshot } from '@afintech/sdk';
const stream = await L1BookSnapshot.streamL1BookSnapshots(
{
market_ids: ['BTC-USDT BINANCE Perpetual/USDT Crypto*BINANCE-FUTURES-USD-M/DIRECT'],
},
'binance-futures-usd-m',
);
stream.on('data', console.log);
// to close the stream, call
// stream.cancel();
// stream.destroy();
Not available in GraphQL
L2 book snapshots
L2 book snapshots include the aggregated bids and asks at different price levels. Price levels may optionally be aggregated into price bands of a specified width.
Use watch_l2_book in one async task to stream book updates and continuously maintain a sorted level book; this method yields on every update. From other tasks, you may lookup the current state of the book in memory at any point in time.
from architect_py.grpc_client.Marketdata.L2BookSnapshot import L2BookSnapshot
from architect_py.scalars import TradableProduct
# subscribe to the book and update it in a background asyncio task
book: L2BookSnapshot = await client.subscribe_l2_book(
symbol="BTC Crypto/USD",
venue="COINBASE"
)
# access the up-to-date book anytime
book.bids
# get a new reference to the same up-to-date book
same_book = client.grpc_client.l2_books[TradableProduct("BTC Crypto/USD")]
stream = client.subscribe_l2_book_stream("BTC Crypto/USD", venue="COINBASE")
async for book in stream:
print(book)
stream = client.subscribe_trades_stream(
symbol="BTC Crypto/USD",
venue="COINBASE"
)
async for trade in stream:
print(trade)
Coming soon
subscription SubscribeTrades($market: MarketId!) {
trades(market: $market) {
time
price
size
direction
}
}
Candles (Klines) streaming
Candles are produced at different fixed periods and include the open, high, low, close, and volumes for that period. Candle widths include:
1s
5s
1m
15m
1h
1d
Not all exchange feeds produce all candle widths.
from architect_py.grpc_client.definitions import CandleWidth
stream = client.subscribe_candles_stream(
symbol="BTC Crypto/USD",
venue="COINBASE",
candle_widths=[CandleWidth.OneSecond]
)
async for candle in stream:
print(candle)
Coming soon
subscription SubscribeCandles($id: MarketId!, $width: CandleWidth!) {
candles(market: $id, candleWidth: $width) {
...CandleFields
}
}
fragment CandleFields on CandleV1 {
time
open
high
low
close
volume
}