0.0.6 • Published 6 years ago

bittrex-api-node v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

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

NameValue
ENDPOINT_V1https://bittrex.com/api/v1.1
ENDPOINT_V2https://bittrex.com/api/v2.0
ENDPOINT_WSwss://socket.bittrex.com/signalr
ENDPOINT_WS_BETAwss://beta.bittrex.com/signalr

Tick Interval

NameValue
TICKINTERVAL_ONEMINoneMin
TICKINTERVAL_FIVEMINfiveMin
TICKINTERVAL_THIRTYMINthirtyMin
TICKINTERVAL_HOURhour
TICKINTERVAL_DAYday

Order Type

NameValue
ORDERTYPE_LIMITLIMIT
ORDERTYPE_MARKETMARKET

Time in Effect

NameValue
TIMEINEFFECT_GOOD_TIL_CANCELLEDGOOD_TIL_CANCELLED
TIMEINEFFECT_IMMEDIATE_OR_CANCELIMMEDIATE_OR_CANCEL
TIMEINEFFECT_FILL_OR_KILLFILL_OR_KILL

Condition Type

NameValue
CONDITIONTYPE_NONENONE
CONDITIONTYPE_GREATER_THANGREATER_THAN
CONDITIONTYPE_LESS_THANLESS_THAN
CONDITIONTYPE_STOP_LOSS_FIXEDSTOP_LOSS_FIXED
CONDITIONTYPE_STOP_LOSS_PERCENTAGESTOP_LOSS_PERCENTAGE

Response Message

NameValue
MESSAGE_APIKEY_INVALIDAPIKEY_INVALID
MESSAGE_INVALID_PERMISSIONINVALID_PERMISSION
MESSAGE_MARKET_NOTPROVIDEDMARKET_NOT_PROVIDED
MESSAGE_INVALID_MARKETINVALID_MARKET
MESSAGE_ADDRESS_GENERATINGADDRESS_GENERATING

Main Hub

NameValue
WEBSOCKET_MAIN_HUBc2

WebSocket Callbacks Delta

NameValue
WEBSOCKET_BALANCE_DELTAuB
WEBSOCKET_MARKET_DELTAuE
WEBSOCKET_SUMMARY_LITE_DELTAuL
WEBSOCKET_ORDER_DELTAuO
WEBSOCKET_SUMMARY_DELTAuS

WebSocket Order Delta

NameValue
WEBSOCKET_ORDER_DELTA_OPEN0
WEBSOCKET_ORDER_DELTA_PARTIAL1
WEBSOCKET_ORDER_DELTA_FILL2
WEBSOCKET_ORDER_DELTA_CANCEL3

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!');
});
{
  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!');
});
{
  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!');
});
{
  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!');
});

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!');
});
{
  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!');
});
{
  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!');
});
{
  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!');
});
{
  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!');
});

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!');
});
{
  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!');
});
{
  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

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.1

6 years ago

0.0.2

6 years ago