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

Commit e65a006

Browse files
author
Jon Eyrick
authored
Add avgPrice functionality, fix for roundStep
2 parents ab0e0d0 + b0bbc16 commit e65a006

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

node-binance-api.js

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ let api = function Binance() {
819819
*/
820820
roundStep: function (qty, stepSize) {
821821
const precision = stepSize.toString().split('.')[1].length || 0;
822-
return ((Math.round(qty / stepSize) | 0) * stepSize).toFixed(precision);
822+
return ((Math.floor(qty / stepSize) | 0) * stepSize).toFixed(precision);
823823
},
824824

825825
/**
@@ -1188,6 +1188,55 @@ let api = function Binance() {
11881188
if (callback) return callback.call(this, error, data, symbol);
11891189
});
11901190
},
1191+
1192+
/**
1193+
* Gets the depth information for a given symbol
1194+
* @param {string} symbol - the symbol
1195+
* @param {function} callback - the callback function
1196+
* @param {int} limit - limit the number of returned orders
1197+
* @return {undefined}
1198+
*/
1199+
depth: function (symbol, callback, limit = 100) {
1200+
publicRequest(base + 'v1/depth', { symbol: symbol, limit: limit }, function (error, data) {
1201+
return callback.call(this, error, depthData(data), symbol);
1202+
});
1203+
},
1204+
1205+
/**
1206+
* Gets the average prices of a given symbol
1207+
* @param {string} symbol - the symbol
1208+
* @param {function} callback - the callback function
1209+
* @return {undefined}
1210+
*/
1211+
avgPrice: function (symbol, callback = false) {
1212+
let socksproxy = process.env.socks_proxy || false;
1213+
1214+
let opt = {
1215+
url: base + 'v3/avgPrice?symbol=' + symbol,
1216+
timeout: Binance.options.recvWindow
1217+
};
1218+
1219+
if (socksproxy !== false) {
1220+
socksproxy = proxyReplacewithIp(socksproxy);
1221+
if (Binance.options.verbose) Binance.options.log('using socks proxy server ' + socksproxy);
1222+
opt.agentClass = SocksProxyAgent;
1223+
opt.agentOptions = {
1224+
protocol: parseProxy(socksproxy)[0],
1225+
host: parseProxy(socksproxy)[1],
1226+
port: parseProxy(socksproxy)[2]
1227+
}
1228+
}
1229+
1230+
request(opt, function (error, response, body) {
1231+
if (!callback) return;
1232+
1233+
if (error) return callback(error);
1234+
1235+
if (response && response.statusCode !== 200) return callback(response);
1236+
1237+
if (callback) return callback(null, priceData(JSON.parse(body)));
1238+
});
1239+
},
11911240

11921241
/**
11931242
* Gets the depth information for a given symbol

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-binance-api",
3-
"version": "0.8.6",
3+
"version": "0.8.7",
44
"description": "Binance API for node https://github.com/jaggedsoft/node-binance-api",
55
"main": "node-binance-api.js",
66
"dependencies": {

0 commit comments

Comments
 (0)