ccxt 4.5.22 → 4.5.23

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 (68) hide show
  1. package/README.md +6 -5
  2. package/dist/ccxt.browser.min.js +2 -2
  3. package/dist/cjs/ccxt.js +6 -1
  4. package/dist/cjs/src/abstract/bullish.js +11 -0
  5. package/dist/cjs/src/base/Exchange.js +3 -2
  6. package/dist/cjs/src/base/ws/WsClient.js +15 -0
  7. package/dist/cjs/src/binance.js +159 -36
  8. package/dist/cjs/src/bingx.js +2 -1
  9. package/dist/cjs/src/bitmart.js +1 -0
  10. package/dist/cjs/src/bullish.js +2919 -0
  11. package/dist/cjs/src/bybit.js +34 -37
  12. package/dist/cjs/src/gate.js +2 -2
  13. package/dist/cjs/src/htx.js +4 -1
  14. package/dist/cjs/src/hyperliquid.js +115 -12
  15. package/dist/cjs/src/kucoin.js +22 -3
  16. package/dist/cjs/src/mexc.js +7 -0
  17. package/dist/cjs/src/okx.js +117 -63
  18. package/dist/cjs/src/paradex.js +78 -3
  19. package/dist/cjs/src/pro/binance.js +131 -29
  20. package/dist/cjs/src/pro/bullish.js +781 -0
  21. package/dist/cjs/src/pro/coinbase.js +2 -2
  22. package/dist/cjs/src/pro/hyperliquid.js +75 -15
  23. package/dist/cjs/src/pro/upbit.js +28 -82
  24. package/js/ccxt.d.ts +8 -2
  25. package/js/ccxt.js +6 -2
  26. package/js/src/abstract/binance.d.ts +1 -0
  27. package/js/src/abstract/binancecoinm.d.ts +1 -0
  28. package/js/src/abstract/binanceus.d.ts +1 -0
  29. package/js/src/abstract/binanceusdm.d.ts +1 -0
  30. package/js/src/abstract/bingx.d.ts +1 -0
  31. package/js/src/abstract/bullish.d.ts +65 -0
  32. package/js/src/abstract/bullish.js +5 -0
  33. package/js/src/abstract/kucoin.d.ts +15 -0
  34. package/js/src/abstract/kucoinfutures.d.ts +15 -0
  35. package/js/src/abstract/mexc.d.ts +7 -0
  36. package/js/src/abstract/myokx.d.ts +90 -39
  37. package/js/src/abstract/okx.d.ts +90 -39
  38. package/js/src/abstract/okxus.d.ts +90 -39
  39. package/js/src/base/Exchange.d.ts +1 -1
  40. package/js/src/base/Exchange.js +3 -2
  41. package/js/src/base/ws/Client.d.ts +1 -0
  42. package/js/src/base/ws/WsClient.js +15 -0
  43. package/js/src/binance.d.ts +14 -5
  44. package/js/src/binance.js +159 -36
  45. package/js/src/bingx.js +2 -1
  46. package/js/src/bitmart.js +1 -0
  47. package/js/src/bullish.d.ts +446 -0
  48. package/js/src/bullish.js +2912 -0
  49. package/js/src/bybit.js +34 -37
  50. package/js/src/gate.js +2 -2
  51. package/js/src/htx.js +4 -1
  52. package/js/src/hyperliquid.d.ts +24 -0
  53. package/js/src/hyperliquid.js +115 -12
  54. package/js/src/kucoin.js +22 -3
  55. package/js/src/mexc.js +7 -0
  56. package/js/src/okx.js +117 -63
  57. package/js/src/paradex.d.ts +15 -1
  58. package/js/src/paradex.js +78 -3
  59. package/js/src/pro/binance.d.ts +7 -0
  60. package/js/src/pro/binance.js +131 -29
  61. package/js/src/pro/bullish.d.ts +108 -0
  62. package/js/src/pro/bullish.js +774 -0
  63. package/js/src/pro/coinbase.js +2 -2
  64. package/js/src/pro/hyperliquid.d.ts +13 -1
  65. package/js/src/pro/hyperliquid.js +75 -15
  66. package/js/src/pro/upbit.d.ts +0 -1
  67. package/js/src/pro/upbit.js +28 -82
  68. package/package.json +2 -2
@@ -580,6 +580,7 @@ class binance extends binance$1["default"] {
580
580
  * @see https://developers.binance.com/docs/binance-spot-api-docs/web-socket-streams#diff-depth-stream
581
581
  * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Partial-Book-Depth-Streams
582
582
  * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Diff-Book-Depth-Streams
583
+ * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Diff-Book-Depth-Streams-RPI
583
584
  * @see https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Partial-Book-Depth-Streams
584
585
  * @see https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Diff-Book-Depth-Streams
585
586
  * @param {string} symbol unified symbol of the market to fetch the order book for
@@ -635,11 +636,13 @@ class binance extends binance$1["default"] {
635
636
  * @see https://developers.binance.com/docs/binance-spot-api-docs/web-socket-streams#diff-depth-stream
636
637
  * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Partial-Book-Depth-Streams
637
638
  * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Diff-Book-Depth-Streams
639
+ * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/Diff-Book-Depth-Streams-RPI
638
640
  * @see https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Partial-Book-Depth-Streams
639
641
  * @see https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Diff-Book-Depth-Streams
640
642
  * @param {string[]} symbols unified array of symbols
641
643
  * @param {int} [limit] the maximum amount of order book entries to return
642
644
  * @param {object} [params] extra parameters specific to the exchange API endpoint
645
+ * @param {boolean} [params.rpi] *future only* set to true to use the RPI endpoint
643
646
  * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
644
647
  */
645
648
  async watchOrderBookForSymbols(symbols, limit = undefined, params = {}) {
@@ -650,7 +653,7 @@ class binance extends binance$1["default"] {
650
653
  if (firstMarket['contract']) {
651
654
  type = firstMarket['linear'] ? 'future' : 'delivery';
652
655
  }
653
- const name = 'depth';
656
+ let name = 'depth';
654
657
  let streamHash = 'multipleOrderbook';
655
658
  if (symbols !== undefined) {
656
659
  const symbolsLength = symbols.length;
@@ -659,7 +662,14 @@ class binance extends binance$1["default"] {
659
662
  }
660
663
  streamHash += '::' + symbols.join(',');
661
664
  }
662
- const watchOrderBookRate = this.safeString(this.options, 'watchOrderBookRate', '100');
665
+ let watchOrderBookRate = undefined;
666
+ [watchOrderBookRate, params] = this.handleOptionAndParams(params, 'watchOrderBookForSymbols', 'watchOrderBookRate', '100');
667
+ let rpi = undefined;
668
+ [rpi, params] = this.handleOptionAndParams(params, 'watchOrderBookForSymbols', 'rpi', false);
669
+ if (rpi && type === 'future') {
670
+ name = 'rpiDepth';
671
+ watchOrderBookRate = '500';
672
+ }
663
673
  const subParams = [];
664
674
  const messageHashes = [];
665
675
  for (let i = 0; i < symbols.length; i++) {
@@ -667,7 +677,7 @@ class binance extends binance$1["default"] {
667
677
  const market = this.market(symbol);
668
678
  messageHashes.push('orderbook::' + symbol);
669
679
  const subscriptionHash = market['lowercaseId'] + '@' + name;
670
- const symbolHash = subscriptionHash + '@' + watchOrderBookRate + 'ms';
680
+ const symbolHash = subscriptionHash + '@' + watchOrderBookRate.toString() + 'ms';
671
681
  subParams.push(symbolHash);
672
682
  }
673
683
  const messageHashesLength = messageHashes.length;
@@ -2992,6 +3002,7 @@ class binance extends binance$1["default"] {
2992
3002
  * @see https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/trading-requests#place-new-order-trade
2993
3003
  * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/New-Order
2994
3004
  * @see https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/websocket-api
3005
+ * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/New-Algo-Order
2995
3006
  * @param {string} symbol unified symbol of the market to create an order in
2996
3007
  * @param {string} type 'market' or 'limit'
2997
3008
  * @param {string} side 'buy' or 'sell'
@@ -3014,12 +3025,25 @@ class binance extends binance$1["default"] {
3014
3025
  const messageHash = requestId.toString();
3015
3026
  const sor = this.safeBool2(params, 'sor', 'SOR', false);
3016
3027
  params = this.omit(params, 'sor', 'SOR');
3028
+ const triggerPrice = this.safeString2(params, 'triggerPrice', 'stopPrice');
3029
+ const stopLossPrice = this.safeString(params, 'stopLossPrice', triggerPrice);
3030
+ const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
3031
+ const trailingDelta = this.safeString(params, 'trailingDelta');
3032
+ const trailingPercent = this.safeStringN(params, ['trailingPercent', 'callbackRate', 'trailingDelta']);
3033
+ const isTrailingPercentOrder = trailingPercent !== undefined;
3034
+ const isStopLoss = stopLossPrice !== undefined || trailingDelta !== undefined;
3035
+ const isTakeProfit = takeProfitPrice !== undefined;
3036
+ const isTriggerOrder = triggerPrice !== undefined;
3037
+ const isConditional = isTriggerOrder || isTrailingPercentOrder || isStopLoss || isTakeProfit;
3017
3038
  const payload = this.createOrderRequest(symbol, type, side, amount, price, params);
3018
3039
  let returnRateLimits = false;
3019
3040
  [returnRateLimits, params] = this.handleOptionAndParams(params, 'createOrderWs', 'returnRateLimits', false);
3020
3041
  payload['returnRateLimits'] = returnRateLimits;
3021
3042
  const test = this.safeBool(params, 'test', false);
3022
3043
  params = this.omit(params, 'test');
3044
+ if (market['linear'] && market['swap'] && isConditional) {
3045
+ payload['algoType'] = 'CONDITIONAL';
3046
+ }
3023
3047
  const message = {
3024
3048
  'id': messageHash,
3025
3049
  'method': 'order.place',
@@ -3033,6 +3057,9 @@ class binance extends binance$1["default"] {
3033
3057
  message['method'] = 'order.test';
3034
3058
  }
3035
3059
  }
3060
+ if (market['linear'] && market['swap'] && isConditional) {
3061
+ message['method'] = 'algoOrder.place';
3062
+ }
3036
3063
  const subscription = {
3037
3064
  'method': this.handleOrderWs,
3038
3065
  };
@@ -3299,10 +3326,12 @@ class binance extends binance$1["default"] {
3299
3326
  * @see https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/trading-requests#cancel-order-trade
3300
3327
  * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Cancel-Order
3301
3328
  * @see https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/websocket-api/Cancel-Order
3329
+ * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Cancel-Algo-Order
3302
3330
  * @param {string} id order id
3303
3331
  * @param {string} [symbol] unified market symbol, default is undefined
3304
3332
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3305
3333
  * @param {string|undefined} [params.cancelRestrictions] Supported values: ONLY_NEW - Cancel will succeed if the order status is NEW. ONLY_PARTIALLY_FILLED - Cancel will succeed if order status is PARTIALLY_FILLED.
3334
+ * @param {boolean} [params.trigger] set to true if you would like to cancel a conditional order
3306
3335
  * @returns {object} an list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
3307
3336
  */
3308
3337
  async cancelOrderWs(id, symbol = undefined, params = {}) {
@@ -3321,19 +3350,34 @@ class binance extends binance$1["default"] {
3321
3350
  'symbol': this.marketId(symbol),
3322
3351
  'returnRateLimits': returnRateLimits,
3323
3352
  };
3324
- const clientOrderId = this.safeString2(params, 'origClientOrderId', 'clientOrderId');
3353
+ const isConditional = this.safeBoolN(params, ['stop', 'trigger', 'conditional']);
3354
+ const clientOrderId = this.safeStringN(params, ['clientAlgoId', 'origClientOrderId', 'clientOrderId']);
3355
+ const shouldUseAlgoOrder = market['linear'] && market['swap'] && isConditional;
3325
3356
  if (clientOrderId !== undefined) {
3326
- payload['origClientOrderId'] = clientOrderId;
3357
+ if (shouldUseAlgoOrder) {
3358
+ payload['clientAlgoId'] = clientOrderId;
3359
+ }
3360
+ else {
3361
+ payload['origClientOrderId'] = clientOrderId;
3362
+ }
3327
3363
  }
3328
3364
  else {
3329
- payload['orderId'] = this.parseToInt(id);
3365
+ if (shouldUseAlgoOrder) {
3366
+ payload['algoId'] = this.numberToString(id);
3367
+ }
3368
+ else {
3369
+ payload['orderId'] = this.numberToString(id);
3370
+ }
3330
3371
  }
3331
- params = this.omit(params, ['origClientOrderId', 'clientOrderId']);
3372
+ params = this.omit(params, ['origClientOrderId', 'clientOrderId', 'stop', 'trigger', 'conditional']);
3332
3373
  const message = {
3333
3374
  'id': messageHash,
3334
3375
  'method': 'order.cancel',
3335
3376
  'params': this.signParams(this.extend(payload, params)),
3336
3377
  };
3378
+ if (shouldUseAlgoOrder) {
3379
+ message['method'] = 'algoOrder.cancel';
3380
+ }
3337
3381
  const subscription = {
3338
3382
  'method': this.handleOrderWs,
3339
3383
  };
@@ -3410,7 +3454,7 @@ class binance extends binance$1["default"] {
3410
3454
  payload['origClientOrderId'] = clientOrderId;
3411
3455
  }
3412
3456
  else {
3413
- payload['orderId'] = this.parseToInt(id);
3457
+ payload['orderId'] = this.numberToString(id);
3414
3458
  }
3415
3459
  const message = {
3416
3460
  'id': messageHash,
@@ -3536,6 +3580,7 @@ class binance extends binance$1["default"] {
3536
3580
  * @see https://developers.binance.com/docs/binance-spot-api-docs/user-data-stream#order-update
3537
3581
  * @see https://developers.binance.com/docs/margin_trading/trade-data-stream/Event-Order-Update
3538
3582
  * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/user-data-streams/Event-Order-Update
3583
+ * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/user-data-streams/Event-Algo-Order-Update
3539
3584
  * @param {string} symbol unified market symbol of the market the orders were made in
3540
3585
  * @param {int} [since] the earliest time in ms to fetch orders for
3541
3586
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -3671,8 +3716,37 @@ class binance extends binance$1["default"] {
3671
3716
  // "rp":"0" // Realized Profit of the trade
3672
3717
  // }
3673
3718
  //
3719
+ // watchOrders: linear swap trigger order
3720
+ //
3721
+ // {
3722
+ // "caid":"Q5xaq5EGKgXXa0fD7fs0Ip", // Client Algo Id
3723
+ // "aid":2148719, // Algo Id
3724
+ // "at":"CONDITIONAL", // Algo Type
3725
+ // "o":"TAKE_PROFIT", // Order Type
3726
+ // "s":"BNBUSDT", // Symbol
3727
+ // "S":"SELL", // Side
3728
+ // "ps":"BOTH", // Position Side
3729
+ // "f":"GTC", // Time in force
3730
+ // "q":"0.01", // quantity
3731
+ // "X":"CANCELED", // Algo status
3732
+ // "ai":"", // order id
3733
+ // "ap": "0.00000", // avg fill price in matching engine, only display when order is triggered and placed in matching engine
3734
+ // "aq": "0.00000", // execuated quantity in matching engine, only display when order is triggered and placed in matching engine
3735
+ // "act": "0", // actual order type in matching engine, only display when order is triggered and placed in matching engine
3736
+ // "tp":"750", // Trigger price
3737
+ // "p":"750", // Order Price
3738
+ // "V":"EXPIRE_MAKER", // STP mode
3739
+ // "wt":"CONTRACT_PRICE", // Working type
3740
+ // "pm":"NONE", // Price match mode
3741
+ // "cp":false, // If Close-All
3742
+ // "pP":false, // If price protection is turned on
3743
+ // "R":false, // Is this reduce only
3744
+ // "tt":0, // Trigger time
3745
+ // "gtd":0, // good till time for GTD time in force
3746
+ // "rm": "Reduce Only reject" // algo order failed reason
3747
+ // }
3748
+ //
3674
3749
  const executionType = this.safeString(order, 'x');
3675
- const orderId = this.safeString(order, 'i');
3676
3750
  const marketId = this.safeString(order, 's');
3677
3751
  const marketType = ('ps' in order) ? 'contract' : 'spot';
3678
3752
  const symbol = this.safeSymbol(marketId, undefined, undefined, marketType);
@@ -3698,21 +3772,13 @@ class binance extends binance$1["default"] {
3698
3772
  'currency': feeCurrency,
3699
3773
  };
3700
3774
  }
3701
- const price = this.safeString(order, 'p');
3702
- const amount = this.safeString(order, 'q');
3703
- const side = this.safeStringLower(order, 'S');
3704
- const type = this.safeStringLower(order, 'o');
3705
- const filled = this.safeString(order, 'z');
3706
- const cost = this.safeString(order, 'Z');
3707
- const average = this.safeString(order, 'ap');
3708
3775
  const rawStatus = this.safeString(order, 'X');
3709
3776
  const status = this.parseOrderStatus(rawStatus);
3710
- const trades = undefined;
3711
- let clientOrderId = this.safeString(order, 'C');
3777
+ let clientOrderId = this.safeString2(order, 'C', 'caid');
3712
3778
  if ((clientOrderId === undefined) || (clientOrderId.length === 0)) {
3713
3779
  clientOrderId = this.safeString(order, 'c');
3714
3780
  }
3715
- const stopPrice = this.safeString2(order, 'P', 'sp');
3781
+ const stopPrice = this.safeStringN(order, ['P', 'sp', 'tp']);
3716
3782
  let timeInForce = this.safeString(order, 'f');
3717
3783
  if (timeInForce === 'GTX') {
3718
3784
  // GTX means "Good Till Crossing" and is an equivalent way of saying Post Only
@@ -3721,28 +3787,28 @@ class binance extends binance$1["default"] {
3721
3787
  return this.safeOrder({
3722
3788
  'info': order,
3723
3789
  'symbol': symbol,
3724
- 'id': orderId,
3790
+ 'id': this.safeString2(order, 'i', 'aid'),
3725
3791
  'clientOrderId': clientOrderId,
3726
3792
  'timestamp': timestamp,
3727
3793
  'datetime': this.iso8601(timestamp),
3728
3794
  'lastTradeTimestamp': lastTradeTimestamp,
3729
3795
  'lastUpdateTimestamp': lastUpdateTimestamp,
3730
- 'type': type,
3796
+ 'type': this.safeStringLower(order, 'o'),
3731
3797
  'timeInForce': timeInForce,
3732
3798
  'postOnly': undefined,
3733
3799
  'reduceOnly': this.safeBool(order, 'R'),
3734
- 'side': side,
3735
- 'price': price,
3800
+ 'side': this.safeStringLower(order, 'S'),
3801
+ 'price': this.safeString(order, 'p'),
3736
3802
  'stopPrice': stopPrice,
3737
3803
  'triggerPrice': stopPrice,
3738
- 'amount': amount,
3739
- 'cost': cost,
3740
- 'average': average,
3741
- 'filled': filled,
3804
+ 'amount': this.safeString(order, 'q'),
3805
+ 'cost': this.safeString(order, 'Z'),
3806
+ 'average': this.safeString(order, 'ap'),
3807
+ 'filled': this.safeString(order, 'z'),
3742
3808
  'remaining': undefined,
3743
3809
  'status': status,
3744
3810
  'fee': fee,
3745
- 'trades': trades,
3811
+ 'trades': undefined,
3746
3812
  });
3747
3813
  }
3748
3814
  handleOrderUpdate(client, message) {
@@ -3827,8 +3893,43 @@ class binance extends binance$1["default"] {
3827
3893
  // }
3828
3894
  // }
3829
3895
  //
3896
+ // linear swap conditional
3897
+ //
3898
+ // {
3899
+ // "e":"ALGO_UPDATE", // Event Type
3900
+ // "T":1750515742297, // Event Time
3901
+ // "E":1750515742303, // Transaction Time
3902
+ // "o":{
3903
+ // "caid":"Q5xaq5EGKgXXa0fD7fs0Ip", // Client Algo Id
3904
+ // "aid":2148719, // Algo Id
3905
+ // "at":"CONDITIONAL", // Algo Type
3906
+ // "o":"TAKE_PROFIT", // Order Type
3907
+ // "s":"BNBUSDT", // Symbol
3908
+ // "S":"SELL", // Side
3909
+ // "ps":"BOTH", // Position Side
3910
+ // "f":"GTC", // Time in force
3911
+ // "q":"0.01", // quantity
3912
+ // "X":"CANCELED", // Algo status
3913
+ // "ai":"", // order id
3914
+ // "ap": "0.00000", // avg fill price in matching engine, only display when order is triggered and placed in matching engine
3915
+ // "aq": "0.00000", // execuated quantity in matching engine, only display when order is triggered and placed in matching engine
3916
+ // "act": "0", // actual order type in matching engine, only display when order is triggered and placed in matching engine
3917
+ // "tp":"750", // Trigger price
3918
+ // "p":"750", // Order Price
3919
+ // "V":"EXPIRE_MAKER", // STP mode
3920
+ // "wt":"CONTRACT_PRICE", // Working type
3921
+ // "pm":"NONE", // Price match mode
3922
+ // "cp":false, // If Close-All
3923
+ // "pP":false, // If price protection is turned on
3924
+ // "R":false, // Is this reduce only
3925
+ // "tt":0, // Trigger time
3926
+ // "gtd":0, // good till time for GTD time in force
3927
+ // "rm": "Reduce Only reject" // algo order failed reason
3928
+ // }
3929
+ // }
3930
+ //
3830
3931
  const e = this.safeString(message, 'e');
3831
- if (e === 'ORDER_TRADE_UPDATE') {
3932
+ if ((e === 'ORDER_TRADE_UPDATE') || (e === 'ALGO_UPDATE')) {
3832
3933
  message = this.safeDict(message, 'o', message);
3833
3934
  }
3834
3935
  this.handleMyTrade(client, message);
@@ -4484,6 +4585,7 @@ class binance extends binance$1["default"] {
4484
4585
  'ACCOUNT_UPDATE': this.handleAcountUpdate,
4485
4586
  'executionReport': this.handleOrderUpdate,
4486
4587
  'ORDER_TRADE_UPDATE': this.handleOrderUpdate,
4588
+ 'ALGO_UPDATE': this.handleOrderUpdate,
4487
4589
  'forceOrder': this.handleLiquidation,
4488
4590
  'eventStreamTerminated': this.handleEventStreamTerminated,
4489
4591
  'externalLockUpdate': this.handleBalance,