Skip to content
This repository was archived by the owner on Apr 12, 2022. It is now read-only.

Public API

Connor Giles edited this page Jul 15, 2017 · 7 revisions

Public API is used to access public market data. All functions can be accessed either via callback or Promises.

REST support is implemented for all exchanges listed with a ✅ next to them.

const xchange = require('xchange-js');
const client = new xchange.Bitstamp.PublicClient();

Pairs

Get an array of supported pairs. Response is an array of the pairs as strings.

client.pairs().then(pairs => {
   console.log(pairs);
});
/* Results in
[ 'BTCUSD',
  'BTCEUR',
  'EURUSD',
  'XRPUSD',
  'XRPEUR',
  'XRPBTC',
  'LTCUSD',
  'LTCEUR',
  'LTCBTC' ]
 */

Ticker

Get the current ticker of the pair. Response is an object of the ticker.

client.ticker('BTCUSD').then(ticker => {
   console.log(ticker);
});
/* Results in
{ last: 2520.42,
  high: 2594.78,
  low: 2500.31,
  bid: 2518.01,
  ask: 2520.27,
  volume: 8991.8225535,
  time: 2017-06-30T08:21:13.000Z }
 */

Trades

Get a list of recent trades for a pair. Response is an array of objects representing the trades.

client.trades('BTCUSD').then(trades => {
   console.log(trades);
});
/* Results in
[ ...
  { tid: 16852237,
    type: 'ask',
    amount: 0.20240753,
    pair: 'BTCUSD',
    price: 2516.45,
    timestamp: 2017-06-30T20:04:27.000Z }
    ...
]
 */

Orderbook

Get the current state of the orderbook for a pair. Response is an Market object with the orderbook.

client.orderbook('BTCUSD').then(market => {
   console.log(market.book.top());
});
/* Results in
{ bid: { price: 0.11151965, amount: 70.39599912 },
  ask: { price: 0.11160863, amount: 14.46006716 } }
*/

Callback

Here is an example of the API using a callback instead of promises.

client.orderbook('BTCUSD', (err, market) => {
   console.log(market.book.state());
});

Clone this wiki locally