ccxt 4.2.1 → 4.2.3

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/js/src/okx.js CHANGED
@@ -3032,12 +3032,13 @@ export default class okx extends Exchange {
3032
3032
  * @param {string} id order id
3033
3033
  * @param {string} symbol unified symbol of the market the order was made in
3034
3034
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3035
+ * @param {boolean} [params.trigger] true if trigger orders
3035
3036
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3036
3037
  */
3037
3038
  if (symbol === undefined) {
3038
3039
  throw new ArgumentsRequired(this.id + ' cancelOrder() requires a symbol argument');
3039
3040
  }
3040
- const stop = this.safeValue(params, 'stop');
3041
+ const stop = this.safeValue2(params, 'stop', 'trigger');
3041
3042
  if (stop) {
3042
3043
  const orderInner = await this.cancelOrders([id], symbol, params);
3043
3044
  return this.safeValue(orderInner, 0);
@@ -3409,6 +3410,7 @@ export default class okx extends Exchange {
3409
3410
  * @param {string} id the order id
3410
3411
  * @param {string} symbol unified market symbol
3411
3412
  * @param {object} [params] extra and exchange specific parameters
3413
+ * @param {boolean} [params.trigger] true if fetching trigger orders
3412
3414
  * @returns [an order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3413
3415
  */
3414
3416
  if (symbol === undefined) {
@@ -3426,7 +3428,7 @@ export default class okx extends Exchange {
3426
3428
  const options = this.safeValue(this.options, 'fetchOrder', {});
3427
3429
  const defaultMethod = this.safeString(options, 'method', 'privateGetTradeOrder');
3428
3430
  let method = this.safeString(params, 'method', defaultMethod);
3429
- const stop = this.safeValue(params, 'stop');
3431
+ const stop = this.safeValue2(params, 'stop', 'trigger');
3430
3432
  if (stop) {
3431
3433
  method = 'privateGetTradeOrderAlgo';
3432
3434
  if (clientOrderId !== undefined) {
@@ -3444,7 +3446,7 @@ export default class okx extends Exchange {
3444
3446
  request['ordId'] = id;
3445
3447
  }
3446
3448
  }
3447
- const query = this.omit(params, ['method', 'clOrdId', 'clientOrderId', 'stop']);
3449
+ const query = this.omit(params, ['method', 'clOrdId', 'clientOrderId', 'stop', 'trigger']);
3448
3450
  let response = undefined;
3449
3451
  if (method === 'privateGetTradeOrderAlgo') {
3450
3452
  response = await this.privateGetTradeOrderAlgo(this.extend(request, query));
@@ -3600,7 +3602,7 @@ export default class okx extends Exchange {
3600
3602
  const defaultMethod = this.safeString(options, 'method', 'privateGetTradeOrdersPending');
3601
3603
  let method = this.safeString(params, 'method', defaultMethod);
3602
3604
  const ordType = this.safeString(params, 'ordType');
3603
- const stop = this.safeValue(params, 'stop');
3605
+ const stop = this.safeValue2(params, 'stop', 'trigger');
3604
3606
  if (stop || (ordType in algoOrderTypes)) {
3605
3607
  method = 'privateGetTradeOrdersAlgoPending';
3606
3608
  if (stop) {
@@ -3609,7 +3611,7 @@ export default class okx extends Exchange {
3609
3611
  }
3610
3612
  }
3611
3613
  }
3612
- const query = this.omit(params, ['method', 'stop']);
3614
+ const query = this.omit(params, ['method', 'stop', 'trigger']);
3613
3615
  let response = undefined;
3614
3616
  if (method === 'privateGetTradeOrdersAlgoPending') {
3615
3617
  response = await this.privateGetTradeOrdersAlgoPending(this.extend(request, query));
@@ -3762,7 +3764,7 @@ export default class okx extends Exchange {
3762
3764
  const defaultMethod = this.safeString(options, 'method', 'privateGetTradeOrdersHistory');
3763
3765
  let method = this.safeString(params, 'method', defaultMethod);
3764
3766
  const ordType = this.safeString(params, 'ordType');
3765
- const stop = this.safeValue(params, 'stop');
3767
+ const stop = this.safeValue2(params, 'stop', 'trigger');
3766
3768
  if (stop || (ordType in algoOrderTypes)) {
3767
3769
  method = 'privateGetTradeOrdersAlgoHistory';
3768
3770
  const algoId = this.safeString(params, 'algoId');
@@ -3787,7 +3789,7 @@ export default class okx extends Exchange {
3787
3789
  query = this.omit(query, ['until', 'till']);
3788
3790
  }
3789
3791
  }
3790
- const send = this.omit(query, ['method', 'stop', 'ordType']);
3792
+ const send = this.omit(query, ['method', 'stop', 'ordType', 'trigger']);
3791
3793
  let response = undefined;
3792
3794
  if (method === 'privateGetTradeOrdersAlgoHistory') {
3793
3795
  response = await this.privateGetTradeOrdersAlgoHistory(this.extend(request, send));
@@ -3949,7 +3951,7 @@ export default class okx extends Exchange {
3949
3951
  const defaultMethod = this.safeString(options, 'method', 'privateGetTradeOrdersHistory');
3950
3952
  let method = this.safeString(params, 'method', defaultMethod);
3951
3953
  const ordType = this.safeString(params, 'ordType');
3952
- const stop = this.safeValue(params, 'stop');
3954
+ const stop = this.safeValue2(params, 'stop', 'trigger');
3953
3955
  if (stop || (ordType in algoOrderTypes)) {
3954
3956
  method = 'privateGetTradeOrdersAlgoHistory';
3955
3957
  if (stop) {
@@ -3970,7 +3972,7 @@ export default class okx extends Exchange {
3970
3972
  }
3971
3973
  request['state'] = 'filled';
3972
3974
  }
3973
- const send = this.omit(query, ['method', 'stop']);
3975
+ const send = this.omit(query, ['method', 'stop', 'trigger']);
3974
3976
  let response = undefined;
3975
3977
  if (method === 'privateGetTradeOrdersAlgoHistory') {
3976
3978
  response = await this.privateGetTradeOrdersAlgoHistory(this.extend(request, send));
@@ -1192,9 +1192,15 @@ export default class poloniexfutures extends Exchange {
1192
1192
  if (symbol !== undefined) {
1193
1193
  request['symbol'] = this.marketId(symbol);
1194
1194
  }
1195
- const stop = this.safeValue(params, 'stop');
1196
- const method = stop ? 'privateDeleteStopOrders' : 'privateDeleteOrders';
1197
- const response = await this[method](this.extend(request, params));
1195
+ const stop = this.safeValue2(params, 'stop', 'trigger');
1196
+ params = this.omit(params, ['stop', 'trigger']);
1197
+ let response = undefined;
1198
+ if (stop) {
1199
+ response = await this.privateDeleteStopOrders(this.extend(request, params));
1200
+ }
1201
+ else {
1202
+ response = await this.privateDeleteOrders(this.extend(request, params));
1203
+ }
1198
1204
  //
1199
1205
  // {
1200
1206
  // "code": "200000",
@@ -1256,9 +1262,9 @@ export default class poloniexfutures extends Exchange {
1256
1262
  * @returns An [array of order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1257
1263
  */
1258
1264
  await this.loadMarkets();
1259
- const stop = this.safeValue(params, 'stop');
1265
+ const stop = this.safeValue2(params, 'stop', 'trigger');
1260
1266
  const until = this.safeInteger2(params, 'until', 'till');
1261
- params = this.omit(params, ['stop', 'until', 'till']);
1267
+ params = this.omit(params, ['triger', 'stop', 'until', 'till']);
1262
1268
  if (status === 'closed') {
1263
1269
  status = 'done';
1264
1270
  }
@@ -1280,8 +1286,13 @@ export default class poloniexfutures extends Exchange {
1280
1286
  if (until !== undefined) {
1281
1287
  request['endAt'] = until;
1282
1288
  }
1283
- const method = stop ? 'privateGetStopOrders' : 'privateGetOrders';
1284
- const response = await this[method](this.extend(request, params));
1289
+ let response = undefined;
1290
+ if (stop) {
1291
+ response = await this.privateGetStopOrders(this.extend(request, params));
1292
+ }
1293
+ else {
1294
+ response = await this.privateGetOrders(this.extend(request, params));
1295
+ }
1285
1296
  //
1286
1297
  // {
1287
1298
  // "code": "200000",
@@ -1391,20 +1402,20 @@ export default class poloniexfutures extends Exchange {
1391
1402
  */
1392
1403
  await this.loadMarkets();
1393
1404
  const request = {};
1394
- let method = 'privateGetOrdersOrderId';
1405
+ let response = undefined;
1395
1406
  if (id === undefined) {
1396
1407
  const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId');
1397
1408
  if (clientOrderId === undefined) {
1398
1409
  throw new InvalidOrder(this.id + ' fetchOrder() requires parameter id or params.clientOid');
1399
1410
  }
1400
1411
  request['clientOid'] = clientOrderId;
1401
- method = 'privateGetOrdersByClientOid';
1402
1412
  params = this.omit(params, ['clientOid', 'clientOrderId']);
1413
+ response = await this.privateGetClientOrderIdClientOid(this.extend(request, params));
1403
1414
  }
1404
1415
  else {
1405
1416
  request['order-id'] = id;
1417
+ response = await this.privateGetOrdersOrderId(this.extend(request, params));
1406
1418
  }
1407
- const response = await this[method](this.extend(request, params));
1408
1419
  //
1409
1420
  // {
1410
1421
  // "code": "200000",
@@ -1724,7 +1735,7 @@ export default class poloniexfutures extends Exchange {
1724
1735
  const version = this.safeString(params, 'version', defaultVersion);
1725
1736
  const tail = '/api/' + version + '/' + this.implodeParams(path, params);
1726
1737
  url += tail;
1727
- const query = this.omit(params, path);
1738
+ const query = this.omit(params, this.extractParams(path));
1728
1739
  const queryLength = Object.keys(query).length;
1729
1740
  if (api === 'public') {
1730
1741
  if (queryLength) {
@@ -1117,25 +1117,27 @@ export default class binance extends binanceRest {
1117
1117
  const listenKeyRefreshRate = this.safeInteger(this.options, 'listenKeyRefreshRate', 1200000);
1118
1118
  const delay = this.sum(listenKeyRefreshRate, 10000);
1119
1119
  if (time - lastAuthenticatedTime > delay) {
1120
- let method = 'publicPostUserDataStream';
1120
+ let response = undefined;
1121
1121
  if (type === 'future') {
1122
- method = 'fapiPrivatePostListenKey';
1122
+ response = await this.fapiPrivatePostListenKey(query);
1123
1123
  }
1124
1124
  else if (type === 'delivery') {
1125
- method = 'dapiPrivatePostListenKey';
1125
+ response = await this.dapiPrivatePostListenKey(query);
1126
1126
  }
1127
1127
  else if (type === 'margin' && isCrossMargin) {
1128
- method = 'sapiPostUserDataStream';
1128
+ response = await this.sapiPostUserDataStream(query);
1129
1129
  }
1130
1130
  else if (isIsolatedMargin) {
1131
- method = 'sapiPostUserDataStreamIsolated';
1132
1131
  if (symbol === undefined) {
1133
1132
  throw new ArgumentsRequired(this.id + ' authenticate() requires a symbol argument for isolated margin mode');
1134
1133
  }
1135
1134
  const marketId = this.marketId(symbol);
1136
1135
  query = this.extend(query, { 'symbol': marketId });
1136
+ response = await this.sapiPostUserDataStreamIsolated(query);
1137
+ }
1138
+ else {
1139
+ response = await this.publicPostUserDataStream(query);
1137
1140
  }
1138
- const response = await this[method](query);
1139
1141
  this.options[type] = this.extend(options, {
1140
1142
  'listenKey': this.safeString(response, 'listenKey'),
1141
1143
  'lastAuthenticatedTime': time,
@@ -1161,26 +1163,27 @@ export default class binance extends binanceRest {
1161
1163
  // A network error happened: we can't renew a listen key that does not exist.
1162
1164
  return;
1163
1165
  }
1164
- let method = 'publicPutUserDataStream';
1165
1166
  const request = {};
1166
1167
  const symbol = this.safeString(params, 'symbol');
1167
1168
  const sendParams = this.omit(params, ['type', 'symbol']);
1168
- if (type === 'future') {
1169
- method = 'fapiPrivatePutListenKey';
1170
- }
1171
- else if (type === 'delivery') {
1172
- method = 'dapiPrivatePutListenKey';
1173
- }
1174
- else {
1175
- request['listenKey'] = listenKey;
1176
- if (type === 'margin') {
1177
- request['symbol'] = symbol;
1178
- method = 'sapiPutUserDataStream';
1179
- }
1180
- }
1181
1169
  const time = this.milliseconds();
1182
1170
  try {
1183
- await this[method](this.extend(request, sendParams));
1171
+ if (type === 'future') {
1172
+ await this.fapiPrivatePutListenKey(this.extend(request, sendParams));
1173
+ }
1174
+ else if (type === 'delivery') {
1175
+ await this.dapiPrivatePutListenKey(this.extend(request, sendParams));
1176
+ }
1177
+ else {
1178
+ request['listenKey'] = listenKey;
1179
+ if (type === 'margin') {
1180
+ request['symbol'] = symbol;
1181
+ await this.sapiPutUserDataStream(this.extend(request, sendParams));
1182
+ }
1183
+ else {
1184
+ await this.publicPutUserDataStream(this.extend(request, sendParams));
1185
+ }
1186
+ }
1184
1187
  }
1185
1188
  catch (error) {
1186
1189
  const url = this.urls['api']['ws'][type] + '/' + this.options[type]['listenKey'];
@@ -33,6 +33,7 @@ export default class bingx extends bingxRest {
33
33
  },
34
34
  },
35
35
  'options': {
36
+ 'listenKeyRefreshRate': 3540000,
36
37
  'ws': {
37
38
  'gunzip': true,
38
39
  },
@@ -630,7 +631,7 @@ export default class bingx extends bingxRest {
630
631
  const lastAuthenticatedTime = this.safeInteger(this.options, 'lastAuthenticatedTime', 0);
631
632
  const listenKeyRefreshRate = this.safeInteger(this.options, 'listenKeyRefreshRate', 3600000); // 1 hour
632
633
  if (time - lastAuthenticatedTime > listenKeyRefreshRate) {
633
- const response = await this.userAuthPrivatePostUserDataStream({ 'listenKey': listenKey }); // extend the expiry
634
+ const response = await this.userAuthPrivatePutUserDataStream({ 'listenKey': listenKey }); // extend the expiry
634
635
  this.options['listenKey'] = this.safeString(response, 'listenKey');
635
636
  this.options['lastAuthenticatedTime'] = time;
636
637
  }
@@ -211,7 +211,7 @@ export default class bybit extends bybitRest {
211
211
  */
212
212
  await this.loadMarkets();
213
213
  symbols = this.marketSymbols(symbols, undefined, false);
214
- const messageHash = 'tickers::' + symbols.join(',');
214
+ const messageHashes = [];
215
215
  const url = this.getUrlByMarketType(symbols[0], false, params);
216
216
  params = this.cleanParams(params);
217
217
  const options = this.safeValue(this.options, 'watchTickers', {});
@@ -221,8 +221,9 @@ export default class bybit extends bybitRest {
221
221
  for (let i = 0; i < marketIds.length; i++) {
222
222
  const marketId = marketIds[i];
223
223
  topics.push(topic + '.' + marketId);
224
+ messageHashes.push('ticker:' + symbols[i]);
224
225
  }
225
- const ticker = await this.watchTopics(url, messageHash, topics, params);
226
+ const ticker = await this.watchTopics(url, messageHashes, topics, params);
226
227
  if (this.newUpdates) {
227
228
  return ticker;
228
229
  }
@@ -358,17 +359,6 @@ export default class bybit extends bybitRest {
358
359
  this.tickers[symbol] = parsed;
359
360
  const messageHash = 'ticker:' + symbol;
360
361
  client.resolve(this.tickers[symbol], messageHash);
361
- // watchTickers part
362
- const messageHashes = this.findMessageHashes(client, 'tickers::');
363
- for (let i = 0; i < messageHashes.length; i++) {
364
- const messageHashTicker = messageHashes[i];
365
- const parts = messageHashTicker.split('::');
366
- const symbolsString = parts[1];
367
- const symbols = symbolsString.split(',');
368
- if (this.inArray(parsed['symbol'], symbols)) {
369
- client.resolve(parsed, messageHashTicker);
370
- }
371
- }
372
362
  }
373
363
  async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
374
364
  /**
@@ -889,10 +879,15 @@ export default class bybit extends bybitRest {
889
879
  }
890
880
  const trades = this.myTrades;
891
881
  const symbols = {};
892
- const method = spot ? 'parseWsTrade' : 'parseTrade';
893
882
  for (let i = 0; i < data.length; i++) {
894
883
  const rawTrade = data[i];
895
- const parsed = this[method](rawTrade);
884
+ let parsed = undefined;
885
+ if (spot) {
886
+ parsed = this.parseWsTrade(rawTrade);
887
+ }
888
+ else {
889
+ parsed = this.parseTrade(rawTrade);
890
+ }
896
891
  const symbol = parsed['symbol'];
897
892
  symbols[symbol] = true;
898
893
  trades.append(parsed);
@@ -15,7 +15,7 @@ export declare class BigInteger {
15
15
  protected intValue(): number;
16
16
  protected byteValue(): number;
17
17
  protected shortValue(): number;
18
- protected signum(): 0 | 1 | -1;
18
+ protected signum(): 1 | 0 | -1;
19
19
  toByteArray(): number[];
20
20
  protected equals(a: BigInteger): boolean;
21
21
  protected min(a: BigInteger): BigInteger;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.2.1",
3
+ "version": "4.2.3",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.js",
6
6
  "type": "module",