ccxt 4.3.32 → 4.3.34

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.
Files changed (128) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.min.js +2 -2
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/base/Exchange.js +26 -0
  5. package/dist/cjs/src/binance.js +1 -0
  6. package/dist/cjs/src/bitget.js +1 -1
  7. package/dist/cjs/src/coinbase.js +106 -53
  8. package/dist/cjs/src/pro/binance.js +352 -0
  9. package/dist/cjs/src/pro/bitmex.js +108 -0
  10. package/dist/cjs/src/pro/bybit.js +85 -0
  11. package/dist/cjs/src/pro/gate.js +183 -0
  12. package/dist/cjs/src/pro/kucoinfutures.js +4 -0
  13. package/dist/cjs/src/pro/okx.js +259 -1
  14. package/dist/cjs/src/whitebit.js +2 -2
  15. package/js/ccxt.d.ts +1 -1
  16. package/js/ccxt.js +1 -1
  17. package/js/src/abstract/binance.d.ts +1 -0
  18. package/js/src/abstract/binancecoinm.d.ts +1 -0
  19. package/js/src/abstract/binanceus.d.ts +1 -0
  20. package/js/src/abstract/binanceusdm.d.ts +1 -0
  21. package/js/src/ace.d.ts +3 -3
  22. package/js/src/alpaca.d.ts +2 -2
  23. package/js/src/ascendex.d.ts +3 -3
  24. package/js/src/base/Exchange.d.ts +13 -3
  25. package/js/src/base/Exchange.js +26 -0
  26. package/js/src/base/types.d.ts +1 -0
  27. package/js/src/bigone.d.ts +3 -3
  28. package/js/src/binance.d.ts +4 -4
  29. package/js/src/binance.js +1 -0
  30. package/js/src/bingx.d.ts +3 -3
  31. package/js/src/bit2c.d.ts +2 -2
  32. package/js/src/bitbank.d.ts +2 -2
  33. package/js/src/bitbns.d.ts +2 -2
  34. package/js/src/bitfinex.d.ts +3 -3
  35. package/js/src/bitfinex2.d.ts +1 -1
  36. package/js/src/bitflyer.d.ts +2 -2
  37. package/js/src/bitget.d.ts +4 -4
  38. package/js/src/bitget.js +1 -1
  39. package/js/src/bithumb.d.ts +2 -2
  40. package/js/src/bitmart.d.ts +3 -3
  41. package/js/src/bitmex.d.ts +4 -4
  42. package/js/src/bitopro.d.ts +4 -4
  43. package/js/src/bitrue.d.ts +3 -3
  44. package/js/src/bitso.d.ts +3 -3
  45. package/js/src/bitstamp.d.ts +3 -3
  46. package/js/src/bitteam.d.ts +4 -4
  47. package/js/src/bitvavo.d.ts +3 -3
  48. package/js/src/blockchaincom.d.ts +2 -2
  49. package/js/src/blofin.d.ts +4 -4
  50. package/js/src/btcalpha.d.ts +4 -4
  51. package/js/src/btcbox.d.ts +2 -2
  52. package/js/src/btcmarkets.d.ts +4 -4
  53. package/js/src/btcturk.d.ts +2 -2
  54. package/js/src/bybit.d.ts +3 -3
  55. package/js/src/cex.d.ts +2 -2
  56. package/js/src/coinbase.d.ts +3 -3
  57. package/js/src/coinbase.js +106 -53
  58. package/js/src/coinbaseexchange.d.ts +2 -2
  59. package/js/src/coinbaseinternational.d.ts +4 -4
  60. package/js/src/coincheck.d.ts +3 -3
  61. package/js/src/coinex.d.ts +3 -3
  62. package/js/src/coinlist.d.ts +3 -3
  63. package/js/src/coinmate.d.ts +3 -3
  64. package/js/src/coinmetro.d.ts +3 -3
  65. package/js/src/coinone.d.ts +2 -2
  66. package/js/src/coinsph.d.ts +3 -3
  67. package/js/src/cryptocom.d.ts +2 -2
  68. package/js/src/currencycom.d.ts +3 -3
  69. package/js/src/delta.d.ts +2 -2
  70. package/js/src/deribit.d.ts +3 -3
  71. package/js/src/digifinex.d.ts +3 -3
  72. package/js/src/exmo.d.ts +3 -3
  73. package/js/src/gate.d.ts +3 -3
  74. package/js/src/gemini.d.ts +3 -3
  75. package/js/src/hitbtc.d.ts +3 -3
  76. package/js/src/hollaex.d.ts +2 -2
  77. package/js/src/htx.d.ts +3 -3
  78. package/js/src/huobijp.d.ts +3 -3
  79. package/js/src/hyperliquid.d.ts +3 -3
  80. package/js/src/idex.d.ts +3 -3
  81. package/js/src/indodax.d.ts +3 -3
  82. package/js/src/kraken.d.ts +3 -3
  83. package/js/src/krakenfutures.d.ts +2 -2
  84. package/js/src/kucoin.d.ts +3 -3
  85. package/js/src/kuna.d.ts +3 -3
  86. package/js/src/latoken.d.ts +3 -3
  87. package/js/src/lbank.d.ts +2 -2
  88. package/js/src/luno.d.ts +2 -2
  89. package/js/src/lykke.d.ts +2 -2
  90. package/js/src/mercado.d.ts +2 -2
  91. package/js/src/mexc.d.ts +2 -2
  92. package/js/src/ndax.d.ts +3 -3
  93. package/js/src/novadax.d.ts +4 -4
  94. package/js/src/oceanex.d.ts +3 -3
  95. package/js/src/okcoin.d.ts +4 -4
  96. package/js/src/okx.d.ts +4 -4
  97. package/js/src/onetrading.d.ts +3 -3
  98. package/js/src/p2b.d.ts +3 -3
  99. package/js/src/paymium.d.ts +2 -2
  100. package/js/src/phemex.d.ts +5 -5
  101. package/js/src/poloniex.d.ts +4 -4
  102. package/js/src/poloniexfutures.d.ts +3 -3
  103. package/js/src/pro/binance.d.ts +9 -2
  104. package/js/src/pro/binance.js +352 -0
  105. package/js/src/pro/bitmex.d.ts +4 -1
  106. package/js/src/pro/bitmex.js +108 -0
  107. package/js/src/pro/bybit.d.ts +4 -1
  108. package/js/src/pro/bybit.js +85 -0
  109. package/js/src/pro/gate.d.ts +5 -1
  110. package/js/src/pro/gate.js +183 -0
  111. package/js/src/pro/kucoinfutures.js +4 -0
  112. package/js/src/pro/okx.d.ts +8 -1
  113. package/js/src/pro/okx.js +259 -1
  114. package/js/src/probit.d.ts +4 -4
  115. package/js/src/timex.d.ts +3 -3
  116. package/js/src/tokocrypto.d.ts +2 -2
  117. package/js/src/tradeogre.d.ts +2 -2
  118. package/js/src/upbit.d.ts +4 -4
  119. package/js/src/wavesexchange.d.ts +2 -2
  120. package/js/src/wazirx.d.ts +4 -4
  121. package/js/src/whitebit.d.ts +4 -4
  122. package/js/src/whitebit.js +2 -2
  123. package/js/src/woo.d.ts +4 -4
  124. package/js/src/woofipro.d.ts +4 -4
  125. package/js/src/yobit.d.ts +2 -2
  126. package/js/src/zaif.d.ts +3 -3
  127. package/js/src/zonda.d.ts +2 -2
  128. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import gateRest from '../gate.js';
2
- import type { Int, Str, Strings, OrderBook, Order, Trade, Ticker, Tickers, OHLCV, Position, Balances } from '../base/types.js';
2
+ import type { Int, Str, Strings, OrderBook, Order, Trade, Ticker, Tickers, OHLCV, Position, Balances, Liquidation } from '../base/types.js';
3
3
  import Client from '../base/ws/Client.js';
4
4
  export default class gate extends gateRest {
5
5
  describe(): any;
@@ -31,6 +31,10 @@ export default class gate extends gateRest {
31
31
  handlePositions(client: any, message: any): void;
32
32
  watchOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
33
33
  handleOrder(client: Client, message: any): void;
34
+ watchMyLiquidations(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Liquidation[]>;
35
+ watchMyLiquidationsForSymbols(symbols?: string[], since?: Int, limit?: Int, params?: {}): Promise<Liquidation[]>;
36
+ handleLiquidation(client: Client, message: any): void;
37
+ parseWsLiquidation(liquidation: any, market?: any): Liquidation;
34
38
  handleErrorMessage(client: Client, message: any): boolean;
35
39
  handleBalanceSubscription(client: Client, message: any, subscription?: any): void;
36
40
  handleSubscriptionStatus(client: Client, message: any): void;
@@ -9,6 +9,7 @@ import gateRest from '../gate.js';
9
9
  import { AuthenticationError, BadRequest, ArgumentsRequired, InvalidNonce } from '../base/errors.js';
10
10
  import { ArrayCache, ArrayCacheByTimestamp, ArrayCacheBySymbolById, ArrayCacheBySymbolBySide } from '../base/ws/Cache.js';
11
11
  import { sha512 } from '../static_dependencies/noble-hashes/sha512.js';
12
+ import Precise from '../base/Precise.js';
12
13
  // ---------------------------------------------------------------------------
13
14
  export default class gate extends gateRest {
14
15
  describe() {
@@ -24,6 +25,10 @@ export default class gate extends gateRest {
24
25
  'watchOHLCV': true,
25
26
  'watchBalance': true,
26
27
  'watchOrders': true,
28
+ 'watchLiquidations': false,
29
+ 'watchLiquidationsForSymbols': false,
30
+ 'watchMyLiquidations': true,
31
+ 'watchMyLiquidationsForSymbols': true,
27
32
  'watchPositions': true,
28
33
  },
29
34
  'urls': {
@@ -1041,6 +1046,183 @@ export default class gate extends gateRest {
1041
1046
  }
1042
1047
  client.resolve(this.orders, 'orders');
1043
1048
  }
1049
+ async watchMyLiquidations(symbol, since = undefined, limit = undefined, params = {}) {
1050
+ /**
1051
+ * @method
1052
+ * @name gate#watchMyLiquidations
1053
+ * @description watch the public liquidations of a trading pair
1054
+ * @see https://www.gate.io/docs/developers/futures/ws/en/#liquidates-api
1055
+ * @see https://www.gate.io/docs/developers/delivery/ws/en/#liquidates-api
1056
+ * @see https://www.gate.io/docs/developers/options/ws/en/#liquidates-channel
1057
+ * @param {string} symbol unified CCXT market symbol
1058
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
1059
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
1060
+ * @param {object} [params] exchange specific parameters for the bitmex api endpoint
1061
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
1062
+ */
1063
+ return this.watchMyLiquidationsForSymbols([symbol], since, limit, params);
1064
+ }
1065
+ async watchMyLiquidationsForSymbols(symbols = undefined, since = undefined, limit = undefined, params = {}) {
1066
+ /**
1067
+ * @method
1068
+ * @name gate#watchMyLiquidationsForSymbols
1069
+ * @description watch the private liquidations of a trading pair
1070
+ * @see https://www.gate.io/docs/developers/futures/ws/en/#liquidates-api
1071
+ * @see https://www.gate.io/docs/developers/delivery/ws/en/#liquidates-api
1072
+ * @see https://www.gate.io/docs/developers/options/ws/en/#liquidates-channel
1073
+ * @param {string} symbol unified CCXT market symbol
1074
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
1075
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
1076
+ * @param {object} [params] exchange specific parameters for the gate api endpoint
1077
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
1078
+ */
1079
+ await this.loadMarkets();
1080
+ symbols = this.marketSymbols(symbols, undefined, true, true);
1081
+ const market = this.getMarketFromSymbols(symbols);
1082
+ let type = undefined;
1083
+ let query = undefined;
1084
+ [type, query] = this.handleMarketTypeAndParams('watchMyLiquidationsForSymbols', market, params);
1085
+ const typeId = this.getSupportedMapping(type, {
1086
+ 'future': 'futures',
1087
+ 'swap': 'futures',
1088
+ 'option': 'options',
1089
+ });
1090
+ let subType = undefined;
1091
+ [subType, query] = this.handleSubTypeAndParams('watchMyLiquidationsForSymbols', market, query);
1092
+ const isInverse = (subType === 'inverse');
1093
+ const url = this.getUrlByMarketType(type, isInverse);
1094
+ const payload = [];
1095
+ let messageHash = '';
1096
+ if (this.isEmpty(symbols)) {
1097
+ if (typeId !== 'futures' && !isInverse) {
1098
+ throw new BadRequest(this.id + ' watchMyLiquidationsForSymbols() does not support listening to all symbols, you must call watchMyLiquidations() instead for each symbol you wish to watch.');
1099
+ }
1100
+ messageHash = 'myLiquidations';
1101
+ payload.push('!all');
1102
+ }
1103
+ else {
1104
+ const symbolsLength = symbols.length;
1105
+ if (symbolsLength !== 1) {
1106
+ throw new BadRequest(this.id + ' watchMyLiquidationsForSymbols() only allows one symbol at a time. To listen to several symbols call watchMyLiquidationsForSymbols() several times.');
1107
+ }
1108
+ messageHash = 'myLiquidations::' + symbols[0];
1109
+ payload.push(market['id']);
1110
+ }
1111
+ const channel = typeId + '.liquidates';
1112
+ const newLiquidations = await this.subscribePrivate(url, messageHash, payload, channel, query, true);
1113
+ if (this.newUpdates) {
1114
+ return newLiquidations;
1115
+ }
1116
+ return this.filterBySymbolsSinceLimit(this.liquidations, symbols, since, limit, true);
1117
+ }
1118
+ handleLiquidation(client, message) {
1119
+ //
1120
+ // future / delivery
1121
+ // {
1122
+ // "channel":"futures.liquidates",
1123
+ // "event":"update",
1124
+ // "time":1541505434,
1125
+ // "time_ms":1541505434123,
1126
+ // "result":[
1127
+ // {
1128
+ // "entry_price":209,
1129
+ // "fill_price":215.1,
1130
+ // "left":0,
1131
+ // "leverage":0.0,
1132
+ // "liq_price":213,
1133
+ // "margin":0.007816722941,
1134
+ // "mark_price":213,
1135
+ // "order_id":4093362,
1136
+ // "order_price":215.1,
1137
+ // "size":-124,
1138
+ // "time":1541486601,
1139
+ // "time_ms":1541486601123,
1140
+ // "contract":"BTC_USD",
1141
+ // "user":"1040xxxx"
1142
+ // }
1143
+ // ]
1144
+ // }
1145
+ // option
1146
+ // {
1147
+ // "channel":"options.liquidates",
1148
+ // "event":"update",
1149
+ // "time":1630654851,
1150
+ // "result":[
1151
+ // {
1152
+ // "user":"1xxxx",
1153
+ // "init_margin":1190,
1154
+ // "maint_margin":1042.5,
1155
+ // "order_margin":0,
1156
+ // "time":1639051907,
1157
+ // "time_ms":1639051907000
1158
+ // }
1159
+ // ]
1160
+ // }
1161
+ //
1162
+ const rawLiquidations = this.safeList(message, 'result', []);
1163
+ const newLiquidations = [];
1164
+ for (let i = 0; i < rawLiquidations.length; i++) {
1165
+ const rawLiquidation = rawLiquidations[i];
1166
+ const liquidation = this.parseWsLiquidation(rawLiquidation);
1167
+ const symbol = this.safeString(liquidation, 'symbol');
1168
+ let liquidations = this.safeValue(this.liquidations, symbol);
1169
+ if (liquidations === undefined) {
1170
+ const limit = this.safeInteger(this.options, 'liquidationsLimit', 1000);
1171
+ liquidations = new ArrayCache(limit);
1172
+ }
1173
+ liquidations.append(liquidation);
1174
+ this.liquidations[symbol] = liquidations;
1175
+ client.resolve(liquidations, 'myLiquidations::' + symbol);
1176
+ }
1177
+ client.resolve(newLiquidations, 'myLiquidations');
1178
+ }
1179
+ parseWsLiquidation(liquidation, market = undefined) {
1180
+ //
1181
+ // future / delivery
1182
+ // {
1183
+ // "entry_price": 209,
1184
+ // "fill_price": 215.1,
1185
+ // "left": 0,
1186
+ // "leverage": 0.0,
1187
+ // "liq_price": 213,
1188
+ // "margin": 0.007816722941,
1189
+ // "mark_price": 213,
1190
+ // "order_id": 4093362,
1191
+ // "order_price": 215.1,
1192
+ // "size": -124,
1193
+ // "time": 1541486601,
1194
+ // "time_ms": 1541486601123,
1195
+ // "contract": "BTC_USD",
1196
+ // "user": "1040xxxx"
1197
+ // }
1198
+ // option
1199
+ // {
1200
+ // "user": "1xxxx",
1201
+ // "init_margin": 1190,
1202
+ // "maint_margin": 1042.5,
1203
+ // "order_margin": 0,
1204
+ // "time": 1639051907,
1205
+ // "time_ms": 1639051907000
1206
+ // }
1207
+ //
1208
+ const marketId = this.safeString(liquidation, 'contract');
1209
+ market = this.safeMarket(marketId, market);
1210
+ const timestamp = this.safeInteger(liquidation, 'time_ms');
1211
+ const originalSize = this.safeString(liquidation, 'size');
1212
+ const left = this.safeString(liquidation, 'left');
1213
+ const amount = Precise.stringAbs(Precise.stringSub(originalSize, left));
1214
+ return this.safeLiquidation({
1215
+ 'info': liquidation,
1216
+ 'symbol': this.safeSymbol(marketId, market),
1217
+ 'contracts': this.parseNumber(amount),
1218
+ 'contractSize': this.safeNumber(market, 'contractSize'),
1219
+ 'price': this.safeNumber(liquidation, 'fill_price'),
1220
+ 'baseValue': undefined,
1221
+ 'quoteValue': undefined,
1222
+ 'timestamp': timestamp,
1223
+ 'datetime': this.iso8601(timestamp),
1224
+ });
1225
+ }
1044
1226
  handleErrorMessage(client, message) {
1045
1227
  // {
1046
1228
  // "time": 1647274664,
@@ -1214,6 +1396,7 @@ export default class gate extends gateRest {
1214
1396
  'trades': this.handleTrades,
1215
1397
  'order_book_update': this.handleOrderBook,
1216
1398
  'balances': this.handleBalance,
1399
+ 'liquidates': this.handleLiquidation,
1217
1400
  };
1218
1401
  const method = this.safeValue(v4Methods, channelType);
1219
1402
  if (method !== undefined) {
@@ -14,6 +14,10 @@ export default class kucoinfutures extends kucoinfuturesRest {
14
14
  return this.deepExtend(super.describe(), {
15
15
  'has': {
16
16
  'ws': true,
17
+ 'watchLiquidations': false,
18
+ 'watchLiquidatinsForSymbols': false,
19
+ 'watchMyLiquidations': undefined,
20
+ 'watchMyLiquidationsForSymbols': undefined,
17
21
  'watchTicker': true,
18
22
  'watchTickers': true,
19
23
  'watchBidsAsks': true,
@@ -1,5 +1,5 @@
1
1
  import okxRest from '../okx.js';
2
- import type { Int, OrderSide, OrderType, Str, Strings, OrderBook, Order, Trade, Ticker, Tickers, OHLCV, Position, Balances, Num, FundingRate, FundingRates } from '../base/types.js';
2
+ import type { Int, OrderSide, OrderType, Str, Strings, OrderBook, Order, Trade, Ticker, Tickers, OHLCV, Position, Balances, Num, FundingRate, FundingRates, Liquidation } from '../base/types.js';
3
3
  import Client from '../base/ws/Client.js';
4
4
  export default class okx extends okxRest {
5
5
  describe(): any;
@@ -15,6 +15,12 @@ export default class okx extends okxRest {
15
15
  watchTicker(symbol: string, params?: {}): Promise<Ticker>;
16
16
  watchTickers(symbols?: Strings, params?: {}): Promise<Tickers>;
17
17
  handleTicker(client: Client, message: any): any;
18
+ watchLiquidationsForSymbols(symbols?: string[], since?: Int, limit?: Int, params?: {}): Promise<Liquidation[]>;
19
+ handleLiquidation(client: Client, message: any): void;
20
+ watchMyLiquidationsForSymbols(symbols?: string[], since?: Int, limit?: Int, params?: {}): Promise<Liquidation[]>;
21
+ handleMyLiquidation(client: Client, message: any): void;
22
+ parseWsMyLiquidation(liquidation: any, market?: any): Liquidation;
23
+ parseWsLiquidation(liquidation: any, market?: any): Liquidation;
18
24
  watchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<OHLCV[]>;
19
25
  watchOHLCVForSymbols(symbolsAndTimeframes: string[][], since?: Int, limit?: Int, params?: {}): Promise<import("../base/types.js").Dictionary<import("../base/types.js").Dictionary<OHLCV[]>>>;
20
26
  handleOHLCV(client: Client, message: any): void;
@@ -26,6 +32,7 @@ export default class okx extends okxRest {
26
32
  handleOrderBook(client: Client, message: any): any;
27
33
  authenticate(params?: {}): Promise<any>;
28
34
  watchBalance(params?: {}): Promise<Balances>;
35
+ handleBalanceAndPosition(client: Client, message: any): void;
29
36
  handleBalance(client: Client, message: any): void;
30
37
  orderToTrade(order: any, market?: any): Trade;
31
38
  watchMyTrades(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
package/js/src/pro/okx.js CHANGED
@@ -22,6 +22,10 @@ export default class okx extends okxRest {
22
22
  'watchTradesForSymbols': true,
23
23
  'watchOrderBookForSymbols': true,
24
24
  'watchBalance': true,
25
+ 'watchLiquidations': 'emulated',
26
+ 'watchLiquidationsForSymbols': true,
27
+ 'watchMyLiquidations': 'emulated',
28
+ 'watchMyLiquidationsForSymbols': true,
25
29
  'watchOHLCV': true,
26
30
  'watchOHLCVForSymbols': true,
27
31
  'watchOrders': true,
@@ -158,7 +162,7 @@ export default class okx extends okxRest {
158
162
  this.deepExtend(firstArgument, params),
159
163
  ],
160
164
  };
161
- return await this.watch(url, messageHash, request, messageHash);
165
+ return this.watch(url, messageHash, request, messageHash);
162
166
  }
163
167
  async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
164
168
  /**
@@ -422,6 +426,255 @@ export default class okx extends okxRest {
422
426
  }
423
427
  return message;
424
428
  }
429
+ async watchLiquidationsForSymbols(symbols = undefined, since = undefined, limit = undefined, params = {}) {
430
+ /**
431
+ * @method
432
+ * @name okx#watchLiquidationsForSymbols
433
+ * @description watch the public liquidations of a trading pair
434
+ * @see https://www.okx.com/docs-v5/en/#public-data-websocket-liquidation-orders-channel
435
+ * @param {string} symbol unified CCXT market symbol
436
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
437
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
438
+ * @param {object} [params] exchange specific parameters for the okx api endpoint
439
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
440
+ */
441
+ await this.loadMarkets();
442
+ symbols = this.marketSymbols(symbols, undefined, true, true);
443
+ let messageHash = 'liquidations';
444
+ if (symbols !== undefined) {
445
+ messageHash += '::' + symbols.join(',');
446
+ }
447
+ const market = this.getMarketFromSymbols(symbols);
448
+ let type = undefined;
449
+ [type, params] = this.handleMarketTypeAndParams('watchliquidationsForSymbols', market, params);
450
+ const channel = 'liquidation-orders';
451
+ if (type === 'spot') {
452
+ type = 'SWAP';
453
+ }
454
+ else if (type === 'future') {
455
+ type = 'futures';
456
+ }
457
+ const uppercaseType = type.toUpperCase();
458
+ const request = {
459
+ 'instType': uppercaseType,
460
+ };
461
+ const newLiquidations = await this.subscribe('public', messageHash, channel, undefined, this.extend(request, params));
462
+ if (this.newUpdates) {
463
+ return newLiquidations;
464
+ }
465
+ return this.filterBySymbolsSinceLimit(this.liquidations, symbols, since, limit, true);
466
+ }
467
+ handleLiquidation(client, message) {
468
+ //
469
+ // {
470
+ // "arg": {
471
+ // "channel": "liquidation-orders",
472
+ // "instType": "SWAP"
473
+ // },
474
+ // "data": [
475
+ // {
476
+ // "details": [
477
+ // {
478
+ // "bkLoss": "0",
479
+ // "bkPx": "0.007831",
480
+ // "ccy": "",
481
+ // "posSide": "short",
482
+ // "side": "buy",
483
+ // "sz": "13",
484
+ // "ts": "1692266434010"
485
+ // }
486
+ // ],
487
+ // "instFamily": "IOST-USDT",
488
+ // "instId": "IOST-USDT-SWAP",
489
+ // "instType": "SWAP",
490
+ // "uly": "IOST-USDT"
491
+ // }
492
+ // ]
493
+ // }
494
+ //
495
+ const rawLiquidations = this.safeList(message, 'data', []);
496
+ for (let i = 0; i < rawLiquidations.length; i++) {
497
+ const rawLiquidation = rawLiquidations[i];
498
+ const liquidation = this.parseWsLiquidation(rawLiquidation);
499
+ const symbol = this.safeString(liquidation, 'symbol');
500
+ let liquidations = this.safeValue(this.liquidations, symbol);
501
+ if (liquidations === undefined) {
502
+ const limit = this.safeInteger(this.options, 'liquidationsLimit', 1000);
503
+ liquidations = new ArrayCache(limit);
504
+ }
505
+ liquidations.append(liquidation);
506
+ this.liquidations[symbol] = liquidations;
507
+ client.resolve([liquidation], 'liquidations');
508
+ client.resolve([liquidation], 'liquidations::' + symbol);
509
+ }
510
+ }
511
+ async watchMyLiquidationsForSymbols(symbols = undefined, since = undefined, limit = undefined, params = {}) {
512
+ /**
513
+ * @method
514
+ * @name okx#watchMyLiquidationsForSymbols
515
+ * @description watch the private liquidations of a trading pair
516
+ * @see https://www.okx.com/docs-v5/en/#trading-account-websocket-balance-and-position-channel
517
+ * @param {string} symbol unified CCXT market symbol
518
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
519
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
520
+ * @param {object} [params] exchange specific parameters for the okx api endpoint
521
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
522
+ */
523
+ await this.loadMarkets();
524
+ const isStop = this.safeValue2(params, 'stop', 'trigger', false);
525
+ params = this.omit(params, ['stop', 'trigger']);
526
+ await this.authenticate({ 'access': isStop ? 'business' : 'private' });
527
+ symbols = this.marketSymbols(symbols, undefined, true, true);
528
+ let messageHash = 'myLiquidations';
529
+ if (symbols !== undefined) {
530
+ messageHash += '::' + symbols.join(',');
531
+ }
532
+ const channel = 'balance_and_position';
533
+ const newLiquidations = await this.subscribe('private', messageHash, channel, undefined, params);
534
+ if (this.newUpdates) {
535
+ return newLiquidations;
536
+ }
537
+ return this.filterBySymbolsSinceLimit(this.liquidations, symbols, since, limit, true);
538
+ }
539
+ handleMyLiquidation(client, message) {
540
+ //
541
+ // {
542
+ // "arg": {
543
+ // "channel": "balance_and_position",
544
+ // "uid": "77982378738415879"
545
+ // },
546
+ // "data": [{
547
+ // "pTime": "1597026383085",
548
+ // "eventType": "snapshot",
549
+ // "balData": [{
550
+ // "ccy": "BTC",
551
+ // "cashBal": "1",
552
+ // "uTime": "1597026383085"
553
+ // }],
554
+ // "posData": [{
555
+ // "posId": "1111111111",
556
+ // "tradeId": "2",
557
+ // "instId": "BTC-USD-191018",
558
+ // "instType": "FUTURES",
559
+ // "mgnMode": "cross",
560
+ // "posSide": "long",
561
+ // "pos": "10",
562
+ // "ccy": "BTC",
563
+ // "posCcy": "",
564
+ // "avgPx": "3320",
565
+ // "uTIme": "1597026383085"
566
+ // }],
567
+ // "trades": [{
568
+ // "instId": "BTC-USD-191018",
569
+ // "tradeId": "2",
570
+ // }]
571
+ // }]
572
+ // }
573
+ //
574
+ const rawLiquidations = this.safeList(message, 'data', []);
575
+ for (let i = 0; i < rawLiquidations.length; i++) {
576
+ const rawLiquidation = rawLiquidations[i];
577
+ const eventType = this.safeString(rawLiquidation, 'eventType');
578
+ if (eventType !== 'liquidation') {
579
+ return;
580
+ }
581
+ const liquidation = this.parseWsMyLiquidation(rawLiquidation);
582
+ const symbol = this.safeString(liquidation, 'symbol');
583
+ let liquidations = this.safeValue(this.liquidations, symbol);
584
+ if (liquidations === undefined) {
585
+ const limit = this.safeInteger(this.options, 'myLiquidationsLimit', 1000);
586
+ liquidations = new ArrayCache(limit);
587
+ }
588
+ liquidations.append(liquidation);
589
+ this.liquidations[symbol] = liquidations;
590
+ client.resolve([liquidation], 'myLiquidations');
591
+ client.resolve([liquidation], 'myLiquidations::' + symbol);
592
+ }
593
+ }
594
+ parseWsMyLiquidation(liquidation, market = undefined) {
595
+ //
596
+ // {
597
+ // "pTime": "1597026383085",
598
+ // "eventType": "snapshot",
599
+ // "balData": [{
600
+ // "ccy": "BTC",
601
+ // "cashBal": "1",
602
+ // "uTime": "1597026383085"
603
+ // }],
604
+ // "posData": [{
605
+ // "posId": "1111111111",
606
+ // "tradeId": "2",
607
+ // "instId": "BTC-USD-191018",
608
+ // "instType": "FUTURES",
609
+ // "mgnMode": "cross",
610
+ // "posSide": "long",
611
+ // "pos": "10",
612
+ // "ccy": "BTC",
613
+ // "posCcy": "",
614
+ // "avgPx": "3320",
615
+ // "uTIme": "1597026383085"
616
+ // }],
617
+ // "trades": [{
618
+ // "instId": "BTC-USD-191018",
619
+ // "tradeId": "2",
620
+ // }]
621
+ // }
622
+ //
623
+ const posData = this.safeList(liquidation, 'posData', []);
624
+ const firstPosData = this.safeDict(posData, 0, {});
625
+ const marketId = this.safeString(firstPosData, 'instId');
626
+ market = this.safeMarket(marketId, market);
627
+ const timestamp = this.safeInteger(firstPosData, 'uTIme');
628
+ return this.safeLiquidation({
629
+ 'info': liquidation,
630
+ 'symbol': this.safeSymbol(marketId, market),
631
+ 'contracts': this.safeNumber(firstPosData, 'pos'),
632
+ 'contractSize': this.safeNumber(market, 'contractSize'),
633
+ 'price': this.safeNumber(liquidation, 'avgPx'),
634
+ 'baseValue': undefined,
635
+ 'quoteValue': undefined,
636
+ 'timestamp': timestamp,
637
+ 'datetime': this.iso8601(timestamp),
638
+ });
639
+ }
640
+ parseWsLiquidation(liquidation, market = undefined) {
641
+ //
642
+ // public liquidation
643
+ // {
644
+ // "details": [
645
+ // {
646
+ // "bkLoss": "0",
647
+ // "bkPx": "0.007831",
648
+ // "ccy": "",
649
+ // "posSide": "short",
650
+ // "side": "buy",
651
+ // "sz": "13",
652
+ // "ts": "1692266434010"
653
+ // }
654
+ // ],
655
+ // "instFamily": "IOST-USDT",
656
+ // "instId": "IOST-USDT-SWAP",
657
+ // "instType": "SWAP",
658
+ // "uly": "IOST-USDT"
659
+ // }
660
+ //
661
+ const details = this.safeList(liquidation, 'details', []);
662
+ const liquidationDetails = this.safeDict(details, 0, {});
663
+ const marketId = this.safeString(liquidation, 'instId');
664
+ market = this.safeMarket(marketId, market);
665
+ const timestamp = this.safeInteger(liquidationDetails, 'ts');
666
+ return this.safeLiquidation({
667
+ 'info': liquidation,
668
+ 'symbol': this.safeSymbol(marketId, market),
669
+ 'contracts': this.safeNumber(liquidationDetails, 'sz'),
670
+ 'contractSize': this.safeNumber(market, 'contractSize'),
671
+ 'price': this.safeNumber(liquidationDetails, 'bkPx'),
672
+ 'baseValue': undefined,
673
+ 'quoteValue': undefined,
674
+ 'timestamp': timestamp,
675
+ 'datetime': this.iso8601(timestamp),
676
+ });
677
+ }
425
678
  async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
426
679
  /**
427
680
  * @method
@@ -881,6 +1134,9 @@ export default class okx extends okxRest {
881
1134
  await this.authenticate();
882
1135
  return await this.subscribe('private', 'account', 'account', undefined, params);
883
1136
  }
1137
+ handleBalanceAndPosition(client, message) {
1138
+ this.handleMyLiquidation(client, message);
1139
+ }
884
1140
  handleBalance(client, message) {
885
1141
  //
886
1142
  // {
@@ -1724,6 +1980,8 @@ export default class okx extends okxRest {
1724
1980
  // 'margin_account': this.handleBalance,
1725
1981
  'orders': this.handleOrders,
1726
1982
  'orders-algo': this.handleOrders,
1983
+ 'liquidation-orders': this.handleLiquidation,
1984
+ 'balance_and_position': this.handleBalanceAndPosition,
1727
1985
  };
1728
1986
  const method = this.safeValue(methods, channel);
1729
1987
  if (method === undefined) {
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/probit.js';
2
- import type { Balances, Currencies, Currency, Dict, Int, Market, Num, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction } from './base/types.js';
2
+ import type { Balances, Currencies, Currency, Dict, Int, Market, Num, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, int } from './base/types.js';
3
3
  /**
4
4
  * @class probit
5
5
  * @augments Exchange
@@ -7,7 +7,7 @@ import type { Balances, Currencies, Currency, Dict, Int, Market, Num, OHLCV, Ord
7
7
  export default class probit extends Exchange {
8
8
  describe(): any;
9
9
  fetchMarkets(params?: {}): Promise<Market[]>;
10
- parseMarket(market: any): Market;
10
+ parseMarket(market: Dict): Market;
11
11
  fetchCurrencies(params?: {}): Promise<Currencies>;
12
12
  parseBalance(response: any): Balances;
13
13
  fetchBalance(params?: {}): Promise<Balances>;
@@ -50,7 +50,7 @@ export default class probit extends Exchange {
50
50
  fetchWithdrawals(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<Transaction[]>;
51
51
  fetchDepositsWithdrawals(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<Transaction[]>;
52
52
  parseTransaction(transaction: Dict, currency?: Currency): Transaction;
53
- parseTransactionStatus(status: any): string;
53
+ parseTransactionStatus(status: Str): string;
54
54
  fetchDepositWithdrawFees(codes?: Strings, params?: {}): Promise<any>;
55
55
  parseDepositWithdrawFee(fee: any, currency?: Currency): any;
56
56
  nonce(): number;
@@ -61,5 +61,5 @@ export default class probit extends Exchange {
61
61
  headers: any;
62
62
  };
63
63
  signIn(params?: {}): Promise<any>;
64
- handleErrors(code: any, reason: any, url: any, method: any, headers: any, body: any, response: any, requestHeaders: any, requestBody: any): any;
64
+ handleErrors(code: int, reason: string, url: string, method: string, headers: Dict, body: string, response: any, requestHeaders: any, requestBody: any): any;
65
65
  }
package/js/src/timex.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/timex.js';
2
- import type { Balances, Currencies, Currency, Dict, Int, Market, Num, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, TradingFeeInterface, Transaction } from './base/types.js';
2
+ import type { Balances, Currencies, Currency, Dict, Int, Market, Num, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, TradingFeeInterface, Transaction, int } from './base/types.js';
3
3
  /**
4
4
  * @class timex
5
5
  * @augments Exchange
@@ -30,7 +30,7 @@ export default class timex extends Exchange {
30
30
  fetchMyTrades(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
31
31
  parseTradingFee(fee: Dict, market?: Market): TradingFeeInterface;
32
32
  fetchTradingFee(symbol: string, params?: {}): Promise<TradingFeeInterface>;
33
- parseMarket(market: any): Market;
33
+ parseMarket(market: Dict): Market;
34
34
  parseCurrency(currency: Dict): {
35
35
  id: string;
36
36
  code: string;
@@ -78,5 +78,5 @@ export default class timex extends Exchange {
78
78
  body: any;
79
79
  headers: any;
80
80
  };
81
- handleErrors(statusCode: any, statusText: any, url: any, method: any, responseHeaders: any, responseBody: any, response: any, requestHeaders: any, requestBody: any): any;
81
+ handleErrors(statusCode: int, statusText: string, url: string, method: string, responseHeaders: Dict, responseBody: any, response: any, requestHeaders: any, requestBody: any): any;
82
82
  }
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/tokocrypto.js';
2
- import type { Balances, Currency, Dict, Int, Market, Num, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction } from './base/types.js';
2
+ import type { Balances, Currency, Dict, Int, Market, Num, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, int } from './base/types.js';
3
3
  /**
4
4
  * @class tokocrypto
5
5
  * @augments Exchange
@@ -49,6 +49,6 @@ export default class tokocrypto extends Exchange {
49
49
  body: any;
50
50
  headers: any;
51
51
  };
52
- handleErrors(code: any, reason: any, url: any, method: any, headers: any, body: any, response: any, requestHeaders: any, requestBody: any): any;
52
+ handleErrors(code: int, reason: string, url: string, method: string, headers: Dict, body: string, response: any, requestHeaders: any, requestBody: any): any;
53
53
  calculateRateLimiterCost(api: any, method: any, path: any, params: any, config?: {}): any;
54
54
  }
@@ -1,6 +1,6 @@
1
1
  import { Market } from '../ccxt.js';
2
2
  import Exchange from './abstract/tradeogre.js';
3
- import type { Int, Num, Order, OrderSide, OrderType, Str, Ticker, IndexType, Dict } from './base/types.js';
3
+ import type { Int, Num, Order, OrderSide, OrderType, Str, Ticker, IndexType, Dict, int } from './base/types.js';
4
4
  /**
5
5
  * @class tradeogre
6
6
  * @augments Exchange
@@ -28,5 +28,5 @@ export default class tradeogre extends Exchange {
28
28
  body: any;
29
29
  headers: any;
30
30
  };
31
- handleErrors(code: any, reason: any, url: any, method: any, headers: any, body: any, response: any, requestHeaders: any, requestBody: any): any;
31
+ handleErrors(code: int, reason: string, url: string, method: string, headers: Dict, body: string, response: any, requestHeaders: any, requestBody: any): any;
32
32
  }