Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
Merge from development
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Eyrick authored Jan 22, 2019
2 parents e65a006 + 1c2e3e0 commit ecf5403
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 3,790 deletions.
43 changes: 2 additions & 41 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,2 @@
**Title**
- bug: XYZ broken
- feature: please add
- enhancement: add this to existing features

**Short Description:**
- Unable to get a result from blah

**Platform:**
- windows
- linux
- macos

**node version:**
- 9.11

**Long descrption**
- Doing xyz results in ypr and failing when fph

**code**
```
const util = require('util');
const binance = require('node-binance-api');
binance.options({
APIKEY: '<key>',
APISECRET: '<secret>',
useServerTime: true, // If you get timestamp errors, synchronize to server time at startup
test: true // If you want to use sandbox mode where orders are simulated
});
util.inspect( binance );
```

**result**
```
{
"result":"result"
}
```

thank you
SUPPORT IS NO LONGER OFFERED BY BINANCE
Please do not post an issue unless it is a feature request
19 changes: 4 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,7 @@ npm install node-binance-api --save
const binance = require('node-binance-api')().options({
APIKEY: '<key>',
APISECRET: '<secret>',
useServerTime: true, // If you get timestamp errors, synchronize to server time at startup
test: true // If you want to use sandbox mode where orders are simulated
});
```

#### Instantiating Multiple Instances
```javascript
const Binance = require('node-binance-api');

const instance1 = new Binance().options({
// ...
});

const instance2 = new Binance().options({
// ...
useServerTime: true // If you get timestamp errors, synchronize to server time at startup
});
```

Expand Down Expand Up @@ -1654,3 +1640,6 @@ binance.useServerTime(function() {
[![Views](http://hits.dwyl.io/jaggedsoft/node-binance-api.svg)](http://hits.dwyl.io/jaggedsoft/node-binance-api)

Thank you to all contributors: dmzoneill, dmitriz, keith1024, usama33, yanislk, learnathoner, vaielab, nickreese, Tuitio, grandmore, itnok, CollinEstes, sethyx, mstijak, MadDeveloper, balthazar, bitoiu, matthewwoop, robaleman, hems and others!

> # ⚠️ Binance no longer offers support for API projects.
> ## No support is offered. No questions will be answered.
16 changes: 16 additions & 0 deletions examples/standalone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Standalone async functions not requiring the library
const axios = require( 'axios' );
async function bookTicker( symbol = false ) {
return new Promise( ( resolve, reject ) => {
params = symbol ? `?symbol=${symbol}` : '';
axios.get( 'https://api.binance.com/api/v3/ticker/bookTicker' + params )
.then( function ( response ) {
resolve( response.data );
} )
.catch( function ( error ) {
throw error;
} );
} );
}
//console.log(await bookTicker());
//console.log(await bookTicker("BTCUSDT"));
76 changes: 43 additions & 33 deletions node-binance-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,17 @@ let api = function Binance() {
'X-MBX-APIKEY': key || ''
}
})

const reqObjPOST = (url, data = {}, method = 'POST', key) => ({
url: url,
form: data,
method: method,
timeout: Binance.options.recvWindow,
headers: {
'User-Agent': userAgent,
'Content-type': contentType,
'X-MBX-APIKEY': key || ''
}
})
/**
* Create a http request to the public API
* @param {string} url - The http endpoint
Expand Down Expand Up @@ -198,14 +208,23 @@ let api = function Binance() {
return a;
}, []).join('&');
let signature = crypto.createHmac('sha256', Binance.options.APISECRET).update(query).digest('hex'); // set the HMAC hash header

let opt = reqObj(
url + '?' + query + '&signature=' + signature,
data,
method,
Binance.options.APIKEY
);
proxyRequest(opt, callback);
if (method === 'POST') {
let opt = reqObjPOST(
url + '?signature=' + signature,
data,
method,
Binance.options.APIKEY
);
proxyRequest(opt, callback);
} else {
let opt = reqObj(
url + '?' + query + '&signature=' + signature,
data,
method,
Binance.options.APIKEY
);
proxyRequest(opt, callback);
}
};

/**
Expand Down Expand Up @@ -313,14 +332,14 @@ let api = function Binance() {
*/
const handleSocketClose = function (reconnect, code, reason) {
delete Binance.subscriptions[this.endpoint];
if ( Binance.subscriptions && Object.keys(Binance.subscriptions).length === 0 ) {
if (Binance.subscriptions && Object.keys(Binance.subscriptions).length === 0) {
clearInterval(Binance.socketHeartbeatInterval);
}
Binance.options.log('WebSocket closed: ' + this.endpoint +
(code ? ' (' + code + ')' : '') +
(reason ? ' ' + reason : ''));
if ( Binance.options.reconnect && this.reconnect && reconnect) {
if ( this.endpoint && parseInt(this.endpoint.length, 10) === 60) Binance.options.log('Account data WebSocket reconnecting...');
if (Binance.options.reconnect && this.reconnect && reconnect) {
if (this.endpoint && parseInt(this.endpoint.length, 10) === 60) Binance.options.log('Account data WebSocket reconnecting...');
else Binance.options.log('WebSocket reconnecting: ' + this.endpoint + '...');
try {
reconnect();
Expand Down Expand Up @@ -807,7 +826,7 @@ let api = function Binance() {
* @param {float} float - get the price precision point
* @return {int} - number of place
*/
getPrecision: function (float) { //
getPrecision: function (float) {
return float.toString().split('.')[1].length || 0;
},

Expand All @@ -818,8 +837,12 @@ let api = function Binance() {
* @return {float} - number
*/
roundStep: function (qty, stepSize) {
const precision = stepSize.toString().split('.')[1].length || 0;
return ((Math.floor(qty / stepSize) | 0) * stepSize).toFixed(precision);
// Integers do not require rounding
if (Number.isInteger(qty)) return qty;
const qtyString = qty.toFixed(16);
const desiredDecimals = Math.max(stepSize.indexOf('1') - 1, 0);
const decimalIndex = qtyString.indexOf('.');
return parseFloat(qtyString.slice(0, decimalIndex + desiredDecimals + 1));
},

/**
Expand All @@ -831,7 +854,7 @@ let api = function Binance() {
roundTicks: function (price, tickSize) {
const formatter = new Intl.NumberFormat('en-US', { style: 'decimal', minimumFractionDigits: 0, maximumFractionDigits: 8 });
const precision = formatter.format(tickSize).split('.')[1].length || 0;
if ( typeof price === 'string' ) price = parseFloat(price);
if (typeof price === 'string') price = parseFloat(price);
return price.toFixed(precision);
},

Expand Down Expand Up @@ -1127,7 +1150,7 @@ let api = function Binance() {
},

/**
* Cancels an order
* Gets the status of an order
* @param {string} symbol - the symbol to check
* @param {string} orderid - the orderid to check
* @param {function} callback - the callback function
Expand Down Expand Up @@ -1188,7 +1211,7 @@ let api = function Binance() {
if (callback) return callback.call(this, error, data, symbol);
});
},

/**
* Gets the depth information for a given symbol
* @param {string} symbol - the symbol
Expand Down Expand Up @@ -1238,19 +1261,6 @@ let api = function Binance() {
});
},

/**
* Gets the depth information for a given symbol
* @param {string} symbol - the symbol
* @param {function} callback - the callback function
* @param {int} limit - limit the number of returned orders
* @return {undefined}
*/
depth: function (symbol, callback, limit = 100) {
publicRequest(base + 'v1/depth', { symbol: symbol, limit: limit }, function (error, data) {
return callback.call(this, error, depthData(data), symbol);
});
},

/**
* Gets the prices of a given symbol(s)
* @param {string} symbol - the symbol
Expand Down Expand Up @@ -1427,7 +1437,7 @@ let api = function Binance() {
* @return {undefined}
*/
tradeFee: function (callback, symbol = false) {
let params = symbol ? {symbol:symbol} : {};
let params = symbol ? { symbol: symbol } : {};
signedRequest(wapi + 'v3/tradeFee.html', params, callback);
},

Expand Down Expand Up @@ -1844,7 +1854,7 @@ let api = function Binance() {
* @param {int} stagger - ms between each depth cache
* @return {Promise} the websocket endpoint
*/
depthCacheStaggered: function(symbols, callback, limit=100, stagger=200) {
depthCacheStaggered: function (symbols, callback, limit = 100, stagger = 200) {
if (!Array.isArray(symbols)) symbols = [symbols];
let chain = null;

Expand Down
Loading

0 comments on commit ecf5403

Please sign in to comment.