Skip to content

Commit a5d92b1

Browse files
committed
fix bybit_unified and provide pair util
1 parent 39c9beb commit a5d92b1

File tree

2 files changed

+88
-79
lines changed

2 files changed

+88
-79
lines changed

src/exchange/bybit_unified.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ module.exports = class BybitUnified {
248248
order.symbol,
249249
order.status,
250250
order.price,
251-
order.qty,
251+
order.amount,
252252
status === ExchangeOrder.STATUS_REJECTED,
253253
order.clientOrderId ? order.clientOrderId : undefined,
254254
order.side.toLowerCase() === 'buy' ? 'buy' : 'sell', // secure the value,

src/utils/instance_util.js

+87-78
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ module.exports = {
66
* @param callback
77
* @returns {Promise<unknown>}
88
*/
9-
binanceInitUsdT: async callback => {
10-
return new Promise(resolve => {
9+
binanceInitUsdT: async callback =>
10+
new Promise(resolve => {
1111
request('https://api.binance.com/api/v1/exchangeInfo', (_error, _res, body) => {
1212
const pairs = [];
1313

@@ -28,10 +28,7 @@ module.exports = {
2828

2929
content.symbols
3030
.filter(
31-
p =>
32-
['USDT'].includes(p.quoteAsset) &&
33-
!['USDC', 'PAX', 'USDS', 'TUSD', 'BUSD'].includes(p.baseAsset) &&
34-
p.status.toLowerCase() === 'trading'
31+
p => ['USDT'].includes(p.quoteAsset) && !['USDC', 'PAX', 'USDS', 'TUSD', 'BUSD'].includes(p.baseAsset) && p.status.toLowerCase() === 'trading'
3532
)
3633
.forEach(pair => {
3734
let result = {
@@ -51,16 +48,15 @@ module.exports = {
5148

5249
resolve(pairs);
5350
});
54-
});
55-
},
51+
}),
5652

5753
/**
5854
* Init helper for Binance to fetch all BUSD pairs
5955
* @param callback
6056
* @returns {Promise<unknown>}
6157
*/
62-
binanceInitBusd: async callback => {
63-
return new Promise(resolve => {
58+
binanceInitBusd: async callback =>
59+
new Promise(resolve => {
6460
request('https://api.binance.com/api/v1/exchangeInfo', (_error, _res, body) => {
6561
const pairs = [];
6662

@@ -81,10 +77,7 @@ module.exports = {
8177

8278
content.symbols
8379
.filter(
84-
p =>
85-
['BUSD'].includes(p.quoteAsset) &&
86-
!['USDC', 'PAX', 'USDS', 'TUSD', 'USDT'].includes(p.baseAsset) &&
87-
p.status.toLowerCase() === 'trading'
80+
p => ['BUSD'].includes(p.quoteAsset) && !['USDC', 'PAX', 'USDS', 'TUSD', 'USDT'].includes(p.baseAsset) && p.status.toLowerCase() === 'trading'
8881
)
8982
.forEach(pair => {
9083
let result = {
@@ -104,16 +97,15 @@ module.exports = {
10497

10598
resolve(pairs);
10699
});
107-
});
108-
},
100+
}),
109101

110102
/**
111103
* Init helper for Binance to fetch all BNB pairs
112104
* @param callback
113105
* @returns {Promise<unknown>}
114106
*/
115-
binanceInitBNB: async callback => {
116-
return new Promise(resolve => {
107+
binanceInitBNB: async callback =>
108+
new Promise(resolve => {
117109
request('https://api.binance.com/api/v1/exchangeInfo', (_error, _res, body) => {
118110
const pairs = [];
119111

@@ -135,9 +127,7 @@ module.exports = {
135127
content.symbols
136128
.filter(
137129
p =>
138-
['BNB'].includes(p.quoteAsset) &&
139-
!['BUSD', 'USDC', 'PAX', 'USDS', 'TUSD', 'USDT'].includes(p.baseAsset) &&
140-
p.status.toLowerCase() === 'trading'
130+
['BNB'].includes(p.quoteAsset) && !['BUSD', 'USDC', 'PAX', 'USDS', 'TUSD', 'USDT'].includes(p.baseAsset) && p.status.toLowerCase() === 'trading'
141131
)
142132
.forEach(pair => {
143133
let result = {
@@ -157,16 +147,15 @@ module.exports = {
157147

158148
resolve(pairs);
159149
});
160-
});
161-
},
150+
}),
162151

163152
/**
164153
* Init helper for Binance to fetch all BTC pairs
165154
* @param callback
166155
* @returns {Promise<unknown>}
167156
*/
168-
binanceInitBTC: async callback => {
169-
return new Promise(resolve => {
157+
binanceInitBTC: async callback =>
158+
new Promise(resolve => {
170159
request('https://api.binance.com/api/v1/exchangeInfo', (_error, _res, body) => {
171160
const pairs = [];
172161

@@ -188,9 +177,7 @@ module.exports = {
188177
content.symbols
189178
.filter(
190179
p =>
191-
['BTC'].includes(p.quoteAsset) &&
192-
!['BUSD', 'USDC', 'PAX', 'USDS', 'TUSD', 'USDT'].includes(p.baseAsset) &&
193-
p.status.toLowerCase() === 'trading'
180+
['BTC'].includes(p.quoteAsset) && !['BUSD', 'USDC', 'PAX', 'USDS', 'TUSD', 'USDT'].includes(p.baseAsset) && p.status.toLowerCase() === 'trading'
194181
)
195182
.forEach(pair => {
196183
let result = {
@@ -210,16 +197,15 @@ module.exports = {
210197

211198
resolve(pairs);
212199
});
213-
});
214-
},
200+
}),
215201

216202
/**
217203
* Init helper for Binance to fetch all ETH pairs
218204
* @param callback
219205
* @returns {Promise<unknown>}
220206
*/
221-
binanceInitETH: async callback => {
222-
return new Promise(resolve => {
207+
binanceInitETH: async callback =>
208+
new Promise(resolve => {
223209
request('https://api.binance.com/api/v1/exchangeInfo', (_error, _res, body) => {
224210
const pairs = [];
225211

@@ -241,9 +227,7 @@ module.exports = {
241227
content.symbols
242228
.filter(
243229
p =>
244-
['ETH'].includes(p.quoteAsset) &&
245-
!['BUSD', 'USDC', 'PAX', 'USDS', 'TUSD', 'USDT'].includes(p.baseAsset) &&
246-
p.status.toLowerCase() === 'trading'
230+
['ETH'].includes(p.quoteAsset) && !['BUSD', 'USDC', 'PAX', 'USDS', 'TUSD', 'USDT'].includes(p.baseAsset) && p.status.toLowerCase() === 'trading'
247231
)
248232
.forEach(pair => {
249233
let result = {
@@ -263,8 +247,7 @@ module.exports = {
263247

264248
resolve(pairs);
265249
});
266-
});
267-
},
250+
}),
268251

269252
/**
270253
* Init helper for Binance to fetch all USDT pairs with spot only
@@ -382,84 +365,79 @@ module.exports = {
382365
* @link https://www.binance.com/de/margin-fee
383366
* @returns {Promise<unknown>}
384367
*/
385-
binancecrossMarginPairsUsdT: () => {
386-
return new Promise(resolve => {
368+
binancecrossMarginPairsUsdT: () =>
369+
new Promise(resolve => {
387370
request('https://www.binance.com/gateway-api/v1/friendly/margin/vip/spec/list-all', (_error, _res, body) => {
388371
const content = JSON.parse(body);
389372
const crossMarginPairsUsdT = content.data.map(i => i.assetName);
390373

391374
resolve(crossMarginPairsUsdT);
392375
});
393-
});
394-
},
376+
}),
395377

396378
/**
397379
* There is API (or not documented) where to filter isolated and cross margin wallet pairs take them from fee page api
398380
*
399381
* @link https://www.binance.com/de/margin-fee
400382
* @returns {Promise<unknown>}
401383
*/
402-
binancecrossMarginPairsBusd: () => {
403-
return new Promise(resolve => {
384+
binancecrossMarginPairsBusd: () =>
385+
new Promise(resolve => {
404386
request('https://www.binance.com/gateway-api/v1/friendly/margin/vip/spec/list-all', (_error, _res, body) => {
405387
const content = JSON.parse(body);
406388
const crossMarginPairsBusd = content.data.map(i => i.assetName);
407389

408390
resolve(crossMarginPairsBusd);
409391
});
410-
});
411-
},
392+
}),
412393

413394
/**
414395
* There is API (or not documented) where to filter isolated and cross margin wallet pairs take them from fee page api
415396
*
416397
* @link https://www.binance.com/de/margin-fee
417398
* @returns {Promise<unknown>}
418399
*/
419-
binancecrossMarginPairsBNB: () => {
420-
return new Promise(resolve => {
400+
binancecrossMarginPairsBNB: () =>
401+
new Promise(resolve => {
421402
request('https://www.binance.com/gateway-api/v1/friendly/margin/vip/spec/list-all', (_error, _res, body) => {
422403
const content = JSON.parse(body);
423404
const crossMarginPairsBNB = content.data.map(i => i.assetName);
424405

425406
resolve(crossMarginPairsBNB);
426407
});
427-
});
428-
},
408+
}),
429409

430410
/**
431411
* There is API (or not documented) where to filter isolated and cross margin wallet pairs take them from fee page api
432412
*
433413
* @link https://www.binance.com/de/margin-fee
434414
* @returns {Promise<unknown>}
435415
*/
436-
binancecrossMarginPairsBTC: () => {
437-
return new Promise(resolve => {
416+
binancecrossMarginPairsBTC: () =>
417+
new Promise(resolve => {
438418
request('https://www.binance.com/gateway-api/v1/friendly/margin/vip/spec/list-all', (_error, _res, body) => {
439419
const content = JSON.parse(body);
440420
const crossMarginPairsBTC = content.data.map(i => i.assetName);
441421

442422
resolve(crossMarginPairsBTC);
443423
});
444-
});
445-
},
424+
}),
446425

447426
/**
448427
* There is API (or not documented) where to filter isolated and cross margin wallet pairs take them from fee page api
449428
*
450429
* @link https://www.binance.com/de/margin-fee
451430
* @returns {Promise<unknown>}
452431
*/
453-
binancecrossMarginPairsETH: () => {
454-
return new Promise(resolve => {
432+
binancecrossMarginPairsETH: () =>
433+
new Promise(resolve => {
455434
request('https://www.binance.com/gateway-api/v1/friendly/margin/vip/spec/list-all', (_error, _res, body) => {
456435
const content = JSON.parse(body);
457436
const crossMarginPairsETH = content.data.map(i => i.assetName);
458437

459438
resolve(crossMarginPairsETH);
460439
});
461-
});
462-
},
440+
}),
463441

464442
/**
465443
* Init helper for Binance to fetch all USDT pairs with margin only
@@ -558,8 +536,8 @@ module.exports = {
558536
* @param callback
559537
* @returns {Promise<unknown>}
560538
*/
561-
bitmexInit: async callback => {
562-
return new Promise(resolve => {
539+
bitmexInit: async callback =>
540+
new Promise(resolve => {
563541
request('https://www.bitmex.com/api/v1/instrument/active', (_error, _res, body) => {
564542
const pairs = [];
565543

@@ -585,16 +563,15 @@ module.exports = {
585563

586564
resolve(pairs);
587565
});
588-
});
589-
},
566+
}),
590567

591568
/**
592569
* Init helper for Binance futures USDT & BUSD exchange to fetch active contracts
593570
* @param callback
594571
* @returns {Promise<unknown>}
595572
*/
596-
binanceFuturesInit: async callback => {
597-
return new Promise(resolve => {
573+
binanceFuturesInit: async callback =>
574+
new Promise(resolve => {
598575
request('https://fapi.binance.com/fapi/v1/exchangeInfo', (_error, _res, body) => {
599576
const pairs = [];
600577

@@ -620,16 +597,15 @@ module.exports = {
620597

621598
resolve(pairs);
622599
});
623-
});
624-
},
600+
}),
625601

626602
/**
627603
* Init helper for Binance futures COIN exchange to fetch active contracts
628604
* @param callback
629605
* @returns {Promise<unknown>}
630606
*/
631-
binanceFuturesCoin: async callback => {
632-
return new Promise(resolve => {
607+
binanceFuturesCoin: async callback =>
608+
new Promise(resolve => {
633609
request('https://dapi.binance.com/dapi/v1/exchangeInfo', (_error, _res, body) => {
634610
const pairs = [];
635611

@@ -655,12 +631,47 @@ module.exports = {
655631

656632
resolve(pairs);
657633
});
658-
});
659-
},
634+
}),
635+
636+
/**
637+
* @param callback
638+
* @param limit
639+
* @returns {Promise<unknown>}
640+
*/
641+
bybitLinearCoin: async (callback, limit = 100) =>
642+
new Promise(resolve => {
643+
request('https://api.bybit.com/v5/market/tickers?category=linear', (_error, _res, body) => {
644+
const pairs = [];
660645

661-
// BitFinex
662-
bitfinexUsdMarginInit: async callback => {
663-
return new Promise(resolve => {
646+
const content = JSON.parse(body);
647+
648+
const arr = (content?.result?.list || [])
649+
.filter(p => p.symbol.toUpperCase().endsWith('USDT'))
650+
.sort((a, b) => b.turnover24h - a.turnover24h);
651+
652+
arr.slice(0, limit).forEach(pair => {
653+
let result = {
654+
symbol: `${pair.symbol.substring(0, pair.symbol.length - 4)}/USDT:USDT`,
655+
periods: ['15m', '1h'],
656+
exchange: 'bybit_unified'
657+
};
658+
659+
if (callback) {
660+
result = callback(result, pair);
661+
}
662+
663+
if (result) {
664+
pairs.push(result);
665+
}
666+
});
667+
668+
resolve(pairs);
669+
});
670+
}),
671+
672+
// BitFinex
673+
bitfinexUsdMarginInit: async callback =>
674+
new Promise(resolve => {
664675
request('https://api.bitfinex.com/v1/symbols_details', (_error, _res, body) => {
665676
const pairs = [];
666677

@@ -686,12 +697,11 @@ module.exports = {
686697

687698
resolve(pairs);
688699
});
689-
});
690-
},
700+
}),
691701

692702
// Bybit
693-
bybitInit: async callback => {
694-
return new Promise(resolve => {
703+
bybitInit: async callback =>
704+
new Promise(resolve => {
695705
request('https://api.bybit.com/v2/public/symbols', (_error, _res, body) => {
696706
const pairs = [];
697707

@@ -735,6 +745,5 @@ module.exports = {
735745

736746
resolve(pairs);
737747
});
738-
});
739-
}
748+
})
740749
};

0 commit comments

Comments
 (0)