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.
Documentation for the Bittrex API: https://bittrex.com/Home/Api
This Library is licensed under the MIT license.
Contributors
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.
- mhuggins
- 192-sean
- caffeinewriter
- apense
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 = ;bittrexoptions 'apikey' : API_KEY 'apisecret' : API_SECRET;bittrex;
Advanced start
fetch the project via git:
$ git clone https://github.com/dparlevliet/node.bittrex.api.git
then meet the package dependencies:
$ cd node-bittrex-api/$ npm install
include node.bittrex.api.js into your project:
var bittrex = ;
configure
bittrexoptions 'apikey' : API_KEY 'apisecret' : API_SECRET 'verbose' : true 'cleartext' : false;
By default the returned data is an object, in order to get clear text you have to add the option cleartext (streams will always return text):
'cleartext' : true
The baseUrl itself can also be set via options
'baseUrl' : 'https://bittrex.com/api/v1''baseUrlv2' : 'https://bittrex.com/Api/v2.0'
Change the callbacks arguments sequence
'inverse_callback_arguments' : true
This simply changes the sequence in which the arguments are passed, instead of e.g.:
;
you'll get the reversed order:
;
Websockets
Basic example
bittrexwebsockets;
Basic example with event emitters
bittrexoptions websockets: { console; bittrexwebsockets; } { console; } ; var websocketClient;bittrexwebsockets;
Available methods
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
bittrexwebsockets;
websockets.subscribe
bittrexwebsockets;
Websocket serviceHandlers example
You can override the libraries logic for the following events. Note, this will replace the libraries logic.
websocketClientserviceHandlers { return true; // set to true stops reconnect/retrying} websocketClientserviceHandlers { console; // the messages received must be parsed as json first e.g. via jsonic(message.utf8Data)}
all possible serviceHandlers
{ console; } { console; } { console; } { console; } { console; } { console; return false; } { console; } { console; } { console; //return retry.count >= 3; // cancel retry true return true;}
Streams
Streams have been removed
Examples
After configuration you can use the object right away: example #1
bittrex;
example #2
bittrex;
Libraries
Websockets depends on the following npm packages:
- signalR websockets client https://www.npmjs.com/package/signalrjs
- jsonic JSON parser https://www.npmjs.com/package/jsonic
- cloudscraper https://www.npmjs.com/package/cloudscraper
Other libraries utilized:
For HmacSHA512 this package is using a part of Googles Crypto.js (the node crypt package could not provide any appropriate result).
Error examples
Example of request/domain based errors (not Bittrex API error)
var url = 'http://fake.bittrex.com/api/v1.1/public/getticker?market=USDT-BTCXXX';bittrex;
Example of request/url based errors (not Bittrex API error)
var url = 'http://bittrex.com/api/v1.1/public/getfakeendpoint';bittrex;
Example of Bittrex API error
bittrex;
Methods
Optional parameters may have to be looked up at https://bittrex.com/Home/Api.
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;
example #2 (credentials applied to request/stream)
bittrex; will result in the Header is being set too:https://bittrex.com/api/v1.1/account/getbalances?currency=BTC&apikey=API_KEY&nonce=4456490600
getticker
bittrex;
getbalances
bittrex;
getmarkethistory
bittrex;
getcandles (v2 method)
bittrex;
getmarketsummaries
bittrex;
getmarketsummary
bittrex;
getorderbook
bittrex;
getwithdrawalhistory
bittrex;
getdepositaddress
bittrex;
getdeposithistory
bittrex;
getbalance
bittrex;
withdraw
bittrex;
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
.
cp tests/tests_example.json tests/config.jsonvim tests/config.json