Skip to main content

MarketDataClient

The MarketDataClient provides access to real-time market data including prices, order books, and trading pairs.

Prices

Get All Prices

const prices = await client.marketData.getPrices();

for (const price of prices) {
console.log(`${price.asset}: ${price.mid}`);
}

Get Specific Assets

const prices = await client.marketData.getPrices(['BTC', 'ETH', 'SOL']);

Get Single Asset Price

const btc = await client.marketData.getPrice('BTC');

console.log(btc);
// {
// asset: 'BTC',
// bid: '49950.00',
// ask: '50050.00',
// mid: '50000.00',
// last: '50010.00',
// volume24h: '1234.56',
// change24h: '2.5',
// high24h: '51000.00',
// low24h: '49000.00',
// timestamp: '2024-01-15T10:30:00Z'
// }

Order Books

Get Order Book

const orderBook = await client.marketData.getOrderBook('BTC', 10);

console.log('Bids:');
for (const level of orderBook.bids) {
console.log(` ${level.price}: ${level.quantity} (${level.orderCount} orders)`);
}

console.log('Asks:');
for (const level of orderBook.asks) {
console.log(` ${level.price}: ${level.quantity} (${level.orderCount} orders)`);
}

Get Multiple Order Books

const orderBooks = await client.marketData.getOrderBooks(['BTC', 'ETH'], 5);

console.log('BTC spread:', orderBooks.BTC.asks[0].price - orderBooks.BTC.bids[0].price);
console.log('ETH spread:', orderBooks.ETH.asks[0].price - orderBooks.ETH.bids[0].price);

Trading Pairs

const pairs = await client.marketData.getTradingPairs();

for (const pair of pairs) {
console.log(`${pair.asset}/${pair.quoteCurrency}`);
console.log(` Min: ${pair.minOrderSize}, Max: ${pair.maxOrderSize}`);
console.log(` Decimals: price=${pair.priceDecimals}, qty=${pair.quantityDecimals}`);
console.log(` Status: ${pair.status}`);
}

24h Statistics

// Get stats for all assets
const allStats = await client.marketData.get24hStats();

// Get stats for specific asset
const btcStats = await client.marketData.get24hStats('BTC');

console.log(btcStats[0]);
// {
// asset: 'BTC',
// volume24h: '15234567.89',
// trades24h: 12345,
// high24h: '51000.00',
// low24h: '49000.00',
// open24h: '49500.00',
// close24h: '50000.00',
// change24h: '1.01',
// timestamp: '2024-01-15T10:30:00Z'
// }

Types

import type {
Price,
OrderBook,
OrderBookLevel,
TradingPair,
Stats24h,
} from 'zenotc';

Price

FieldTypeDescription
assetstringAsset symbol
bidstringBest bid price
askstringBest ask price
midstringMid price
laststringLast trade price
volume24hstring24h volume
change24hstring24h change %
high24hstring24h high
low24hstring24h low
timestampstringISO timestamp

OrderBook

FieldTypeDescription
assetstringAsset symbol
bidsOrderBookLevel[]Bid levels (descending)
asksOrderBookLevel[]Ask levels (ascending)
timestampstringISO timestamp
sequencenumberSequence number

OrderBookLevel

FieldTypeDescription
pricestringPrice level
quantitystringTotal quantity
orderCountnumberNumber of orders