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

Commit f30d372

Browse files
authored
Now supporting Promises, Futures, Margin, and OCO
2 parents d9209f3 + f9c95e8 commit f30d372

6 files changed

Lines changed: 5399 additions & 1031 deletions

File tree

README.md

Lines changed: 110 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
[![Latest Version](https://img.shields.io/github/release/jaggedsoft/node-binance-api.svg?style=flat-square)](https://github.com/jaggedsoft/node-binance-api/releases)
2-
[![GitHub last commit](https://img.shields.io/github/last-commit/jaggedsoft/node-binance-api.svg?maxAge=2400)](#)
3-
[![npm downloads](https://img.shields.io/npm/dt/node-binance-api.svg?maxAge=7200)](https://www.npmjs.com/package/node-binance-api)
4-
[![jaggedsoft on Twitter](https://img.shields.io/twitter/follow/jaggedsoft.svg?style=social)](https://twitter.com/jaggedsoft)
1+
[![Latest Version](https://img.shields.io/github/release/jaggedsoft/node-binance-api.svg?style=flat-square)](https://github.com/jaggedsoft/node-binance-api/releases) [![GitHub last commit](https://img.shields.io/github/last-commit/jaggedsoft/node-binance-api.svg?maxAge=2400)](#) <!-- [![npm downloads](https://img.shields.io/npm/dt/node-binance-api.svg?maxAge=7200)](https://www.npmjs.com/package/node-binance-api) --> [![jaggedsoft on Twitter](https://img.shields.io/twitter/follow/jaggedsoft.svg?style=social)](https://twitter.com/jaggedsoft)
52

63
[![NPM](https://nodei.co/npm/node-binance-api.png?compact=true)](https://npmjs.org/package/node-binance-api)
74

8-
[![Build Status](https://travis-ci.org/jaggedsoft/node-binance-api.svg?branch=master&style=flat-square)](https://travis-ci.org/jaggedsoft/node-binance-api)
9-
[![Coverage Status](https://coveralls.io/repos/github/jaggedsoft/node-binance-api/badge.svg?branch=master&style=flat-square)](https://coveralls.io/github/jaggedsoft/node-binance-api)
10-
[![CodeCov](https://codecov.io/gh/jaggedsoft/node-binance-api/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/github/jaggedsoft/node-binance-api/)
11-
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/996757cec66542c0a64fca2b4cf8a936)](https://www.codacy.com/app/dmzoneill/node-binance-api?utm_source=github.com&utm_medium=referral&utm_content=jaggedsoft/node-binance-api&utm_campaign=Badge_Coverage)
12-
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/996757cec66542c0a64fca2b4cf8a936)](https://www.codacy.com/app/dmzoneill/node-binance-api?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=jaggedsoft/node-binance-api&amp;utm_campaign=Badge_Grade)
5+
[![Build Status](https://travis-ci.org/jaggedsoft/node-binance-api.svg?branch=master&style=flat-square)](https://travis-ci.org/jaggedsoft/node-binance-api) [![Coverage Status](https://coveralls.io/repos/github/jaggedsoft/node-binance-api/badge.svg?branch=master&style=flat-square)](https://coveralls.io/github/jaggedsoft/node-binance-api) [![CodeCov](https://codecov.io/gh/jaggedsoft/node-binance-api/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/github/jaggedsoft/node-binance-api/) <!-- [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/996757cec66542c0a64fca2b4cf8a936)](https://www.codacy.com/app/jaggedsoft/node-binance-api?utm_source=github.com&utm_medium=referral&utm_content=jaggedsoft/node-binance-api&utm_campaign=Badge_Coverage) --> [![Codacy Grade](https://api.codacy.com/project/badge/Grade/996757cec66542c0a64fca2b4cf8a936)](https://www.codacy.com/app/jaggedsoft/node-binance-api)
136

147
# Node Binance API
158
This project is designed to help you make your own projects that interact with the [Binance API](https://github.com/binance-exchange/binance-official-api-docs). 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.
9+
**Now supporting Promises, Margin, Futures and OCO**
1610

1711
#### Installation
1812
```
@@ -21,25 +15,58 @@ npm install node-binance-api --save
2115

2216
#### Getting started
2317
```javascript
24-
const binance = require('node-binance-api')().options({
18+
const Binance = require('node-binance-api');
19+
const binance = new Binance().options({
2520
APIKEY: '<key>',
26-
APISECRET: '<secret>',
27-
useServerTime: true // If you get timestamp errors, synchronize to server time at startup
21+
APISECRET: '<secret>'
2822
});
2923
```
3024

31-
#### Getting latest price of a symbol
25+
# Binance Futures API
26+
> **Work in progress, including documentation. Promises only**
3227
```js
33-
binance.prices('BNBBTC', (error, ticker) => {
34-
console.log("Price of BNB: ", ticker.BNBBTC);
35-
});
28+
console.info( await binance.futuresPrices() );
29+
console.info( await binance.futuresTime() );
30+
console.info( await binance.futuresExchangeInfo() );
31+
console.info( await binance.futuresCandles( "TRXUSDT", "1m" ) );
32+
console.info( await binance.futuresDepth( "ADAUSDT" ) );
33+
console.info( await binance.futuresQuote() );
34+
console.info( await binance.futuresQuote( "BCHUSDT" ) );
35+
console.info( await binance.futuresDaily() );
36+
console.info( await binance.futuresOpenInterest( "BTCUSDT" ) );
37+
console.info( await binance.futuresMarkPrice() );
38+
console.info( await binance.futuresMarkPrice( "ETHUSDT" ) );
39+
console.info( await binance.futuresTrades( "LTCUSDT" ) );
40+
console.info( await binance.futuresAggTrades( "XTZUSDT" ) );
41+
console.info( await binance.futuresLiquidationOrders() );
42+
console.info( await binance.futuresFundingRate() );
43+
console.info( await binance.futuresHistoricalTrades( "XMRUSDT" ) );
44+
console.info( await binance.futuresLeverageBracket( "LINKUSDT" ) );
45+
46+
/* Currently in development:
47+
futuresMarketBuy
48+
futuresMarketSell
49+
futuresOrderStatus
50+
futuresOrder: private 'v1/order'
51+
futuresCancelOrder: private 'v1/order' 'DELETE'
52+
futuresOpenOrders: private 'v1/openOrders'
53+
futuresPositionRisk: private 'v1/positionRisk'
54+
futuresGetDataStream: private 'v1/listenKey' 'POST'
55+
futuresKeepDataStream: private 'v1/listenKey' 'PUT'
56+
futuresCloseDataStream: private 'v1/listenKey' 'DELETE'
57+
Futures WebSockets */
3658
```
3759

3860
#### Getting latest price of all symbols
3961
```javascript
40-
binance.prices((error, ticker) => {
41-
console.log("prices()", ticker);
42-
console.log("Price of BTC: ", ticker.BTCUSDT);
62+
let ticker = await binance.prices();
63+
console.log(`Price of BNB: ${ticker.BNBUSDT}`);
64+
```
65+
66+
#### Getting latest price of a symbol
67+
```js
68+
binance.prices('BNBBTC', (error, ticker) => {
69+
console.log("Price of BNB: ", ticker.BNBBTC);
4370
});
4471
```
4572
<details>
@@ -1563,23 +1590,72 @@ let amount = 0.1;
15631590
binance.withdraw("XMR", address, amount, addressTag);
15641591
```
15651592

1566-
#### Withdraw with Callback
1593+
#### Withdraw
15671594
```js
1568-
binance.withdraw("ETH", "0x1d2034348c851ea29c7d03731c7968a5bcc91564", 1, false, (error, response) => {
1569-
console.log(response);
1595+
binance.withdraw("BTC", "1C5gqLRs96Xq4V2ZZAR1347yUCpHie7sa", 0.2);
1596+
```
1597+
1598+
# Binance Margin API
1599+
1600+
#### Transfer from Main account to Margin account
1601+
```js
1602+
binance.mgTransferMainToMargin(asset, amount, (error, response) => {
1603+
if ( error ) return console.warn(error);
1604+
// Success! Transaction ID: response.tranId
1605+
});
1606+
1607+
```
1608+
#### Transfer from Margin account to Main account
1609+
```js
1610+
binance.mgTransferMarginToMain(asset, amount, (error, response) => {
1611+
if ( error ) return console.warn(error);
1612+
// Success! Transaction ID: response.tranId
15701613
});
15711614
```
15721615

1573-
#### Withdraw
1616+
#### Borrow from margin account
15741617
```js
1575-
binance.withdraw("BTC", "1C5gqLRs96Xq4V2ZZAR1347yUCpHie7sa", 0.2);
1618+
binance.mgBorrow(asset, amount, (error, response) => {
1619+
if ( error ) return console.warn(error);
1620+
// Success! Transaction ID: response.tranId
1621+
});
1622+
```
1623+
1624+
#### Repay margin account
1625+
```js
1626+
binance.mgRepay(asset, amount, (error, response) => {
1627+
if ( error ) return console.warn(error);
1628+
// Success! Transaction ID: response.tranId
1629+
});
15761630
```
15771631

1578-
#### Withdraw with custom name
1632+
#### Margin BUY and SELL orders
1633+
Instead of `binance.buy()` use `binance.mgBuy()` and instead of `binance.sell()` use `binance.mgSell()`.
1634+
1635+
For market orders use `binance.mgMarketBuy()` and `binance.mgMarketSell()`.
1636+
1637+
Usage and callbacks are the same as the 'regular account' counterparts.
1638+
1639+
#### Cancel a margin order
1640+
```javascript
1641+
binance.mgCancel("ETHBTC", orderid, (error, response, symbol) => {
1642+
console.log(symbol+" cancel response:", response);
1643+
});
1644+
```
1645+
1646+
#### Cancel all open margin orders
15791647
```js
1580-
// let name = false // Falsy value won't save address to address book
1581-
let name = 'My Withdrawal Address'
1582-
binance.withdraw("BTC", "1C5gqLRs96Xq4V2ZZAR1347yUCpHie7sa", 0.2, undefined, name)
1648+
binance.mgCancelOrders("XMRBTC", (error, response, symbol) => {
1649+
console.log(symbol+" cancel response:", response);
1650+
});
1651+
```
1652+
1653+
#### Check a margin order's status
1654+
```javascript
1655+
let orderid = "7610385";
1656+
binance.mgOrderStatus("ETHBTC", orderid, (error, orderStatus, symbol) => {
1657+
console.log(symbol+" order status:", orderStatus);
1658+
});
15831659
```
15841660

15851661
#### [Advanced Examples](https://github.com/jaggedsoft/node-binance-api/blob/master/examples/advanced.md)
@@ -1592,39 +1668,8 @@ binance.withdraw("BTC", "1C5gqLRs96Xq4V2ZZAR1347yUCpHie7sa", 0.2, undefined, nam
15921668
[Recent Trades (historicalTrades, recentTrades, aggTrades functions)](https://github.com/jaggedsoft/node-binance-api/blob/master/examples/advanced.md#recent-trades-historicaltrades-recenttrades-aggtrades-functions)\
15931669
[Terminate WebSocket connections](https://github.com/jaggedsoft/node-binance-api/blob/master/examples/advanced.md#terminate-websocket-connections)\
15941670
[User Data: Account Balance Updates, Trade Updates, New Orders, Filled Orders, Cancelled Orders via WebSocket](https://github.com/jaggedsoft/node-binance-api/blob/master/examples/advanced.md#user-data-account-balance-updates-trade-updates-new-orders-filled-orders-cancelled-orders-via-websocket)
1595-
1596-
1597-
### Proxy Support
1598-
For the standard REST API the https_proxy or socks_proxy variable is honoured
1599-
*NOTE* proxy package has no dns name support, please use proxy IP address
1600-
1601-
**Linux**
1602-
```bash
1603-
export https_proxy=http://ip:port
1604-
#export socks_proxy=socks://ip:port
1605-
# run your app
1606-
```
1607-
1608-
**Windows**
1609-
```bash
1610-
set https_proxy=http://ip:port
1611-
#set socks_proxy=socks://ip:port
1612-
# run your app
1613-
```
1614-
1615-
For web sockets currently only the socks method is functional at this time
1616-
1617-
**linux**
1618-
```bash
1619-
export socks_proxy=socks://ip:port
1620-
# run your app
1621-
```
1622-
1623-
**windows**
1624-
```bash
1625-
set socks_proxy=socks://ip:port
1626-
# run your app
1627-
```
1671+
[Margin User Data: Account Balance Updates, Trade Updates, New Orders, Filled Orders, Cancelled Orders via WebSocket](https://github.com/jaggedsoft/node-binance-api/blob/master/examples/advanced.md#margin-user-data-account-balance-updates-trade-updates-new-orders-filled-orders-cancelled-orders-via-websocket)
1672+
[Asynchronous Syntax Options](https://github.com/jaggedsoft/node-binance-api/blob/master/examples/advanced.md#asynchronous-syntax-options)
16281673

16291674
### Troubleshooting
16301675
Verify that your system time is correct. If you have any suggestions don't hesitate to file an issue.
@@ -1645,7 +1690,7 @@ binance.options({
16451690

16461691
Problems getting your balance? Wrap the entry point of your application in useServerTime:
16471692
```js
1648-
binance.useServerTime(function() {
1693+
binance.useServerTime(() => {
16491694
binance.balance((error, balances) => {
16501695
if ( error ) return console.error(error);
16511696
console.log("balances()", balances);
@@ -1654,16 +1699,12 @@ binance.useServerTime(function() {
16541699
});
16551700
```
16561701

1657-
Thank you to all contributors: bmino, dmzoneill, dmitriz, keith1024, pavlovdog, usama33, yanislk, learnathoner, vaielab, nickreese, Tuitio, grandmore, itnok, CollinEstes, sethyx, mstijak, MadDeveloper, balthazar, bitoiu, matthewwoop, robaleman, hems and others!
1658-
1659-
> # ⚠️ Binance no longer offers support for API projects.
1660-
> ## No support is offered. No questions will be answered. Pull requests are still welcome.
1661-
1702+
> ### For support go to [Telegram](https://t.me/binance_api_english)
16621703
1663-
## Stargazers over time
1704+
***Thank you to all contributors:*** Eluvade, dbvcode, bmino, dmzoneill, dmitriz, keith1024, pavlovdog, usama33, yanislk, learnathoner, vaielab, nickreese, Tuitio, grandmore, itnok, CollinEstes, sethyx, mstijak, MadDeveloper, balthazar, bitoiu, matthewwoop, robaleman, hems and others!
16641705

1706+
![Downloads](https://img.shields.io/npm/dt/node-binance-api.svg?style=for-the-badge&maxAge=86400) ![Stars](https://img.shields.io/github/stars/jaggedsoft/node-binance-api.svg?style=for-the-badge&label=Stars) ![Contributors](https://img.shields.io/github/contributors/jaggedsoft/node-binance-api.svg?style=for-the-badge&maxAge=86400)
16651707
[![Stargazers over time](https://starcharts.herokuapp.com/jaggedsoft/node-binance-api.svg)](https://starcharts.herokuapp.com/jaggedsoft/node-binance-api)
16661708

16671709
[![Views](http://hits.dwyl.io/jaggedsoft/node-binance-api.svg)](http://hits.dwyl.io/jaggedsoft/node-binance-api)
16681710
[![jaggedsoft on Twitter](https://img.shields.io/twitter/follow/jaggedsoft.svg?style=social)](https://twitter.com/jaggedsoft)
1669-
[![Chartaholic on Twitter](https://img.shields.io/twitter/follow/Chartaholic.svg?style=social)](https://twitter.com/Chartaholic)

async.js

Lines changed: 0 additions & 115 deletions
This file was deleted.

0 commit comments

Comments
 (0)