npm

npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

bittrex-api-node

0.0.6 • Public • Published

NPM

travis GitHub last commit npm license

bittrex-api-node

Overview

Bittrex.com Exchange API for Node.js.

Installation

npm

npm install bittrex-api-node --save

yarn

yarn add bittrex-api-node

Usage

Getting started

import Api from 'bittrex-api-node';
 
const api = Api({
  publicKey: '<api-key>',
  secretKey: '<api-secret>',
  verbose: true,
  ...
});

Public constants

Endpoint

Name Value
ENDPOINT_V1 https://bittrex.com/api/v1.1
ENDPOINT_V2 https://bittrex.com/api/v2.0
ENDPOINT_WS wss://socket.bittrex.com/signalr
ENDPOINT_WS_BETA wss://beta.bittrex.com/signalr

Tick Interval

Name Value
TICKINTERVAL_ONEMIN oneMin
TICKINTERVAL_FIVEMIN fiveMin
TICKINTERVAL_THIRTYMIN thirtyMin
TICKINTERVAL_HOUR hour
TICKINTERVAL_DAY day

Order Type

Name Value
ORDERTYPE_LIMIT LIMIT
ORDERTYPE_MARKET MARKET

Time in Effect

Name Value
TIMEINEFFECT_GOOD_TIL_CANCELLED GOOD_TIL_CANCELLED
TIMEINEFFECT_IMMEDIATE_OR_CANCEL IMMEDIATE_OR_CANCEL
TIMEINEFFECT_FILL_OR_KILL FILL_OR_KILL

Condition Type

Name Value
CONDITIONTYPE_NONE NONE
CONDITIONTYPE_GREATER_THAN GREATER_THAN
CONDITIONTYPE_LESS_THAN LESS_THAN
CONDITIONTYPE_STOP_LOSS_FIXED STOP_LOSS_FIXED
CONDITIONTYPE_STOP_LOSS_PERCENTAGE STOP_LOSS_PERCENTAGE

Response Message

Name Value
MESSAGE_APIKEY_INVALID APIKEY_INVALID
MESSAGE_INVALID_PERMISSION INVALID_PERMISSION
MESSAGE_MARKET_NOTPROVIDED MARKET_NOT_PROVIDED
MESSAGE_INVALID_MARKET INVALID_MARKET
MESSAGE_ADDRESS_GENERATING ADDRESS_GENERATING

Main Hub

Name Value
WEBSOCKET_MAIN_HUB c2

WebSocket Callbacks Delta

Name Value
WEBSOCKET_BALANCE_DELTA uB
WEBSOCKET_MARKET_DELTA uE
WEBSOCKET_SUMMARY_LITE_DELTA uL
WEBSOCKET_ORDER_DELTA uO
WEBSOCKET_SUMMARY_DELTA uS

WebSocket Order Delta

Name Value
WEBSOCKET_ORDER_DELTA_OPEN 0
WEBSOCKET_ORDER_DELTA_PARTIAL 1
WEBSOCKET_ORDER_DELTA_FILL 2
WEBSOCKET_ORDER_DELTA_CANCEL 3

Public methods

Get Bitcoin price in USD

api.getBTCPrice().then((response) => {
  console.log('[getBTCPrice] response:', response);
}).catch((error) => {
  console.error('[getBTCPrice] error:', error);
}).finally(() => {
  console.log('[getBTCPrice] done!');
});
Response:
{
  success: true,
  message: '',
  result: {
    bpi: {
      USD: {
        rate_float: 123456.789
      }
    }
  }
}

Get Ethereum price in USD

api.getETHPrice().then((response) => {
  console.log('[getETHPrice] response:', response);
}).catch((error) => {
  console.error('[getETHPrice] error:', error);
}).finally(() => {
  console.log('[getETHPrice] done!');
});
Response:
{
  success: true,
  message: '',
  result: {
    Bid: 123,
    Ask: 123.456789,
    Last: 123.45678
  }
}

Get the current tick values for a market

api.getTicker('BTC-ZEN').then((response) => {
  console.log('[getTicker(BTC-ZEN)] response:', response);
}).catch((error) => {
  console.error('[getTicker(BTC-ZEN)] error:', error);
}).finally(() => {
  console.log('[getTicker(BTC-ZEN)] done!');
});
Response:
{
  success: true,
  message: '',
  result: {
    Bid: 0.00448959,
    Ask: 0.00449948,
    Last: 0.00449948
  }
}

Get the chart data

api.getTicks('BTC-ZEN', Api.TICKINTERVAL_DAY).then((response) => {
  console.log('[getTicks(BTC-ZEN, day)] response:', response);
}).catch((error) => {
  console.error('[getTicks(BTC-ZEN, day)] error:', error);
}).finally(() => {
  console.log('[getTicks(BTC-ZEN, day)] done!');
});
Response:

keysMap option let you use your own key names.

{
  success: true,
  message: '',
  result: [
    {
      Orders: 0.008,
      High: 0.008,
      Low: 0.00311003,
      Closed: 0.00715,
      Volume: 209161.28332431,
      TimeStamp: '2017-06-05T00:00:00',
      BV: 1284.20909435
    },
    {
      Orders: 0.00716,
      High: 0.00719649,
      Low: 0.005501,
      Closed: 0.00585594,
      Volume: 109507.61923489,
      TimeStamp: '2017-06-06T00:00:00',
      BV: 674.00135455
    },
    {
      Orders: 0.00585594,
      High: 0.00609601,
      Low: 0.00472194,
      Closed: 0.00483018,
      Volume: 79194.8663556,
      TimeStamp: '2017-06-07T00:00:00',
      BV: 405.75784734
    },
    {
      Orders: 0.00487505,
      High: 0.00554995,
      Low: 0.001929,
      Closed: 0.0029678,
      Volume: 164038.29225956,
      TimeStamp: '2017-06-08T00:00:00',
      BV: 617.12961997
    }
  ]
}

Get all supported currencies at Bittrex along with other meta data

api.getCurrencies().then((response) => {
  console.log('[getCurrencies] response:', response);
}).catch((error) => {
  console.error('[getCurrencies] error:', error);
}).finally(() => {
  console.log('[getCurrencies] done!');
});
Response:
{
  success: true,
  message: '',
  result: [
    {
      Currency: 'BTC',
      CurrencyLong: 'Bitcoin',
      MinConfirmation: 2,
      TxFee: 0.0005,
      IsActive: true,
      CoinType: 'BITCOIN',
      BaseAddress: '1N52wHoVR79PMDishab2XmRHsbekCdGquK',
      Notice: null
    },
    {
      Currency: 'LTC',
      CurrencyLong: 'Litecoin',
      MinConfirmation: 6,
      TxFee: 0.01,
      IsActive: true,
      CoinType: 'BITCOIN',
      BaseAddress: 'LhyLNfBkoKshT7R8Pce6vkB9T2cP2o84hx',
      Notice: null
    },
    {
      Currency: 'DOGE',
      CurrencyLong: 'Dogecoin',
      MinConfirmation: 6,
      TxFee: 2,
      IsActive: true,
      CoinType: 'BITCOIN',
      BaseAddress: 'D9GqmkGCpgtnXP7xMD78v9xfqeDkqBZBMT',
      Notice: null
    }
  ]
}

Get the last 24 hour summary of all active markets

api.getMarketSummaries().then((response) => {
  console.log('[getMarketSummaries] response:', response);
}).catch((error) => {
  console.error('[getMarketSummaries] error:', error);
}).finally(() => {
  console.log('[getMarketSummaries] done!');
});
Response:
{
  success: true,
  message: '',
  result: [
    {
      Market: {
        MarketCurrency: 'BTC',
        BaseCurrency: 'USDT',
        MarketCurrencyLong: 'Bitcoin',
        BaseCurrencyLong: 'Tether',
        MinTradeSize: 0.0003358,
        MarketName: 'USDT-BTC',
        IsActive: true,
        Created: '2015-12-11T06:31:40.633',
        Notice: null,
        IsSponsored: null,
        LogoUrl: 'https://bittrex.com/Content/img/symbols/BTC.png'
      },
      Summary: {
        MarketName: 'USDT-BTC',
        High: 8277.99999999,
        Low: 7780,
        Volume: 2039.47901727,
        Last: 7928.81,
        BaseVolume: 16240931.86328923,
        TimeStamp: '2018-05-23T13:33:40.747',
        Bid: 7925.99,
        Ask: 7934.58,
        OpenBuyOrders: 2131,
        OpenSellOrders: 3018,
        PrevDay: 8215,
        Created: '2015-12-11T06:31:40.633'
      },
      IsVerified: false
    },
    {
      Market: {
        MarketCurrency: 'LTC',
        BaseCurrency: 'USDT',
        MarketCurrencyLong: 'Litecoin',
        BaseCurrencyLong: 'Tether',
        MinTradeSize: 0.01928167,
        MarketName: 'USDT-LTC',
        IsActive: true,
        Created: '2017-07-14T17:10:10.72',
        Notice: null,
        IsSponsored: null,
        LogoUrl: 'https://bittrexblobstorage.blob.core.windows.net/public/6defbc41-582d-47a6-bb2e-d0fa88663524.png'
      },
      Summary: {
        MarketName: 'USDT-LTC',
        High: 133.86899999,
        Low: 122.37423123,
        Volume: 3960.64501216,
        Last: 125,
        BaseVolume: 501542.4326011,
        TimeStamp: '2018-05-23T13:33:40.45',
        Bid: 124.5,
        Ask: 125,
        OpenBuyOrders: 241,
        OpenSellOrders: 1198,
        PrevDay: 132.32,
        Created: '2017-07-14T17:10:10.72'
      },
      IsVerified: false
    },
    {
      Market: {
        MarketCurrency: 'ZEN',
        BaseCurrency: 'BTC',
        MarketCurrencyLong: 'Zencash',
        BaseCurrencyLong: 'Bitcoin',
        MinTradeSize: 0.0653482,
        MarketName: 'BTC-ZEN',
        IsActive: true,
        Created: '2017-06-05T16:39:49.07',
        Notice: null,
        IsSponsored: null,
        LogoUrl: 'https://bittrexblobstorage.blob.core.windows.net/public/9a2691a9-c068-4bb3-8214-fe212727da59.png'
      },
      Summary: {
        MarketName: 'BTC-ZEN',
        High: 0.00641082,
        Low: 0.00408,
        Volume: 558876.84382165,
        Last: 0.00467984,
        BaseVolume: 3055.50177773,
        TimeStamp: '2018-05-23T13:33:40.917',
        Bid: 0.004645,
        Ask: 0.00467984,
        OpenBuyOrders: 822,
        OpenSellOrders: 1677,
        PrevDay: 0.00410697,
        Created: '2017-06-05T16:39:49.07'
      },
      IsVerified: false
    }
  ]
}

Get the last 24 hour summary of a specific market

api.getMarketSummary('BTC-ZEN').then((response) => {
  console.log('[getMarketSummary(BTC-ZEN)] response:', response);
}).catch((error) => {
  console.error('[getMarketSummary(BTC-ZEN)] error:', error);
}).finally(() => {
  console.log('[getMarketSummary(BTC-ZEN)] done!');
});
Response:
{
  success: true,
  message: '',
  result: {
    MarketName: 'BTC-ZEN',
    High: 0.00641082,
    Low: 0.00408,
    Volume: 558994.74594262,
    Last: 0.00472384,
    BaseVolume: 3056.05580003,
    TimeStamp: '2018-05-23T13:37:22.987',
    Bid: 0.00473418,
    Ask: 0.00474009,
    OpenBuyOrders: 817,
    OpenSellOrders: 1676,
    PrevDay: 0.00411929,
    Created: '2017-06-05T16:39:49.07'
  }
}

Retrieve the latest trades that have occurred for a specific market

api.getMarketHistory('BTC-ZEN').then((response) => {
  console.log('[getMarketHistory(BTC-ZEN)] response:', response);
}).catch((error) => {
  console.error('[getMarketHistory(BTC-ZEN)] error:', error);
}).finally(() => {
  console.log('[getMarketHistory(BTC-ZEN)] done!');
});
Response:
{
  success: true,
  message: '',
  result: [
    {
      Id: 18210797,
      TimeStamp: '2018-05-23T14:05:41.46',
      Quantity: 0.21412496,
      Price: 0.00465,
      Total: 0.00099568,
      FillType: 'FILL',
      OrderType: 'BUY',
    },
    {
      Id: 18210785,
      TimeStamp: '2018-05-23T14:05:36.053',
      Quantity: 0.89772904,
      Price: 0.00465,
      Total: 0.00417444,
      FillType: 'FILL',
      OrderType: 'SELL',
    },
    {
      Id: 18210782,
      TimeStamp: '2018-05-23T14:05:34.943',
      Quantity: 10.02792573,
      Price: 0.00465,
      Total: 0.04662985,
      FillType: 'PARTIAL_FILL',
      OrderType: 'SELL',
    },
    {
      Id: 18210780,
      TimeStamp: '2018-05-23T14:05:32.693',
      Quantity: 1.431,
      Price: 0.00465,
      Total: 0.00665415,
      FillType: 'PARTIAL_FILL',
      OrderType: 'SELL',
    },
    {
      Id: 18210779,
      TimeStamp: '2018-05-23T14:05:30.787',
      Quantity: 19.77251308,
      Price: 0.00465,
      Total: 0.09194218,
      FillType: 'PARTIAL_FILL',
      OrderType: 'SELL',
    },
  ],
}

Get retrieve the orderbook for a given market

api.getOrderBook('BTC-ZEN').then((response) => {
  console.log('[getOrderBook(BTC-ZEN)] response:', response);
}).catch((error) => {
  console.error('[getOrderBook(BTC-ZEN)] error:', error);
}).finally(() => {
  console.log('[getOrderBook(BTC-ZEN)] done!');
});
Response:
{
  success: true,
  message: '',
  result: {
    buy: [
      {
        Quantity: 4.70962245,
        Rate: 0.07603643,
      },
      {
        Quantity: 2.32817822,
        Rate: 0.07603543,
      },
      {
        Quantity: 0.63761091,
        Rate: 0.07603542,
      },
      {
        Quantity: 0.29818749,
        Rate: 0.07601922,
      },
      {
        Quantity: 10,
        Rate: 0.0760152,
      },
      {
        Quantity: 10.8852406,
        Rate: 0.076,
      },
    ],
  },
}

Get the wallet health

api.getWalletHealth().then((response) => {
  console.log('[getWalletHealth] response:', response);
}).catch((error) => {
  console.error('[getWalletHealth] error:', error);
}).finally(() => {
  console.log('[getWalletHealth] done!');
});
Response:
{
  success: true,
  message: '',
  result: [
    {
      Health: {
        Currency: 'BTC',
        DepositQueueDepth: 0,
        WithdrawQueueDepth: 49,
        BlockHeight: 524009,
        WalletBalance: 0,
        WalletConnections: 8,
        MinutesSinceBHUpdated: 0,
        LastChecked: '2018-05-23T14:36:16.23',
        IsActive: true,
      },
      Currency: {
        Currency: 'BTC',
        CurrencyLong: 'Bitcoin',
        MinConfirmation: 2,
        TxFee: 0.0005,
        IsActive: true,
        CoinType: 'BITCOIN',
        BaseAddress: '1N52wHoVR79PMDishab2XmRHsbekCdGquK',
        Notice: null,
      },
    },
    {
      Health: {
        Currency: 'LTC',
        DepositQueueDepth: 0,
        WithdrawQueueDepth: 4,
        BlockHeight: 1426715,
        WalletBalance: 0,
        WalletConnections: 8,
        MinutesSinceBHUpdated: 0,
        LastChecked: '2018-05-23T14:35:28.063',
        IsActive: true,
      },
      Currency: {
        Currency: 'LTC',
        CurrencyLong: 'Litecoin',
        MinConfirmation: 6,
        TxFee: 0.01,
        IsActive: true,
        CoinType: 'BITCOIN',
        BaseAddress: 'LhyLNfBkoKshT7R8Pce6vkB9T2cP2o84hx',
        Notice: null,
      },
    },
    {
      Health: {
        Currency: 'DOGE',
        DepositQueueDepth: 0,
        WithdrawQueueDepth: 1,
        BlockHeight: 2231937,
        WalletBalance: 0,
        WalletConnections: 8,
        MinutesSinceBHUpdated: 0,
        LastChecked: '2018-05-23T14:36:50.28',
        IsActive: true,
      },
      Currency: {
        Currency: 'DOGE',
        CurrencyLong: 'Dogecoin',
        MinConfirmation: 6,
        TxFee: 2,
        IsActive: true,
        CoinType: 'BITCOIN',
        BaseAddress: 'D9GqmkGCpgtnXP7xMD78v9xfqeDkqBZBMT',
        Notice: null,
      },
    },
  ],
}

Private methods

Retrieve all balances from your account

api.getBalances().then((response) => {
  console.log('[getBalances] response:', response);
}).catch((error) => {
  console.error('[getBalances] error:', error);
}).finally(() => {
  console.log('[getBalances] done!');
});
Response:
{
  success: true,
  message: '',
  result: [
    {
      Currency: {
        Currency: 'BTC',
        CurrencyLong: 'Bitcoin',
        MinConfirmation: 2,
        TxFee: 0.0005,
        IsActive: true,
        CoinType: 'BITCOIN',
        BaseAddress: '1N52wHoVR79PMDishab2XmRHsbekCdGquK',
        Notice: null,
      },
      Balance: {
        Uuid: '00000000-0000-0000-0000-000000000000',
        AccountId: 0,
        Currency: 'BTC',
        Balance: 0,
        Available: 0,
        Pending: 0,
        CryptoAddress: '0000000000000000000000000000000000',
        Requested: false,
        Updated: '2018-05-23T17:48:17.913',
        AutoSell: null,
      },
      BitcoinMarket: null,
      EthereumMarket: null,
      FiatMarket: null,
    },
    {
      Currency: {
        Currency: 'LTC',
        CurrencyLong: 'Litecoin',
        MinConfirmation: 6,
        TxFee: 0.01,
        IsActive: true,
        CoinType: 'BITCOIN',
        BaseAddress: 'LhyLNfBkoKshT7R8Pce6vkB9T2cP2o84hx',
        Notice: null,
      },
      Balance: {
        Uuid: '00000000-0000-0000-0000-00000000000',
        AccountId: 0,
        Currency: 'LTC',
        Balance: 0,
        Available: 0,
        Pending: 0,
        CryptoAddress: '0000000000000000000000000000000000',
        Requested: false,
        Updated: null,
        AutoSell: null,
      },
      BitcoinMarket: {
        MarketName: 'BTC-LTC',
        High: 0.01614,
        Low: 0.0155,
        Volume: 15017.40266959,
        Last: 0.01566001,
        BaseVolume: 238.08523649,
        TimeStamp: '2018-05-23T18:22:22.07',
        Bid: 0.01566001,
        Ask: 0.01567,
        OpenBuyOrders: 1109,
        OpenSellOrders: 4161,
        PrevDay: 0.01602562,
        Created: '2014-02-13T00:00:00',
      },
      EthereumMarket: {
        MarketName: 'ETH-LTC',
        High: 0.20607336,
        Low: 0.19499305,
        Volume: 2484.61446931,
        Last: 0.20527968,
        BaseVolume: 500.93710535,
        TimeStamp: '2018-05-23T18:22:21.913',
        Bid: 0.20527968,
        Ask: 0.20539331,
        OpenBuyOrders: 665,
        OpenSellOrders: 563,
        PrevDay: 0.19499305,
        Created: '2017-06-25T03:06:46.83',
      },
      FiatMarket: null,
    },
    {
      Currency: {
        Currency: 'USDT',
        CurrencyLong: 'Tether',
        MinConfirmation: 2,
        TxFee: 25,
        IsActive: true,
        CoinType: 'OMNI',
        BaseAddress: '1DUb2YYbQA1jjaNYzVXLZ7ZioEhLXtbUru',
        Notice: null,
      },
      Balance: {
        Uuid: '00000000-0000-0000-0000-000000000000',
        AccountId: 0,
        Currency: 'USDT',
        Balance: 0.0,
        Available: 0.0,
        Pending: 0,
        CryptoAddress: null,
        Requested: false,
        Updated: '2018-05-22T01:27:13.843',
        AutoSell: null,
      },
      BitcoinMarket: null,
      EthereumMarket: null,
      FiatMarket: {
        MarketName: 'USDT-BTC',
        High: 8218.9,
        Low: 7444.0000001,
        Volume: 2874.75877057,
        Last: 7500.72836065,
        BaseVolume: 22505202.07378581,
        TimeStamp: '2018-05-23T18:22:22.32',
        Bid: 7500.72836065,
        Ask: 7510.32813361,
        OpenBuyOrders: 1817,
        OpenSellOrders: 2991,
        PrevDay: 8177.12496199,
        Created: '2015-12-11T06:31:40.633',
      },
    },
  ],
}

...

...

...

...

...

...

WebSocket

const ws = api.webSocket();
 
ws.on('connected', () => { /* ... */ });
ws.on('disconnected', () => { /* ... */ });
 
ws.connect((client) => {
  client.authenticate();
    
  client.getSummaryDeltas((data) => {
    console.log('[getSummaryDeltas]:', data);
  });
 
  client.getBalanceDelta((data) => {
    console.log('[getBalanceDelta]:', data);
  });
  
  client.getOrderDelta((data) => {
    console.log('[getOrderDelta]:', data);
 
    const order = data.order;
    const market = order.exchange;
    const units = order.quantity.toFixed(8);
    const limit = order.limit.toFixed(8);
 
    switch (data.type) {
      case Api.WEBSOCKET_ORDER_DELTA_OPEN: {
        console.log(`[${market} Buy Placed] Your Buy order of ${units} units in ${market} at ${limit} per unit has been placed.`);
        break;
      }
      
      case Api.WEBSOCKET_ORDER_DELTA_PARTIAL: {
        const filled = (order.quantity - order.quantityRemaining).toFixed(8);
        console.log(`[${market} Buy Partially Filled] Your Buy order has partially filled ${filled} out of ${units} units in ${market} at ${limit} per unit.`);
        break;
      }
      
      case Api.WEBSOCKET_ORDER_DELTA_FILL: {
        console.log(`[${market} Sell Completed] Your Sell order of ${units} units in ${market} at ${limit} per unit has processed.`);
        break;
      }
      
      case Api.WEBSOCKET_ORDER_DELTA_CANCEL: {
        console.log(`[${market} Buy Cancelled] Your Buy order of ${units} units in ${market} at ${limit} per unit has cancelled.`);
        break;
      }
      
      default: {
        break;
      }
    }
  });
});

License

MIT

Copyright (c) 2018 Vadim Malykhin

install

npm i bittrex-api-node

version

0.0.6

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability