ccxt 4.3.84 → 4.3.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/ccxt.browser.min.js +2 -2
- package/dist/cjs/ccxt.js +2 -1
- package/dist/cjs/src/base/errors.js +8 -1
- package/dist/cjs/src/bitmex.js +4 -0
- package/dist/cjs/src/bybit.js +15 -14
- package/dist/cjs/src/cryptocom.js +117 -2
- package/dist/cjs/src/kraken.js +29 -1
- package/dist/cjs/src/kucoinfutures.js +5 -0
- package/dist/cjs/src/mexc.js +2 -2
- package/dist/cjs/src/pro/binance.js +1 -1
- package/dist/cjs/src/pro/bitget.js +113 -4
- package/dist/cjs/src/pro/okx.js +25 -4
- package/js/ccxt.d.ts +3 -3
- package/js/ccxt.js +3 -3
- package/js/src/abstract/cryptocom.d.ts +2 -0
- package/js/src/abstract/kucoinfutures.d.ts +2 -0
- package/js/src/base/errorHierarchy.d.ts +1 -0
- package/js/src/base/errorHierarchy.js +1 -0
- package/js/src/base/errors.d.ts +5 -1
- package/js/src/base/errors.js +8 -2
- package/js/src/bitmex.js +4 -0
- package/js/src/bybit.js +16 -15
- package/js/src/cryptocom.d.ts +5 -1
- package/js/src/cryptocom.js +117 -2
- package/js/src/kraken.js +29 -1
- package/js/src/kucoinfutures.js +5 -0
- package/js/src/mexc.js +2 -2
- package/js/src/pro/binance.js +1 -1
- package/js/src/pro/bitget.d.ts +4 -0
- package/js/src/pro/bitget.js +113 -4
- package/js/src/pro/okx.js +25 -4
- package/package.json +1 -1
package/js/src/pro/bitget.js
CHANGED
|
@@ -442,6 +442,35 @@ export default class bitget extends bitgetRest {
|
|
|
442
442
|
*/
|
|
443
443
|
return await this.watchOrderBookForSymbols([symbol], limit, params);
|
|
444
444
|
}
|
|
445
|
+
async unWatchOrderBook(symbol, params = {}) {
|
|
446
|
+
/**
|
|
447
|
+
* @method
|
|
448
|
+
* @name bitget#unWatchOrderBook
|
|
449
|
+
* @description unsubscribe from the orderbook channel
|
|
450
|
+
* @see https://www.bitget.com/api-doc/spot/websocket/public/Depth-Channel
|
|
451
|
+
* @see https://www.bitget.com/api-doc/contract/websocket/public/Order-Book-Channel
|
|
452
|
+
* @param {string} symbol unified symbol of the market to fetch the order book for
|
|
453
|
+
* @param {int} [params.limit] orderbook limit, default is undefined
|
|
454
|
+
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
|
|
455
|
+
*/
|
|
456
|
+
await this.loadMarkets();
|
|
457
|
+
const market = this.market(symbol);
|
|
458
|
+
const messageHash = 'unsubscribe:orderbook:' + market['symbol'];
|
|
459
|
+
let channel = 'books';
|
|
460
|
+
const limit = this.safeInteger(params, 'limit');
|
|
461
|
+
if ((limit === 1) || (limit === 5) || (limit === 15)) {
|
|
462
|
+
params = this.omit(params, 'limit');
|
|
463
|
+
channel += limit.toString();
|
|
464
|
+
}
|
|
465
|
+
let instType = undefined;
|
|
466
|
+
[instType, params] = this.getInstType(market, params);
|
|
467
|
+
const args = {
|
|
468
|
+
'instType': instType,
|
|
469
|
+
'channel': channel,
|
|
470
|
+
'instId': market['id'],
|
|
471
|
+
};
|
|
472
|
+
return await this.unWatchPublic(messageHash, args, params);
|
|
473
|
+
}
|
|
445
474
|
async watchOrderBookForSymbols(symbols, limit = undefined, params = {}) {
|
|
446
475
|
/**
|
|
447
476
|
* @method
|
|
@@ -565,10 +594,11 @@ export default class bitget extends bitgetRest {
|
|
|
565
594
|
const calculatedChecksum = this.crc32(payload, true);
|
|
566
595
|
const responseChecksum = this.safeInteger(rawOrderBook, 'checksum');
|
|
567
596
|
if (calculatedChecksum !== responseChecksum) {
|
|
568
|
-
|
|
569
|
-
delete
|
|
570
|
-
|
|
571
|
-
|
|
597
|
+
// if (messageHash in client.subscriptions) {
|
|
598
|
+
// // delete client.subscriptions[messageHash];
|
|
599
|
+
// // delete this.orderbooks[symbol];
|
|
600
|
+
// }
|
|
601
|
+
this.spawn(this.handleCheckSumError, client, symbol, messageHash);
|
|
572
602
|
return;
|
|
573
603
|
}
|
|
574
604
|
}
|
|
@@ -581,6 +611,11 @@ export default class bitget extends bitgetRest {
|
|
|
581
611
|
}
|
|
582
612
|
client.resolve(this.orderbooks[symbol], messageHash);
|
|
583
613
|
}
|
|
614
|
+
async handleCheckSumError(client, symbol, messageHash) {
|
|
615
|
+
await this.unWatchOrderBook(symbol);
|
|
616
|
+
const error = new ChecksumError(this.id + ' ' + this.orderbookChecksumMessage(symbol));
|
|
617
|
+
client.reject(error, messageHash);
|
|
618
|
+
}
|
|
584
619
|
handleDelta(bookside, delta) {
|
|
585
620
|
const bidAsk = this.parseBidAsk(delta, 0, 1);
|
|
586
621
|
// we store the string representations in the orderbook for checksum calculation
|
|
@@ -1627,6 +1662,15 @@ export default class bitget extends bitgetRest {
|
|
|
1627
1662
|
const message = this.extend(request, params);
|
|
1628
1663
|
return await this.watch(url, messageHash, message, messageHash);
|
|
1629
1664
|
}
|
|
1665
|
+
async unWatchPublic(messageHash, args, params = {}) {
|
|
1666
|
+
const url = this.urls['api']['ws']['public'];
|
|
1667
|
+
const request = {
|
|
1668
|
+
'op': 'unsubscribe',
|
|
1669
|
+
'args': [args],
|
|
1670
|
+
};
|
|
1671
|
+
const message = this.extend(request, params);
|
|
1672
|
+
return await this.watch(url, messageHash, message, messageHash);
|
|
1673
|
+
}
|
|
1630
1674
|
async watchPublicMultiple(messageHashes, argsArray, params = {}) {
|
|
1631
1675
|
const url = this.urls['api']['ws']['public'];
|
|
1632
1676
|
const request = {
|
|
@@ -1747,6 +1791,17 @@ export default class bitget extends bitgetRest {
|
|
|
1747
1791
|
// "event": "subscribe",
|
|
1748
1792
|
// "arg": { instType: 'SPOT', channel: "account", instId: "default" }
|
|
1749
1793
|
// }
|
|
1794
|
+
// unsubscribe
|
|
1795
|
+
// {
|
|
1796
|
+
// "op":"unsubscribe",
|
|
1797
|
+
// "args":[
|
|
1798
|
+
// {
|
|
1799
|
+
// "instType":"USDT-FUTURES",
|
|
1800
|
+
// "channel":"ticker",
|
|
1801
|
+
// "instId":"BTCUSDT"
|
|
1802
|
+
// }
|
|
1803
|
+
// ]
|
|
1804
|
+
// }
|
|
1750
1805
|
//
|
|
1751
1806
|
if (this.handleErrorMessage(client, message)) {
|
|
1752
1807
|
return;
|
|
@@ -1769,6 +1824,10 @@ export default class bitget extends bitgetRest {
|
|
|
1769
1824
|
this.handleSubscriptionStatus(client, message);
|
|
1770
1825
|
return;
|
|
1771
1826
|
}
|
|
1827
|
+
if (event === 'unsubscribe') {
|
|
1828
|
+
this.handleUnSubscriptionStatus(client, message);
|
|
1829
|
+
return;
|
|
1830
|
+
}
|
|
1772
1831
|
const methods = {
|
|
1773
1832
|
'ticker': this.handleTicker,
|
|
1774
1833
|
'trade': this.handleTrades,
|
|
@@ -1812,4 +1871,54 @@ export default class bitget extends bitgetRest {
|
|
|
1812
1871
|
//
|
|
1813
1872
|
return message;
|
|
1814
1873
|
}
|
|
1874
|
+
handleUnSubscriptionStatus(client, message) {
|
|
1875
|
+
//
|
|
1876
|
+
// {
|
|
1877
|
+
// "op":"unsubscribe",
|
|
1878
|
+
// "args":[
|
|
1879
|
+
// {
|
|
1880
|
+
// "instType":"USDT-FUTURES",
|
|
1881
|
+
// "channel":"ticker",
|
|
1882
|
+
// "instId":"BTCUSDT"
|
|
1883
|
+
// },
|
|
1884
|
+
// {
|
|
1885
|
+
// "instType":"USDT-FUTURES",
|
|
1886
|
+
// "channel":"candle1m",
|
|
1887
|
+
// "instId":"BTCUSDT"
|
|
1888
|
+
// }
|
|
1889
|
+
// ]
|
|
1890
|
+
// }
|
|
1891
|
+
// or
|
|
1892
|
+
// {"event":"unsubscribe","arg":{"instType":"SPOT","channel":"books","instId":"BTCUSDT"}}
|
|
1893
|
+
//
|
|
1894
|
+
let argsList = this.safeList(message, 'args');
|
|
1895
|
+
if (argsList === undefined) {
|
|
1896
|
+
argsList = [this.safeDict(message, 'arg', {})];
|
|
1897
|
+
}
|
|
1898
|
+
for (let i = 0; i < argsList.length; i++) {
|
|
1899
|
+
const arg = argsList[i];
|
|
1900
|
+
const channel = this.safeString(arg, 'channel');
|
|
1901
|
+
if (channel === 'books') {
|
|
1902
|
+
// for now only unWatchOrderBook is supporteod
|
|
1903
|
+
const instType = this.safeStringLower(arg, 'instType');
|
|
1904
|
+
const type = (instType === 'spot') ? 'spot' : 'contract';
|
|
1905
|
+
const instId = this.safeString(arg, 'instId');
|
|
1906
|
+
const market = this.safeMarket(instId, undefined, undefined, type);
|
|
1907
|
+
const symbol = market['symbol'];
|
|
1908
|
+
const messageHash = 'unsubscribe:orderbook:' + market['symbol'];
|
|
1909
|
+
const subMessageHash = 'orderbook:' + symbol;
|
|
1910
|
+
if (symbol in this.orderbooks) {
|
|
1911
|
+
delete this.orderbooks[symbol];
|
|
1912
|
+
}
|
|
1913
|
+
if (subMessageHash in client.subscriptions) {
|
|
1914
|
+
delete client.subscriptions[subMessageHash];
|
|
1915
|
+
}
|
|
1916
|
+
if (messageHash in client.subscriptions) {
|
|
1917
|
+
delete client.subscriptions[messageHash];
|
|
1918
|
+
}
|
|
1919
|
+
client.resolve(true, messageHash);
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
return message;
|
|
1923
|
+
}
|
|
1815
1924
|
}
|
package/js/src/pro/okx.js
CHANGED
|
@@ -442,9 +442,16 @@ export default class okx extends okxRest {
|
|
|
442
442
|
*/
|
|
443
443
|
await this.loadMarkets();
|
|
444
444
|
symbols = this.marketSymbols(symbols, undefined, true, true);
|
|
445
|
-
|
|
445
|
+
const messageHash = 'liquidations';
|
|
446
|
+
const messageHashes = [];
|
|
446
447
|
if (symbols !== undefined) {
|
|
447
|
-
|
|
448
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
449
|
+
const symbol = symbols[i];
|
|
450
|
+
messageHashes.push(messageHash + '::' + symbol);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
messageHashes.push(messageHash);
|
|
448
455
|
}
|
|
449
456
|
const market = this.getMarketFromSymbols(symbols);
|
|
450
457
|
let type = undefined;
|
|
@@ -458,9 +465,16 @@ export default class okx extends okxRest {
|
|
|
458
465
|
}
|
|
459
466
|
const uppercaseType = type.toUpperCase();
|
|
460
467
|
const request = {
|
|
461
|
-
'
|
|
468
|
+
'op': 'subscribe',
|
|
469
|
+
'args': [
|
|
470
|
+
{
|
|
471
|
+
'channel': channel,
|
|
472
|
+
'instType': uppercaseType,
|
|
473
|
+
},
|
|
474
|
+
],
|
|
462
475
|
};
|
|
463
|
-
const
|
|
476
|
+
const url = this.getUrl(channel, 'public');
|
|
477
|
+
const newLiquidations = await this.watchMultiple(url, messageHashes, request, messageHashes);
|
|
464
478
|
if (this.newUpdates) {
|
|
465
479
|
return newLiquidations;
|
|
466
480
|
}
|
|
@@ -1396,6 +1410,13 @@ export default class okx extends okxRest {
|
|
|
1396
1410
|
for (let i = 0; i < data.length; i++) {
|
|
1397
1411
|
const rawPosition = data[i];
|
|
1398
1412
|
const position = this.parsePosition(rawPosition);
|
|
1413
|
+
if (position['contracts'] === 0) {
|
|
1414
|
+
position['side'] = 'long';
|
|
1415
|
+
const shortPosition = this.clone(position);
|
|
1416
|
+
shortPosition['side'] = 'short';
|
|
1417
|
+
cache.append(shortPosition);
|
|
1418
|
+
newPositions.push(shortPosition);
|
|
1419
|
+
}
|
|
1399
1420
|
newPositions.push(position);
|
|
1400
1421
|
cache.append(position);
|
|
1401
1422
|
}
|
package/package.json
CHANGED