ccxt 4.2.22 → 4.2.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.
package/js/src/bitget.js CHANGED
@@ -47,16 +47,16 @@ export default class bitget extends Exchange {
47
47
  'createOrder': true,
48
48
  'createOrders': true,
49
49
  'createOrderWithTakeProfitAndStopLoss': true,
50
- 'createReduceOnlyOrder': false,
51
- 'createStopLossOrder': true,
52
- 'createTakeProfitOrder': true,
53
50
  'createPostOnlyOrder': true,
54
- 'createStopOrder': true,
51
+ 'createReduceOnlyOrder': false,
55
52
  'createStopLimitOrder': true,
53
+ 'createStopLossOrder': true,
56
54
  'createStopMarketOrder': true,
55
+ 'createStopOrder': true,
56
+ 'createTakeProfitOrder': true,
57
+ 'createTrailingAmountOrder': false,
57
58
  'createTrailingPercentOrder': true,
58
59
  'createTriggerOrder': true,
59
- 'signIn': false,
60
60
  'editOrder': true,
61
61
  'fetchAccounts': false,
62
62
  'fetchBalance': true,
@@ -72,12 +72,10 @@ export default class bitget extends Exchange {
72
72
  'fetchDepositAddress': true,
73
73
  'fetchDepositAddresses': false,
74
74
  'fetchDeposits': true,
75
+ 'fetchDepositsWithdrawals': false,
75
76
  'fetchDepositWithdrawFee': 'emulated',
76
77
  'fetchDepositWithdrawFees': true,
77
- 'fetchDepositsWithdrawals': false,
78
78
  'fetchFundingHistory': true,
79
- 'fetchWithdrawAddresses': false,
80
- 'fetchTransactions': false,
81
79
  'fetchFundingRate': true,
82
80
  'fetchFundingRateHistory': true,
83
81
  'fetchFundingRates': false,
@@ -101,7 +99,6 @@ export default class bitget extends Exchange {
101
99
  'fetchOrder': true,
102
100
  'fetchOrderBook': true,
103
101
  'fetchOrders': false,
104
- 'createTrailingAmountOrder': false,
105
102
  'fetchOrderTrades': false,
106
103
  'fetchPosition': true,
107
104
  'fetchPositionMode': false,
@@ -114,8 +111,10 @@ export default class bitget extends Exchange {
114
111
  'fetchTrades': true,
115
112
  'fetchTradingFee': true,
116
113
  'fetchTradingFees': true,
114
+ 'fetchTransactions': false,
117
115
  'fetchTransfer': false,
118
116
  'fetchTransfers': true,
117
+ 'fetchWithdrawAddresses': false,
119
118
  'fetchWithdrawal': false,
120
119
  'fetchWithdrawals': true,
121
120
  'reduceMargin': true,
@@ -124,6 +123,7 @@ export default class bitget extends Exchange {
124
123
  'setLeverage': true,
125
124
  'setMarginMode': true,
126
125
  'setPositionMode': true,
126
+ 'signIn': false,
127
127
  'transfer': true,
128
128
  'withdraw': true,
129
129
  },
@@ -45,8 +45,8 @@ export default class coinbasepro extends Exchange {
45
45
  'fetchDepositAddress': false,
46
46
  'fetchDeposits': true,
47
47
  'fetchDepositsWithdrawals': true,
48
- 'fetchLedger': true,
49
48
  'fetchFundingRate': false,
49
+ 'fetchLedger': true,
50
50
  'fetchMarginMode': false,
51
51
  'fetchMarkets': true,
52
52
  'fetchMyTrades': true,
package/js/src/coinex.js CHANGED
@@ -3517,11 +3517,17 @@ export default class coinex extends Exchange {
3517
3517
  * @name coinex#fetchPositions
3518
3518
  * @description fetch all open positions
3519
3519
  * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http033_pending_position
3520
- * @param {string[]|undefined} symbols list of unified market symbols
3520
+ * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http033-0_finished_position
3521
+ * @param {string[]} [symbols] list of unified market symbols
3521
3522
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3523
+ * @param {string} [params.method] the method to use 'perpetualPrivateGetPositionPending' or 'perpetualPrivateGetPositionFinished' default is 'perpetualPrivateGetPositionPending'
3524
+ * @param {int} [params.side] *history endpoint only* 0: All, 1: Sell, 2: Buy, default is 0
3522
3525
  * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
3523
3526
  */
3524
3527
  await this.loadMarkets();
3528
+ let defaultMethod = undefined;
3529
+ [defaultMethod, params] = this.handleOptionAndParams(params, 'fetchPositions', 'method', 'perpetualPrivateGetPositionPending');
3530
+ const isHistory = (defaultMethod === 'perpetualPrivateGetPositionFinished');
3525
3531
  symbols = this.marketSymbols(symbols);
3526
3532
  const request = {};
3527
3533
  let market = undefined;
@@ -3540,7 +3546,22 @@ export default class coinex extends Exchange {
3540
3546
  market = this.market(symbol);
3541
3547
  request['market'] = market['id'];
3542
3548
  }
3543
- const response = await this.perpetualPrivateGetPositionPending(this.extend(request, params));
3549
+ else {
3550
+ if (isHistory) {
3551
+ throw new ArgumentsRequired(this.id + ' fetchPositions() requires a symbol argument for closed positions');
3552
+ }
3553
+ }
3554
+ if (isHistory) {
3555
+ request['limit'] = 100;
3556
+ request['side'] = this.safeInteger(params, 'side', 0); // 0: All, 1: Sell, 2: Buy
3557
+ }
3558
+ let response = undefined;
3559
+ if (defaultMethod === 'perpetualPrivateGetPositionPending') {
3560
+ response = await this.perpetualPrivateGetPositionPending(this.extend(request, params));
3561
+ }
3562
+ else {
3563
+ response = await this.perpetualPrivateGetPositionFinished(this.extend(request, params));
3564
+ }
3544
3565
  //
3545
3566
  // {
3546
3567
  // "code": 0,
package/js/src/okx.js CHANGED
@@ -2917,12 +2917,26 @@ export default class okx extends Exchange {
2917
2917
  const request = {
2918
2918
  'instId': market['id'],
2919
2919
  };
2920
+ let isAlgoOrder = undefined;
2921
+ if ((type === 'trigger') || (type === 'conditional') || (type === 'move_order_stop') || (type === 'oco') || (type === 'iceberg') || (type === 'twap')) {
2922
+ isAlgoOrder = true;
2923
+ }
2920
2924
  const clientOrderId = this.safeString2(params, 'clOrdId', 'clientOrderId');
2921
2925
  if (clientOrderId !== undefined) {
2922
- request['clOrdId'] = clientOrderId;
2926
+ if (isAlgoOrder) {
2927
+ request['algoClOrdId'] = clientOrderId;
2928
+ }
2929
+ else {
2930
+ request['clOrdId'] = clientOrderId;
2931
+ }
2923
2932
  }
2924
2933
  else {
2925
- request['ordId'] = id;
2934
+ if (isAlgoOrder) {
2935
+ request['algoId'] = id;
2936
+ }
2937
+ else {
2938
+ request['ordId'] = id;
2939
+ }
2926
2940
  }
2927
2941
  let stopLossTriggerPrice = this.safeValue2(params, 'stopLossPrice', 'newSlTriggerPx');
2928
2942
  let stopLossPrice = this.safeValue(params, 'newSlOrdPx');
@@ -2934,37 +2948,62 @@ export default class okx extends Exchange {
2934
2948
  const takeProfit = this.safeValue(params, 'takeProfit');
2935
2949
  const stopLossDefined = (stopLoss !== undefined);
2936
2950
  const takeProfitDefined = (takeProfit !== undefined);
2937
- if (stopLossTriggerPrice !== undefined) {
2938
- request['newSlTriggerPx'] = this.priceToPrecision(symbol, stopLossTriggerPrice);
2939
- request['newSlOrdPx'] = (type === 'market') ? '-1' : this.priceToPrecision(symbol, stopLossPrice);
2940
- request['newSlTriggerPxType'] = stopLossTriggerPriceType;
2941
- }
2942
- if (takeProfitTriggerPrice !== undefined) {
2943
- request['newTpTriggerPx'] = this.priceToPrecision(symbol, takeProfitTriggerPrice);
2944
- request['newTpOrdPx'] = (type === 'market') ? '-1' : this.priceToPrecision(symbol, takeProfitPrice);
2945
- request['newTpTriggerPxType'] = takeProfitTriggerPriceType;
2946
- }
2947
- if (stopLossDefined) {
2948
- stopLossTriggerPrice = this.safeValue(stopLoss, 'triggerPrice');
2949
- stopLossPrice = this.safeValue(stopLoss, 'price');
2950
- const stopLossType = this.safeString(stopLoss, 'type');
2951
- request['newSlTriggerPx'] = this.priceToPrecision(symbol, stopLossTriggerPrice);
2952
- request['newSlOrdPx'] = (stopLossType === 'market') ? '-1' : this.priceToPrecision(symbol, stopLossPrice);
2953
- request['newSlTriggerPxType'] = stopLossTriggerPriceType;
2954
- }
2955
- if (takeProfitDefined) {
2956
- takeProfitTriggerPrice = this.safeValue(takeProfit, 'triggerPrice');
2957
- takeProfitPrice = this.safeValue(takeProfit, 'price');
2958
- const takeProfitType = this.safeString(takeProfit, 'type');
2959
- request['newTpTriggerPx'] = this.priceToPrecision(symbol, takeProfitTriggerPrice);
2960
- request['newTpOrdPx'] = (takeProfitType === 'market') ? '-1' : this.priceToPrecision(symbol, takeProfitPrice);
2961
- request['newTpTriggerPxType'] = takeProfitTriggerPriceType;
2951
+ if (isAlgoOrder) {
2952
+ if ((stopLossTriggerPrice === undefined) && (takeProfitTriggerPrice === undefined)) {
2953
+ throw new BadRequest(this.id + ' editOrder() requires a stopLossPrice or takeProfitPrice parameter for editing an algo order');
2954
+ }
2955
+ if (stopLossTriggerPrice !== undefined) {
2956
+ if (stopLossPrice === undefined) {
2957
+ throw new BadRequest(this.id + ' editOrder() requires a newSlOrdPx parameter for editing an algo order');
2958
+ }
2959
+ request['newSlTriggerPx'] = this.priceToPrecision(symbol, stopLossTriggerPrice);
2960
+ request['newSlOrdPx'] = (type === 'market') ? '-1' : this.priceToPrecision(symbol, stopLossPrice);
2961
+ request['newSlTriggerPxType'] = stopLossTriggerPriceType;
2962
+ }
2963
+ if (takeProfitTriggerPrice !== undefined) {
2964
+ if (takeProfitPrice === undefined) {
2965
+ throw new BadRequest(this.id + ' editOrder() requires a newTpOrdPx parameter for editing an algo order');
2966
+ }
2967
+ request['newTpTriggerPx'] = this.priceToPrecision(symbol, takeProfitTriggerPrice);
2968
+ request['newTpOrdPx'] = (type === 'market') ? '-1' : this.priceToPrecision(symbol, takeProfitPrice);
2969
+ request['newTpTriggerPxType'] = takeProfitTriggerPriceType;
2970
+ }
2971
+ }
2972
+ else {
2973
+ if (stopLossTriggerPrice !== undefined) {
2974
+ request['newSlTriggerPx'] = this.priceToPrecision(symbol, stopLossTriggerPrice);
2975
+ request['newSlOrdPx'] = (type === 'market') ? '-1' : this.priceToPrecision(symbol, stopLossPrice);
2976
+ request['newSlTriggerPxType'] = stopLossTriggerPriceType;
2977
+ }
2978
+ if (takeProfitTriggerPrice !== undefined) {
2979
+ request['newTpTriggerPx'] = this.priceToPrecision(symbol, takeProfitTriggerPrice);
2980
+ request['newTpOrdPx'] = (type === 'market') ? '-1' : this.priceToPrecision(symbol, takeProfitPrice);
2981
+ request['newTpTriggerPxType'] = takeProfitTriggerPriceType;
2982
+ }
2983
+ if (stopLossDefined) {
2984
+ stopLossTriggerPrice = this.safeValue(stopLoss, 'triggerPrice');
2985
+ stopLossPrice = this.safeValue(stopLoss, 'price');
2986
+ const stopLossType = this.safeString(stopLoss, 'type');
2987
+ request['newSlTriggerPx'] = this.priceToPrecision(symbol, stopLossTriggerPrice);
2988
+ request['newSlOrdPx'] = (stopLossType === 'market') ? '-1' : this.priceToPrecision(symbol, stopLossPrice);
2989
+ request['newSlTriggerPxType'] = stopLossTriggerPriceType;
2990
+ }
2991
+ if (takeProfitDefined) {
2992
+ takeProfitTriggerPrice = this.safeValue(takeProfit, 'triggerPrice');
2993
+ takeProfitPrice = this.safeValue(takeProfit, 'price');
2994
+ const takeProfitType = this.safeString(takeProfit, 'type');
2995
+ request['newTpTriggerPx'] = this.priceToPrecision(symbol, takeProfitTriggerPrice);
2996
+ request['newTpOrdPx'] = (takeProfitType === 'market') ? '-1' : this.priceToPrecision(symbol, takeProfitPrice);
2997
+ request['newTpTriggerPxType'] = takeProfitTriggerPriceType;
2998
+ }
2962
2999
  }
2963
3000
  if (amount !== undefined) {
2964
3001
  request['newSz'] = this.amountToPrecision(symbol, amount);
2965
3002
  }
2966
- if (price !== undefined) {
2967
- request['newPx'] = this.priceToPrecision(symbol, price);
3003
+ if (!isAlgoOrder) {
3004
+ if (price !== undefined) {
3005
+ request['newPx'] = this.priceToPrecision(symbol, price);
3006
+ }
2968
3007
  }
2969
3008
  params = this.omit(params, ['clOrdId', 'clientOrderId', 'takeProfitPrice', 'stopLossPrice', 'stopLoss', 'takeProfit']);
2970
3009
  return this.extend(request, params);
@@ -2974,7 +3013,8 @@ export default class okx extends Exchange {
2974
3013
  * @method
2975
3014
  * @name okx#editOrder
2976
3015
  * @description edit a trade order
2977
- * @see https://www.okx.com/docs-v5/en/#rest-api-trade-amend-order
3016
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-amend-order
3017
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-post-amend-algo-order
2978
3018
  * @param {string} id order id
2979
3019
  * @param {string} symbol unified symbol of the market to create an order in
2980
3020
  * @param {string} type 'market' or 'limit'
@@ -3002,7 +3042,17 @@ export default class okx extends Exchange {
3002
3042
  await this.loadMarkets();
3003
3043
  const market = this.market(symbol);
3004
3044
  const request = this.editOrderRequest(id, symbol, type, side, amount, price, params);
3005
- const response = await this.privatePostTradeAmendOrder(this.extend(request, params));
3045
+ let isAlgoOrder = undefined;
3046
+ if ((type === 'trigger') || (type === 'conditional') || (type === 'move_order_stop') || (type === 'oco') || (type === 'iceberg') || (type === 'twap')) {
3047
+ isAlgoOrder = true;
3048
+ }
3049
+ let response = undefined;
3050
+ if (isAlgoOrder) {
3051
+ response = await this.privatePostTradeAmendAlgos(this.extend(request, params));
3052
+ }
3053
+ else {
3054
+ response = await this.privatePostTradeAmendOrder(this.extend(request, params));
3055
+ }
3006
3056
  //
3007
3057
  // {
3008
3058
  // "code": "0",
package/js/src/phemex.js CHANGED
@@ -3548,8 +3548,10 @@ export default class phemex extends Exchange {
3548
3548
  * @description fetch all open positions
3549
3549
  * @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md#query-trading-account-and-positions
3550
3550
  * @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#query-account-positions
3551
- * @param {string[]|undefined} symbols list of unified market symbols
3551
+ * @see https://phemex-docs.github.io/#query-account-positions-with-unrealized-pnl
3552
+ * @param {string[]} [symbols] list of unified market symbols
3552
3553
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3554
+ * @param {string} [param.method] *USDT contracts only* 'privateGetGAccountsAccountPositions' or 'privateGetAccountsPositions' default is 'privateGetGAccountsAccountPositions'
3553
3555
  * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
3554
3556
  */
3555
3557
  await this.loadMarkets();
@@ -3584,7 +3586,14 @@ export default class phemex extends Exchange {
3584
3586
  };
3585
3587
  let response = undefined;
3586
3588
  if (isUSDTSettled) {
3587
- response = await this.privateGetGAccountsAccountPositions(this.extend(request, params));
3589
+ let method = undefined;
3590
+ [method, params] = this.handleOptionAndParams(params, 'fetchPositions', 'method', 'privateGetGAccountsAccountPositions');
3591
+ if (method === 'privateGetGAccountsAccountPositions') {
3592
+ response = await this.privateGetGAccountsAccountPositions(this.extend(request, params));
3593
+ }
3594
+ else {
3595
+ response = await this.privateGetAccountsPositions(this.extend(request, params));
3596
+ }
3588
3597
  }
3589
3598
  else {
3590
3599
  response = await this.privateGetAccountsAccountPositions(this.extend(request, params));
@@ -3760,7 +3769,7 @@ export default class phemex extends Exchange {
3760
3769
  const contracts = this.safeString(position, 'size');
3761
3770
  const contractSize = this.safeValue(market, 'contractSize');
3762
3771
  const contractSizeString = this.numberToString(contractSize);
3763
- const leverage = this.safeNumber2(position, 'leverage', 'leverageRr');
3772
+ const leverage = this.parseNumber(Precise.stringAbs((this.safeString(position, 'leverage', 'leverageRr'))));
3764
3773
  const entryPriceString = this.safeString2(position, 'avgEntryPrice', 'avgEntryPriceRp');
3765
3774
  const rawSide = this.safeString(position, 'side');
3766
3775
  let side = undefined;
@@ -48,6 +48,7 @@ export default class poloniex extends Exchange {
48
48
  'fetchDepositsWithdrawals': true,
49
49
  'fetchDepositWithdrawFee': 'emulated',
50
50
  'fetchDepositWithdrawFees': true,
51
+ 'fetchFundingRate': false,
51
52
  'fetchMarginMode': false,
52
53
  'fetchMarkets': true,
53
54
  'fetchMyTrades': true,
@@ -58,7 +59,6 @@ export default class poloniex extends Exchange {
58
59
  'fetchOrder': true,
59
60
  'fetchOrderBook': true,
60
61
  'fetchOrderBooks': false,
61
- 'fetchFundingRate': false,
62
62
  'fetchOrderTrades': true,
63
63
  'fetchPosition': false,
64
64
  'fetchPositionMode': false,
@@ -989,7 +989,7 @@ export default class binance extends binanceRest {
989
989
  }
990
990
  else {
991
991
  // take the timestamp of the closing price for candlestick streams
992
- timestamp = this.safeInteger(message, 'C');
992
+ timestamp = this.safeInteger2(message, 'C', 'E');
993
993
  }
994
994
  const marketId = this.safeString(message, 's');
995
995
  const symbol = this.safeSymbol(marketId, undefined, undefined, marketType);
@@ -35,6 +35,12 @@ export default class hitbtc extends hitbtcRest {
35
35
  'private': 'wss://api.hitbtc.com/api/3/ws/trading',
36
36
  },
37
37
  },
38
+ 'test': {
39
+ 'ws': {
40
+ 'public': 'wss://api.demo.hitbtc.com/api/3/ws/public',
41
+ 'private': 'wss://api.demo.hitbtc.com/api/3/ws/trading',
42
+ },
43
+ },
38
44
  },
39
45
  'options': {
40
46
  'tradesLimit': 1000,
package/js/src/pro/okx.js CHANGED
@@ -853,13 +853,15 @@ export default class okx extends okxRest {
853
853
  /**
854
854
  * @method
855
855
  * @name okx#watchMyTrades
856
- * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-order-channel
857
856
  * @description watches information on multiple trades made by the user
857
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-order-channel
858
858
  * @param {string} [symbol] unified market symbol of the market trades were made in
859
859
  * @param {int} [since] the earliest time in ms to fetch trades for
860
860
  * @param {int} [limit] the maximum number of trade structures to retrieve
861
861
  * @param {object} [params] extra parameters specific to the exchange API endpoint
862
862
  * @param {bool} [params.stop] true if fetching trigger or conditional trades
863
+ * @param {string} [params.type] 'spot', 'swap', 'future', 'option', 'ANY', 'SPOT', 'MARGIN', 'SWAP', 'FUTURES' or 'OPTION'
864
+ * @param {string} [params.marginMode] 'cross' or 'isolated', for automatically setting the type to spot margin
863
865
  * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure
864
866
  */
865
867
  // By default, receive order updates from any instrument type
@@ -881,7 +883,14 @@ export default class okx extends okxRest {
881
883
  if (type === 'future') {
882
884
  type = 'futures';
883
885
  }
884
- const uppercaseType = type.toUpperCase();
886
+ let uppercaseType = type.toUpperCase();
887
+ let marginMode = undefined;
888
+ [marginMode, params] = this.handleMarginModeAndParams('watchMyTrades', params);
889
+ if (uppercaseType === 'SPOT') {
890
+ if (marginMode !== undefined) {
891
+ uppercaseType = 'MARGIN';
892
+ }
893
+ }
885
894
  const request = {
886
895
  'instType': uppercaseType,
887
896
  };
@@ -1027,7 +1036,6 @@ export default class okx extends okxRest {
1027
1036
  */
1028
1037
  let type = undefined;
1029
1038
  // By default, receive order updates from any instrument type
1030
- [type, params] = this.handleOptionAndParams(params, 'watchOrders', 'defaultType');
1031
1039
  [type, params] = this.handleOptionAndParams(params, 'watchOrders', 'type', 'ANY');
1032
1040
  const isStop = this.safeValue2(params, 'stop', 'trigger', false);
1033
1041
  params = this.omit(params, ['stop', 'trigger']);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.2.22",
3
+ "version": "4.2.23",
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",