Skip to content

Commit a7cd063

Browse files
committed
format document
1 parent caac710 commit a7cd063

1 file changed

Lines changed: 133 additions & 112 deletions

File tree

test/static-tests.js

Lines changed: 133 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,24 @@ test.serial.beforeEach(t => {
2727
nock(/.*/)
2828
.get(/.*/)
2929
.reply(200, function (uri, requestBody) {
30-
interceptedUrl = `${this.req.options.proto}://${this.req.options.hostname}${uri}`;
30+
interceptedUrl = `${this.req.options.proto}://${this.req.options.hostname}${uri}`;
3131
interceptedBody = requestBody;
3232
return { success: true };
3333
});
3434
nock(/.*/)
3535
.post(/.*/)
3636
.reply(200, function (uri, requestBody) {
37-
interceptedUrl = `${this.req.options.proto}://${this.req.options.hostname}${uri}`;
37+
interceptedUrl = `${this.req.options.proto}://${this.req.options.hostname}${uri}`;
3838
interceptedBody = requestBody;
3939
return { success: true };
4040
});
4141
nock(/.*/)
4242
.delete(/.*/)
4343
.reply(200, function (uri, requestBody) {
44-
interceptedUrl = `${this.req.options.proto}://${this.req.options.hostname}${uri}`;
44+
interceptedUrl = `${this.req.options.proto}://${this.req.options.hostname}${uri}`;
4545
interceptedBody = requestBody;
4646
return { success: true };
47-
});
47+
});
4848
});
4949

5050
test.serial('[Rest] Spot demo url', async t => {
@@ -87,35 +87,35 @@ test.serial('[REST] Futures Orderbook', async t => {
8787
})
8888

8989
test.serial('[REST] OHLCVS', async t => {
90-
try {
91-
await binance.candles({ symbol: 'BTCUSDT' })
92-
} catch (e) {
93-
// it can throw an error because of the mocked response
94-
}
95-
t.true(interceptedUrl.startsWith('https://api.binance.com/api/v3/klines?interval=5m&symbol=BTCUSDT'))
90+
try {
91+
await binance.candles({ symbol: 'BTCUSDT' })
92+
} catch (e) {
93+
// it can throw an error because of the mocked response
94+
}
95+
t.true(interceptedUrl.startsWith('https://api.binance.com/api/v3/klines?interval=5m&symbol=BTCUSDT'))
9696
})
9797

9898
test.serial('[REST] Futures OHLCVS', async t => {
99-
try {
100-
await binance.futuresCandles({ symbol: 'BTCUSDT', interval: '30m' })
101-
} catch (e) {
102-
// it can throw an error because of the mocked response
103-
}
104-
t.is(interceptedUrl, 'https://fapi.binance.com/fapi/v1/klines?interval=30m&symbol=BTCUSDT')
99+
try {
100+
await binance.futuresCandles({ symbol: 'BTCUSDT', interval: '30m' })
101+
} catch (e) {
102+
// it can throw an error because of the mocked response
103+
}
104+
t.is(interceptedUrl, 'https://fapi.binance.com/fapi/v1/klines?interval=30m&symbol=BTCUSDT')
105105
})
106106

107107
test.serial('[REST] Recent Trades', async t => {
108-
await binance.trades({ symbol: 'BTCUSDT', limit: 500 })
109-
t.is(interceptedUrl, 'https://api.binance.com/api/v3/trades?symbol=BTCUSDT&limit=500')
108+
await binance.trades({ symbol: 'BTCUSDT', limit: 500 })
109+
t.is(interceptedUrl, 'https://api.binance.com/api/v3/trades?symbol=BTCUSDT&limit=500')
110110
})
111111

112112
test.serial('[REST] Agg Trades', async t => {
113-
try {
114-
await binance.aggTrades({ symbol: 'BTCUSDT' })
115-
} catch (e) {
113+
try {
114+
await binance.aggTrades({ symbol: 'BTCUSDT' })
115+
} catch (e) {
116116
// it can throw an error because of the mocked response
117-
}
118-
t.is(interceptedUrl, 'https://api.binance.com/api/v3/aggTrades?symbol=BTCUSDT')
117+
}
118+
t.is(interceptedUrl, 'https://api.binance.com/api/v3/aggTrades?symbol=BTCUSDT')
119119
})
120120

121121
test.serial('[REST] FuturesTrades', async t => {
@@ -128,139 +128,160 @@ test.serial('[REST] FuturesTrades', async t => {
128128
})
129129

130130
test.serial('[REST] FuturesAggTrades', async t => {
131-
try {
131+
try {
132132
await binance.futuresAggTrades({ symbol: 'BTCUSDT' })
133-
} catch (e) {
134-
// it can throw an error because of the mocked response
135-
}
136-
t.is(interceptedUrl, 'https://fapi.binance.com/fapi/v1/aggTrades?symbol=BTCUSDT')
133+
} catch (e) {
134+
// it can throw an error because of the mocked response
135+
}
136+
t.is(interceptedUrl, 'https://fapi.binance.com/fapi/v1/aggTrades?symbol=BTCUSDT')
137137
})
138138

139139
test.serial('[REST] PositionRisk V2', async t => {
140-
await binance.futuresPositionRisk()
141-
t.true(interceptedUrl.startsWith('https://fapi.binance.com/fapi/v2/positionRisk'))
140+
await binance.futuresPositionRisk()
141+
t.true(interceptedUrl.startsWith('https://fapi.binance.com/fapi/v2/positionRisk'))
142142
})
143143

144144

145145
test.serial('[REST] CancelOrder', async t => {
146-
await binance.cancelOrder({ symbol: 'LTCUSDT', orderId: '34234234' })
147-
t.true(interceptedUrl.startsWith('https://api.binance.com/api/v3/order'))
148-
const obj = urlToObject(interceptedUrl.replace('https://api.binance.com/api/v3/order', ''))
149-
t.is(obj.symbol, 'LTCUSDT')
150-
t.is(obj.orderId, '34234234')
146+
await binance.cancelOrder({ symbol: 'LTCUSDT', orderId: '34234234' })
147+
t.true(interceptedUrl.startsWith('https://api.binance.com/api/v3/order'))
148+
const obj = urlToObject(interceptedUrl.replace('https://api.binance.com/api/v3/order', ''))
149+
t.is(obj.symbol, 'LTCUSDT')
150+
t.is(obj.orderId, '34234234')
151151
})
152152

153153
test.serial('[REST] Futures CancelOrder', async t => {
154-
await binance.futuresCancelOrder({ symbol: 'LTCUSDT', orderId: '34234234' })
155-
t.true(interceptedUrl.startsWith('https://fapi.binance.com/fapi/v1/order'))
156-
const obj = urlToObject(interceptedUrl.replace('https://fapi.binance.com/fapi/v1/order', ''))
157-
t.is(obj.symbol, 'LTCUSDT')
158-
t.is(obj.orderId, '34234234')
154+
await binance.futuresCancelOrder({ symbol: 'LTCUSDT', orderId: '34234234' })
155+
t.true(interceptedUrl.startsWith('https://fapi.binance.com/fapi/v1/order'))
156+
const obj = urlToObject(interceptedUrl.replace('https://fapi.binance.com/fapi/v1/order', ''))
157+
t.is(obj.symbol, 'LTCUSDT')
158+
t.is(obj.orderId, '34234234')
159159
})
160160

161161

162162
test.serial('[REST] MarketBuy', async t => {
163-
await binance.order({ symbol: 'LTCUSDT', side: 'BUY', type: 'MARKET', quantity: 0.5 })
164-
t.true(interceptedUrl.startsWith('https://api.binance.com/api/v3/order'))
165-
const body = interceptedUrl.replace('https://api.binance.com/api/v3/order', '')
166-
const obj = urlToObject(body)
167-
t.is(obj.symbol, 'LTCUSDT')
168-
t.is(obj.side, 'BUY')
169-
t.is(obj.type, 'MARKET')
170-
t.is(obj.quantity, '0.5')
163+
await binance.order({ symbol: 'LTCUSDT', side: 'BUY', type: 'MARKET', quantity: 0.5 })
164+
t.true(interceptedUrl.startsWith('https://api.binance.com/api/v3/order'))
165+
const body = interceptedUrl.replace('https://api.binance.com/api/v3/order', '')
166+
const obj = urlToObject(body)
167+
t.is(obj.symbol, 'LTCUSDT')
168+
t.is(obj.side, 'BUY')
169+
t.is(obj.type, 'MARKET')
170+
t.is(obj.quantity, '0.5')
171171
})
172172

173173
test.serial('[REST] MarketSell', async t => {
174-
await binance.order({ symbol: 'LTCUSDT', side: 'SELL', type: 'MARKET', quantity: 0.5 })
174+
await binance.order({ symbol: 'LTCUSDT', side: 'SELL', type: 'MARKET', quantity: 0.5 })
175175
t.true(interceptedUrl.startsWith('https://api.binance.com/api/v3/order'))
176176
const body = interceptedUrl.replace('https://api.binance.com/api/v3/order', '')
177-
const obj = urlToObject(body)
178-
t.is(obj.symbol, 'LTCUSDT')
179-
t.is(obj.side, 'SELL')
180-
t.is(obj.type, 'MARKET')
181-
t.is(obj.quantity, '0.5')
177+
const obj = urlToObject(body)
178+
t.is(obj.symbol, 'LTCUSDT')
179+
t.is(obj.side, 'SELL')
180+
t.is(obj.type, 'MARKET')
181+
t.is(obj.quantity, '0.5')
182182
})
183183

184184
test.serial('[REST] LimitBuy', async t => {
185-
await binance.order({ symbol: 'LTCUSDT', side: 'BUY', type: 'LIMIT', quantity: 0.5, price: 100 })
186-
t.true(interceptedUrl.startsWith('https://api.binance.com/api/v3/order'))
187-
const body = interceptedUrl.replace('https://api.binance.com/api/v3/order', '')
188-
const obj = urlToObject(body)
189-
t.is(obj.symbol, 'LTCUSDT')
190-
t.is(obj.side, 'BUY')
191-
t.is(obj.type, 'LIMIT')
192-
t.is(obj.quantity, '0.5')
185+
await binance.order({ symbol: 'LTCUSDT', side: 'BUY', type: 'LIMIT', quantity: 0.5, price: 100 })
186+
t.true(interceptedUrl.startsWith('https://api.binance.com/api/v3/order'))
187+
const body = interceptedUrl.replace('https://api.binance.com/api/v3/order', '')
188+
const obj = urlToObject(body)
189+
t.is(obj.symbol, 'LTCUSDT')
190+
t.is(obj.side, 'BUY')
191+
t.is(obj.type, 'LIMIT')
192+
t.is(obj.quantity, '0.5')
193193
})
194194

195195
test.serial('[REST] LimitSell', async t => {
196-
await binance.order({ symbol: 'LTCUSDT', side: 'SELL', type: 'LIMIT', quantity: 0.5, price: 100 })
197-
t.true(interceptedUrl.startsWith('https://api.binance.com/api/v3/order'))
198-
const body = interceptedUrl.replace('https://api.binance.com/api/v3/order', '')
199-
const obj = urlToObject(body)
200-
t.is(obj.symbol, 'LTCUSDT')
201-
t.is(obj.side, 'SELL')
202-
t.is(obj.type, 'LIMIT')
203-
t.is(obj.quantity, '0.5')
196+
await binance.order({ symbol: 'LTCUSDT', side: 'SELL', type: 'LIMIT', quantity: 0.5, price: 100 })
197+
t.true(interceptedUrl.startsWith('https://api.binance.com/api/v3/order'))
198+
const body = interceptedUrl.replace('https://api.binance.com/api/v3/order', '')
199+
const obj = urlToObject(body)
200+
t.is(obj.symbol, 'LTCUSDT')
201+
t.is(obj.side, 'SELL')
202+
t.is(obj.type, 'LIMIT')
203+
t.is(obj.quantity, '0.5')
204204
})
205205

206206

207207
test.serial('[REST] Futures MarketBuy', async t => {
208-
await binance.futuresOrder({ symbol: 'LTCUSDT', side: 'BUY', type: 'MARKET', quantity: 0.5 })
209-
t.true(interceptedUrl.startsWith('https://fapi.binance.com/fapi/v1/order'))
210-
const obj = urlToObject(interceptedUrl.replace('https://fapi.binance.com/fapi/v1/order?', ''))
211-
t.is(obj.symbol, 'LTCUSDT')
212-
t.is(obj.side, 'BUY')
213-
t.is(obj.type, 'MARKET')
214-
t.is(obj.quantity, '0.5')
208+
await binance.futuresOrder({ symbol: 'LTCUSDT', side: 'BUY', type: 'MARKET', quantity: 0.5 })
209+
t.true(interceptedUrl.startsWith('https://fapi.binance.com/fapi/v1/order'))
210+
const obj = urlToObject(interceptedUrl.replace('https://fapi.binance.com/fapi/v1/order?', ''))
211+
t.is(obj.symbol, 'LTCUSDT')
212+
t.is(obj.side, 'BUY')
213+
t.is(obj.type, 'MARKET')
214+
t.is(obj.quantity, '0.5')
215215
})
216216

217217
test.serial('[REST] Futures MarketSell', async t => {
218-
await binance.futuresOrder({ symbol: 'LTCUSDT', side: 'SELL', type: 'MARKET', quantity: 0.5 })
219-
t.true(interceptedUrl.startsWith('https://fapi.binance.com/fapi/v1/order'))
220-
const obj = urlToObject(interceptedUrl.replace('https://fapi.binance.com/fapi/v1/order?', ''))
221-
t.is(obj.symbol, 'LTCUSDT')
222-
t.is(obj.side, 'SELL')
223-
t.is(obj.type, 'MARKET')
224-
t.is(obj.quantity, '0.5')
218+
await binance.futuresOrder({ symbol: 'LTCUSDT', side: 'SELL', type: 'MARKET', quantity: 0.5 })
219+
t.true(interceptedUrl.startsWith('https://fapi.binance.com/fapi/v1/order'))
220+
const obj = urlToObject(interceptedUrl.replace('https://fapi.binance.com/fapi/v1/order?', ''))
221+
t.is(obj.symbol, 'LTCUSDT')
222+
t.is(obj.side, 'SELL')
223+
t.is(obj.type, 'MARKET')
224+
t.is(obj.quantity, '0.5')
225225
})
226226

227227
test.serial('[REST] Futures LimitBuy', async t => {
228-
await binance.futuresOrder({ symbol: 'LTCUSDT', side: 'BUY', type: 'LIMIT', quantity: 0.5, price: 100 })
229-
t.true(interceptedUrl.startsWith('https://fapi.binance.com/fapi/v1/order'))
230-
const obj = urlToObject(interceptedUrl.replace('https://fapi.binance.com/fapi/v1/order?', ''))
231-
t.is(obj.symbol, 'LTCUSDT')
232-
t.is(obj.side, 'BUY')
233-
t.is(obj.type, 'LIMIT')
234-
t.is(obj.quantity, '0.5')
228+
await binance.futuresOrder({ symbol: 'LTCUSDT', side: 'BUY', type: 'LIMIT', quantity: 0.5, price: 100 })
229+
t.true(interceptedUrl.startsWith('https://fapi.binance.com/fapi/v1/order'))
230+
const obj = urlToObject(interceptedUrl.replace('https://fapi.binance.com/fapi/v1/order?', ''))
231+
t.is(obj.symbol, 'LTCUSDT')
232+
t.is(obj.side, 'BUY')
233+
t.is(obj.type, 'LIMIT')
234+
t.is(obj.quantity, '0.5')
235235
})
236236

237237
test.serial('[REST] Futures LimitSell', async t => {
238-
await binance.futuresOrder({ symbol: 'LTCUSDT', side: 'SELL', type: 'LIMIT', quantity: 0.5, price: 100 })
239-
t.true(interceptedUrl.startsWith('https://fapi.binance.com/fapi/v1/order'))
240-
const obj = urlToObject(interceptedUrl.replace('https://fapi.binance.com/fapi/v1/order?', ''))
241-
t.is(obj.symbol, 'LTCUSDT')
242-
t.is(obj.side, 'SELL')
243-
t.is(obj.type, 'LIMIT')
244-
t.is(obj.quantity, '0.5')
238+
await binance.futuresOrder({ symbol: 'LTCUSDT', side: 'SELL', type: 'LIMIT', quantity: 0.5, price: 100 })
239+
t.true(interceptedUrl.startsWith('https://fapi.binance.com/fapi/v1/order'))
240+
const obj = urlToObject(interceptedUrl.replace('https://fapi.binance.com/fapi/v1/order?', ''))
241+
t.is(obj.symbol, 'LTCUSDT')
242+
t.is(obj.side, 'SELL')
243+
t.is(obj.type, 'LIMIT')
244+
t.is(obj.quantity, '0.5')
245245
})
246246

247247

248248
test.serial('[REST] Futures cancel order', async t => {
249-
await binance.futuresCancelOrder({ symbol: 'LTCUSDT', orderId: '34234234' })
250-
const url = 'https://fapi.binance.com/fapi/v1/order'
251-
t.true(interceptedUrl.startsWith(url))
252-
const obj = urlToObject(interceptedUrl.replace(url, ''))
253-
t.is(obj.orderId, '34234234')
254-
t.is(obj.symbol, 'LTCUSDT')
249+
await binance.futuresCancelOrder({ symbol: 'LTCUSDT', orderId: '34234234' })
250+
const url = 'https://fapi.binance.com/fapi/v1/order'
251+
t.true(interceptedUrl.startsWith(url))
252+
const obj = urlToObject(interceptedUrl.replace(url, ''))
253+
t.is(obj.orderId, '34234234')
254+
t.is(obj.symbol, 'LTCUSDT')
255255
})
256256

257257
test.serial('[REST] MarketBuy test', async t => {
258-
await binance.orderTest({ symbol: 'LTCUSDT', side: 'BUY', type: 'MARKET', quantity: 0.5 })
259-
t.true(interceptedUrl.startsWith('https://api.binance.com/api/v3/order/test'))
260-
const body = interceptedUrl.replace('https://api.binance.com/api/v3/order/test', '')
261-
const obj = urlToObject(body)
262-
t.is(obj.symbol, 'LTCUSDT')
263-
t.is(obj.side, 'BUY')
264-
t.is(obj.type, 'MARKET')
265-
t.is(obj.quantity, '0.5')
258+
await binance.orderTest({ symbol: 'LTCUSDT', side: 'BUY', type: 'MARKET', quantity: 0.5 })
259+
t.true(interceptedUrl.startsWith('https://api.binance.com/api/v3/order/test'))
260+
const body = interceptedUrl.replace('https://api.binance.com/api/v3/order/test', '')
261+
const obj = urlToObject(body)
262+
t.is(obj.symbol, 'LTCUSDT')
263+
t.is(obj.side, 'BUY')
264+
t.is(obj.type, 'MARKET')
265+
t.is(obj.quantity, '0.5')
266+
})
267+
268+
test.serial('[REST] spot open orders', async t => {
269+
await binance.openOrders({ symbol: 'LTCUSDT' })
270+
t.true(interceptedUrl.startsWith('https://api.binance.com/api/v3/openOrders'))
271+
})
272+
273+
test.serial('[REST] margin open orders', async t => {
274+
await binance.marginOpenOrders({ symbol: 'LTCUSDT' })
275+
t.true(interceptedUrl.startsWith('https://api.binance.com/sapi/v1/margin/openOrders'))
276+
})
277+
278+
test.serial('[REST] Margin MarketBuy order', async t => {
279+
await binance.marginOrder({ symbol: 'LTCUSDT', side: 'BUY', type: 'MARKET', quantity: 0.5 })
280+
t.true(interceptedUrl.startsWith('https://api.binance.com/sapi/v1/margin/order'))
281+
const body = interceptedUrl.replace('https://api.binance.com/sapi/v1/margin/order', '')
282+
const obj = urlToObject(body)
283+
t.is(obj.symbol, 'LTCUSDT')
284+
t.is(obj.side, 'BUY')
285+
t.is(obj.type, 'MARKET')
286+
t.is(obj.quantity, '0.5')
266287
})

0 commit comments

Comments
 (0)