This is a maintained fork of the original package. The npm package name has
changed because we could not get access to the npmjs repository to keep it
updated. Please see the Quick start section for the new package name and
instructions.
Also, the websocket code has changed after Bittrex switched to using Cloudflare
so please see the new Websockets documentation and updated unit tests and
examples in the examples/ folder.
Node Bittrex API
Node Bittrex API is an asynchronous node.js library for the Bittrex API - https://bittrex.com/.
The Bittrex API data can be received either as a GET request or via Websockets API.
Thanks go to the people who have contributed code to this Library.
n0mad01 Special kudos - the original creator of the library. Thanks for the hard work.
cyberwlf & armandohg - Special thanks to them for the cloudflare websocket research and fix but also thanks to everyone else in issue #67
samuelhei Special kudos - thanks to him all missing calls are complemented as also structural improvements have been made.
Before you start
This is just a quick reminder that you are handling coins with this library (and thus real money), so, understand the situation as much as possible and make everything to prevent losing them.
Here is a small checklist you should go through before you start:
Make sure you don't give your api key more rights as absolutely necessary - for first testing READ INFO alone should be enough! (bittrex.com under: Settings/API Keys)
make sure to understand the API Key permissions
READ INFO - Allows you to read private details such as open orders, order history, balances, etc
TRADE LIMIT - Allows you to create/cancel trade limit buy/sell orders
TRADE MARKET - allows you to create/cancel market buy/sell orders
WITHDRAW - Allows you to withdraw to another address
Make use of the Bittrex IP Whitelist as also the Withdrawal Whitelist features
Do not ever commit your API Keys to GitHub or expose them under any circumstances!
Quick start
$ npm install node-bittrex-api
var bittrex = require('node-bittrex-api');bittrex.options({ 'apikey' : API_KEY, 'apisecret' : API_SECRET,});bittrex.getmarketsummaries( function( data, err ) { if (err) { return console.error(err); } for( var i in data.result ) { bittrex.getticker( { market : data.result[i].MarketName }, function( ticker ) { console.log( ticker ); }); }});
All of these methods will build a websocket client and attempt a connection if
you have not run websockets.client yourself. See examples/ for a better
understanding.
websockets.listen
This will subscribe to just the global ticker updates.
Note: It is recommended to use this in onConnect() - see example examples/.
This will subscribe to the specified markets data. To build
your candle data, order book and market history, etc. you will need to subscribe
to the individual markets you wish to watch. You can subscribe to all of them.
This can be called multiple times.
Note: It is recommended to use this in onConnect() - see example examples/.
bittrex.websockets.subscribe(['BTC-ETH','BTC-SC','BTC-ZEN'], function(data, client) { if (data.M === 'updateExchangeState') { data.A.forEach(function(data_for) { console.log('Market Update for '+ data_for.MarketName, data_for); }); }});
Websocket serviceHandlers example
You can override the libraries logic for the following events. Note, this will
replace the libraries logic.
bittrex.websockets.client(function(client) { client.serviceHandlers.reconnecting = function (message) { return true; // set to true stops reconnect/retrying } client.serviceHandlers.messageReceived = function (message) { console.log(message); // the messages received must be parsed as json first e.g. via jsonic(message.utf8Data) }});
It may happen that some Bittrex API methods are missing, also they could have been forgotten in the documentation. In this case, if this strikes you, feel free to open a issue or send me a pull request.
Also: the method sendCustomRequest enables completely custom requests, regardless the specific API methods.
sendCustomRequest
url String
callback Function
credentials Boolean optional whether the credentials should be applied to the request/stream or not, default is set to false.
example #1
var url = 'https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC';bittrex.sendCustomRequest( url, function( data, err ) { console.log( data );});
example #2 (credentials applied to request/stream)
bittrex.sendCustomRequest( 'https://bittrex.com/api/v1.1/account/getbalances?currency=BTC', function( data, err ) { console.log( data );}, true );will result in (the Header is being set too):https://bittrex.com/api/v1.1/account/getbalances?currency=BTC&apikey=API_KEY&nonce=4456490600
Little is known about the v2 api at present. We have support for only a few methods
with very little documentation. Given that the v2 api is still in development by
Bittrex it is possible these methods will change or become invalid without notice.
bittrex.tradesell({ MarketName: 'BTC-ZEC', OrderType: 'LIMIT', Quantity: 1.00000000, Rate: 0.04423432, TimeInEffect: 'IMMEDIATE_OR_CANCEL', // supported options are 'IMMEDIATE_OR_CANCEL', 'GOOD_TIL_CANCELLED', 'FILL_OR_KILL' ConditionType: 'NONE', // supported options are 'NONE', 'GREATER_THAN', 'LESS_THAN' Target: 0, // used in conjunction with ConditionType}, function( data, err ) { console.log( data );});
tradebuy
bittrex.tradebuy({ MarketName: 'BTC-ZEC', OrderType: 'LIMIT', Quantity: 1.00000000, Rate: 0.04423432, TimeInEffect: 'IMMEDIATE_OR_CANCEL', // supported options are 'IMMEDIATE_OR_CANCEL', 'GOOD_TIL_CANCELLED', 'FILL_OR_KILL' ConditionType: 'NONE', // supported options are 'NONE', 'GREATER_THAN', 'LESS_THAN' Target: 0, // used in conjunction with ConditionType}, function( data, err ) { console.log( data );});
Testing
Installing test gear
npm install --only=dev
Running all tests
npm test tests
or individually
npm test tests/public.jsnpm test tests/private.js
Testing private methods
Testing private method endpoints requires an api key/secret which should be
installed in to tests/config.json - you will find an example file in
tests/config_example.json.