ccxt 4.1.9 → 4.1.11

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 (76) hide show
  1. package/.git-templates/hooks/pre-push +55 -0
  2. package/CONTRIBUTING.md +2 -0
  3. package/README.md +3 -3
  4. package/build.sh +3 -1
  5. package/dist/ccxt.browser.js +433 -191
  6. package/dist/ccxt.browser.min.js +3 -3
  7. package/dist/cjs/ccxt.js +1 -1
  8. package/dist/cjs/src/base/Exchange.js +31 -3
  9. package/dist/cjs/src/binance.js +21 -10
  10. package/dist/cjs/src/bingx.js +18 -11
  11. package/dist/cjs/src/bitbns.js +107 -83
  12. package/dist/cjs/src/bitget.js +11 -17
  13. package/dist/cjs/src/bitmart.js +2 -2
  14. package/dist/cjs/src/btcalpha.js +9 -1
  15. package/dist/cjs/src/btcmarkets.js +5 -5
  16. package/dist/cjs/src/bybit.js +2 -2
  17. package/dist/cjs/src/coinex.js +17 -5
  18. package/dist/cjs/src/coinspot.js +103 -8
  19. package/dist/cjs/src/delta.js +2 -2
  20. package/dist/cjs/src/deribit.js +7 -1
  21. package/dist/cjs/src/hitbtc.js +20 -2
  22. package/dist/cjs/src/huobi.js +5 -6
  23. package/dist/cjs/src/okx.js +3 -3
  24. package/dist/cjs/src/phemex.js +20 -1
  25. package/dist/cjs/src/pro/binance.js +3 -9
  26. package/dist/cjs/src/pro/phemex.js +2 -2
  27. package/dist/cjs/src/probit.js +3 -0
  28. package/dist/cjs/src/whitebit.js +14 -11
  29. package/dist/cjs/src/woo.js +21 -1
  30. package/js/ccxt.d.ts +1 -1
  31. package/js/ccxt.js +1 -1
  32. package/js/src/abstract/binance.d.ts +3 -0
  33. package/js/src/abstract/binancecoinm.d.ts +3 -0
  34. package/js/src/abstract/binanceus.d.ts +3 -0
  35. package/js/src/abstract/binanceusdm.d.ts +3 -0
  36. package/js/src/abstract/bingx.d.ts +1 -0
  37. package/js/src/base/Exchange.d.ts +7 -6
  38. package/js/src/base/Exchange.js +31 -3
  39. package/js/src/base/types.d.ts +10 -0
  40. package/js/src/binance.d.ts +5 -13
  41. package/js/src/binance.js +21 -10
  42. package/js/src/bingx.d.ts +2 -16
  43. package/js/src/bingx.js +18 -11
  44. package/js/src/bitbns.d.ts +1 -1
  45. package/js/src/bitbns.js +107 -83
  46. package/js/src/bitget.d.ts +2 -16
  47. package/js/src/bitget.js +11 -17
  48. package/js/src/bitmart.d.ts +2 -16
  49. package/js/src/bitmart.js +2 -2
  50. package/js/src/btcalpha.js +9 -1
  51. package/js/src/btcmarkets.js +5 -5
  52. package/js/src/bybit.d.ts +5 -19
  53. package/js/src/bybit.js +2 -2
  54. package/js/src/coinex.d.ts +1 -1
  55. package/js/src/coinex.js +17 -5
  56. package/js/src/coinspot.d.ts +1 -0
  57. package/js/src/coinspot.js +103 -8
  58. package/js/src/delta.d.ts +2 -20
  59. package/js/src/delta.js +2 -2
  60. package/js/src/deribit.js +7 -1
  61. package/js/src/gate.d.ts +2 -2
  62. package/js/src/hitbtc.d.ts +2 -2
  63. package/js/src/hitbtc.js +20 -2
  64. package/js/src/huobi.d.ts +3 -12
  65. package/js/src/huobi.js +5 -6
  66. package/js/src/okx.d.ts +3 -21
  67. package/js/src/okx.js +3 -3
  68. package/js/src/phemex.js +20 -1
  69. package/js/src/pro/binance.js +3 -9
  70. package/js/src/pro/phemex.js +2 -2
  71. package/js/src/probit.js +3 -0
  72. package/js/src/whitebit.js +14 -11
  73. package/js/src/woo.js +21 -1
  74. package/package.json +2 -2
  75. package/pyproject.toml +8 -0
  76. package/skip-tests.json +1 -1
package/js/src/bingx.js CHANGED
@@ -176,6 +176,13 @@ export default class bingx extends Exchange {
176
176
  },
177
177
  },
178
178
  },
179
+ 'v3': {
180
+ 'public': {
181
+ 'get': {
182
+ 'quote/klines': 1,
183
+ },
184
+ },
185
+ },
179
186
  },
180
187
  'contract': {
181
188
  'v1': {
@@ -633,12 +640,12 @@ export default class bingx extends Exchange {
633
640
  * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
634
641
  * @see https://bingx-api.github.io/docs/#/swapV2/market-api.html#K-Line%20Data
635
642
  * @see https://bingx-api.github.io/docs/#/spot/market-api.html#Candlestick%20chart%20data
643
+ * @see https://bingx-api.github.io/docs/#/swapV2/market-api.html#%20K-Line%20Data
636
644
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
637
645
  * @param {string} timeframe the length of time each candle represents
638
646
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
639
647
  * @param {int} [limit] the maximum amount of candles to fetch
640
648
  * @param {object} [params] extra parameters specific to the bingx api endpoint
641
- * @param {string} [params.price] "mark" or "index" for mark price and index price candles
642
649
  * @param {int} [params.until] timestamp in ms of the latest candle to fetch
643
650
  * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
644
651
  * @returns {[[int]]} A list of candles ordered as timestamp, open, high, low, close, volume
@@ -660,20 +667,17 @@ export default class bingx extends Exchange {
660
667
  if (limit !== undefined) {
661
668
  request['limit'] = limit;
662
669
  }
663
- else {
664
- request['limit'] = 50;
665
- }
666
- const until = this.safeInteger2(params, 'until', 'startTime');
670
+ const until = this.safeInteger2(params, 'until', 'endTime');
667
671
  if (until !== undefined) {
668
672
  params = this.omit(params, ['until']);
669
- request['startTime'] = until;
673
+ request['endTime'] = until;
670
674
  }
671
675
  let response = undefined;
672
676
  if (market['spot']) {
673
677
  response = await this.spotV1PublicGetMarketKline(this.extend(request, params));
674
678
  }
675
679
  else {
676
- response = await this.swapV2PublicGetQuoteKlines(this.extend(request, params));
680
+ response = await this.swapV3PublicGetQuoteKlines(this.extend(request, params));
677
681
  }
678
682
  //
679
683
  // {
@@ -1174,14 +1178,16 @@ export default class bingx extends Exchange {
1174
1178
  const id = this.safeString(interest, 'symbol');
1175
1179
  const symbol = this.safeSymbol(id, market, '-', 'swap');
1176
1180
  const openInterest = this.safeNumber(interest, 'openInterest');
1177
- return {
1181
+ return this.safeOpenInterest({
1178
1182
  'symbol': symbol,
1183
+ 'baseVolume': undefined,
1184
+ 'quoteVolume': undefined,
1179
1185
  'openInterestAmount': undefined,
1180
1186
  'openInterestValue': openInterest,
1181
1187
  'timestamp': timestamp,
1182
1188
  'datetime': this.iso8601(timestamp),
1183
1189
  'info': interest,
1184
- };
1190
+ }, market);
1185
1191
  }
1186
1192
  async fetchTicker(symbol, params = {}) {
1187
1193
  /**
@@ -1554,8 +1560,9 @@ export default class bingx extends Exchange {
1554
1560
  'liquidationPrice': undefined,
1555
1561
  'entryPrice': this.safeNumber2(position, 'avgPrice', 'entryPrice'),
1556
1562
  'unrealizedPnl': this.safeNumber(position, 'unrealizedProfit'),
1563
+ 'realizedPnl': this.safeNumber(position, 'realisedProfit'),
1557
1564
  'percentage': undefined,
1558
- 'contracts': undefined,
1565
+ 'contracts': this.safeNumber(position, 'positionAmt'),
1559
1566
  'contractSize': undefined,
1560
1567
  'markPrice': undefined,
1561
1568
  'lastPrice': undefined,
@@ -1566,7 +1573,7 @@ export default class bingx extends Exchange {
1566
1573
  'lastUpdateTimestamp': undefined,
1567
1574
  'maintenanceMargin': undefined,
1568
1575
  'maintenanceMarginPercentage': undefined,
1569
- 'collateral': this.safeString(position, 'positionAmt'),
1576
+ 'collateral': this.safeNumber(position, 'positionAmt'),
1570
1577
  'initialMargin': this.safeNumber(position, 'initialMargin'),
1571
1578
  'initialMarginPercentage': undefined,
1572
1579
  'leverage': this.safeNumber(position, 'leverage'),
@@ -19,7 +19,7 @@ export default class bitbns extends Exchange {
19
19
  fetchTickers(symbols?: string[], params?: {}): Promise<import("./base/types.js").Dictionary<import("./base/types.js").Ticker>>;
20
20
  parseBalance(response: any): import("./base/types.js").Balances;
21
21
  fetchBalance(params?: {}): Promise<import("./base/types.js").Balances>;
22
- parseOrderStatus(status: any): string;
22
+ parseStatus(status: any): string;
23
23
  parseOrder(order: any, market?: any): import("./base/types.js").Order;
24
24
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): Promise<import("./base/types.js").Order>;
25
25
  cancelOrder(id: string, symbol?: string, params?: {}): Promise<import("./base/types.js").Order>;
package/js/src/bitbns.js CHANGED
@@ -482,9 +482,12 @@ export default class bitbns extends Exchange {
482
482
  // note that "Money" stands for INR - the only fiat in bitbns
483
483
  return this.parseBalance(response);
484
484
  }
485
- parseOrderStatus(status) {
485
+ parseStatus(status) {
486
486
  const statuses = {
487
+ '-1': 'cancelled',
487
488
  '0': 'open',
489
+ '1': 'open',
490
+ '2': 'done',
488
491
  // 'PARTIALLY_FILLED': 'open',
489
492
  // 'FILLED': 'closed',
490
493
  // 'CANCELED': 'canceled',
@@ -499,90 +502,78 @@ export default class bitbns extends Exchange {
499
502
  // createOrder
500
503
  //
501
504
  // {
502
- // "data":"Successfully placed bid to purchase currency",
503
- // "status":1,
504
- // "error":null,
505
- // "id":5424475,
506
- // "code":200
505
+ // "data": "Successfully placed bid to purchase currency",
506
+ // "status": 1,
507
+ // "error": null,
508
+ // "id": 5424475,
509
+ // "code": 200
507
510
  // }
508
511
  //
509
- // fetchOrder
512
+ // fetchOpenOrders, fetchOrder
510
513
  //
511
- // {
512
- // "entry_id":5424475,
513
- // "btc":0.01,
514
- // "rate":2000,
515
- // "time":"2021-04-25T17:05:42.000Z",
516
- // "type":0,
517
- // "status":0,
518
- // "total":0.01,
519
- // "avg_cost":null,
520
- // "side":"BUY",
521
- // "amount":0.01,
522
- // "remaining":0.01,
523
- // "filled":0,
524
- // "cost":null,
525
- // "fee":0.05
526
- // }
514
+ // {
515
+ // "entry_id": 5424475,
516
+ // "btc": 0.01,
517
+ // "rate": 2000,
518
+ // "time": "2021-04-25T17:05:42.000Z",
519
+ // "type": 0,
520
+ // "status": 0
521
+ // "t_rate": 0.45, // only stop orders
522
+ // "trail": 0 // only stop orders
523
+ // }
527
524
  //
528
- // fetchOpenOrders
525
+ // cancelOrder
529
526
  //
530
- // {
531
- // "entry_id":5424475,
532
- // "btc":0.01,
533
- // "rate":2000,
534
- // "time":"2021-04-25T17:05:42.000Z",
535
- // "type":0,
536
- // "status":0
537
- // }
527
+ // {
528
+ // "data": "Successfully cancelled the order",
529
+ // "status": 1,
530
+ // "error": null,
531
+ // "code": 200
532
+ // }
538
533
  //
539
534
  const id = this.safeString2(order, 'id', 'entry_id');
540
- const marketId = this.safeString(order, 'symbol');
541
- const symbol = this.safeSymbol(marketId, market);
542
- const timestamp = this.parse8601(this.safeString(order, 'time'));
543
- const price = this.safeString(order, 'rate');
544
- const amount = this.safeString2(order, 'amount', 'btc');
545
- const filled = this.safeString(order, 'filled');
546
- const remaining = this.safeString(order, 'remaining');
547
- const average = this.safeString(order, 'avg_cost');
548
- const cost = this.safeString(order, 'cost');
549
- let type = this.safeStringLower(order, 'type');
550
- if (type === '0') {
551
- type = 'limit';
535
+ const datetime = this.safeString(order, 'time');
536
+ const triggerPrice = this.safeString(order, 't_rate');
537
+ let side = this.safeString(order, 'type');
538
+ if (side === '0') {
539
+ side = 'buy';
552
540
  }
553
- const status = this.parseOrderStatus(this.safeString(order, 'status'));
554
- const side = this.safeStringLower(order, 'side');
555
- const feeCost = this.safeNumber(order, 'fee');
556
- let fee = undefined;
557
- if (feeCost !== undefined) {
558
- const feeCurrencyCode = undefined;
559
- fee = {
560
- 'cost': feeCost,
561
- 'currency': feeCurrencyCode,
562
- };
541
+ else if (side === '1') {
542
+ side = 'sell';
543
+ }
544
+ const data = this.safeString(order, 'data');
545
+ let status = this.safeString(order, 'status');
546
+ if (data === 'Successfully cancelled the order') {
547
+ status = 'cancelled';
548
+ }
549
+ else {
550
+ status = this.parseStatus(status);
563
551
  }
564
552
  return this.safeOrder({
565
553
  'info': order,
566
554
  'id': id,
567
555
  'clientOrderId': undefined,
568
- 'timestamp': timestamp,
569
- 'datetime': this.iso8601(timestamp),
556
+ 'timestamp': this.parse8601(datetime),
557
+ 'datetime': datetime,
570
558
  'lastTradeTimestamp': undefined,
571
- 'symbol': symbol,
572
- 'type': type,
559
+ 'symbol': this.safeString(market, 'symbol'),
573
560
  'timeInForce': undefined,
574
561
  'postOnly': undefined,
575
562
  'side': side,
576
- 'price': price,
577
- 'stopPrice': undefined,
578
- 'triggerPrice': undefined,
579
- 'amount': amount,
580
- 'cost': cost,
581
- 'average': average,
582
- 'filled': filled,
583
- 'remaining': remaining,
563
+ 'price': this.safeString(order, 'rate'),
564
+ 'stopPrice': triggerPrice,
565
+ 'triggerPrice': triggerPrice,
566
+ 'amount': this.safeString(order, 'btc'),
567
+ 'cost': undefined,
568
+ 'average': undefined,
569
+ 'filled': undefined,
570
+ 'remaining': undefined,
584
571
  'status': status,
585
- 'fee': fee,
572
+ 'fee': {
573
+ 'cost': undefined,
574
+ 'currency': undefined,
575
+ 'rate': undefined,
576
+ },
586
577
  'trades': undefined,
587
578
  }, market);
588
579
  }
@@ -591,19 +582,27 @@ export default class bitbns extends Exchange {
591
582
  * @method
592
583
  * @name bitbns#createOrder
593
584
  * @description create a trade order
585
+ * @see https://docs.bitbns.com/bitbns/rest-endpoints/order-apis/version-2/place-orders
586
+ * @see https://docs.bitbns.com/bitbns/rest-endpoints/order-apis/version-1/market-orders-quantity // market orders
594
587
  * @param {string} symbol unified symbol of the market to create an order in
595
588
  * @param {string} type 'market' or 'limit'
596
589
  * @param {string} side 'buy' or 'sell'
597
590
  * @param {float} amount how much of currency you want to trade in units of base currency
598
591
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
599
592
  * @param {object} [params] extra parameters specific to the bitbns api endpoint
593
+ * @param {float} [params.triggerPrice] the price at which a trigger order is triggered at
594
+ *
595
+ * EXCHANGE SPECIFIC PARAMETERS
596
+ * @param {float} [params.target_rate] *requires params.trail_rate when set, type must be 'limit'* a bracket order is placed when set
597
+ * @param {float} [params.trail_rate] *requires params.target_rate when set, type must be 'limit'* a bracket order is placed when set
600
598
  * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
601
599
  */
602
- if (type !== 'limit' && type !== 'market') {
603
- throw new ExchangeError(this.id + ' allows limit and market orders only');
604
- }
605
600
  await this.loadMarkets();
606
601
  const market = this.market(symbol);
602
+ const triggerPrice = this.safeStringN(params, ['triggerPrice', 'stopPrice', 't_rate']);
603
+ const targetRate = this.safeString(params, 'target_rate');
604
+ const trailRate = this.safeString(params, 'trail_rate');
605
+ params = this.omit(params, ['triggerPrice', 'stopPrice', 'trail_rate', 'target_rate', 't_rate']);
607
606
  const request = {
608
607
  'side': side.toUpperCase(),
609
608
  'symbol': market['uppercaseId'],
@@ -611,20 +610,23 @@ export default class bitbns extends Exchange {
611
610
  // 'target_rate': this.priceToPrecision (symbol, targetRate),
612
611
  // 't_rate': this.priceToPrecision (symbol, stopPrice),
613
612
  // 'trail_rate': this.priceToPrecision (symbol, trailRate),
614
- // To Place Simple Buy or Sell Order use rate
615
- // To Place Stoploss Buy or Sell Order use rate & t_rate
616
- // To Place Bracket Buy or Sell Order use rate , t_rate, target_rate & trail_rate
617
613
  };
618
614
  let method = 'v2PostOrders';
619
615
  if (type === 'limit') {
620
616
  request['rate'] = this.priceToPrecision(symbol, price);
621
617
  }
622
- else if (type === 'market') {
618
+ else {
623
619
  method = 'v1PostPlaceMarketOrderQntySymbol';
624
620
  request['market'] = market['quoteId'];
625
621
  }
626
- else {
627
- throw new ExchangeError(this.id + ' allows limit and market orders only');
622
+ if (triggerPrice !== undefined) {
623
+ request['t_rate'] = this.priceToPrecision(symbol, triggerPrice);
624
+ }
625
+ if (targetRate !== undefined) {
626
+ request['target_rate'] = this.priceToPrecision(symbol, targetRate);
627
+ }
628
+ if (trailRate !== undefined) {
629
+ request['trail_rate'] = this.priceToPrecision(symbol, trailRate);
628
630
  }
629
631
  const response = await this[method](this.extend(request, params));
630
632
  //
@@ -643,9 +645,12 @@ export default class bitbns extends Exchange {
643
645
  * @method
644
646
  * @name bitbns#cancelOrder
645
647
  * @description cancels an open order
648
+ * @see https://docs.bitbns.com/bitbns/rest-endpoints/order-apis/version-2/cancel-orders
649
+ * @see https://docs.bitbns.com/bitbns/rest-endpoints/order-apis/version-1/cancel-stop-loss-orders
646
650
  * @param {string} id order id
647
651
  * @param {string} symbol unified symbol of the market the order was made in
648
652
  * @param {object} [params] extra parameters specific to the bitbns api endpoint
653
+ * @param {boolean} [params.trigger] true if cancelling a trigger order
649
654
  * @returns {object} An [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
650
655
  */
651
656
  if (symbol === undefined) {
@@ -653,13 +658,18 @@ export default class bitbns extends Exchange {
653
658
  }
654
659
  await this.loadMarkets();
655
660
  const market = this.market(symbol);
656
- const quoteSide = (market['quoteId'] === 'USDT') ? 'usdtcancelOrder' : 'cancelOrder';
661
+ const isTrigger = this.safeValue2(params, 'trigger', 'stop');
662
+ params = this.omit(params, ['trigger', 'stop']);
657
663
  const request = {
658
664
  'entry_id': id,
659
665
  'symbol': market['uppercaseId'],
660
- 'side': quoteSide,
661
666
  };
662
- const response = await this.v2PostCancel(this.extend(request, params));
667
+ let response = undefined;
668
+ const tail = isTrigger ? 'StopLossOrder' : 'Order';
669
+ let quoteSide = (market['quoteId'] === 'USDT') ? 'usdtcancel' : 'cancel';
670
+ quoteSide += tail;
671
+ request['side'] = quoteSide;
672
+ response = await this.v2PostCancel(this.extend(request, params));
663
673
  return this.parseOrder(response, market);
664
674
  }
665
675
  async fetchOrder(id, symbol = undefined, params = {}) {
@@ -667,6 +677,8 @@ export default class bitbns extends Exchange {
667
677
  * @method
668
678
  * @name bitbns#fetchOrder
669
679
  * @description fetches information on an order made by the user
680
+ * @see https://docs.bitbns.com/bitbns/rest-endpoints/order-apis/version-1/order-status
681
+ * @param {string} id order id
670
682
  * @param {string} symbol unified symbol of the market the order was made in
671
683
  * @param {object} [params] extra parameters specific to the bitbns api endpoint
672
684
  * @returns {object} An [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
@@ -680,6 +692,10 @@ export default class bitbns extends Exchange {
680
692
  'symbol': market['id'],
681
693
  'entry_id': id,
682
694
  };
695
+ const trigger = this.safeValue2(params, 'trigger', 'stop');
696
+ if (trigger) {
697
+ throw new BadRequest(this.id + ' fetchOrder cannot fetch stop orders');
698
+ }
683
699
  const response = await this.v1PostOrderStatusSymbol(this.extend(request, params));
684
700
  //
685
701
  // {
@@ -715,10 +731,13 @@ export default class bitbns extends Exchange {
715
731
  * @method
716
732
  * @name bitbns#fetchOpenOrders
717
733
  * @description fetch all unfilled currently open orders
734
+ * @see https://docs.bitbns.com/bitbns/rest-endpoints/order-apis/version-2/order-status-limit
735
+ * @see https://docs.bitbns.com/bitbns/rest-endpoints/order-apis/version-2/order-status-limit/order-status-stop-limit
718
736
  * @param {string} symbol unified market symbol
719
737
  * @param {int} [since] the earliest time in ms to fetch open orders for
720
- * @param {int} [limit] the maximum number of open orders structures to retrieve
738
+ * @param {int} [limit] the maximum number of open orders structures to retrieve
721
739
  * @param {object} [params] extra parameters specific to the bitbns api endpoint
740
+ * @param {boolean} [params.trigger] true if fetching trigger orders
722
741
  * @returns {Order[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
723
742
  */
724
743
  if (symbol === undefined) {
@@ -726,11 +745,13 @@ export default class bitbns extends Exchange {
726
745
  }
727
746
  await this.loadMarkets();
728
747
  const market = this.market(symbol);
729
- const quoteSide = (market['quoteId'] === 'USDT') ? 'usdtListOpenOrders' : 'listOpenOrders';
748
+ const isTrigger = this.safeValue2(params, 'trigger', 'stop');
749
+ params = this.omit(params, ['trigger', 'stop']);
750
+ const quoteSide = (market['quoteId'] === 'USDT') ? 'usdtListOpen' : 'listOpen';
730
751
  const request = {
731
752
  'symbol': market['uppercaseId'],
732
- 'side': quoteSide,
733
753
  'page': 0,
754
+ 'side': isTrigger ? (quoteSide + 'StopOrders') : (quoteSide + 'Orders'),
734
755
  };
735
756
  const response = await this.v2PostGetordersnew(this.extend(request, params));
736
757
  //
@@ -743,6 +764,9 @@ export default class bitbns extends Exchange {
743
764
  // "time":"2021-04-25T17:05:42.000Z",
744
765
  // "type":0,
745
766
  // "status":0
767
+ // "t_rate":0.45, // only stop orders
768
+ // "type":1, // only stop orders
769
+ // "trail":0 // only stop orders
746
770
  // }
747
771
  // ],
748
772
  // "status":1,
@@ -1165,7 +1189,7 @@ export default class bitbns extends Exchange {
1165
1189
  'body': body,
1166
1190
  };
1167
1191
  const payload = this.stringToBase64(this.json(auth));
1168
- const signature = this.hmac(payload, this.encode(this.secret), sha512);
1192
+ const signature = this.hmac(this.encode(payload), this.encode(this.secret), sha512);
1169
1193
  headers['X-BITBNS-PAYLOAD'] = payload;
1170
1194
  headers['X-BITBNS-SIGNATURE'] = signature;
1171
1195
  headers['Content-Type'] = 'application/x-www-form-urlencoded';
@@ -247,14 +247,7 @@ export default class bitget extends Exchange {
247
247
  setLeverage(leverage: any, symbol?: string, params?: {}): Promise<any>;
248
248
  setMarginMode(marginMode: any, symbol?: string, params?: {}): Promise<any>;
249
249
  setPositionMode(hedged: any, symbol?: string, params?: {}): Promise<any>;
250
- fetchOpenInterest(symbol: string, params?: {}): Promise<{
251
- symbol: any;
252
- openInterestAmount: number;
253
- openInterestValue: any;
254
- timestamp: number;
255
- datetime: string;
256
- info: any;
257
- }>;
250
+ fetchOpenInterest(symbol: string, params?: {}): Promise<import("./base/types.js").OpenInterest>;
258
251
  fetchTransfers(code?: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
259
252
  transfer(code: string, amount: any, fromAccount: any, toAccount: any, params?: {}): Promise<{
260
253
  info: any;
@@ -292,14 +285,7 @@ export default class bitget extends Exchange {
292
285
  };
293
286
  fetchDepositWithdrawFees(codes?: string[], params?: {}): Promise<any>;
294
287
  parseTransferStatus(status: any): string;
295
- parseOpenInterest(interest: any, market?: any): {
296
- symbol: any;
297
- openInterestAmount: number;
298
- openInterestValue: any;
299
- timestamp: number;
300
- datetime: string;
301
- info: any;
302
- };
288
+ parseOpenInterest(interest: any, market?: any): import("./base/types.js").OpenInterest;
303
289
  handleErrors(code: any, reason: any, url: any, method: any, headers: any, body: any, response: any, requestHeaders: any, requestBody: any): any;
304
290
  sign(path: any, api?: any[], method?: string, params?: {}, headers?: any, body?: any): {
305
291
  url: string;
package/js/src/bitget.js CHANGED
@@ -3324,7 +3324,6 @@ export default class bitget extends Exchange {
3324
3324
  * @see https://bitgetlimited.github.io/apidoc/en/mix/#cancel-all-trigger-order-tpsl
3325
3325
  * @param {string} symbol unified market symbol
3326
3326
  * @param {object} [params] extra parameters specific to the bitget api endpoint
3327
- * @param {string} [params.code] marginCoin unified currency code
3328
3327
  * @returns {object[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
3329
3328
  */
3330
3329
  const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
@@ -3339,33 +3338,28 @@ export default class bitget extends Exchange {
3339
3338
  if (sandboxMode) {
3340
3339
  productType = 'S' + productType;
3341
3340
  }
3342
- const [marketType, query] = this.handleMarketTypeAndParams('cancelAllOrders', market, params);
3341
+ let marketType = undefined;
3342
+ [marketType, params] = this.handleMarketTypeAndParams('cancelAllOrders', market, params);
3343
3343
  if (marketType === 'spot') {
3344
3344
  throw new NotSupported(this.id + ' cancelAllOrders () does not support spot markets');
3345
3345
  }
3346
3346
  const request = {
3347
3347
  'productType': productType,
3348
+ 'marginCoin': market['settleId'],
3348
3349
  };
3349
- let method = undefined;
3350
- const stop = this.safeValue(query, 'stop');
3351
- const planType = this.safeString(query, 'planType');
3350
+ const stop = this.safeValue2(params, 'stop', 'trigger');
3351
+ const planType = this.safeString(params, 'planType');
3352
+ params = this.omit(params, ['stop', 'trigger']);
3353
+ let response = undefined;
3352
3354
  if (stop !== undefined || planType !== undefined) {
3353
3355
  if (planType === undefined) {
3354
3356
  throw new ArgumentsRequired(this.id + ' cancelOrder() requires a planType parameter for stop orders, either normal_plan, profit_plan, loss_plan, pos_profit, pos_loss, moving_plan or track_plan');
3355
3357
  }
3356
- method = 'privateMixPostPlanCancelAllPlan';
3358
+ response = await this.privateMixPostPlanCancelAllPlan(this.extend(request, params));
3357
3359
  }
3358
3360
  else {
3359
- const code = this.safeString2(params, 'code', 'marginCoin');
3360
- if (code === undefined) {
3361
- throw new ArgumentsRequired(this.id + ' cancelAllOrders () requires a code argument [marginCoin] in the params');
3362
- }
3363
- const currency = this.currency(code);
3364
- request['marginCoin'] = this.safeCurrencyCode(code, currency);
3365
- method = 'privateMixPostOrderCancelAllOrders';
3361
+ response = await this.privateMixPostOrderCancelAllOrders(this.extend(request, params));
3366
3362
  }
3367
- const ommitted = this.omit(query, ['stop', 'code', 'marginCoin']);
3368
- const response = await this[method](this.extend(request, ommitted));
3369
3363
  //
3370
3364
  // {
3371
3365
  // "code": "00000",
@@ -5182,14 +5176,14 @@ export default class bitget extends Exchange {
5182
5176
  const id = this.safeString(interest, 'symbol');
5183
5177
  const symbol = this.safeSymbol(id, market);
5184
5178
  const amount = this.safeNumber(interest, 'amount');
5185
- return {
5179
+ return this.safeOpenInterest({
5186
5180
  'symbol': symbol,
5187
5181
  'openInterestAmount': amount,
5188
5182
  'openInterestValue': undefined,
5189
5183
  'timestamp': timestamp,
5190
5184
  'datetime': this.iso8601(timestamp),
5191
5185
  'info': interest,
5192
- };
5186
+ }, market);
5193
5187
  }
5194
5188
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
5195
5189
  if (!response) {
@@ -212,22 +212,8 @@ export default class bitmart extends Exchange {
212
212
  datetime: string;
213
213
  info: any;
214
214
  };
215
- fetchOpenInterest(symbol: string, params?: {}): Promise<{
216
- symbol: any;
217
- openInterestAmount: number;
218
- openInterestValue: number;
219
- timestamp: number;
220
- datetime: string;
221
- info: any;
222
- }>;
223
- parseOpenInterest(interest: any, market?: any): {
224
- symbol: any;
225
- openInterestAmount: number;
226
- openInterestValue: number;
227
- timestamp: number;
228
- datetime: string;
229
- info: any;
230
- };
215
+ fetchOpenInterest(symbol: string, params?: {}): Promise<import("./base/types.js").OpenInterest>;
216
+ parseOpenInterest(interest: any, market?: any): import("./base/types.js").OpenInterest;
231
217
  setLeverage(leverage: any, symbol?: string, params?: {}): Promise<any>;
232
218
  fetchFundingRate(symbol: string, params?: {}): Promise<{
233
219
  info: any;
package/js/src/bitmart.js CHANGED
@@ -3660,14 +3660,14 @@ export default class bitmart extends Exchange {
3660
3660
  //
3661
3661
  const timestamp = this.safeInteger(interest, 'timestamp');
3662
3662
  const id = this.safeString(interest, 'symbol');
3663
- return {
3663
+ return this.safeOpenInterest({
3664
3664
  'symbol': this.safeSymbol(id, market),
3665
3665
  'openInterestAmount': this.safeNumber(interest, 'open_interest'),
3666
3666
  'openInterestValue': this.safeNumber(interest, 'open_interest_value'),
3667
3667
  'timestamp': timestamp,
3668
3668
  'datetime': this.iso8601(timestamp),
3669
3669
  'info': interest,
3670
- };
3670
+ }, market);
3671
3671
  }
3672
3672
  async setLeverage(leverage, symbol = undefined, params = {}) {
3673
3673
  /**
@@ -340,6 +340,7 @@ export default class btcalpha extends Exchange {
340
340
  /**
341
341
  * @method
342
342
  * @name btcalpha#fetchOrderBook
343
+ * @see https://btc-alpha.github.io/api-docs/#get-orderbook
343
344
  * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
344
345
  * @param {string} symbol unified symbol of the market to fetch the order book for
345
346
  * @param {int} [limit] the maximum amount of order book entries to return
@@ -720,15 +721,19 @@ export default class btcalpha extends Exchange {
720
721
  /**
721
722
  * @method
722
723
  * @name btcalpha#createOrder
724
+ * @see https://btc-alpha.github.io/api-docs/#create-order
723
725
  * @description create a trade order
724
726
  * @param {string} symbol unified symbol of the market to create an order in
725
- * @param {string} type 'market' or 'limit'
727
+ * @param {string} type 'limit'
726
728
  * @param {string} side 'buy' or 'sell'
727
729
  * @param {float} amount how much of currency you want to trade in units of base currency
728
730
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
729
731
  * @param {object} [params] extra parameters specific to the btcalpha api endpoint
730
732
  * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
731
733
  */
734
+ if (type === 'market') {
735
+ throw new InvalidOrder(this.id + ' only limits orders are supported');
736
+ }
732
737
  await this.loadMarkets();
733
738
  const market = this.market(symbol);
734
739
  const request = {
@@ -752,6 +757,7 @@ export default class btcalpha extends Exchange {
752
757
  /**
753
758
  * @method
754
759
  * @name btcalpha#cancelOrder
760
+ * @see https://btc-alpha.github.io/api-docs/#cancel-order
755
761
  * @description cancels an open order
756
762
  * @param {string} id order id
757
763
  * @param {string} symbol unified symbol of the market the order was made in
@@ -768,6 +774,7 @@ export default class btcalpha extends Exchange {
768
774
  /**
769
775
  * @method
770
776
  * @name btcalpha#fetchOrder
777
+ * @see https://btc-alpha.github.io/api-docs/#retrieve-single-order
771
778
  * @description fetches information on an order made by the user
772
779
  * @param {string} symbol not used by btcalpha fetchOrder
773
780
  * @param {object} [params] extra parameters specific to the btcalpha api endpoint
@@ -784,6 +791,7 @@ export default class btcalpha extends Exchange {
784
791
  /**
785
792
  * @method
786
793
  * @name btcalpha#fetchOrders
794
+ * @see https://btc-alpha.github.io/api-docs/#list-own-orders
787
795
  * @description fetches information on multiple orders made by the user
788
796
  * @param {string} symbol unified market symbol of the market orders were made in
789
797
  * @param {int} [since] the earliest time in ms to fetch orders for