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

Commit

Permalink
v0.4.0 - (Breaking:) Improved error handling, thanks hems and robaleman!
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Eyrick authored Jan 18, 2018
2 parents 3a0c754 + b30399d commit 719771b
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 91 deletions.
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# Node Binance API
This project is designed to help you make your own projects that interact with the [Binance API](https://www.binance.com/restapipub.html). You can stream candlestick chart data, market depth, or use other advanced features such as setting stop losses and iceberg orders. This project seeks to have complete API coverage including WebSockets.

### [Important: Breaking changes: See improvements in `v0.4.0` (Thanks hems and robaleman!)](https://github.com/jaggedsoft/node-binance-api/commit/b5d81071677227ff33041ae6b5e0ed42622f351a)

#### Installation
```
npm install node-binance-api --save
Expand Down Expand Up @@ -33,7 +35,7 @@ binance.options({

#### Getting latest price of a symbol
```javascript
binance.prices(function(ticker) {
binance.prices(function(error, ticker) {
console.log("prices()", ticker);
console.log("Price of BNB: ", ticker.BNBBTC);
});
Expand Down Expand Up @@ -107,7 +109,7 @@ binance.prices(function(ticker) {

#### Getting list of current balances
```javascript
binance.balance(function(balances) {
binance.balance(function(error, balances) {
console.log("balances()", balances);
console.log("ETH balance: ", balances.ETH.available);
});
Expand Down Expand Up @@ -172,7 +174,7 @@ binance.balance(function(balances) {

#### Getting bid/ask prices for a symbol
```javascript
binance.bookTickers(function(ticker) {
binance.bookTickers(function(error, ticker) {
console.log("bookTickers()", ticker);
console.log("Price of BNB: ", ticker.BNBBTC);
});
Expand Down Expand Up @@ -501,7 +503,7 @@ binance.bookTickers(function(ticker) {

#### Get all bid/ask prices
```javascript
binance.bookTickers(function(ticker) {
binance.bookTickers(function(error, ticker) {
console.log("bookTickers", ticker);
});
```
Expand Down Expand Up @@ -824,7 +826,7 @@ binance.bookTickers(function(ticker) {

#### Get market depth for a symbol
```javascript
binance.depth("BNBBTC", function(depth, symbol) {
binance.depth("BNBBTC", function(error, depth, symbol) {
console.log(symbol+" market depth", depth);
});
```
Expand Down Expand Up @@ -1104,7 +1106,7 @@ Market Buy response {
transactTime: 1509049376261,
price: '0.00000000',
origQty: '1.00000000',
utedQty: '1.00000000',
status: 'FILLED',
timeInForce: 'GTC',
Expand Down Expand Up @@ -1137,43 +1139,43 @@ binance.sell("ETHBTC", quantity, price, {icebergQty: 10});

#### Cancel an order
```javascript
binance.cancel("ETHBTC", orderid, function(response, symbol) {
binance.cancel("ETHBTC", orderid, function(error, response, symbol) {
console.log(symbol+" cancel response:", response);
});
```

#### Cancel all open orders
```js
binance.cancelOrders("XMRBTC", function(response, symbol) {
binance.cancelOrders("XMRBTC", function(error, response, symbol) {
console.log(symbol+" cancel response:", response);
});
```

#### Get open orders for a symbol
```javascript
binance.openOrders("ETHBTC", function(openOrders, symbol) {
binance.openOrders("ETHBTC", function(error, openOrders, symbol) {
console.log("openOrders("+symbol+")", openOrders);
});
```

#### Get list of all open orders
```javascript
binance.openOrders(false, function(openOrders) {
binance.openOrders(false, function(error, openOrders) {
console.log("openOrders()", openOrders);
});
```

#### Check an order's status
```javascript
let orderid = "7610385";
binance.orderStatus("ETHBTC", orderid, function(orderStatus, symbol) {
binance.orderStatus("ETHBTC", orderid, function(error, orderStatus, symbol) {
console.log(symbol+" order status:", orderStatus);
});
```

#### Trade history
```javascript
binance.trades("SNMBTC", function(trades, symbol) {
binance.trades("SNMBTC", function(error, trades, symbol) {
console.log(symbol+" trade history", trades);
});
```
Expand Down Expand Up @@ -1206,14 +1208,14 @@ binance.trades("SNMBTC", function(trades, symbol) {

#### Get all account orders; active, canceled, or filled.
```javascript
binance.allOrders("ETHBTC", function(orders, symbol) {
binance.allOrders("ETHBTC", function(error, orders, symbol) {
console.log(symbol+" orders:", orders);
});
```

#### Getting 24hr ticker price change statistics for a symbol
```javascript
binance.prevDay("BNBBTC", function(prevDay, symbol) {
binance.prevDay("BNBBTC", function(error, prevDay, symbol) {
console.log(symbol+" previous day:", prevDay);
console.log("BNB change since yesterday: "+prevDay.priceChangePercent+"%")
});
Expand All @@ -1225,7 +1227,7 @@ Optional parameters: limit (max/default 500), startTime, endTime.

```javascript
// Intervals: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M
binance.candlesticks("BNBBTC", "5m", function(ticks, symbol) {
binance.candlesticks("BNBBTC", "5m", function(error, ticks, symbol) {
console.log("candlesticks()", ticks);
let last_tick = ticks[ticks.length - 1];
let [time, open, high, low, close, volume, closeTime, assetVolume, trades, buyBaseVolume, buyAssetVolume, ignored] = last_tick;
Expand Down
22 changes: 11 additions & 11 deletions examples/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,58 @@ binance.options({
});

// Get bid/ask prices
//binance.allBookTickers(function(json) {
//binance.allBookTickers(function(error, json) {
// console.log("allBookTickers",json);
//});

// Getting latest price of a symbol
binance.prices(function(ticker) {
binance.prices(function(error, ticker) {
console.log("prices()", ticker);
console.log("Price of BNB: ", ticker.BNBBTC);
});

// Getting list of current balances
binance.balance(function(balances) {
binance.balance(function(error, balances) {
console.log("balances()", balances);
if ( typeof balances.ETH !== "undefined" ) {
console.log("ETH balance: ", balances.ETH.available);
}
});

// Getting bid/ask prices for a symbol
//binance.bookTickers(function(ticker) {
//binance.bookTickers(function(error, ticker) {
// console.log("bookTickers()", ticker);
// console.log("Price of BNB: ", ticker.BNBBTC);
//});

// Get market depth for a symbol
//binance.depth("SNMBTC", function(json) {
//binance.depth("SNMBTC", function(error, json) {
// console.log("market depth",json);
//});

// Getting list of open orders
//binance.openOrders("ETHBTC", function(json) {
//binance.openOrders("ETHBTC", function(error, json) {
// console.log("openOrders()",json);
//});

// Check an order's status
//let orderid = "7610385";
//binance.orderStatus("ETHBTC", orderid, function(json) {
//binance.orderStatus("ETHBTC", orderid, function(error, json) {
// console.log("orderStatus()",json);
//});

// Cancel an order
//binance.cancel("ETHBTC", orderid, function(response) {
//binance.cancel("ETHBTC", orderid, function(error, response) {
// console.log("cancel()",response);
//});

// Trade history
//binance.trades("SNMBTC", function(json) {
//binance.trades("SNMBTC", function(error, json) {
// console.log("trade history",json);
//});

// Get all account orders; active, canceled, or filled.
//binance.allOrders("ETHBTC", function(json) {
//binance.allOrders("ETHBTC", function(error, json) {
// console.log(json);
//});

Expand All @@ -71,7 +71,7 @@ binance.balance(function(balances) {
//binance.sell(symbol, quantity, 0, "MARKET");

// Periods: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M
binance.candlesticks("BNBBTC", "5m", function(ticks) {
binance.candlesticks("BNBBTC", "5m", function(error, ticks) {
console.log("candlesticks()", ticks);
let last_tick = ticks[ticks.length - 1];
let [time, open, high, low, close, volume, closeTime, assetVolume, trades, buyBaseVolume, buyAssetVolume, ignored] = last_tick;
Expand Down
Loading

0 comments on commit 719771b

Please sign in to comment.