Market Data API
Order book, ticker, and market information endpoints.
Get Order Book
Retrieve the full order book snapshot with statistics.
Endpoint: get_order_book(market_id: text) -> Result<OrderBookData> (query)
Response
type OrderBookData = record {
symbol: text;
bids: vec PriceLevel;
asks: vec PriceLevel;
best_bid: opt nat64;
best_ask: opt nat64;
spread: opt nat64;
spread_percentage: opt float64;
last_trade_price: opt nat64;
volume_24h: nat64;
high_24h: opt nat64;
low_24h: opt nat64;
timestamp: nat64;
};
type PriceLevel = record {
price: nat64;
quantity: nat64;
count: nat64;
};Example
const result = await backend.get_order_book('BTC/USDT')
if ('Ok' in result) {
const book = result.Ok
console.log(`Spread: ${book.spread_percentage}%`)
console.log('BIDS:')
book.bids.slice(0, 5).forEach((level) => {
console.log(` ${level.price}: ${level.quantity}`)
})
console.log('ASKS:')
book.asks.slice(0, 5).forEach((level) => {
console.log(` ${level.price}: ${level.quantity}`)
})
}Get Depth (Simplified)
Retrieve orderbook depth as price/quantity tuples.
Endpoint: depth(market_id: text, size: nat32) -> Depth (query)
const depth = await backend.depth('BTC/USDT', 20)
console.log('Top 5 Bids:', depth.bids.slice(0, 5))
console.log('Top 5 Asks:', depth.asks.slice(0, 5))Get Market Data
Retrieve comprehensive market statistics.
Endpoint: get_market_data(market_id: text) -> Result<MarketData> (query)
Response
type MarketData = record {
symbol: text;
best_bid: opt nat64;
best_ask: opt nat64;
spread: opt nat64;
spread_percentage: opt float64;
mid_price: opt float64;
last_trade_price: opt nat64;
volume_24h: nat64;
trades_24h: nat64;
high_24h: opt nat64;
low_24h: opt nat64;
change_24h: opt float64;
change_24h_percentage: opt float64;
timestamp: nat64;
};Get Ticker
Get 24-hour market ticker.
Endpoint: ticker(market_id: text) -> opt MarketTicker (query)
const ticker = await backend.ticker('BTC/USDT')
if (ticker[0]) {
console.log(`Price: ${ticker[0].price}`)
console.log(`24h Change: ${ticker[0].price_change_percent}%`)
console.log(`24h Volume: ${ticker[0].volume}`)
}Get All Tickers
Get tickers for all markets.
Endpoint: tickers() -> vec MarketTicker (query)
Get K-Lines (Candlesticks)
Retrieve OHLCV candlestick data for charting.
Endpoint: k_lines(market_id: text, interval: nat64, start_time: opt nat64, end_time: opt nat64) -> Result<vec KLine> (query)
Supported Intervals
| Interval | Value (ms) |
|---|---|
| 1 minute | 60_000 |
| 5 minutes | 300_000 |
| 15 minutes | 900_000 |
| 1 hour | 3_600_000 |
| 4 hours | 14_400_000 |
| 1 day | 86_400_000 |
Example
const HOUR_MS = 60 * 60 * 1000n
const now = BigInt(Date.now())
const dayAgo = now - 24n * HOUR_MS
const result = await backend.k_lines('BTC/USDT', HOUR_MS, [dayAgo], [now])
if ('Ok' in result) {
result.Ok.forEach((candle) => {
console.log(`O=${candle.open} H=${candle.high} L=${candle.low} C=${candle.close}`)
})
}Get Market Metrics
Retrieve detailed market performance metrics.
Endpoint: market_metrics(market_id: text) -> Result<MarketMetrics> (query)
Includes:
- Volume & activity metrics
- Price data
- Performance metrics (fill rate, liquidity score)
- Risk metrics
Get Spread
Get the current bid-ask spread.
Endpoint: spread(market_id: text) -> opt nat64 (query)
Get Markets
List all available markets.
Endpoint: markets() -> vec Market (query)
type Market = record {
symbol: text;
base_symbol: text;
quote_symbol: text;
market_type: MarketType;
status: MarketStatus;
min_order_size: nat64;
max_position_size: nat64;
};
type MarketType = variant { Spot; Perp };
type MarketStatus = variant { Open; Closed };Get Assets
List all supported assets with token information.
Endpoint: assets() -> vec MarketAsset (query)
type MarketAsset = record {
symbol: text;
display_name: text;
coingecko_id: text;
tokens: vec Token;
};
type Token = record {
blockchain: Blockchain;
contract_address: text;
decimals: nat8;
deposit_enabled: bool;
withdraw_enabled: bool;
minimum_deposit: nat64;
minimum_withdrawal: nat64;
withdrawal_fee: nat64;
};