Market data

Unified historical and realtime market data

Candlestick

Fetch OHLCV (aggregated trades) for selected period of time
grouped by minute/hour/day/month

Available period groups

Seconds: 1SEC, 2SEC, ..., 59SEC
Minutes: 1MIN, 2MIN, ..., 59MIN
Hours: 1HRS, 2HRS, ..., 23HRS
Days: 1DAY, 2DAY, ..., 14DAY
Month: 1MTH

Rest API

/**
 * @param exchanger: string
 * @param market: string
 * @param groupBy: string
 * @param periodFrom: string
 * @param periodTo: string
 */
const candles = await egRest.fetchOhlcv(
    'binance',
    'btc-usdt',
    '1MTH',
    '2021-01-01T00:00:00Z',
    '2021-03-01T00:00:00Z'
);

/* Expected `candles`:
{
    exchanger: string,
    market: string,
    ohlcv: [
        {
            periodFrom: string,
            periodTo: string,
            timeOpen: string,
            timeClose: string,
            open: string,
            high: string,
            low: string,
            close: string,
            volume: string,
            trades: number
        },
        ...
    ]
}*/

Socket RPC

/**
 * @param exchanger: string
 * @param market: string
 * @param groupBy: string
 * @param periodFrom: string
 * @param periodTo: string
 */
const candles = await egRealtime.rpc.fetchOhlcv(
        'binance',
        'btc-usdt',
        '1MTH',
        '2021-01-01T00:00:00Z',
        '2021-03-01T00:00:00Z'
);

/* Expected `candles`:
{
    exchanger: string,
    market: string,
    ohlcv: [
        {
            periodFrom: string,
            periodTo: string,
            timeOpen: string,
            timeClose: string,
            open: string,
            high: string,
            low: string,
            close: string,
            volume: string,
            trades: number
        },
        ...
    ]
}*/

Price ticker

Fetch price ticker (based from last trade price) for selected exchanger markets

Rest API

/**
 * @param exchanger: string
 * @param markets: string[]
 */
const priceTicker = await egRest.fetchPriceTicker(
    'binance',
    [
        'btc-usdt',
        'btc-eth'
    ]
);

/* Expected `priceTicker`:
{
    exchanger: string,
    ticker: {
        'btc-usdt': {
            market: string,
            price: string,
            time: number,
            side: number
        },
        'btc-eth': { ... }
    }
}*/

Socket RPC

/**
 * @param exchanger: string
 * @param markets: string[]
 */
const priceTicker = await egRealtime.rpc.fetchPriceTicker(
    'binance',
    [
        'btc-usdt',
        'btc-eth'
    ]
);

/* Expected `priceTicker`:
{
    exchanger: string,
    ticker: {
        'btc-usdt': {
            market: string,
            price: string,
            time: number,
            side: number
        },
        'btc-eth': { ... }
    }
}*/

Stream

Subscribe market price ticker stream. Price ticker (based from last trade price) for selected exchanger markets, published once per second

/**
 * @param exchanger: string
 * @param markets: string[]
 */
const streamSubscription = egRealtime.stream.priceTicker(
    'binance',
    [
        'btc-usdt',
        'btc-eth'
    ]
);

(async () => {
    for await (const event of streamSubscription.consumer()) {
        console.log('on-event', event.name, event.data);
        /* Expected `event.data`:
        {
            exchanger: string,
            ticker: {
                'btc-usdt': {
                    market: string,
                    price: string,
                    time: number,
                    side: number
                },
                'btc-eth': { ... }
            }
        }*/
    }
})();

Order book ticker

Fetch order book ticker (based from best bid/ask) for selected exchanger markets

Rest API

/**
 * @param exchanger: string
 * @param markets: string[]
 */
const bookTicker = await egRest.fetchOrderBookTicker(
    'binance',
    [
        'btc-usdt',
        'btc-eth'
    ]
);

/* Expected `bookTicker`:
{
    exchanger: string,
    ticker: {
        'btc-usdt': {
            market: string,
            book: {
                bid: [bidPrice: string, bidAmount: string],
                ask: [askPrice: string, askAmount: string]
            },
            time: number
        },
        'btc-eth': { ... }
    }
}*/

Socket RPC

/**
 * @param exchanger: string
 * @param markets: string[]
 */
const bookTicker = await egRealtime.rpc.fetchOrderBookTicker(
    'binance',
    [
        'btc-usdt',
        'btc-eth'
    ]
);

/* Expected `bookTicker`:
{
    exchanger: string,
    ticker: {
        'btc-usdt': {
            market: string,
            book: {
                bid: [bidPrice: string, bidAmount: string],
                ask: [askPrice: string, askAmount: string]
            },
            time: number
        },
        'btc-eth': { ... }
    }
}*/

Stream

Subscribe market order book ticker stream. Order book ticker (based from best bid/ask) for selected exchanger markets, published once per second

/**
 * @param exchanger: string
 * @param markets: string[]
 */
const streamSubscription = egRealtime.stream.orderBook(
    'binance',
    [
        'btc-usdt',
        'btc-eth'
    ]
);

(async () => {
    for await (const event of streamSubscription.consumer()) {
        console.log('on-event', event.name, event.data);
        /* Expected `event.data`:
        {
            exchanger: string,
            ticker: {
                'btc-usdt': {
                    market: string,
                    book: {
                        bid: [bidPrice: string, bidAmount: string],
                        ask: [askPrice: string, askAmount: string]
                    },
                    time: number
                },
                'btc-eth': { ... }
            }
        }*/
    }
})();

Public trades snapshot

Fetch latest x100 public trades

Rest API

/**
 * @param exchanger: string
 * @param market: string
 */
const publicTrades = await egRest.fetchPublicTradesSnapshot(
    'binance',
    'btc-usdt'
);

/* Expected `publicTrades`:
{
    exchanger: string,
    market: string,
    trades: [
        {
            id: number,
            time: number,
            timeConsumed: number,
            timeReceived: number,
            price: string,
            amount: string,
            side: number
        },
        ...
    ];
}*/

Socket RPC

/**
 * @param exchanger: string
 * @param market: string
 */
const publicTrades = await egRealtime.rpc.fetchPublicTradesSnapshot(
    'binance',
    'btc-usdt'
);

/* Expected `publicTrades`:
{
    exchanger: string,
    market: string,
    trades: [
        {
            id: number,
            time: number,
            timeConsumed: number,
            timeReceived: number,
            price: string,
            amount: string,
            side: number
        },
        ...
    ];
}*/

Stream

Fetch snapshot and continuously stream public trades in realtime.

/**
 * @param exchanger: string
 * @param market: string
 */
const streamSubscription = egRealtime.stream.publicTrades(
    'binance',
    'btc-usdt'
);

(async () => {
    for await (const event of streamSubscription.consumer()) {
        console.log('on-event', event.name, event.data);
        /* Expected `event.data`:
        {
            id: number,
            time: number,
            timeConsumed: number,
            timeReceived: number,
            price: string,
            amount: string,
            side: number
        }*/
    }
})();

Public trades (historical)

Fetch historical public trades

Rest API

/**
 * @param exchanger: string
 * @param market: string
 * @param periodFrom: string,
 * @param periodTo: string
 */
const historicalTrades = await egRest.fetchHistoricalTrades(
    'binance',
    'btc-usdt',
    '2021-01-01T00:00:00Z',
    '2021-03-01T00:00:00Z'
);

/* Expected `historicalTrades`:
{
    exchanger: string,
    market: string,
    trades: [
        {
            id: number,
            time: number,
            price: string,
            amount: string,
            side: number
        },
        ...
    ];
}*/

Socket RPC

/**
 * @param exchanger: string
 * @param market: string
 * @param periodFrom: string,
 * @param periodTo: string
 */
const historicalTrades = await egRealtime.rpc.fetchHistoricalTrades(
      'binance',
      'btc-usdt',
      '2021-01-01T00:00:00Z',
      '2021-03-01T00:00:00Z'
);

/* Expected `historicalTrades`:
{
    exchanger: string,
    market: string,
    trades: [
        {
            id: number,
            time: number,
            price: string,
            amount: string,
            side: number
        },
        ...
    ];
}*/

Order book snapshot

Fetch OrderBook snapshot x100 best Bids/Asks

Rest API

/**
 * @param exchanger: string
 * @param market: string
 */
const orderBook = await egRest.fetchOrderBookSnapshot(
    'binance',
    'btc-usdt'
);

/* Expected `orderBook`:
{
    exchanger: string,
    market: string,
    sequenceProcessed: number,
    book: {
        bids: [[bidPrice: string, bidAmount: string], ...],    
        asks: [[askPrice: string, askAmount: string], ...]
    }
}*/

Socket RPC

/**
 * @param exchanger: string
 * @param market: string
 */
const orderBook = await egRealtime.rpc.fetchOrderBookSnapshot(
    'binance',
    'btc-usdt'
);

/* Expected `orderBook`:
{
    exchanger: string,
    market: string,
    sequenceProcessed: number,
    book: {
        bids: [[bidPrice: string, bidAmount: string], ...],    
        asks: [[askPrice: string, askAmount: string], ...]
    }
}*/

Stream

Subscribe order book stream.
Always verified and synchronized with server snapshot, even after dropped connection silently sync's back to guarantee bid/ask precision;
emitTimeoutMs - default 500, set to 0 for realtime.

/**
 * @param exchanger: string
 * @param market: string
 * @param emitTimeoutMs: number = 500
 */
const streamSubscription = egRealtime.stream.orderBook(
    'binance',
    'btc-usdt'
);

(async () => {
    for await (const event of streamSubscription.consumer()) {
        console.log('on-event', event.name, event.data);
        /* Expected `event.data`:
        {
            sequenceProcessed: number,
            book: {
                bids: [[bidPrice: string, bidAmount: string], ...],    
                asks: [[askPrice: string, askAmount: string], ...]
            }
        }*/
    }
})();