Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
node-bittrex-api
Advanced tools
Node Bittrex API - asynchronous node.js library for the Bittrex API https://bittrex.com/
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 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.
Thanks go to the people who have contributed code to this Library.
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:
$ 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 );
});
}
});
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 = require('./node.bittrex.api.js');
bittrex.options({
'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.:
getmarkethistory({market : 'USDT-BTC'}, function(data, error) {});
you'll get the reversed order:
getmarkethistory({market : 'USDT-BTC'}, function(data, error) {});
bittrex.websockets.client(function() {
console.log('Websocket connected');
bittrex.websockets.subscribe(['BTC-ETH'], function(data) {
if (data.M === 'updateExchangeState') {
data.A.forEach(function(data_for) {
console.log('Market Update for '+ data_for.MarketName, data_for);
});
}
});
});
bittrex.options({
websockets: {
onConnect: function() {
console.log('Websocket connected');
bittrex.websockets.subscribe(['BTC-ETH'], function(data) {
if (data.M === 'updateExchangeState') {
data.A.forEach(function(data_for) {
console.log('Market Update for '+ data_for.MarketName, data_for);
});
}
});
},
onDisconnect: function() {
console.log('Websocket disconnected');
}
}
});
var websocketClient;
bittrex.websockets.client(function(client) {
websocketClient = client;
});
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.
This will subscribe to just the global ticker updates.
Note: It is recommended to use this in onConnect()
- see example examples/
.
bittrex.websockets.listen(function(data, client) {
if (data.M === 'updateSummaryState') {
data.A.forEach(function(data_for) {
data_for.Deltas.forEach(function(marketsDelta) {
console.log('Ticker Update for '+ marketsDelta.MarketName, marketsDelta);
});
});
}
});
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);
});
}
});
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)
}
});
all possible serviceHandlers
bound: function() { console.log("Websocket bound"); },
connectFailed: function(error) { console.log("Websocket connectFailed: ", error); },
connected: function(connection) { console.log("Websocket connected"); },
disconnected: function() { console.log("Websocket disconnected"); },
onerror: function (error) { console.log("Websocket onerror: ", error); },
messageReceived: function (message) { console.log("Websocket messageReceived: ", message); return false; },
bindingError: function (error) { console.log("Websocket bindingError: ", error); },
connectionLost: function (error) { console.log("Connection Lost: ", error); },
reconnecting: function (retry { inital: true/false, count: 0} ) {
console.log("Websocket Retrying: ", retry);
//return retry.count >= 3; // cancel retry true
return true;
}
Streams have been removed
After configuration you can use the object right away: example #1
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 );
});
}
});
example #2
bittrex.getbalance({ currency : 'BTC' }, function( data, err ) {
if (err) {
return console.error(err);
}
console.log( data );
});
Websockets depends on the following npm packages:
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).
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.sendCustomRequest( url, function( data, err ) {
if (err) {
/**
{
success: false,
message: 'URL request error',
error:
{ Error: getaddrinfo ENOTFOUND fake.bittrex.com fake.bittrex.com:80
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'fake.bittrex.com',
host: 'fake.bittrex.com',
port: 80 },
result: undefined
}
*/
return console.error(err);
}
console.log(data);
});
Example of request/url based errors (not Bittrex API error)
var url = 'http://bittrex.com/api/v1.1/public/getfakeendpoint';
bittrex.sendCustomRequest( url, function( data, err ) {
if (err) {
/**
{
success: false,
message: 'URL request error',
error: undefined,
result: {
statusCode: 404,
statusMessage: 'Not Found',
body: '<!DOCTYPE html>\r\n<html > ...'
}
}
*/
return console.error(err);
}
console.log(data);
});
Example of Bittrex API error
bittrex.getcandles({
marketName: 'USDT-BTC',
tickInterval: 300
}, function(data, err) {
if (err) {
/**
{
success: false,
message: 'INVALID_TICK_INTERVAL',
result: null
}
*/
return console.error(err);
}
console.log(data);
});
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.
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
bittrex.getticker( { market : 'BTC-LTC' }, function( data, err ) {
console.log( data );
});
bittrex.getbalances( function( data, err ) {
console.log( data );
});
bittrex.getmarkethistory({ market : 'BTC-LTC' }, function( data, err ) {
console.log( data );
});
bittrex.getmarketsummaries( function( data, err ) {
console.log( data );
});
bittrex.getmarketsummary( { market : 'BTC-LTC'}, function( data, err ) {
console.log( data );
});
bittrex.getorderbook({ market : 'BTC-LTC', type : 'both' }, function( data, err ) {
console.log( data );
});
bittrex.getwithdrawalhistory({ currency : 'BTC' }, function( data, err ) {
console.log( data );
});
bittrex.getdepositaddress({ currency : 'BTC' }, function( data, err ) {
console.log( data );
});
bittrex.getdeposithistory({ currency : 'BTC' }, function( data, err ) {
console.log( data );
});
bittrex.getbalance({ currency : 'BTC' }, function( data, err ) {
console.log( data );
});
bittrex.withdraw({ currency : 'BTC', quantity : '1.5112', address : 'THE_ADDRESS' }, function( data, err ) {
console.log( data );
});
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.getcandles({
marketName: 'USDT-BTC',
tickInterval: 'fiveMin', // intervals are keywords: 'oneMin', 'fiveMin', 'thirtyMin', 'hour', 'day'
}, function( data, err ) {
console.log( data );
});
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 );
});
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 );
});
Installing test gear
npm install --only=dev
Running all tests
npm test tests
or individually
npm test tests/public.js
npm test tests/private.js
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.json
vim tests/config.json
FAQs
Node Bittrex API - asynchronous node.js library for the Bittrex API https://bittrex.com/
We found that node-bittrex-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.