ccxt 4.3.33 → 4.3.35

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 (135) 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/alpaca.js +1 -1
  5. package/dist/cjs/src/base/Exchange.js +37 -0
  6. package/dist/cjs/src/binance.js +1 -0
  7. package/dist/cjs/src/bitmart.js +2 -9
  8. package/dist/cjs/src/coinbase.js +169 -55
  9. package/dist/cjs/src/coinex.js +26 -19
  10. package/dist/cjs/src/kraken.js +3 -1
  11. package/dist/cjs/src/pro/binance.js +352 -0
  12. package/dist/cjs/src/pro/bitget.js +31 -1
  13. package/dist/cjs/src/pro/bitmex.js +108 -0
  14. package/dist/cjs/src/pro/bybit.js +85 -0
  15. package/dist/cjs/src/pro/gate.js +183 -0
  16. package/dist/cjs/src/pro/kucoinfutures.js +4 -0
  17. package/dist/cjs/src/pro/okx.js +258 -0
  18. package/js/ccxt.d.ts +1 -1
  19. package/js/ccxt.js +1 -1
  20. package/js/src/abstract/binance.d.ts +1 -0
  21. package/js/src/abstract/binancecoinm.d.ts +1 -0
  22. package/js/src/abstract/binanceus.d.ts +1 -0
  23. package/js/src/abstract/binanceusdm.d.ts +1 -0
  24. package/js/src/ace.d.ts +3 -3
  25. package/js/src/alpaca.d.ts +3 -3
  26. package/js/src/alpaca.js +1 -1
  27. package/js/src/ascendex.d.ts +3 -3
  28. package/js/src/base/Exchange.d.ts +14 -3
  29. package/js/src/base/Exchange.js +37 -0
  30. package/js/src/base/types.d.ts +1 -0
  31. package/js/src/bigone.d.ts +3 -3
  32. package/js/src/binance.d.ts +4 -4
  33. package/js/src/binance.js +1 -0
  34. package/js/src/bingx.d.ts +3 -3
  35. package/js/src/bit2c.d.ts +2 -2
  36. package/js/src/bitbank.d.ts +2 -2
  37. package/js/src/bitbns.d.ts +2 -2
  38. package/js/src/bitfinex.d.ts +3 -3
  39. package/js/src/bitfinex2.d.ts +1 -1
  40. package/js/src/bitflyer.d.ts +2 -2
  41. package/js/src/bitget.d.ts +4 -4
  42. package/js/src/bithumb.d.ts +2 -2
  43. package/js/src/bitmart.d.ts +3 -3
  44. package/js/src/bitmart.js +2 -9
  45. package/js/src/bitmex.d.ts +4 -4
  46. package/js/src/bitopro.d.ts +4 -4
  47. package/js/src/bitrue.d.ts +3 -3
  48. package/js/src/bitso.d.ts +3 -3
  49. package/js/src/bitstamp.d.ts +3 -3
  50. package/js/src/bitteam.d.ts +4 -4
  51. package/js/src/bitvavo.d.ts +3 -3
  52. package/js/src/blockchaincom.d.ts +2 -2
  53. package/js/src/blofin.d.ts +4 -4
  54. package/js/src/btcalpha.d.ts +4 -4
  55. package/js/src/btcbox.d.ts +2 -2
  56. package/js/src/btcmarkets.d.ts +4 -4
  57. package/js/src/btcturk.d.ts +2 -2
  58. package/js/src/bybit.d.ts +3 -3
  59. package/js/src/cex.d.ts +2 -2
  60. package/js/src/coinbase.d.ts +4 -3
  61. package/js/src/coinbase.js +169 -55
  62. package/js/src/coinbaseexchange.d.ts +2 -2
  63. package/js/src/coinbaseinternational.d.ts +4 -4
  64. package/js/src/coincheck.d.ts +3 -3
  65. package/js/src/coinex.d.ts +3 -3
  66. package/js/src/coinex.js +26 -19
  67. package/js/src/coinlist.d.ts +3 -3
  68. package/js/src/coinmate.d.ts +3 -3
  69. package/js/src/coinmetro.d.ts +3 -3
  70. package/js/src/coinone.d.ts +2 -2
  71. package/js/src/coinsph.d.ts +3 -3
  72. package/js/src/cryptocom.d.ts +2 -2
  73. package/js/src/currencycom.d.ts +3 -3
  74. package/js/src/delta.d.ts +2 -2
  75. package/js/src/deribit.d.ts +3 -3
  76. package/js/src/digifinex.d.ts +3 -3
  77. package/js/src/exmo.d.ts +3 -3
  78. package/js/src/gate.d.ts +3 -3
  79. package/js/src/gemini.d.ts +3 -3
  80. package/js/src/hitbtc.d.ts +3 -3
  81. package/js/src/hollaex.d.ts +2 -2
  82. package/js/src/htx.d.ts +3 -3
  83. package/js/src/huobijp.d.ts +3 -3
  84. package/js/src/hyperliquid.d.ts +3 -3
  85. package/js/src/idex.d.ts +3 -3
  86. package/js/src/indodax.d.ts +3 -3
  87. package/js/src/kraken.d.ts +3 -3
  88. package/js/src/kraken.js +3 -1
  89. package/js/src/krakenfutures.d.ts +2 -2
  90. package/js/src/kucoin.d.ts +3 -3
  91. package/js/src/kuna.d.ts +3 -3
  92. package/js/src/latoken.d.ts +3 -3
  93. package/js/src/lbank.d.ts +2 -2
  94. package/js/src/luno.d.ts +2 -2
  95. package/js/src/lykke.d.ts +2 -2
  96. package/js/src/mercado.d.ts +2 -2
  97. package/js/src/mexc.d.ts +2 -2
  98. package/js/src/ndax.d.ts +3 -3
  99. package/js/src/novadax.d.ts +4 -4
  100. package/js/src/oceanex.d.ts +3 -3
  101. package/js/src/okcoin.d.ts +4 -4
  102. package/js/src/okx.d.ts +4 -4
  103. package/js/src/onetrading.d.ts +3 -3
  104. package/js/src/p2b.d.ts +3 -3
  105. package/js/src/paymium.d.ts +2 -2
  106. package/js/src/phemex.d.ts +5 -5
  107. package/js/src/poloniex.d.ts +4 -4
  108. package/js/src/poloniexfutures.d.ts +3 -3
  109. package/js/src/pro/binance.d.ts +9 -2
  110. package/js/src/pro/binance.js +352 -0
  111. package/js/src/pro/bitget.js +31 -1
  112. package/js/src/pro/bitmex.d.ts +4 -1
  113. package/js/src/pro/bitmex.js +108 -0
  114. package/js/src/pro/bybit.d.ts +4 -1
  115. package/js/src/pro/bybit.js +85 -0
  116. package/js/src/pro/gate.d.ts +5 -1
  117. package/js/src/pro/gate.js +183 -0
  118. package/js/src/pro/kucoinfutures.js +4 -0
  119. package/js/src/pro/okx.d.ts +8 -1
  120. package/js/src/pro/okx.js +258 -0
  121. package/js/src/probit.d.ts +4 -4
  122. package/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.d.ts +1 -1
  123. package/js/src/timex.d.ts +3 -3
  124. package/js/src/tokocrypto.d.ts +2 -2
  125. package/js/src/tradeogre.d.ts +2 -2
  126. package/js/src/upbit.d.ts +4 -4
  127. package/js/src/wavesexchange.d.ts +2 -2
  128. package/js/src/wazirx.d.ts +4 -4
  129. package/js/src/whitebit.d.ts +4 -4
  130. package/js/src/woo.d.ts +4 -4
  131. package/js/src/woofipro.d.ts +4 -4
  132. package/js/src/yobit.d.ts +2 -2
  133. package/js/src/zaif.d.ts +3 -3
  134. package/js/src/zonda.d.ts +2 -2
  135. package/package.json +1 -1
@@ -22,6 +22,10 @@ class bybit extends bybit$1 {
22
22
  'fetchTradesWs': false,
23
23
  'fetchBalanceWs': false,
24
24
  'watchBalance': true,
25
+ 'watchLiquidations': true,
26
+ 'watchLiquidationsForSymbols': false,
27
+ 'watchMyLiquidations': false,
28
+ 'watchMyLiquidationsForSymbols': false,
25
29
  'watchMyTrades': true,
26
30
  'watchOHLCV': true,
27
31
  'watchOHLCVForSymbols': false,
@@ -1199,6 +1203,86 @@ class bybit extends bybit$1 {
1199
1203
  }
1200
1204
  client.resolve(newPositions, 'positions');
1201
1205
  }
1206
+ async watchLiquidations(symbol, since = undefined, limit = undefined, params = {}) {
1207
+ /**
1208
+ * @method
1209
+ * @name bybit#watchLiquidations
1210
+ * @description watch the public liquidations of a trading pair
1211
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/liquidation
1212
+ * @param {string} symbol unified CCXT market symbol
1213
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
1214
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
1215
+ * @param {object} [params] exchange specific parameters for the bitmex api endpoint
1216
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
1217
+ */
1218
+ await this.loadMarkets();
1219
+ const market = this.market(symbol);
1220
+ symbol = market['symbol'];
1221
+ const url = this.getUrlByMarketType(symbol, false, 'watchLiquidations', params);
1222
+ params = this.cleanParams(params);
1223
+ const messageHash = 'liquidations::' + symbol;
1224
+ const topic = 'liquidation.' + market['id'];
1225
+ const newLiquidation = await this.watchTopics(url, [messageHash], [topic], params);
1226
+ if (this.newUpdates) {
1227
+ return [newLiquidation];
1228
+ }
1229
+ return this.filterBySymbolsSinceLimit(this.liquidations, [symbol], since, limit, true);
1230
+ }
1231
+ handleLiquidation(client, message) {
1232
+ //
1233
+ // {
1234
+ // "data": {
1235
+ // "price": "0.03803",
1236
+ // "side": "Buy",
1237
+ // "size": "1637",
1238
+ // "symbol": "GALAUSDT",
1239
+ // "updatedTime": 1673251091822
1240
+ // },
1241
+ // "topic": "liquidation.GALAUSDT",
1242
+ // "ts": 1673251091822,
1243
+ // "type": "snapshot"
1244
+ // }
1245
+ //
1246
+ const rawLiquidation = this.safeDict(message, 'data', {});
1247
+ const marketId = this.safeString(rawLiquidation, 'symbol');
1248
+ const market = this.safeMarket(marketId, undefined, '', 'contract');
1249
+ const symbol = this.safeSymbol(marketId);
1250
+ const liquidation = this.parseWsLiquidation(rawLiquidation, market);
1251
+ let liquidations = this.safeValue(this.liquidations, symbol);
1252
+ if (liquidations === undefined) {
1253
+ const limit = this.safeInteger(this.options, 'liquidationsLimit', 1000);
1254
+ liquidations = new Cache.ArrayCache(limit);
1255
+ }
1256
+ liquidations.append(liquidation);
1257
+ this.liquidations[symbol] = liquidations;
1258
+ client.resolve([liquidation], 'liquidations');
1259
+ client.resolve([liquidation], 'liquidations::' + symbol);
1260
+ }
1261
+ parseWsLiquidation(liquidation, market = undefined) {
1262
+ //
1263
+ // {
1264
+ // "price": "0.03803",
1265
+ // "side": "Buy",
1266
+ // "size": "1637",
1267
+ // "symbol": "GALAUSDT",
1268
+ // "updatedTime": 1673251091822
1269
+ // }
1270
+ //
1271
+ const marketId = this.safeString(liquidation, 'symbol');
1272
+ market = this.safeMarket(marketId, market, '', 'contract');
1273
+ const timestamp = this.safeInteger(liquidation, 'updatedTime');
1274
+ return this.safeLiquidation({
1275
+ 'info': liquidation,
1276
+ 'symbol': this.safeSymbol(marketId, market),
1277
+ 'contracts': this.safeNumber(liquidation, 'size'),
1278
+ 'contractSize': this.safeNumber(market, 'contractSize'),
1279
+ 'price': this.safeNumber(liquidation, 'price'),
1280
+ 'baseValue': undefined,
1281
+ 'quoteValue': undefined,
1282
+ 'timestamp': timestamp,
1283
+ 'datetime': this.iso8601(timestamp),
1284
+ });
1285
+ }
1202
1286
  async watchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1203
1287
  /**
1204
1288
  * @method
@@ -1959,6 +2043,7 @@ class bybit extends bybit$1 {
1959
2043
  'ticketInfo': this.handleMyTrades,
1960
2044
  'user.openapi.perp.trade': this.handleMyTrades,
1961
2045
  'position': this.handlePositions,
2046
+ 'liquidation': this.handleLiquidation,
1962
2047
  'pong': this.handlePong,
1963
2048
  'order.create': this.handleOrderWs,
1964
2049
  'order.amend': this.handleOrderWs,
@@ -4,6 +4,7 @@ var gate$1 = require('../gate.js');
4
4
  var errors = require('../base/errors.js');
5
5
  var Cache = require('../base/ws/Cache.js');
6
6
  var sha512 = require('../static_dependencies/noble-hashes/sha512.js');
7
+ var Precise = require('../base/Precise.js');
7
8
 
8
9
  // ---------------------------------------------------------------------------
9
10
  // ---------------------------------------------------------------------------
@@ -21,6 +22,10 @@ class gate extends gate$1 {
21
22
  'watchOHLCV': true,
22
23
  'watchBalance': true,
23
24
  'watchOrders': true,
25
+ 'watchLiquidations': false,
26
+ 'watchLiquidationsForSymbols': false,
27
+ 'watchMyLiquidations': true,
28
+ 'watchMyLiquidationsForSymbols': true,
24
29
  'watchPositions': true,
25
30
  },
26
31
  'urls': {
@@ -1038,6 +1043,183 @@ class gate extends gate$1 {
1038
1043
  }
1039
1044
  client.resolve(this.orders, 'orders');
1040
1045
  }
1046
+ async watchMyLiquidations(symbol, since = undefined, limit = undefined, params = {}) {
1047
+ /**
1048
+ * @method
1049
+ * @name gate#watchMyLiquidations
1050
+ * @description watch the public liquidations of a trading pair
1051
+ * @see https://www.gate.io/docs/developers/futures/ws/en/#liquidates-api
1052
+ * @see https://www.gate.io/docs/developers/delivery/ws/en/#liquidates-api
1053
+ * @see https://www.gate.io/docs/developers/options/ws/en/#liquidates-channel
1054
+ * @param {string} symbol unified CCXT market symbol
1055
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
1056
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
1057
+ * @param {object} [params] exchange specific parameters for the bitmex api endpoint
1058
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
1059
+ */
1060
+ return this.watchMyLiquidationsForSymbols([symbol], since, limit, params);
1061
+ }
1062
+ async watchMyLiquidationsForSymbols(symbols = undefined, since = undefined, limit = undefined, params = {}) {
1063
+ /**
1064
+ * @method
1065
+ * @name gate#watchMyLiquidationsForSymbols
1066
+ * @description watch the private liquidations of a trading pair
1067
+ * @see https://www.gate.io/docs/developers/futures/ws/en/#liquidates-api
1068
+ * @see https://www.gate.io/docs/developers/delivery/ws/en/#liquidates-api
1069
+ * @see https://www.gate.io/docs/developers/options/ws/en/#liquidates-channel
1070
+ * @param {string} symbol unified CCXT market symbol
1071
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
1072
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
1073
+ * @param {object} [params] exchange specific parameters for the gate api endpoint
1074
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
1075
+ */
1076
+ await this.loadMarkets();
1077
+ symbols = this.marketSymbols(symbols, undefined, true, true);
1078
+ const market = this.getMarketFromSymbols(symbols);
1079
+ let type = undefined;
1080
+ let query = undefined;
1081
+ [type, query] = this.handleMarketTypeAndParams('watchMyLiquidationsForSymbols', market, params);
1082
+ const typeId = this.getSupportedMapping(type, {
1083
+ 'future': 'futures',
1084
+ 'swap': 'futures',
1085
+ 'option': 'options',
1086
+ });
1087
+ let subType = undefined;
1088
+ [subType, query] = this.handleSubTypeAndParams('watchMyLiquidationsForSymbols', market, query);
1089
+ const isInverse = (subType === 'inverse');
1090
+ const url = this.getUrlByMarketType(type, isInverse);
1091
+ const payload = [];
1092
+ let messageHash = '';
1093
+ if (this.isEmpty(symbols)) {
1094
+ if (typeId !== 'futures' && !isInverse) {
1095
+ throw new errors.BadRequest(this.id + ' watchMyLiquidationsForSymbols() does not support listening to all symbols, you must call watchMyLiquidations() instead for each symbol you wish to watch.');
1096
+ }
1097
+ messageHash = 'myLiquidations';
1098
+ payload.push('!all');
1099
+ }
1100
+ else {
1101
+ const symbolsLength = symbols.length;
1102
+ if (symbolsLength !== 1) {
1103
+ throw new errors.BadRequest(this.id + ' watchMyLiquidationsForSymbols() only allows one symbol at a time. To listen to several symbols call watchMyLiquidationsForSymbols() several times.');
1104
+ }
1105
+ messageHash = 'myLiquidations::' + symbols[0];
1106
+ payload.push(market['id']);
1107
+ }
1108
+ const channel = typeId + '.liquidates';
1109
+ const newLiquidations = await this.subscribePrivate(url, messageHash, payload, channel, query, true);
1110
+ if (this.newUpdates) {
1111
+ return newLiquidations;
1112
+ }
1113
+ return this.filterBySymbolsSinceLimit(this.liquidations, symbols, since, limit, true);
1114
+ }
1115
+ handleLiquidation(client, message) {
1116
+ //
1117
+ // future / delivery
1118
+ // {
1119
+ // "channel":"futures.liquidates",
1120
+ // "event":"update",
1121
+ // "time":1541505434,
1122
+ // "time_ms":1541505434123,
1123
+ // "result":[
1124
+ // {
1125
+ // "entry_price":209,
1126
+ // "fill_price":215.1,
1127
+ // "left":0,
1128
+ // "leverage":0.0,
1129
+ // "liq_price":213,
1130
+ // "margin":0.007816722941,
1131
+ // "mark_price":213,
1132
+ // "order_id":4093362,
1133
+ // "order_price":215.1,
1134
+ // "size":-124,
1135
+ // "time":1541486601,
1136
+ // "time_ms":1541486601123,
1137
+ // "contract":"BTC_USD",
1138
+ // "user":"1040xxxx"
1139
+ // }
1140
+ // ]
1141
+ // }
1142
+ // option
1143
+ // {
1144
+ // "channel":"options.liquidates",
1145
+ // "event":"update",
1146
+ // "time":1630654851,
1147
+ // "result":[
1148
+ // {
1149
+ // "user":"1xxxx",
1150
+ // "init_margin":1190,
1151
+ // "maint_margin":1042.5,
1152
+ // "order_margin":0,
1153
+ // "time":1639051907,
1154
+ // "time_ms":1639051907000
1155
+ // }
1156
+ // ]
1157
+ // }
1158
+ //
1159
+ const rawLiquidations = this.safeList(message, 'result', []);
1160
+ const newLiquidations = [];
1161
+ for (let i = 0; i < rawLiquidations.length; i++) {
1162
+ const rawLiquidation = rawLiquidations[i];
1163
+ const liquidation = this.parseWsLiquidation(rawLiquidation);
1164
+ const symbol = this.safeString(liquidation, 'symbol');
1165
+ let liquidations = this.safeValue(this.liquidations, symbol);
1166
+ if (liquidations === undefined) {
1167
+ const limit = this.safeInteger(this.options, 'liquidationsLimit', 1000);
1168
+ liquidations = new Cache.ArrayCache(limit);
1169
+ }
1170
+ liquidations.append(liquidation);
1171
+ this.liquidations[symbol] = liquidations;
1172
+ client.resolve(liquidations, 'myLiquidations::' + symbol);
1173
+ }
1174
+ client.resolve(newLiquidations, 'myLiquidations');
1175
+ }
1176
+ parseWsLiquidation(liquidation, market = undefined) {
1177
+ //
1178
+ // future / delivery
1179
+ // {
1180
+ // "entry_price": 209,
1181
+ // "fill_price": 215.1,
1182
+ // "left": 0,
1183
+ // "leverage": 0.0,
1184
+ // "liq_price": 213,
1185
+ // "margin": 0.007816722941,
1186
+ // "mark_price": 213,
1187
+ // "order_id": 4093362,
1188
+ // "order_price": 215.1,
1189
+ // "size": -124,
1190
+ // "time": 1541486601,
1191
+ // "time_ms": 1541486601123,
1192
+ // "contract": "BTC_USD",
1193
+ // "user": "1040xxxx"
1194
+ // }
1195
+ // option
1196
+ // {
1197
+ // "user": "1xxxx",
1198
+ // "init_margin": 1190,
1199
+ // "maint_margin": 1042.5,
1200
+ // "order_margin": 0,
1201
+ // "time": 1639051907,
1202
+ // "time_ms": 1639051907000
1203
+ // }
1204
+ //
1205
+ const marketId = this.safeString(liquidation, 'contract');
1206
+ market = this.safeMarket(marketId, market);
1207
+ const timestamp = this.safeInteger(liquidation, 'time_ms');
1208
+ const originalSize = this.safeString(liquidation, 'size');
1209
+ const left = this.safeString(liquidation, 'left');
1210
+ const amount = Precise["default"].stringAbs(Precise["default"].stringSub(originalSize, left));
1211
+ return this.safeLiquidation({
1212
+ 'info': liquidation,
1213
+ 'symbol': this.safeSymbol(marketId, market),
1214
+ 'contracts': this.parseNumber(amount),
1215
+ 'contractSize': this.safeNumber(market, 'contractSize'),
1216
+ 'price': this.safeNumber(liquidation, 'fill_price'),
1217
+ 'baseValue': undefined,
1218
+ 'quoteValue': undefined,
1219
+ 'timestamp': timestamp,
1220
+ 'datetime': this.iso8601(timestamp),
1221
+ });
1222
+ }
1041
1223
  handleErrorMessage(client, message) {
1042
1224
  // {
1043
1225
  // "time": 1647274664,
@@ -1211,6 +1393,7 @@ class gate extends gate$1 {
1211
1393
  'trades': this.handleTrades,
1212
1394
  'order_book_update': this.handleOrderBook,
1213
1395
  'balances': this.handleBalance,
1396
+ 'liquidates': this.handleLiquidation,
1214
1397
  };
1215
1398
  const method = this.safeValue(v4Methods, channelType);
1216
1399
  if (method !== undefined) {
@@ -11,6 +11,10 @@ class kucoinfutures extends kucoinfutures$1 {
11
11
  return this.deepExtend(super.describe(), {
12
12
  'has': {
13
13
  'ws': true,
14
+ 'watchLiquidations': false,
15
+ 'watchLiquidatinsForSymbols': false,
16
+ 'watchMyLiquidations': undefined,
17
+ 'watchMyLiquidationsForSymbols': undefined,
14
18
  'watchTicker': true,
15
19
  'watchTickers': true,
16
20
  'watchBidsAsks': true,
@@ -19,6 +19,10 @@ class okx extends okx$1 {
19
19
  'watchTradesForSymbols': true,
20
20
  'watchOrderBookForSymbols': true,
21
21
  'watchBalance': true,
22
+ 'watchLiquidations': 'emulated',
23
+ 'watchLiquidationsForSymbols': true,
24
+ 'watchMyLiquidations': 'emulated',
25
+ 'watchMyLiquidationsForSymbols': true,
22
26
  'watchOHLCV': true,
23
27
  'watchOHLCVForSymbols': true,
24
28
  'watchOrders': true,
@@ -419,6 +423,255 @@ class okx extends okx$1 {
419
423
  }
420
424
  return message;
421
425
  }
426
+ async watchLiquidationsForSymbols(symbols = undefined, since = undefined, limit = undefined, params = {}) {
427
+ /**
428
+ * @method
429
+ * @name okx#watchLiquidationsForSymbols
430
+ * @description watch the public liquidations of a trading pair
431
+ * @see https://www.okx.com/docs-v5/en/#public-data-websocket-liquidation-orders-channel
432
+ * @param {string} symbol unified CCXT market symbol
433
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
434
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
435
+ * @param {object} [params] exchange specific parameters for the okx api endpoint
436
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
437
+ */
438
+ await this.loadMarkets();
439
+ symbols = this.marketSymbols(symbols, undefined, true, true);
440
+ let messageHash = 'liquidations';
441
+ if (symbols !== undefined) {
442
+ messageHash += '::' + symbols.join(',');
443
+ }
444
+ const market = this.getMarketFromSymbols(symbols);
445
+ let type = undefined;
446
+ [type, params] = this.handleMarketTypeAndParams('watchliquidationsForSymbols', market, params);
447
+ const channel = 'liquidation-orders';
448
+ if (type === 'spot') {
449
+ type = 'SWAP';
450
+ }
451
+ else if (type === 'future') {
452
+ type = 'futures';
453
+ }
454
+ const uppercaseType = type.toUpperCase();
455
+ const request = {
456
+ 'instType': uppercaseType,
457
+ };
458
+ const newLiquidations = await this.subscribe('public', messageHash, channel, undefined, this.extend(request, params));
459
+ if (this.newUpdates) {
460
+ return newLiquidations;
461
+ }
462
+ return this.filterBySymbolsSinceLimit(this.liquidations, symbols, since, limit, true);
463
+ }
464
+ handleLiquidation(client, message) {
465
+ //
466
+ // {
467
+ // "arg": {
468
+ // "channel": "liquidation-orders",
469
+ // "instType": "SWAP"
470
+ // },
471
+ // "data": [
472
+ // {
473
+ // "details": [
474
+ // {
475
+ // "bkLoss": "0",
476
+ // "bkPx": "0.007831",
477
+ // "ccy": "",
478
+ // "posSide": "short",
479
+ // "side": "buy",
480
+ // "sz": "13",
481
+ // "ts": "1692266434010"
482
+ // }
483
+ // ],
484
+ // "instFamily": "IOST-USDT",
485
+ // "instId": "IOST-USDT-SWAP",
486
+ // "instType": "SWAP",
487
+ // "uly": "IOST-USDT"
488
+ // }
489
+ // ]
490
+ // }
491
+ //
492
+ const rawLiquidations = this.safeList(message, 'data', []);
493
+ for (let i = 0; i < rawLiquidations.length; i++) {
494
+ const rawLiquidation = rawLiquidations[i];
495
+ const liquidation = this.parseWsLiquidation(rawLiquidation);
496
+ const symbol = this.safeString(liquidation, 'symbol');
497
+ let liquidations = this.safeValue(this.liquidations, symbol);
498
+ if (liquidations === undefined) {
499
+ const limit = this.safeInteger(this.options, 'liquidationsLimit', 1000);
500
+ liquidations = new Cache.ArrayCache(limit);
501
+ }
502
+ liquidations.append(liquidation);
503
+ this.liquidations[symbol] = liquidations;
504
+ client.resolve([liquidation], 'liquidations');
505
+ client.resolve([liquidation], 'liquidations::' + symbol);
506
+ }
507
+ }
508
+ async watchMyLiquidationsForSymbols(symbols = undefined, since = undefined, limit = undefined, params = {}) {
509
+ /**
510
+ * @method
511
+ * @name okx#watchMyLiquidationsForSymbols
512
+ * @description watch the private liquidations of a trading pair
513
+ * @see https://www.okx.com/docs-v5/en/#trading-account-websocket-balance-and-position-channel
514
+ * @param {string} symbol unified CCXT market symbol
515
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
516
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
517
+ * @param {object} [params] exchange specific parameters for the okx api endpoint
518
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
519
+ */
520
+ await this.loadMarkets();
521
+ const isStop = this.safeValue2(params, 'stop', 'trigger', false);
522
+ params = this.omit(params, ['stop', 'trigger']);
523
+ await this.authenticate({ 'access': isStop ? 'business' : 'private' });
524
+ symbols = this.marketSymbols(symbols, undefined, true, true);
525
+ let messageHash = 'myLiquidations';
526
+ if (symbols !== undefined) {
527
+ messageHash += '::' + symbols.join(',');
528
+ }
529
+ const channel = 'balance_and_position';
530
+ const newLiquidations = await this.subscribe('private', messageHash, channel, undefined, params);
531
+ if (this.newUpdates) {
532
+ return newLiquidations;
533
+ }
534
+ return this.filterBySymbolsSinceLimit(this.liquidations, symbols, since, limit, true);
535
+ }
536
+ handleMyLiquidation(client, message) {
537
+ //
538
+ // {
539
+ // "arg": {
540
+ // "channel": "balance_and_position",
541
+ // "uid": "77982378738415879"
542
+ // },
543
+ // "data": [{
544
+ // "pTime": "1597026383085",
545
+ // "eventType": "snapshot",
546
+ // "balData": [{
547
+ // "ccy": "BTC",
548
+ // "cashBal": "1",
549
+ // "uTime": "1597026383085"
550
+ // }],
551
+ // "posData": [{
552
+ // "posId": "1111111111",
553
+ // "tradeId": "2",
554
+ // "instId": "BTC-USD-191018",
555
+ // "instType": "FUTURES",
556
+ // "mgnMode": "cross",
557
+ // "posSide": "long",
558
+ // "pos": "10",
559
+ // "ccy": "BTC",
560
+ // "posCcy": "",
561
+ // "avgPx": "3320",
562
+ // "uTIme": "1597026383085"
563
+ // }],
564
+ // "trades": [{
565
+ // "instId": "BTC-USD-191018",
566
+ // "tradeId": "2",
567
+ // }]
568
+ // }]
569
+ // }
570
+ //
571
+ const rawLiquidations = this.safeList(message, 'data', []);
572
+ for (let i = 0; i < rawLiquidations.length; i++) {
573
+ const rawLiquidation = rawLiquidations[i];
574
+ const eventType = this.safeString(rawLiquidation, 'eventType');
575
+ if (eventType !== 'liquidation') {
576
+ return;
577
+ }
578
+ const liquidation = this.parseWsMyLiquidation(rawLiquidation);
579
+ const symbol = this.safeString(liquidation, 'symbol');
580
+ let liquidations = this.safeValue(this.liquidations, symbol);
581
+ if (liquidations === undefined) {
582
+ const limit = this.safeInteger(this.options, 'myLiquidationsLimit', 1000);
583
+ liquidations = new Cache.ArrayCache(limit);
584
+ }
585
+ liquidations.append(liquidation);
586
+ this.liquidations[symbol] = liquidations;
587
+ client.resolve([liquidation], 'myLiquidations');
588
+ client.resolve([liquidation], 'myLiquidations::' + symbol);
589
+ }
590
+ }
591
+ parseWsMyLiquidation(liquidation, market = undefined) {
592
+ //
593
+ // {
594
+ // "pTime": "1597026383085",
595
+ // "eventType": "snapshot",
596
+ // "balData": [{
597
+ // "ccy": "BTC",
598
+ // "cashBal": "1",
599
+ // "uTime": "1597026383085"
600
+ // }],
601
+ // "posData": [{
602
+ // "posId": "1111111111",
603
+ // "tradeId": "2",
604
+ // "instId": "BTC-USD-191018",
605
+ // "instType": "FUTURES",
606
+ // "mgnMode": "cross",
607
+ // "posSide": "long",
608
+ // "pos": "10",
609
+ // "ccy": "BTC",
610
+ // "posCcy": "",
611
+ // "avgPx": "3320",
612
+ // "uTIme": "1597026383085"
613
+ // }],
614
+ // "trades": [{
615
+ // "instId": "BTC-USD-191018",
616
+ // "tradeId": "2",
617
+ // }]
618
+ // }
619
+ //
620
+ const posData = this.safeList(liquidation, 'posData', []);
621
+ const firstPosData = this.safeDict(posData, 0, {});
622
+ const marketId = this.safeString(firstPosData, 'instId');
623
+ market = this.safeMarket(marketId, market);
624
+ const timestamp = this.safeInteger(firstPosData, 'uTIme');
625
+ return this.safeLiquidation({
626
+ 'info': liquidation,
627
+ 'symbol': this.safeSymbol(marketId, market),
628
+ 'contracts': this.safeNumber(firstPosData, 'pos'),
629
+ 'contractSize': this.safeNumber(market, 'contractSize'),
630
+ 'price': this.safeNumber(liquidation, 'avgPx'),
631
+ 'baseValue': undefined,
632
+ 'quoteValue': undefined,
633
+ 'timestamp': timestamp,
634
+ 'datetime': this.iso8601(timestamp),
635
+ });
636
+ }
637
+ parseWsLiquidation(liquidation, market = undefined) {
638
+ //
639
+ // public liquidation
640
+ // {
641
+ // "details": [
642
+ // {
643
+ // "bkLoss": "0",
644
+ // "bkPx": "0.007831",
645
+ // "ccy": "",
646
+ // "posSide": "short",
647
+ // "side": "buy",
648
+ // "sz": "13",
649
+ // "ts": "1692266434010"
650
+ // }
651
+ // ],
652
+ // "instFamily": "IOST-USDT",
653
+ // "instId": "IOST-USDT-SWAP",
654
+ // "instType": "SWAP",
655
+ // "uly": "IOST-USDT"
656
+ // }
657
+ //
658
+ const details = this.safeList(liquidation, 'details', []);
659
+ const liquidationDetails = this.safeDict(details, 0, {});
660
+ const marketId = this.safeString(liquidation, 'instId');
661
+ market = this.safeMarket(marketId, market);
662
+ const timestamp = this.safeInteger(liquidationDetails, 'ts');
663
+ return this.safeLiquidation({
664
+ 'info': liquidation,
665
+ 'symbol': this.safeSymbol(marketId, market),
666
+ 'contracts': this.safeNumber(liquidationDetails, 'sz'),
667
+ 'contractSize': this.safeNumber(market, 'contractSize'),
668
+ 'price': this.safeNumber(liquidationDetails, 'bkPx'),
669
+ 'baseValue': undefined,
670
+ 'quoteValue': undefined,
671
+ 'timestamp': timestamp,
672
+ 'datetime': this.iso8601(timestamp),
673
+ });
674
+ }
422
675
  async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
423
676
  /**
424
677
  * @method
@@ -878,6 +1131,9 @@ class okx extends okx$1 {
878
1131
  await this.authenticate();
879
1132
  return await this.subscribe('private', 'account', 'account', undefined, params);
880
1133
  }
1134
+ handleBalanceAndPosition(client, message) {
1135
+ this.handleMyLiquidation(client, message);
1136
+ }
881
1137
  handleBalance(client, message) {
882
1138
  //
883
1139
  // {
@@ -1721,6 +1977,8 @@ class okx extends okx$1 {
1721
1977
  // 'margin_account': this.handleBalance,
1722
1978
  'orders': this.handleOrders,
1723
1979
  'orders-algo': this.handleOrders,
1980
+ 'liquidation-orders': this.handleLiquidation,
1981
+ 'balance_and_position': this.handleBalanceAndPosition,
1724
1982
  };
1725
1983
  const method = this.safeValue(methods, channel);
1726
1984
  if (method === undefined) {
package/js/ccxt.d.ts CHANGED
@@ -4,7 +4,7 @@ import * as functions from './src/base/functions.js';
4
4
  import * as errors from './src/base/errors.js';
5
5
  import type { Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position, FundingRateHistory, Liquidation, FundingHistory, MarginMode, Greeks, Leverage, Leverages, Option, OptionChain, Conversion } from './src/base/types.js';
6
6
  import { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, ProxyError, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout } from './src/base/errors.js';
7
- declare const version = "4.3.32";
7
+ declare const version = "4.3.34";
8
8
  import ace from './src/ace.js';
9
9
  import alpaca from './src/alpaca.js';
10
10
  import ascendex from './src/ascendex.js';
package/js/ccxt.js CHANGED
@@ -38,7 +38,7 @@ import * as errors from './src/base/errors.js';
38
38
  import { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, ProxyError, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.3.33';
41
+ const version = '4.3.35';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
@@ -3,6 +3,7 @@ import { Exchange as _Exchange } from '../base/Exchange.js';
3
3
  interface Exchange {
4
4
  sapiGetSystemStatus(params?: {}): Promise<implicitReturnType>;
5
5
  sapiGetAccountSnapshot(params?: {}): Promise<implicitReturnType>;
6
+ sapiGetAccountInfo(params?: {}): Promise<implicitReturnType>;
6
7
  sapiGetMarginAsset(params?: {}): Promise<implicitReturnType>;
7
8
  sapiGetMarginPair(params?: {}): Promise<implicitReturnType>;
8
9
  sapiGetMarginAllAssets(params?: {}): Promise<implicitReturnType>;
@@ -3,6 +3,7 @@ import _binance from '../binance.js';
3
3
  interface binance {
4
4
  sapiGetSystemStatus(params?: {}): Promise<implicitReturnType>;
5
5
  sapiGetAccountSnapshot(params?: {}): Promise<implicitReturnType>;
6
+ sapiGetAccountInfo(params?: {}): Promise<implicitReturnType>;
6
7
  sapiGetMarginAsset(params?: {}): Promise<implicitReturnType>;
7
8
  sapiGetMarginPair(params?: {}): Promise<implicitReturnType>;
8
9
  sapiGetMarginAllAssets(params?: {}): Promise<implicitReturnType>;
@@ -3,6 +3,7 @@ import _binance from '../binance.js';
3
3
  interface binance {
4
4
  sapiGetSystemStatus(params?: {}): Promise<implicitReturnType>;
5
5
  sapiGetAccountSnapshot(params?: {}): Promise<implicitReturnType>;
6
+ sapiGetAccountInfo(params?: {}): Promise<implicitReturnType>;
6
7
  sapiGetMarginAsset(params?: {}): Promise<implicitReturnType>;
7
8
  sapiGetMarginPair(params?: {}): Promise<implicitReturnType>;
8
9
  sapiGetMarginAllAssets(params?: {}): Promise<implicitReturnType>;