Skip to content

Commit 549a07f

Browse files
authored
Merge pull request #12 from binance/v2.0.0
2 parents 95cd3a7 + ce63996 commit 549a07f

File tree

12 files changed

+1578
-694
lines changed

12 files changed

+1578
-694
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change log
22

3+
## 2.0.0 - 2025-11-06
4+
5+
### Updated
6+
- update connector dependencies to new connector
7+
- upgrade dependency packages
8+
39
## 1.2.2 - 2024-08-21
410

511
### Updated

README.md

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export BINANCE_FUTURES_API_SECRET=<the_api_secret>
3434
# For SPOT
3535
export SERVER=https://testnet.binance.vision
3636

37+
# For Websocket Streams
38+
export SERVER=wss://stream.binance.com:9443
39+
3740
# For Futures
3841
export FUTURES_SERVER=https://testnet.binancefuture.com
3942
# then the command request will be sent to the testnet.
@@ -62,58 +65,77 @@ binance-cli i | jq '.symbols[] | select(.symbol == "BNBUSDT") |.filters'
6265
```bash
6366
# binance-cli book <symbol>
6467
# binance-cli book -l <limit> <symbol>
65-
binance-cli book bnbusdt
66-
binance-cli book --limit 10 bnbusdt
68+
binance-cli book BNBUSDT
69+
binance-cli book --limit 10 BNBUSDT
6770
```
6871

6972
##### Get Trades
7073
```bash
7174
# binance-cli trades <symbol>
72-
binance-cli trades bnbusdt
73-
binance-cli trades -l 10 bnbusdt
75+
binance-cli trades BNBUSDT
76+
binance-cli trades -l 10 BNBUSDT
77+
```
78+
79+
##### UI Klines Data
80+
```bash
81+
# binance-cli ui_k <symbol> <interval>
82+
binance-cli ui_k BNBUSDT 1m
83+
binance-cli ui_k -l 1 BNBUSDT 1m
7484
```
7585

7686
##### Get Aggregate Trades List
7787
```bash
7888
# binance-cli at <symbol>
79-
binance-cli at bnbusdt
89+
binance-cli at BNBUSDT
8090

8191
# get aggregate Trades List with parameters
8292
# binance-cli at <symbol>
83-
binance-cli at --limit 10 --startTime 1595937694913 --endTime 1595937794913 bnbusdt
93+
binance-cli at --limit 10 --startTime 1595937694913 --endTime 1595937794913 BNBUSDT
8494
```
8595

8696
##### Get Klines Data
8797
```bash
8898
# binance-cli k <symbol> <interval>
89-
binance-cli k bnbusdt 1m
90-
binance-cli k -l 1 bnbusdt 1m
99+
binance-cli k BNBUSDT 1m
100+
binance-cli k -l 1 BNBUSDT 1m
91101

92102
```
93103
##### Get Average Price
94104
```bash
95105
# binance-cli ap <symbol>
96-
binance-cli ap bnbusdt
106+
binance-cli ap BNBUSDT
97107
```
98108

99-
##### Get 24hr Ticker
109+
##### Get Ticker
100110
```bash
101111
# binance-cli ticker -s <symbol>
102-
binance-cli ticker -s bnbusdt
112+
binance-cli ticker -s BNBUSDT
113+
```
114+
115+
##### Get 24hr Ticker
116+
```bash
117+
# binance-cli ticker24 -s <symbol>
118+
binance-cli ticker24 -s BNBUSDT
119+
```
120+
121+
##### Get Ticker Trading Day
122+
```bash
123+
# binance-cli td -s <symbol>
124+
binance-cli td -s BNBUSDT
103125
```
104126

105127
##### Get Ticker Price
106128
```bash
107129
binance-cli price
108130
# or with a symbol
109-
binance-cli price -s bnbusdt
131+
binance-cli price -s BNBUSDT
110132
```
111133

112134
##### Get Order Book Ticker
113135
```bash
114136
# binance-cli bt
115137
# binance-cli bt -s <symbol>
116-
binance-cli bt -s bnbusdt
138+
binance-cli bt -s BNBUSDT
117139
```
118140

119141
#### Listen To Streams
@@ -133,26 +155,30 @@ binance-cli buy -s BNBUSDT -t LIMIT -q 0.05 -p 350 -f GTC
133155
##### Sell
134156
```bash
135157
# place a limit sell order on BNBUSDT with price=500 and qty=0.03
136-
binance-cli sell -s bnbusdt -t limit -q 0.03 -p 500 -f GTC
158+
binance-cli sell -s BNBUSDT -t limit -q 0.03 -p 500 -f GTC
137159
```
138160

139161
##### Get Order Details
140162
```bash
141-
binance-cli get bnbusdt -i 12345
142-
binance-cli get bnbusdt -c my_order_123
163+
binance-cli get BNBUSDT -i 12345
164+
binance-cli get BNBUSDT -c my_order_123
143165
```
144166

145167
##### Cancel An Order
146168
```bash
147-
binance-cli cancel bnbusdt -i 12345
148-
binance-cli cancel bnbusdt -c my_order_123
169+
binance-cli cancel BNBUSDT -i 12345
170+
binance-cli cancel BNBUSDT -c my_order_123
149171
```
150172

151173
##### Cancel All Open Orders
152174
```bash
153-
binance-cli cancel_all bnbusdt
175+
binance-cli cancel_all BNBUSDT
154176
```
155177

178+
##### Get Account Information
179+
```bash
180+
binance-cli account
181+
```
156182

157183

158184
### UM Futures

bin/binance-cli.js

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,43 @@ program
225225
.option('-u, --quoteOrderQty [quoteOrderQty]', 'For market order, please see details from API document.')
226226
.action(async (args) => await Trade.newOrder({ side: 'SELL', ...args }))
227227

228-
// get 24hr ticker data
228+
// get latest price for a symbol or symbols
229229
//
230230
// binance-cli ticker -s <symbol>
231231
//
232232
// Example:
233233
// - `binance-cli ticker -s bnbusdt`
234234
program
235235
.command('ticker')
236-
.description('Get 24hr ticker data')
236+
.description('Get latest price for a symbol or symbols')
237237
.option('-s, --symbol <symbol>', 'trading symbol, e.g. bnbusdt')
238238
.action(async (args) => await Market.ticker(args))
239239

240+
// get 24hr ticker data
241+
//
242+
// binance-cli ticker24 -s <symbol>
243+
//
244+
// Example:
245+
// - `binance-cli ticker24 -s bnbusdt`
246+
program
247+
.command('ticker24')
248+
.description('Get 24hr ticker data')
249+
.option('-s, --symbol <symbol>', 'trading symbol, e.g. bnbusdt')
250+
.action(async (args) => await Market.ticker24hr(args))
251+
252+
// get Price change statistics for a trading day
253+
//
254+
// binance-cli ticker_day -s <symbol>
255+
//
256+
// Example:
257+
// - `binance-cli ticker_day -s bnbusdt`
258+
program
259+
.command('ticker_day')
260+
.alias('td')
261+
.description('Get Price change statistics for a trading day')
262+
.option('-s, --symbol <symbol>', 'trading symbol, e.g. bnbusdt')
263+
.action(async (args) => await Market.tickerTradingDay(args))
264+
240265
// get current server time
241266
//
242267
// Example:
@@ -259,6 +284,24 @@ program
259284
.option('-l, --limit <limit>', 'Default 500; max 1000.')
260285
.action(async (symbol, args) => await Market.trades(symbol, args.limit))
261286

287+
// get UIKlines data
288+
//
289+
// binance-cli uik <symbol> <interval>
290+
//
291+
// Example:
292+
// - `binance-cli ui_k bnbusdt 1m`
293+
// - `binance-cli ui_k -l 10 -s 1722336104001 -e 1722336214030 bnbusdt 3m`
294+
program
295+
.command('uiklines')
296+
.description('Get UI Kline/Candlestick data')
297+
.alias('ui_k')
298+
.argument('<symbol>', 'trading symbol, e.g. bnbusdt')
299+
.argument('<interval>', 'kline interval, values: 1m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w, 1M')
300+
.option('-l, --limit <limit>', 'Default 500; max 1000.')
301+
.option('-s, --startTime <startTime>', 'Timestamp in ms to get aggregate trades from INCLUSIVE.')
302+
.option('-e, --endTime <endTime>', 'Timestamp in ms to get aggregate trades until INCLUSIVE.')
303+
.action(async (symbol, interval, args) => await Market.uiKlines(symbol, interval, args))
304+
262305
// Futures UM
263306

264307
// get current UM futures server time

commands/futures/cm/market.js

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
1-
const { CMFutures } = require("@binance/futures-connector")
1+
const {
2+
DerivativesTradingCoinFutures,
3+
DERIVATIVES_TRADING_COIN_FUTURES_REST_API_PROD_URL
4+
} = require("@binance/derivatives-trading-coin-futures")
25
const { print, printError } = require('../../../helpers/prettyPrint')
36
const { checkAPIKey } = require('../../../helpers/util')
47

5-
const apiKey = process.env.BINANCE_FUTURES_API_KEY
6-
const server = process.env.FUTURES_SERVER || "https://dapi.binance.com"
8+
const configurationRestAPI = {
9+
apiKey: process.env.BINANCE_FUTURES_API_KEY,
10+
basePath: process.env.FUTURES_SERVER || DERIVATIVES_TRADING_COIN_FUTURES_REST_API_PROD_URL
11+
}
712

8-
const cmFuturesClient = new CMFutures(apiKey, null, { baseURL: server })
13+
const client = new DerivativesTradingCoinFutures({ configurationRestAPI })
914

10-
const time = async () =>
11-
cmFuturesClient.getTime().then(response => print(response.data))
12-
.catch(error => print(error))
15+
const time = async () => client.restAPI.checkServerTime().then(async response => print(await response.data()))
16+
.catch(error => print(error))
1317

1418
const exchangeInfo = async () =>
15-
cmFuturesClient.getExchangeInfo().then(response => print(response.data))
19+
client.restAPI.exchangeInformation().then(async response => print(await response.data()))
1620
.catch(error => print(error))
1721

1822
const depth = async (symbol, limit = 100) => {
1923
try {
20-
const result = await cmFuturesClient.getDepth(symbol, Number.parseInt(limit, 10))
21-
print(result.data)
24+
const result = await client.restAPI.orderBook({ symbol, limit: Number.parseInt(limit, 10) })
25+
const data = await result.data()
26+
print(data)
2227
} catch (e) {
2328
printError(e)
2429
}
2530
}
2631

2732
const trades = async (symbol, limit = 500) => {
2833
try {
29-
const result = await cmFuturesClient.getTrades(symbol, Number.parseInt(limit, 10))
30-
print(result.data)
34+
const result = await client.restAPI.recentTradesList({ symbol, limit: Number.parseInt(limit, 10) })
35+
const data = await result.data()
36+
print(data)
3137
} catch (e) {
3238
printError(e)
3339
}
@@ -36,8 +42,9 @@ const trades = async (symbol, limit = 500) => {
3642
const histTrades = async (symbol, {limit, fromId}) => {
3743
if (checkAPIKey(apiKey)) {
3844
try {
39-
const result = await cmFuturesClient.getHistoricalTrades(symbol, Number.parseInt(limit, 10), fromId)
40-
print(result.data)
45+
const result = await client.restAPI.oldTradesLookup({symbol, limit: Number.parseInt(limit, 10), fromId})
46+
const data = await result.data()
47+
print(data)
4148
} catch (e) {
4249
printError(e)
4350
}
@@ -46,44 +53,57 @@ const histTrades = async (symbol, {limit, fromId}) => {
4653

4754
const aggTrades = async (symbol, { fromId, startTime, endTime, limit }) => {
4855
try {
49-
const result = await cmFuturesClient.getAggTrades(symbol, fromId, startTime, endTime, Number.parseInt(limit) )
50-
print(result.data)
56+
let param = {}
57+
if (limit) param.limit = Number.parseInt(limit)
58+
59+
const result = await client.restAPI.compressedAggregateTradesList(
60+
{ symbol, fromId, startTime, endTime, ...param }
61+
)
62+
const data = await result.data()
63+
print(data)
5164
} catch (e) {
5265
printError(e)
5366
}
5467
}
5568

5669
const klines = async (symbol, interval, { startTime, endTime, limit }) => {
5770
try {
58-
const result = await cmFuturesClient.getKlines(symbol, interval, startTime, endTime, Number.parseInt(limit))
59-
print(result.data)
71+
let param = {}
72+
if (limit) param.limit = Number.parseInt(limit)
73+
74+
const result = await client.restAPI.klineCandlestickData({ symbol, interval, startTime, endTime, ...param })
75+
const data = await result.data()
76+
print(data)
6077
} catch (e) {
6178
printError(e)
6279
}
6380
}
6481

6582
const ticker = async ({ symbol }) => {
6683
try {
67-
const result = await cmFuturesClient.get24hrTicker(symbol)
68-
print(result.data)
84+
const result = await client.restAPI.ticker24hrPriceChangeStatistics({ symbol })
85+
const data = await result.data()
86+
print(data)
6987
} catch (e) {
7088
printError(e)
7189
}
7290
}
7391

7492
const tickerPrice = async ({ symbol }) => {
7593
try {
76-
const result = await cmFuturesClient.getPriceTicker(symbol)
77-
print(result.data)
94+
const result = await client.restAPI.symbolPriceTicker({ symbol })
95+
const data = await result.data()
96+
print(data)
7897
} catch (e) {
7998
printError(e)
8099
}
81100
}
82101

83102
const bookTicker = async ({ symbol }) => {
84103
try {
85-
const result = await cmFuturesClient.getBookTicker(symbol)
86-
print(result.data)
104+
const result = await client.restAPI.symbolOrderBookTicker({ symbol })
105+
const data = await result.data()
106+
print(data)
87107
} catch (e) {
88108
printError(e)
89109
}

0 commit comments

Comments
 (0)