ccxt 4.3.9 → 4.3.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.
package/js/src/coinex.js CHANGED
@@ -1743,7 +1743,7 @@ export default class coinex extends Exchange {
1743
1743
  // "client_id": "",
1744
1744
  // }
1745
1745
  //
1746
- // Spot and Margin cancelOrder, cancelOrders, fetchOrder
1746
+ // Spot and Margin cancelOrder, fetchOrder
1747
1747
  //
1748
1748
  // {
1749
1749
  // "amount":"1.5",
@@ -1938,49 +1938,7 @@ export default class coinex extends Exchange {
1938
1938
  // "user_id": 3620173
1939
1939
  // }
1940
1940
  //
1941
- // swap: cancelOrders
1942
- //
1943
- // {
1944
- // "amount": "0.0005",
1945
- // "client_id": "x-167673045-b0cee0c584718b65",
1946
- // "create_time": 1701233683.294231,
1947
- // "deal_asset_fee": "0.00000000000000000000",
1948
- // "deal_fee": "0.00000000000000000000",
1949
- // "deal_profit": "0.00000000000000000000",
1950
- // "deal_stock": "0.00000000000000000000",
1951
- // "effect_type": 1,
1952
- // "fee_asset": "",
1953
- // "fee_discount": "0.00000000000000000000",
1954
- // "last_deal_amount": "0.00000000000000000000",
1955
- // "last_deal_id": 0,
1956
- // "last_deal_price": "0.00000000000000000000",
1957
- // "last_deal_role": 0,
1958
- // "last_deal_time": 0,
1959
- // "last_deal_type": 0,
1960
- // "left": "0.0005",
1961
- // "leverage": "3",
1962
- // "maker_fee": "0.00030",
1963
- // "market": "BTCUSDT",
1964
- // "option": 0,
1965
- // "order_id": 115940476323,
1966
- // "position_id": 0,
1967
- // "position_type": 2,
1968
- // "price": "25000.00",
1969
- // "side": 2,
1970
- // "source": "api.v1",
1971
- // "stop_id": 0,
1972
- // "stop_loss_price": "0.00000000000000000000",
1973
- // "stop_loss_type": 0,
1974
- // "take_profit_price": "0.00000000000000000000",
1975
- // "take_profit_type": 0,
1976
- // "taker_fee": "0.00050",
1977
- // "target": 0,
1978
- // "type": 1,
1979
- // "update_time": 1701233721.718884,
1980
- // "user_id": 3620173
1981
- // }
1982
- //
1983
- // Spot and Margin createOrder, createOrders v2
1941
+ // Spot and Margin createOrder, createOrders, cancelOrders v2
1984
1942
  //
1985
1943
  // {
1986
1944
  // "amount": "0.0001",
@@ -2012,7 +1970,7 @@ export default class coinex extends Exchange {
2012
1970
  // "stop_id": 117180138153
2013
1971
  // }
2014
1972
  //
2015
- // Swap createOrder, createOrders v2
1973
+ // Swap createOrder, createOrders, cancelOrders v2
2016
1974
  //
2017
1975
  // {
2018
1976
  // "amount": "0.0001",
@@ -2072,6 +2030,24 @@ export default class coinex extends Exchange {
2072
2030
  // "updated_at": 1714119054559
2073
2031
  // }
2074
2032
  //
2033
+ // Swap and Spot stop cancelOrders v2
2034
+ //
2035
+ // {
2036
+ // "amount": "0.0001",
2037
+ // "client_id": "x-167673045-a7d7714c6478acf6",
2038
+ // "created_at": 1714187923820,
2039
+ // "market": "BTCUSDT",
2040
+ // "market_type": "FUTURES",
2041
+ // "price": "61000",
2042
+ // "side": "buy",
2043
+ // "stop_id": 136984426097,
2044
+ // "trigger_direction": "higher",
2045
+ // "trigger_price": "62000",
2046
+ // "trigger_price_type": "latest_price",
2047
+ // "type": "limit",
2048
+ // "updated_at": 1714187974363
2049
+ // }
2050
+ //
2075
2051
  const rawStatus = this.safeString(order, 'status');
2076
2052
  let timestamp = this.safeTimestamp(order, 'create_time');
2077
2053
  if (timestamp === undefined) {
@@ -2144,8 +2120,8 @@ export default class coinex extends Exchange {
2144
2120
  'reduceOnly': undefined,
2145
2121
  'side': side,
2146
2122
  'price': this.safeString(order, 'price'),
2147
- 'stopPrice': this.safeString(order, 'stop_price'),
2148
- 'triggerPrice': this.safeString(order, 'stop_price'),
2123
+ 'stopPrice': this.safeString2(order, 'stop_price', 'trigger_price'),
2124
+ 'triggerPrice': this.safeString2(order, 'stop_price', 'trigger_price'),
2149
2125
  'takeProfitPrice': this.safeNumber(order, 'take_profit_price'),
2150
2126
  'stopLossPrice': this.safeNumber(order, 'stop_loss_price'),
2151
2127
  'cost': this.safeString2(order, 'deal_money', 'filled_value'),
@@ -2751,11 +2727,14 @@ export default class coinex extends Exchange {
2751
2727
  * @method
2752
2728
  * @name coinex#cancelOrders
2753
2729
  * @description cancel multiple orders
2754
- * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade016_batch_cancel_order
2755
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http021-0_cancel_order_batch
2730
+ * @see https://docs.coinex.com/api/v2/spot/order/http/cancel-batch-order
2731
+ * @see https://docs.coinex.com/api/v2/spot/order/http/cancel-batch-stop-order
2732
+ * @see https://docs.coinex.com/api/v2/futures/order/http/cancel-batch-order
2733
+ * @see https://docs.coinex.com/api/v2/futures/order/http/cancel-batch-stop-order
2756
2734
  * @param {string[]} ids order ids
2757
2735
  * @param {string} symbol unified market symbol
2758
2736
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2737
+ * @param {boolean} [params.stop] set to true for canceling stop orders
2759
2738
  * @returns {object} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2760
2739
  */
2761
2740
  if (symbol === undefined) {
@@ -2766,113 +2745,161 @@ export default class coinex extends Exchange {
2766
2745
  const request = {
2767
2746
  'market': market['id'],
2768
2747
  };
2769
- const idsString = ids.join(',');
2748
+ const stop = this.safeBool2(params, 'stop', 'trigger');
2749
+ params = this.omit(params, ['stop', 'trigger']);
2770
2750
  let response = undefined;
2751
+ if (stop) {
2752
+ request['stop_ids'] = ids;
2753
+ }
2754
+ else {
2755
+ request['order_ids'] = ids;
2756
+ }
2771
2757
  if (market['spot']) {
2772
- request['batch_ids'] = idsString;
2773
- response = await this.v1PrivateDeleteOrderPendingBatch(this.extend(request, params));
2758
+ if (stop) {
2759
+ response = await this.v2PrivatePostSpotCancelBatchStopOrder(this.extend(request, params));
2760
+ //
2761
+ // {
2762
+ // "code": 0,
2763
+ // "data": [
2764
+ // {
2765
+ // "code": 0,
2766
+ // "data": {
2767
+ // "amount": "0.0001",
2768
+ // "ccy": "BTC",
2769
+ // "client_id": "x-167673045-8e33d6f4a4bcb022",
2770
+ // "created_at": 1714188827291,
2771
+ // "market": "BTCUSDT",
2772
+ // "market_type": "SPOT",
2773
+ // "price": "61000",
2774
+ // "side": "buy",
2775
+ // "stop_id": 117248845854,
2776
+ // "trigger_direction": "higher",
2777
+ // "trigger_price": "62000",
2778
+ // "trigger_price_type": "mark_price",
2779
+ // "type": "limit",
2780
+ // "updated_at": 1714188827291
2781
+ // },
2782
+ // "message": "OK"
2783
+ // },
2784
+ // ],
2785
+ // "message": "OK"
2786
+ // }
2787
+ //
2788
+ }
2789
+ else {
2790
+ response = await this.v2PrivatePostSpotCancelBatchOrder(this.extend(request, params));
2791
+ //
2792
+ // {
2793
+ // "code": 0,
2794
+ // "data": [
2795
+ // {
2796
+ // "code": 0,
2797
+ // "data": {
2798
+ // "amount": "0.0001",
2799
+ // "base_fee": "0",
2800
+ // "ccy": "BTC",
2801
+ // "client_id": "x-167673045-c1cc78e5b42d8c4e",
2802
+ // "created_at": 1714188449497,
2803
+ // "discount_fee": "0",
2804
+ // "filled_amount": "0",
2805
+ // "filled_value": "0",
2806
+ // "last_fill_amount": "0",
2807
+ // "last_fill_price": "0",
2808
+ // "maker_fee_rate": "0.002",
2809
+ // "market": "BTCUSDT",
2810
+ // "market_type": "SPOT",
2811
+ // "order_id": 117248494358,
2812
+ // "price": "60000",
2813
+ // "quote_fee": "0",
2814
+ // "side": "buy",
2815
+ // "taker_fee_rate": "0.002",
2816
+ // "type": "limit",
2817
+ // "unfilled_amount": "0.0001",
2818
+ // "updated_at": 1714188449497
2819
+ // },
2820
+ // "message": ""
2821
+ // },
2822
+ // ],
2823
+ // "message": "OK"
2824
+ // }
2825
+ //
2826
+ }
2774
2827
  }
2775
2828
  else {
2776
- request['order_ids'] = idsString;
2777
- response = await this.v1PerpetualPrivatePostOrderCancelBatch(this.extend(request, params));
2829
+ request['market_type'] = 'FUTURES';
2830
+ if (stop) {
2831
+ response = await this.v2PrivatePostFuturesCancelBatchStopOrder(this.extend(request, params));
2832
+ //
2833
+ // {
2834
+ // "code": 0,
2835
+ // "data": [
2836
+ // {
2837
+ // "code": 0,
2838
+ // "data": {
2839
+ // "amount": "0.0001",
2840
+ // "client_id": "x-167673045-a7d7714c6478acf6",
2841
+ // "created_at": 1714187923820,
2842
+ // "market": "BTCUSDT",
2843
+ // "market_type": "FUTURES",
2844
+ // "price": "61000",
2845
+ // "side": "buy",
2846
+ // "stop_id": 136984426097,
2847
+ // "trigger_direction": "higher",
2848
+ // "trigger_price": "62000",
2849
+ // "trigger_price_type": "latest_price",
2850
+ // "type": "limit",
2851
+ // "updated_at": 1714187974363
2852
+ // },
2853
+ // "message": ""
2854
+ // },
2855
+ // ],
2856
+ // "message": "OK"
2857
+ // }
2858
+ //
2859
+ }
2860
+ else {
2861
+ response = await this.v2PrivatePostFuturesCancelBatchOrder(this.extend(request, params));
2862
+ //
2863
+ // {
2864
+ // "code": 0,
2865
+ // "data": [
2866
+ // {
2867
+ // "code": 0,
2868
+ // "data": {
2869
+ // "amount": "0.0001",
2870
+ // "client_id": "x-167673045-9f80fde284339a72",
2871
+ // "created_at": 1714187491784,
2872
+ // "fee": "0",
2873
+ // "fee_ccy": "USDT",
2874
+ // "filled_amount": "0",
2875
+ // "filled_value": "0",
2876
+ // "last_filled_amount": "0",
2877
+ // "last_filled_price": "0",
2878
+ // "maker_fee_rate": "0.0003",
2879
+ // "market": "BTCUSDT",
2880
+ // "market_type": "FUTURES",
2881
+ // "order_id": 136983851788,
2882
+ // "price": "61000",
2883
+ // "realized_pnl": "0",
2884
+ // "side": "buy",
2885
+ // "taker_fee_rate": "0.0005",
2886
+ // "type": "limit",
2887
+ // "unfilled_amount": "0.0001",
2888
+ // "updated_at": 1714187567079
2889
+ // },
2890
+ // "message": ""
2891
+ // },
2892
+ // ],
2893
+ // "message": "OK"
2894
+ // }
2895
+ //
2896
+ }
2778
2897
  }
2779
- //
2780
- // spot
2781
- //
2782
- // {
2783
- // "code": 0,
2784
- // "data": [
2785
- // {
2786
- // "code": 0,
2787
- // "data": {
2788
- // "account_id": 0,
2789
- // "amount": "0.0005",
2790
- // "asset_fee": "0",
2791
- // "avg_price": "0.00",
2792
- // "client_id": "x-167673045-d4e03c38f4d19b4e",
2793
- // "create_time": 1701229157,
2794
- // "deal_amount": "0",
2795
- // "deal_fee": "0",
2796
- // "deal_money": "0",
2797
- // "fee_asset": null,
2798
- // "fee_discount": "1",
2799
- // "finished_time": 0,
2800
- // "id": 107745856682,
2801
- // "left": "0",
2802
- // "maker_fee_rate": "0.002",
2803
- // "market": "BTCUSDT",
2804
- // "money_fee": "0",
2805
- // "order_type": "limit",
2806
- // "price": "22000",
2807
- // "status": "not_deal",
2808
- // "stock_fee": "0",
2809
- // "taker_fee_rate": "0.002",
2810
- // "type": "buy"
2811
- // },
2812
- // "message": ""
2813
- // },
2814
- // ],
2815
- // "message": "Success"
2816
- // }
2817
- //
2818
- // swap
2819
- //
2820
- // {
2821
- // "code": 0,
2822
- // "data": [
2823
- // {
2824
- // "code": 0,
2825
- // "message": "",
2826
- // "order": {
2827
- // "amount": "0.0005",
2828
- // "client_id": "x-167673045-b0cee0c584718b65",
2829
- // "create_time": 1701233683.294231,
2830
- // "deal_asset_fee": "0.00000000000000000000",
2831
- // "deal_fee": "0.00000000000000000000",
2832
- // "deal_profit": "0.00000000000000000000",
2833
- // "deal_stock": "0.00000000000000000000",
2834
- // "effect_type": 1,
2835
- // "fee_asset": "",
2836
- // "fee_discount": "0.00000000000000000000",
2837
- // "last_deal_amount": "0.00000000000000000000",
2838
- // "last_deal_id": 0,
2839
- // "last_deal_price": "0.00000000000000000000",
2840
- // "last_deal_role": 0,
2841
- // "last_deal_time": 0,
2842
- // "last_deal_type": 0,
2843
- // "left": "0.0005",
2844
- // "leverage": "3",
2845
- // "maker_fee": "0.00030",
2846
- // "market": "BTCUSDT",
2847
- // "option": 0,
2848
- // "order_id": 115940476323,
2849
- // "position_id": 0,
2850
- // "position_type": 2,
2851
- // "price": "25000.00",
2852
- // "side": 2,
2853
- // "source": "api.v1",
2854
- // "stop_id": 0,
2855
- // "stop_loss_price": "0.00000000000000000000",
2856
- // "stop_loss_type": 0,
2857
- // "take_profit_price": "0.00000000000000000000",
2858
- // "take_profit_type": 0,
2859
- // "taker_fee": "0.00050",
2860
- // "target": 0,
2861
- // "type": 1,
2862
- // "update_time": 1701233721.718884,
2863
- // "user_id": 3620173
2864
- // }
2865
- // },
2866
- // ],
2867
- // "message": "OK"
2868
- // }
2869
- //
2870
- const data = this.safeValue(response, 'data', []);
2898
+ const data = this.safeList(response, 'data', []);
2871
2899
  const results = [];
2872
2900
  for (let i = 0; i < data.length; i++) {
2873
2901
  const entry = data[i];
2874
- const dataRequest = market['spot'] ? 'data' : 'order';
2875
- const item = this.safeValue(entry, dataRequest, {});
2902
+ const item = this.safeDict(entry, 'data', {});
2876
2903
  const order = this.parseOrder(item, market);
2877
2904
  results.push(order);
2878
2905
  }
@@ -1,5 +1,5 @@
1
1
  import kucoin from './abstract/kucoinfutures.js';
2
- import type { TransferEntry, Int, OrderSide, OrderType, OHLCV, Order, Trade, OrderRequest, FundingHistory, Balances, Str, Ticker, Tickers, OrderBook, Transaction, Strings, Market, Currency, Num, MarginModification } from './base/types.js';
2
+ import type { TransferEntry, Int, OrderSide, OrderType, OHLCV, Order, Trade, OrderRequest, FundingHistory, Balances, Str, Ticker, Tickers, OrderBook, Transaction, Strings, Market, Currency, Num, MarginModification, TradingFeeInterface } from './base/types.js';
3
3
  /**
4
4
  * @class kucoinfutures
5
5
  * @augments Exchange
@@ -31,6 +31,7 @@ export default class kucoinfutures extends kucoin {
31
31
  fetchFundingHistory(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<FundingHistory[]>;
32
32
  fetchPosition(symbol: string, params?: {}): Promise<import("./base/types.js").Position>;
33
33
  fetchPositions(symbols?: Strings, params?: {}): Promise<import("./base/types.js").Position[]>;
34
+ fetchPositionsHistory(symbols?: Strings, since?: Int, limit?: Int, params?: {}): Promise<import("./base/types.js").Position[]>;
34
35
  parsePosition(position: any, market?: Market): import("./base/types.js").Position;
35
36
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: number, price?: Num, params?: {}): Promise<Order>;
36
37
  createOrders(orders: OrderRequest[], params?: {}): Promise<Order[]>;
@@ -94,4 +95,5 @@ export default class kucoinfutures extends kucoin {
94
95
  datetime: string;
95
96
  };
96
97
  closePosition(symbol: string, side?: OrderSide, params?: {}): Promise<Order>;
98
+ fetchTradingFee(symbol: string, params?: {}): Promise<TradingFeeInterface>;
97
99
  }
@@ -84,13 +84,14 @@ export default class kucoinfutures extends kucoin {
84
84
  'fetchPositionHistory': false,
85
85
  'fetchPositionMode': false,
86
86
  'fetchPositions': true,
87
- 'fetchPositionsHistory': false,
87
+ 'fetchPositionsHistory': true,
88
88
  'fetchPremiumIndexOHLCV': false,
89
89
  'fetchStatus': true,
90
90
  'fetchTicker': true,
91
91
  'fetchTickers': true,
92
92
  'fetchTime': true,
93
93
  'fetchTrades': true,
94
+ 'fetchTradingFee': true,
94
95
  'fetchTransactionFee': false,
95
96
  'fetchWithdrawals': true,
96
97
  'setLeverage': false,
@@ -167,6 +168,8 @@ export default class kucoinfutures extends kucoin {
167
168
  'funding-history': 4.44,
168
169
  'sub/api-key': 1,
169
170
  'trade-statistics': 1,
171
+ 'trade-fees': 1,
172
+ 'history-positions': 1,
170
173
  },
171
174
  'post': {
172
175
  'withdrawals': 1,
@@ -1140,6 +1143,76 @@ export default class kucoinfutures extends kucoin {
1140
1143
  const data = this.safeList(response, 'data');
1141
1144
  return this.parsePositions(data, symbols);
1142
1145
  }
1146
+ async fetchPositionsHistory(symbols = undefined, since = undefined, limit = undefined, params = {}) {
1147
+ /**
1148
+ * @method
1149
+ * @name kucoinfutures#fetchPositionsHistory
1150
+ * @description fetches historical positions
1151
+ * @see https://www.kucoin.com/docs/rest/futures-trading/positions/get-positions-history
1152
+ * @param {string[]} [symbols] list of unified market symbols
1153
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1154
+ * @param {int} [params.until] closing end time
1155
+ * @param {int} [params.pageId] page id
1156
+ * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
1157
+ */
1158
+ await this.loadMarkets();
1159
+ if (limit === undefined) {
1160
+ limit = 200;
1161
+ }
1162
+ const request = {
1163
+ 'limit': limit,
1164
+ };
1165
+ if (since !== undefined) {
1166
+ request['from'] = since;
1167
+ }
1168
+ const until = this.safeInteger(params, 'until');
1169
+ if (until !== undefined) {
1170
+ params = this.omit(params, 'until');
1171
+ request['to'] = until;
1172
+ }
1173
+ const response = await this.futuresPrivateGetHistoryPositions(this.extend(request, params));
1174
+ //
1175
+ // {
1176
+ // "success": true,
1177
+ // "code": "200",
1178
+ // "msg": "success",
1179
+ // "retry": false,
1180
+ // "data": {
1181
+ // "currentPage": 1,
1182
+ // "pageSize": 10,
1183
+ // "totalNum": 25,
1184
+ // "totalPage": 3,
1185
+ // "items": [
1186
+ // {
1187
+ // "closeId": "300000000000000030",
1188
+ // "positionId": "300000000000000009",
1189
+ // "uid": 99996908309485,
1190
+ // "userId": "6527d4fc8c7f3d0001f40f5f",
1191
+ // "symbol": "XBTUSDM",
1192
+ // "settleCurrency": "XBT",
1193
+ // "leverage": "0.0",
1194
+ // "type": "LIQUID_LONG",
1195
+ // "side": null,
1196
+ // "closeSize": null,
1197
+ // "pnl": "-1.0000003793999999",
1198
+ // "realisedGrossCost": "0.9993849748999999",
1199
+ // "withdrawPnl": "0.0",
1200
+ // "roe": null,
1201
+ // "tradeFee": "0.0006154045",
1202
+ // "fundingFee": "0.0",
1203
+ // "openTime": 1713785751181,
1204
+ // "closeTime": 1713785752784,
1205
+ // "openPrice": null,
1206
+ // "closePrice": null
1207
+ // }
1208
+ // ]
1209
+ // }
1210
+ // }
1211
+ //
1212
+ const data = this.safeDict(response, 'data');
1213
+ const items = this.safeList(data, 'items', []);
1214
+ return this.parsePositions(items, symbols);
1215
+ }
1143
1216
  parsePosition(position, market = undefined) {
1144
1217
  //
1145
1218
  // {
@@ -1186,17 +1259,51 @@ export default class kucoinfutures extends kucoin {
1186
1259
  // }
1187
1260
  // ]
1188
1261
  // }
1262
+ // position history
1263
+ // {
1264
+ // "closeId": "300000000000000030",
1265
+ // "positionId": "300000000000000009",
1266
+ // "uid": 99996908309485,
1267
+ // "userId": "6527d4fc8c7f3d0001f40f5f",
1268
+ // "symbol": "XBTUSDM",
1269
+ // "settleCurrency": "XBT",
1270
+ // "leverage": "0.0",
1271
+ // "type": "LIQUID_LONG",
1272
+ // "side": null,
1273
+ // "closeSize": null,
1274
+ // "pnl": "-1.0000003793999999",
1275
+ // "realisedGrossCost": "0.9993849748999999",
1276
+ // "withdrawPnl": "0.0",
1277
+ // "roe": null,
1278
+ // "tradeFee": "0.0006154045",
1279
+ // "fundingFee": "0.0",
1280
+ // "openTime": 1713785751181,
1281
+ // "closeTime": 1713785752784,
1282
+ // "openPrice": null,
1283
+ // "closePrice": null
1284
+ // }
1189
1285
  //
1190
1286
  const symbol = this.safeString(position, 'symbol');
1191
1287
  market = this.safeMarket(symbol, market);
1192
1288
  const timestamp = this.safeInteger(position, 'currentTimestamp');
1193
1289
  const size = this.safeString(position, 'currentQty');
1194
1290
  let side = undefined;
1195
- if (Precise.stringGt(size, '0')) {
1196
- side = 'long';
1291
+ const type = this.safeStringLower(position, 'type');
1292
+ if (size !== undefined) {
1293
+ if (Precise.stringGt(size, '0')) {
1294
+ side = 'long';
1295
+ }
1296
+ else if (Precise.stringLt(size, '0')) {
1297
+ side = 'short';
1298
+ }
1197
1299
  }
1198
- else if (Precise.stringLt(size, '0')) {
1199
- side = 'short';
1300
+ else if (type !== undefined) {
1301
+ if (type.indexOf('long') > -1) {
1302
+ side = 'long';
1303
+ }
1304
+ else {
1305
+ side = 'short';
1306
+ }
1200
1307
  }
1201
1308
  const notional = Precise.stringAbs(this.safeString(position, 'posCost'));
1202
1309
  const initialMargin = this.safeString(position, 'posInit');
@@ -1205,25 +1312,28 @@ export default class kucoinfutures extends kucoin {
1205
1312
  const unrealisedPnl = this.safeString(position, 'unrealisedPnl');
1206
1313
  const crossMode = this.safeValue(position, 'crossMode');
1207
1314
  // currently crossMode is always set to false and only isolated positions are supported
1208
- const marginMode = crossMode ? 'cross' : 'isolated';
1315
+ let marginMode = undefined;
1316
+ if (crossMode !== undefined) {
1317
+ marginMode = crossMode ? 'cross' : 'isolated';
1318
+ }
1209
1319
  return this.safePosition({
1210
1320
  'info': position,
1211
- 'id': this.safeString(position, 'id'),
1321
+ 'id': this.safeString2(position, 'id', 'positionId'),
1212
1322
  'symbol': this.safeString(market, 'symbol'),
1213
1323
  'timestamp': timestamp,
1214
1324
  'datetime': this.iso8601(timestamp),
1215
- 'lastUpdateTimestamp': undefined,
1325
+ 'lastUpdateTimestamp': this.safeInteger(position, 'closeTime'),
1216
1326
  'initialMargin': this.parseNumber(initialMargin),
1217
1327
  'initialMarginPercentage': this.parseNumber(initialMarginPercentage),
1218
1328
  'maintenanceMargin': this.safeNumber(position, 'posMaint'),
1219
1329
  'maintenanceMarginPercentage': this.safeNumber(position, 'maintMarginReq'),
1220
- 'entryPrice': this.safeNumber(position, 'avgEntryPrice'),
1330
+ 'entryPrice': this.safeNumber2(position, 'avgEntryPrice', 'openPrice'),
1221
1331
  'notional': this.parseNumber(notional),
1222
- 'leverage': this.safeNumber(position, 'realLeverage'),
1332
+ 'leverage': this.safeNumber2(position, 'realLeverage', 'leverage'),
1223
1333
  'unrealizedPnl': this.parseNumber(unrealisedPnl),
1224
1334
  'contracts': this.parseNumber(Precise.stringAbs(size)),
1225
1335
  'contractSize': this.safeValue(market, 'contractSize'),
1226
- 'realizedPnl': this.safeNumber(position, 'realisedPnl'),
1336
+ 'realizedPnl': this.safeNumber2(position, 'realisedPnl', 'pnl'),
1227
1337
  'marginRatio': undefined,
1228
1338
  'liquidationPrice': this.safeNumber(position, 'liquidationPrice'),
1229
1339
  'markPrice': this.safeNumber(position, 'markPrice'),
@@ -2704,4 +2814,42 @@ export default class kucoinfutures extends kucoin {
2704
2814
  }
2705
2815
  return this.parseOrder(response, market);
2706
2816
  }
2817
+ async fetchTradingFee(symbol, params = {}) {
2818
+ /**
2819
+ * @method
2820
+ * @name kucoinfutures#fetchTradingFee
2821
+ * @description fetch the trading fees for a market
2822
+ * @see https://www.kucoin.com/docs/rest/funding/trade-fee/trading-pair-actual-fee-futures
2823
+ * @param {string} symbol unified market symbol
2824
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2825
+ * @returns {object} a [fee structure]{@link https://docs.ccxt.com/#/?id=fee-structure}
2826
+ */
2827
+ await this.loadMarkets();
2828
+ const market = this.market(symbol);
2829
+ const request = {
2830
+ 'symbols': market['id'],
2831
+ };
2832
+ const response = await this.privateGetTradeFees(this.extend(request, params));
2833
+ //
2834
+ // {
2835
+ // "code": "200000",
2836
+ // "data": {
2837
+ // "symbol": "XBTUSDTM",
2838
+ // "takerFeeRate": "0.0006",
2839
+ // "makerFeeRate": "0.0002"
2840
+ // }
2841
+ // }
2842
+ //
2843
+ const data = this.safeList(response, 'data', []);
2844
+ const first = this.safeDict(data, 0);
2845
+ const marketId = this.safeString(first, 'symbol');
2846
+ return {
2847
+ 'info': response,
2848
+ 'symbol': this.safeSymbol(marketId, market),
2849
+ 'maker': this.safeNumber(first, 'makerFeeRate'),
2850
+ 'taker': this.safeNumber(first, 'takerFeeRate'),
2851
+ 'percentage': true,
2852
+ 'tierBased': true,
2853
+ };
2854
+ }
2707
2855
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.3.9",
3
+ "version": "4.3.11",
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",
@@ -30,6 +30,7 @@
30
30
  "coverage-js": "npm run instrument && npm run nyc-coverage && rm -rf jsInstrumented",
31
31
  "docker": "docker-compose run --rm ccxt",
32
32
  "fixTSBug": "node build/fixTSBug",
33
+ "transpileCsSingle": "tsx build/csharpTranspiler.ts",
33
34
  "transpileCS": "tsx build/csharpTranspiler.ts --multi",
34
35
  "transpileCSWs": "tsx build/csharpTranspiler.ts --ws",
35
36
  "buildCS": "dotnet build cs/ccxt.sln",