ccxt 4.5.44 → 4.5.45

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 (81) hide show
  1. package/README.md +9 -12
  2. package/dist/ccxt.browser.min.js +3 -3
  3. package/dist/cjs/ccxt.js +1 -12
  4. package/dist/cjs/src/abstract/kucoinfutures.js +1 -1
  5. package/dist/cjs/src/base/Exchange.js +36 -3
  6. package/dist/cjs/src/base/functions/encode.js +2 -2
  7. package/dist/cjs/src/base/functions/generic.js +8 -2
  8. package/dist/cjs/src/bitrue.js +1 -1
  9. package/dist/cjs/src/bitteam.js +1 -1
  10. package/dist/cjs/src/btcbox.js +1 -1
  11. package/dist/cjs/src/cex.js +1 -0
  12. package/dist/cjs/src/gate.js +227 -168
  13. package/dist/cjs/src/grvt.js +3 -2
  14. package/dist/cjs/src/hyperliquid.js +16 -5
  15. package/dist/cjs/src/kraken.js +2 -2
  16. package/dist/cjs/src/krakenfutures.js +1 -5
  17. package/dist/cjs/src/kucoin.js +4729 -970
  18. package/dist/cjs/src/kucoinfutures.js +14 -3434
  19. package/dist/cjs/src/lbank.js +1 -1
  20. package/dist/cjs/src/poloniex.js +1 -1
  21. package/dist/cjs/src/pro/gate.js +37 -1
  22. package/dist/cjs/src/pro/kucoin.js +819 -178
  23. package/dist/cjs/src/pro/kucoinfutures.js +95 -1261
  24. package/dist/cjs/src/pro/mexc.js +10 -5
  25. package/dist/cjs/src/pro/okx.js +84 -39
  26. package/js/ccxt.d.ts +2 -14
  27. package/js/ccxt.js +2 -10
  28. package/js/src/abstract/kucoin.d.ts +46 -3
  29. package/js/src/abstract/kucoinfutures.d.ts +27 -12
  30. package/js/src/base/Exchange.d.ts +12 -1
  31. package/js/src/base/Exchange.js +36 -3
  32. package/js/src/base/functions/encode.js +2 -2
  33. package/js/src/base/functions/generic.js +9 -3
  34. package/js/src/bitrue.js +1 -1
  35. package/js/src/bitteam.js +1 -1
  36. package/js/src/btcbox.js +1 -1
  37. package/js/src/cex.js +2 -1
  38. package/js/src/gate.d.ts +125 -119
  39. package/js/src/gate.js +227 -168
  40. package/js/src/grvt.js +3 -2
  41. package/js/src/hyperliquid.d.ts +3 -1
  42. package/js/src/hyperliquid.js +16 -5
  43. package/js/src/kraken.js +2 -2
  44. package/js/src/krakenfutures.js +1 -5
  45. package/js/src/kucoin.d.ts +696 -100
  46. package/js/src/kucoin.js +4730 -971
  47. package/js/src/kucoinfutures.d.ts +4 -522
  48. package/js/src/kucoinfutures.js +14 -3434
  49. package/js/src/lbank.js +1 -1
  50. package/js/src/poloniex.js +1 -1
  51. package/js/src/pro/gate.d.ts +30 -1
  52. package/js/src/pro/gate.js +37 -1
  53. package/js/src/pro/kucoin.d.ts +70 -30
  54. package/js/src/pro/kucoin.js +821 -180
  55. package/js/src/pro/kucoinfutures.d.ts +17 -195
  56. package/js/src/pro/kucoinfutures.js +96 -1262
  57. package/js/src/pro/mexc.js +10 -5
  58. package/js/src/pro/okx.d.ts +1 -0
  59. package/js/src/pro/okx.js +84 -39
  60. package/package.json +1 -1
  61. package/dist/cjs/src/abstract/alp.js +0 -11
  62. package/dist/cjs/src/abstract/defx.js +0 -11
  63. package/dist/cjs/src/abstract/timex.js +0 -11
  64. package/dist/cjs/src/alp.js +0 -1059
  65. package/dist/cjs/src/defx.js +0 -2142
  66. package/dist/cjs/src/pro/defx.js +0 -866
  67. package/dist/cjs/src/timex.js +0 -1793
  68. package/js/src/abstract/alp.d.ts +0 -21
  69. package/js/src/abstract/alp.js +0 -5
  70. package/js/src/abstract/defx.d.ts +0 -72
  71. package/js/src/abstract/defx.js +0 -5
  72. package/js/src/abstract/timex.d.ts +0 -65
  73. package/js/src/abstract/timex.js +0 -5
  74. package/js/src/alp.d.ts +0 -209
  75. package/js/src/alp.js +0 -1052
  76. package/js/src/defx.d.ts +0 -348
  77. package/js/src/defx.js +0 -2135
  78. package/js/src/pro/defx.d.ts +0 -236
  79. package/js/src/pro/defx.js +0 -859
  80. package/js/src/timex.d.ts +0 -247
  81. package/js/src/timex.js +0 -1786
@@ -1,1103 +1,37 @@
1
1
  // ---------------------------------------------------------------------------
2
- import { ArgumentsRequired, ExchangeNotAvailable, InvalidOrder, InsufficientFunds, AccountSuspended, InvalidNonce, NotSupported, OrderNotFound, BadRequest, AuthenticationError, RateLimitExceeded, PermissionDenied } from './base/errors.js';
3
- import { Precise } from './base/Precise.js';
4
- import { TICK_SIZE } from './base/functions/number.js';
5
- import kucoin from './abstract/kucoinfutures.js';
2
+ import kucoin from './kucoin.js';
3
+ import { BadRequest } from './base/errors.js';
6
4
  // ---------------------------------------------------------------------------
7
- /**
8
- * @class kucoinfutures
9
- * @augments Exchange
10
- */
11
5
  export default class kucoinfutures extends kucoin {
12
6
  describe() {
13
7
  return this.deepExtend(super.describe(), {
14
8
  'id': 'kucoinfutures',
15
9
  'name': 'KuCoin Futures',
16
- 'countries': ['SC'],
17
- 'rateLimit': 75,
18
- 'version': 'v1',
19
- 'certified': true,
20
- 'pro': true,
21
- 'comment': 'Platform 2.0',
22
- 'quoteJsonNumbers': false,
10
+ 'urls': {
11
+ 'logo': 'https://user-images.githubusercontent.com/1294454/147508995-9e35030a-d046-43a1-a006-6fabd981b554.jpg',
12
+ 'www': 'https://futures.kucoin.com/',
13
+ 'referral': 'https://futures.kucoin.com/?rcode=E5wkqe',
14
+ },
23
15
  'has': {
24
16
  'CORS': undefined,
25
17
  'spot': false,
26
18
  'margin': false,
27
19
  'swap': true,
28
20
  'future': true,
29
- 'option': false,
30
- 'addMargin': true,
31
- 'cancelAllOrders': true,
32
- 'cancelOrder': true,
33
- 'cancelOrders': true,
34
- 'closeAllPositions': false,
35
- 'closePosition': true,
36
- 'closePositions': false,
37
- 'createDepositAddress': true,
38
- 'createOrder': true,
39
- 'createOrders': true,
40
- 'createOrderWithTakeProfitAndStopLoss': true,
41
- 'createReduceOnlyOrder': true,
42
- 'createStopLimitOrder': true,
43
- 'createStopLossOrder': true,
44
- 'createStopMarketOrder': true,
45
- 'createStopOrder': true,
46
- 'createTakeProfitOrder': true,
47
- 'createTriggerOrder': true,
48
- 'fetchAccounts': true,
49
- 'fetchBalance': true,
21
+ 'option': undefined,
50
22
  'fetchBidsAsks': true,
51
- 'fetchBorrowRateHistories': false,
52
- 'fetchBorrowRateHistory': false,
53
- 'fetchClosedOrders': true,
54
- 'fetchCrossBorrowRate': false,
55
- 'fetchCrossBorrowRates': false,
56
- 'fetchCurrencies': false,
57
- 'fetchDepositAddress': true,
58
- 'fetchDepositAddresses': false,
59
- 'fetchDepositAddressesByNetwork': false,
60
- 'fetchDeposits': true,
61
- 'fetchDepositWithdrawFee': false,
62
- 'fetchDepositWithdrawFees': false,
63
- 'fetchFundingHistory': true,
64
- 'fetchFundingInterval': true,
65
- 'fetchFundingIntervals': false,
66
- 'fetchFundingRate': true,
67
- 'fetchFundingRateHistory': true,
68
- 'fetchIndexOHLCV': false,
69
- 'fetchIsolatedBorrowRate': false,
70
- 'fetchIsolatedBorrowRates': false,
71
- 'fetchL3OrderBook': true,
72
- 'fetchLedger': true,
73
- 'fetchLeverage': true,
74
- 'fetchLeverageTiers': false,
75
- 'fetchMarginAdjustmentHistory': false,
76
- 'fetchMarginMode': true,
77
- 'fetchMarketLeverageTiers': true,
78
- 'fetchMarkets': true,
79
- 'fetchMarkOHLCV': false,
80
- 'fetchMarkPrice': true,
81
- 'fetchMyTrades': true,
82
- 'fetchOHLCV': true,
83
- 'fetchOpenOrders': true,
84
- 'fetchOrder': true,
85
- 'fetchOrderBook': true,
86
- 'fetchPosition': true,
87
- 'fetchPositionADLRank': true,
88
- 'fetchPositionHistory': false,
89
- 'fetchPositionMode': false,
90
- 'fetchPositions': true,
91
- 'fetchPositionsADLRank': true,
92
- 'fetchPositionsHistory': true,
93
- 'fetchPremiumIndexOHLCV': false,
94
- 'fetchStatus': true,
95
- 'fetchTicker': true,
96
- 'fetchTickers': true,
97
- 'fetchTime': true,
98
- 'fetchTrades': true,
99
- 'fetchTradingFee': true,
100
- 'fetchTransactionFee': false,
101
- 'fetchWithdrawals': true,
102
- 'setLeverage': false,
103
- 'setMarginMode': true,
104
- 'setPositionMode': true,
105
- 'transfer': true,
106
- 'withdraw': undefined,
107
- },
108
- 'urls': {
109
- 'logo': 'https://user-images.githubusercontent.com/1294454/147508995-9e35030a-d046-43a1-a006-6fabd981b554.jpg',
110
- 'doc': [
111
- 'https://docs.kucoin.com/futures',
112
- 'https://docs.kucoin.com',
113
- ],
114
- 'www': 'https://futures.kucoin.com/',
115
- 'referral': 'https://futures.kucoin.com/?rcode=E5wkqe',
116
- 'api': {
117
- 'public': 'https://openapi-v2.kucoin.com',
118
- 'private': 'https://openapi-v2.kucoin.com',
119
- 'futuresPrivate': 'https://api-futures.kucoin.com',
120
- 'futuresPublic': 'https://api-futures.kucoin.com',
121
- 'webExchange': 'https://futures.kucoin.com/_api/web-front',
122
- },
123
- },
124
- 'requiredCredentials': {
125
- 'apiKey': true,
126
- 'secret': true,
127
- 'password': true,
128
- },
129
- 'api': {
130
- 'futuresPublic': {
131
- 'get': {
132
- 'contracts/active': 1,
133
- 'contracts/{symbol}': 1,
134
- 'contracts/risk-limit/{symbol}': 1,
135
- 'ticker': 1,
136
- 'allTickers': 1,
137
- 'level2/snapshot': 1.33,
138
- 'level2/depth{limit}': 1,
139
- 'level2/message/query': 1,
140
- 'level3/message/query': 1,
141
- 'level3/snapshot': 1,
142
- 'trade/history': 1,
143
- 'interest/query': 1,
144
- 'index/query': 1,
145
- 'mark-price/{symbol}/current': 1,
146
- 'premium/query': 1,
147
- 'funding-rate/{symbol}/current': 1,
148
- 'timestamp': 1,
149
- 'status': 1,
150
- 'kline/query': 1,
151
- },
152
- 'post': {
153
- 'bullet-public': 1,
154
- },
155
- },
156
- 'futuresPrivate': {
157
- 'get': {
158
- 'account-overview': 1.33,
159
- 'transaction-history': 4.44,
160
- 'deposit-address': 1,
161
- 'deposit-list': 1,
162
- 'withdrawals/quotas': 1,
163
- 'withdrawal-list': 1,
164
- 'transfer-list': 1,
165
- 'orders': 1.33,
166
- 'stopOrders': 1,
167
- 'recentDoneOrders': 1,
168
- 'orders/{orderId}': 1,
169
- 'orders/byClientOid': 1,
170
- 'fills': 4.44,
171
- 'recentFills': 4.44,
172
- 'openOrderStatistics': 1,
173
- 'position': 1,
174
- 'positions': 4.44,
175
- 'funding-history': 4.44,
176
- 'sub/api-key': 1,
177
- 'trade-statistics': 1,
178
- 'trade-fees': 1,
179
- 'history-positions': 1,
180
- 'getMaxOpenSize': 1,
181
- 'getCrossUserLeverage': 1,
182
- 'position/getMarginMode': 1,
183
- },
184
- 'post': {
185
- 'withdrawals': 1,
186
- 'transfer-out': 1,
187
- 'transfer-in': 1,
188
- 'orders': 1.33,
189
- 'st-orders': 1.33,
190
- 'orders/test': 1.33,
191
- 'position/margin/auto-deposit-status': 1,
192
- 'position/margin/deposit-margin': 1,
193
- 'position/risk-limit-level/change': 1,
194
- 'bullet-private': 1,
195
- 'sub/api-key': 1,
196
- 'sub/api-key/update': 1,
197
- 'changeCrossUserLeverage': 1,
198
- 'position/changeMarginMode': 1,
199
- 'position/switchPositionMode': 1,
200
- },
201
- 'delete': {
202
- 'withdrawals/{withdrawalId}': 1,
203
- 'cancel/transfer-out': 1,
204
- 'orders/{orderId}': 1,
205
- 'orders': 4.44,
206
- 'stopOrders': 1,
207
- 'sub/api-key': 1,
208
- 'orders/client-order/{clientOid}': 1,
209
- 'orders/multi-cancel': 20,
210
- },
211
- },
212
- 'webExchange': {
213
- 'get': {
214
- 'contract/{symbol}/funding-rates': 1,
215
- },
216
- },
217
- },
218
- 'precisionMode': TICK_SIZE,
219
- 'exceptions': {
220
- 'exact': {
221
- '400': BadRequest,
222
- '401': AuthenticationError,
223
- '403': NotSupported,
224
- '404': NotSupported,
225
- '405': NotSupported,
226
- '415': BadRequest,
227
- '429': RateLimitExceeded,
228
- '500': ExchangeNotAvailable,
229
- '503': ExchangeNotAvailable,
230
- '100001': OrderNotFound,
231
- '100004': BadRequest,
232
- '101030': PermissionDenied,
233
- '200004': InsufficientFunds,
234
- '230003': InsufficientFunds,
235
- '260100': InsufficientFunds,
236
- '300003': InsufficientFunds,
237
- '300012': InvalidOrder,
238
- '400001': AuthenticationError,
239
- '400002': InvalidNonce,
240
- '400003': AuthenticationError,
241
- '400004': AuthenticationError,
242
- '400005': AuthenticationError,
243
- '400006': AuthenticationError,
244
- '400007': AuthenticationError,
245
- '404000': NotSupported,
246
- '400100': BadRequest,
247
- '411100': AccountSuspended,
248
- '500000': ExchangeNotAvailable,
249
- '300009': InvalidOrder,
250
- '330008': InsufficientFunds, // {"msg":"Your current margin and leverage have reached the maximum open limit. Please increase your margin or raise your leverage to open larger positions.","code":"330008"}
251
- },
252
- 'broad': {
253
- 'Position does not exist': OrderNotFound, // { "code":"200000", "msg":"Position does not exist" }
254
- },
255
- },
256
- 'fees': {
257
- 'trading': {
258
- 'tierBased': true,
259
- 'percentage': true,
260
- 'taker': this.parseNumber('0.0006'),
261
- 'maker': this.parseNumber('0.0002'),
262
- 'tiers': {
263
- 'taker': [
264
- [this.parseNumber('0'), this.parseNumber('0.0006')],
265
- [this.parseNumber('50'), this.parseNumber('0.0006')],
266
- [this.parseNumber('200'), this.parseNumber('0.0006')],
267
- [this.parseNumber('500'), this.parseNumber('0.0005')],
268
- [this.parseNumber('1000'), this.parseNumber('0.0004')],
269
- [this.parseNumber('2000'), this.parseNumber('0.0004')],
270
- [this.parseNumber('4000'), this.parseNumber('0.00038')],
271
- [this.parseNumber('8000'), this.parseNumber('0.00035')],
272
- [this.parseNumber('15000'), this.parseNumber('0.00032')],
273
- [this.parseNumber('25000'), this.parseNumber('0.0003')],
274
- [this.parseNumber('40000'), this.parseNumber('0.0003')],
275
- [this.parseNumber('60000'), this.parseNumber('0.0003')],
276
- [this.parseNumber('80000'), this.parseNumber('0.0003')],
277
- ],
278
- 'maker': [
279
- [this.parseNumber('0'), this.parseNumber('0.02')],
280
- [this.parseNumber('50'), this.parseNumber('0.015')],
281
- [this.parseNumber('200'), this.parseNumber('0.01')],
282
- [this.parseNumber('500'), this.parseNumber('0.01')],
283
- [this.parseNumber('1000'), this.parseNumber('0.01')],
284
- [this.parseNumber('2000'), this.parseNumber('0')],
285
- [this.parseNumber('4000'), this.parseNumber('0')],
286
- [this.parseNumber('8000'), this.parseNumber('0')],
287
- [this.parseNumber('15000'), this.parseNumber('-0.003')],
288
- [this.parseNumber('25000'), this.parseNumber('-0.006')],
289
- [this.parseNumber('40000'), this.parseNumber('-0.009')],
290
- [this.parseNumber('60000'), this.parseNumber('-0.012')],
291
- [this.parseNumber('80000'), this.parseNumber('-0.015')],
292
- ],
293
- },
294
- },
295
- 'funding': {
296
- 'tierBased': false,
297
- 'percentage': false,
298
- 'withdraw': {},
299
- 'deposit': {},
300
- },
301
- },
302
- 'commonCurrencies': {
303
- 'HOT': 'HOTNOW',
304
- 'EDGE': 'DADI',
305
- 'WAX': 'WAXP',
306
- 'TRY': 'Trias',
307
- 'VAI': 'VAIOT',
308
- 'XBT': 'BTC',
309
- },
310
- 'timeframes': {
311
- '1m': 1,
312
- '3m': undefined,
313
- '5m': 5,
314
- '15m': 15,
315
- '30m': 30,
316
- '1h': 60,
317
- '2h': 120,
318
- '4h': 240,
319
- '6h': undefined,
320
- '8h': 480,
321
- '12h': 720,
322
- '1d': 1440,
323
- '1w': 10080,
324
23
  },
325
24
  'options': {
326
- 'version': 'v1',
327
- 'symbolSeparator': '-',
328
- 'defaultType': 'swap',
329
- 'code': 'USDT',
330
- 'marginModes': {},
331
- 'marginTypes': {},
332
- // endpoint versions
333
- 'versions': {
334
- 'futuresPrivate': {
335
- 'GET': {
336
- 'getMaxOpenSize': 'v2',
337
- 'getCrossUserLeverage': 'v2',
338
- 'position/getMarginMode': 'v2',
339
- },
340
- 'POST': {
341
- 'transfer-out': 'v2',
342
- 'changeCrossUserLeverage': 'v2',
343
- 'position/changeMarginMode': 'v2',
344
- 'position/switchPositionMode': 'v2',
345
- },
346
- },
347
- 'futuresPublic': {
348
- 'GET': {
349
- 'level3/snapshot': 'v2',
350
- },
351
- },
352
- },
353
- 'networks': {
354
- 'OMNI': 'omni',
355
- 'ERC20': 'eth',
356
- 'TRC20': 'trx',
357
- },
358
- // 'code': 'BTC',
359
- // 'fetchBalance': {
360
- // 'code': 'BTC',
361
- // },
362
- },
363
- 'features': {
364
- 'spot': undefined,
365
- 'forDerivs': {
366
- 'sandbox': false,
367
- 'createOrder': {
368
- 'marginMode': true,
369
- 'triggerPrice': true,
370
- 'triggerPriceType': {
371
- 'last': true,
372
- 'mark': true,
373
- 'index': true,
374
- },
375
- 'triggerDirection': true,
376
- 'stopLossPrice': true,
377
- 'takeProfitPrice': true,
378
- 'attachedStopLossTakeProfit': {
379
- 'triggerPriceType': undefined,
380
- 'price': true,
381
- },
382
- 'timeInForce': {
383
- 'IOC': true,
384
- 'FOK': false,
385
- 'PO': true,
386
- 'GTD': false,
387
- },
388
- 'hedged': false,
389
- 'trailing': false,
390
- 'leverage': true,
391
- 'marketBuyByCost': true,
392
- 'marketBuyRequiresPrice': false,
393
- 'selfTradePrevention': true,
394
- 'iceberg': true,
395
- },
396
- 'createOrders': {
397
- 'max': 20,
398
- },
399
- 'fetchMyTrades': {
400
- 'marginMode': true,
401
- 'limit': 1000,
402
- 'daysBack': undefined,
403
- 'untilDays': 7,
404
- 'symbolRequired': false,
405
- },
406
- 'fetchOrder': {
407
- 'marginMode': false,
408
- 'trigger': false,
409
- 'trailing': false,
410
- 'symbolRequired': false,
411
- },
412
- 'fetchOpenOrders': {
413
- 'marginMode': false,
414
- 'limit': 1000,
415
- 'trigger': true,
416
- 'trailing': false,
417
- 'symbolRequired': false,
418
- },
419
- 'fetchOrders': undefined,
420
- 'fetchClosedOrders': {
421
- 'marginMode': false,
422
- 'limit': 1000,
423
- 'daysBack': undefined,
424
- 'daysBackCanceled': undefined,
425
- 'untilDays': undefined,
426
- 'trigger': true,
427
- 'trailing': false,
428
- 'symbolRequired': false,
429
- },
430
- 'fetchOHLCV': {
431
- 'limit': 500,
432
- },
433
- },
434
- 'swap': {
435
- 'linear': {
436
- 'extends': 'forDerivs',
437
- },
438
- 'inverse': {
439
- 'extends': 'forDerivs',
440
- },
441
- },
442
- 'future': {
443
- 'linear': {
444
- 'extends': 'forDerivs',
445
- },
446
- 'inverse': {
447
- 'extends': 'forDerivs',
448
- },
25
+ 'fetchMarkets': {
26
+ 'types': ['swap', 'future', 'contract'],
27
+ 'fetchTickersFees': false,
449
28
  },
29
+ 'defaultType': 'swap',
30
+ 'defaultAccountType': 'contract',
31
+ 'uta': false,
450
32
  },
451
33
  });
452
34
  }
453
- /**
454
- * @method
455
- * @name kucoinfutures#fetchStatus
456
- * @description the latest known information on the availability of the exchange API
457
- * @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-service-status
458
- * @param {object} [params] extra parameters specific to the exchange API endpoint
459
- * @returns {object} a [status structure]{@link https://docs.ccxt.com/?id=exchange-status-structure}
460
- */
461
- async fetchStatus(params = {}) {
462
- const response = await this.futuresPublicGetStatus(params);
463
- //
464
- // {
465
- // "code":"200000",
466
- // "data":{
467
- // "status": "open", // open, close, cancelonly
468
- // "msg": "upgrade match engine" // remark for operation when status not open
469
- // }
470
- // }
471
- //
472
- const data = this.safeDict(response, 'data', {});
473
- const status = this.safeString(data, 'status');
474
- return {
475
- 'status': (status === 'open') ? 'ok' : 'maintenance',
476
- 'updated': undefined,
477
- 'eta': undefined,
478
- 'url': undefined,
479
- 'info': response,
480
- };
481
- }
482
- /**
483
- * @method
484
- * @name kucoinfutures#fetchMarkets
485
- * @description retrieves data on all markets for kucoinfutures
486
- * @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-symbols-list
487
- * @param {object} [params] extra parameters specific to the exchange api endpoint
488
- * @returns {object[]} an array of objects representing market data
489
- */
490
- async fetchMarkets(params = {}) {
491
- const response = await this.futuresPublicGetContractsActive(params);
492
- //
493
- // {
494
- // "code": "200000",
495
- // "data": {
496
- // "symbol": "ETHUSDTM",
497
- // "rootSymbol": "USDT",
498
- // "type": "FFWCSX",
499
- // "firstOpenDate": 1591086000000,
500
- // "expireDate": null,
501
- // "settleDate": null,
502
- // "baseCurrency": "ETH",
503
- // "quoteCurrency": "USDT",
504
- // "settleCurrency": "USDT",
505
- // "maxOrderQty": 1000000,
506
- // "maxPrice": 1000000.0000000000,
507
- // "lotSize": 1,
508
- // "tickSize": 0.05,
509
- // "indexPriceTickSize": 0.01,
510
- // "multiplier": 0.01,
511
- // "initialMargin": 0.01,
512
- // "maintainMargin": 0.005,
513
- // "maxRiskLimit": 1000000,
514
- // "minRiskLimit": 1000000,
515
- // "riskStep": 500000,
516
- // "makerFeeRate": 0.00020,
517
- // "takerFeeRate": 0.00060,
518
- // "takerFixFee": 0.0000000000,
519
- // "makerFixFee": 0.0000000000,
520
- // "settlementFee": null,
521
- // "isDeleverage": true,
522
- // "isQuanto": true,
523
- // "isInverse": false,
524
- // "markMethod": "FairPrice",
525
- // "fairMethod": "FundingRate",
526
- // "fundingBaseSymbol": ".ETHINT8H",
527
- // "fundingQuoteSymbol": ".USDTINT8H",
528
- // "fundingRateSymbol": ".ETHUSDTMFPI8H",
529
- // "indexSymbol": ".KETHUSDT",
530
- // "settlementSymbol": "",
531
- // "status": "Open",
532
- // "fundingFeeRate": 0.000535,
533
- // "predictedFundingFeeRate": 0.002197,
534
- // "openInterest": "8724443",
535
- // "turnoverOf24h": 341156641.03354263,
536
- // "volumeOf24h": 74833.54000000,
537
- // "markPrice": 4534.07,
538
- // "indexPrice":4531.92,
539
- // "lastTradePrice": 4545.4500000000,
540
- // "nextFundingRateTime": 25481884,
541
- // "maxLeverage": 100,
542
- // "sourceExchanges": [ "huobi", "Okex", "Binance", "Kucoin", "Poloniex", "Hitbtc" ],
543
- // "premiumsSymbol1M": ".ETHUSDTMPI",
544
- // "premiumsSymbol8H": ".ETHUSDTMPI8H",
545
- // "fundingBaseSymbol1M": ".ETHINT",
546
- // "fundingQuoteSymbol1M": ".USDTINT",
547
- // "lowPrice": 4456.90,
548
- // "highPrice": 4674.25,
549
- // "priceChgPct": 0.0046,
550
- // "priceChg": 21.15
551
- // }
552
- // }
553
- //
554
- const result = [];
555
- const data = this.safeList(response, 'data', []);
556
- for (let i = 0; i < data.length; i++) {
557
- const market = data[i];
558
- const id = this.safeString(market, 'symbol');
559
- const expiry = this.safeInteger(market, 'expireDate');
560
- const future = this.safeString(market, 'nextFundingRateTime') === undefined;
561
- const swap = !future;
562
- const baseId = this.safeString(market, 'baseCurrency');
563
- const quoteId = this.safeString(market, 'quoteCurrency');
564
- const settleId = this.safeString(market, 'settleCurrency');
565
- const base = this.safeCurrencyCode(baseId);
566
- const quote = this.safeCurrencyCode(quoteId);
567
- const settle = this.safeCurrencyCode(settleId);
568
- let symbol = base + '/' + quote + ':' + settle;
569
- let type = 'swap';
570
- if (future) {
571
- symbol = symbol + '-' + this.yymmdd(expiry, '');
572
- type = 'future';
573
- }
574
- const inverse = this.safeValue(market, 'isInverse');
575
- const status = this.safeString(market, 'status');
576
- const multiplier = this.safeString(market, 'multiplier');
577
- const tickSize = this.safeNumber(market, 'tickSize');
578
- const lotSize = this.safeNumber(market, 'lotSize');
579
- let limitAmountMin = lotSize;
580
- if (limitAmountMin === undefined) {
581
- limitAmountMin = this.safeNumber(market, 'baseMinSize');
582
- }
583
- let limitAmountMax = this.safeNumber(market, 'maxOrderQty');
584
- if (limitAmountMax === undefined) {
585
- limitAmountMax = this.safeNumber(market, 'baseMaxSize');
586
- }
587
- let limitPriceMax = this.safeNumber(market, 'maxPrice');
588
- if (limitPriceMax === undefined) {
589
- const baseMinSizeString = this.safeString(market, 'baseMinSize');
590
- const quoteMaxSizeString = this.safeString(market, 'quoteMaxSize');
591
- limitPriceMax = this.parseNumber(Precise.stringDiv(quoteMaxSizeString, baseMinSizeString));
592
- }
593
- result.push({
594
- 'id': id,
595
- 'symbol': symbol,
596
- 'base': base,
597
- 'quote': quote,
598
- 'settle': settle,
599
- 'baseId': baseId,
600
- 'quoteId': quoteId,
601
- 'settleId': settleId,
602
- 'type': type,
603
- 'spot': false,
604
- 'margin': false,
605
- 'swap': swap,
606
- 'future': future,
607
- 'option': false,
608
- 'active': (status === 'Open'),
609
- 'contract': true,
610
- 'linear': !inverse,
611
- 'inverse': inverse,
612
- 'taker': this.safeNumber(market, 'takerFeeRate'),
613
- 'maker': this.safeNumber(market, 'makerFeeRate'),
614
- 'contractSize': this.parseNumber(Precise.stringAbs(multiplier)),
615
- 'expiry': expiry,
616
- 'expiryDatetime': this.iso8601(expiry),
617
- 'strike': undefined,
618
- 'optionType': undefined,
619
- 'precision': {
620
- 'amount': lotSize,
621
- 'price': tickSize,
622
- },
623
- 'limits': {
624
- 'leverage': {
625
- 'min': this.parseNumber('1'),
626
- 'max': this.safeNumber(market, 'maxLeverage'),
627
- },
628
- 'amount': {
629
- 'min': limitAmountMin,
630
- 'max': limitAmountMax,
631
- },
632
- 'price': {
633
- 'min': tickSize,
634
- 'max': limitPriceMax,
635
- },
636
- 'cost': {
637
- 'min': this.safeNumber(market, 'quoteMinSize'),
638
- 'max': this.safeNumber(market, 'quoteMaxSize'),
639
- },
640
- },
641
- 'created': this.safeInteger(market, 'firstOpenDate'),
642
- 'info': market,
643
- });
644
- }
645
- return result;
646
- }
647
- /**
648
- * @method
649
- * @name kucoinfutures#fetchTime
650
- * @description fetches the current integer timestamp in milliseconds from the exchange server
651
- * @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-server-time
652
- * @param {object} [params] extra parameters specific to the exchange API endpoint
653
- * @returns {int} the current integer timestamp in milliseconds from the exchange server
654
- */
655
- async fetchTime(params = {}) {
656
- const response = await this.futuresPublicGetTimestamp(params);
657
- //
658
- // {
659
- // "code": "200000",
660
- // "data": 1637385119302,
661
- // }
662
- //
663
- return this.safeInteger(response, 'data');
664
- }
665
- /**
666
- * @method
667
- * @name kucoinfutures#fetchOHLCV
668
- * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
669
- * @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-klines
670
- * @param {string} symbol unified symbol of the market to fetch OHLCV data for
671
- * @param {string} timeframe the length of time each candle represents
672
- * @param {int} [since] timestamp in ms of the earliest candle to fetch
673
- * @param {int} [limit] the maximum amount of candles to fetch
674
- * @param {object} [params] extra parameters specific to the exchange API endpoint
675
- * @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)
676
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
677
- */
678
- async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
679
- await this.loadMarkets();
680
- let paginate = false;
681
- [paginate, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'paginate');
682
- if (paginate) {
683
- return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 200);
684
- }
685
- const market = this.market(symbol);
686
- const marketId = market['id'];
687
- const parsedTimeframe = this.safeInteger(this.timeframes, timeframe);
688
- const request = {
689
- 'symbol': marketId,
690
- };
691
- if (parsedTimeframe !== undefined) {
692
- request['granularity'] = parsedTimeframe;
693
- }
694
- else {
695
- request['granularity'] = timeframe;
696
- }
697
- const duration = this.parseTimeframe(timeframe) * 1000;
698
- let endAt = this.milliseconds();
699
- if (since !== undefined) {
700
- request['from'] = since;
701
- if (limit === undefined) {
702
- limit = this.safeInteger(this.options, 'fetchOHLCVLimit', 200);
703
- }
704
- endAt = this.sum(since, limit * duration);
705
- }
706
- else if (limit !== undefined) {
707
- since = endAt - limit * duration;
708
- request['from'] = since;
709
- }
710
- request['to'] = endAt;
711
- const response = await this.futuresPublicGetKlineQuery(this.extend(request, params));
712
- //
713
- // {
714
- // "code": "200000",
715
- // "data": [
716
- // [1636459200000, 4779.3, 4792.1, 4768.7, 4770.3, 78051],
717
- // [1636460100000, 4770.25, 4778.55, 4757.55, 4777.25, 80164],
718
- // [1636461000000, 4777.25, 4791.45, 4774.5, 4791.3, 51555]
719
- // ]
720
- // }
721
- //
722
- const data = this.safeList(response, 'data', []);
723
- return this.parseOHLCVs(data, market, timeframe, since, limit);
724
- }
725
- parseOHLCV(ohlcv, market = undefined) {
726
- //
727
- // [
728
- // "1545904980000", // Start time of the candle cycle
729
- // "0.058", // opening price
730
- // "0.049", // closing price
731
- // "0.058", // highest price
732
- // "0.049", // lowest price
733
- // "0.018", // base volume
734
- // "0.000945", // quote volume
735
- // ]
736
- //
737
- return [
738
- this.safeInteger(ohlcv, 0),
739
- this.safeNumber(ohlcv, 1),
740
- this.safeNumber(ohlcv, 2),
741
- this.safeNumber(ohlcv, 3),
742
- this.safeNumber(ohlcv, 4),
743
- this.safeNumber(ohlcv, 5),
744
- ];
745
- }
746
- /**
747
- * @method
748
- * @name kucoinfutures#fetchDepositAddress
749
- * @description fetch the deposit address for a currency associated with this account
750
- * @see https://www.kucoin.com/docs/rest/funding/deposit/get-deposit-address
751
- * @param {string} code unified currency code
752
- * @param {object} [params] extra parameters specific to the exchange API endpoint
753
- * @returns {object} an [address structure]{@link https://docs.ccxt.com/?id=address-structure}
754
- */
755
- async fetchDepositAddress(code, params = {}) {
756
- await this.loadMarkets();
757
- const currency = this.currency(code);
758
- const currencyId = currency['id'];
759
- const request = {
760
- 'currency': currencyId, // Currency,including XBT,USDT
761
- };
762
- const response = await this.futuresPrivateGetDepositAddress(this.extend(request, params));
763
- //
764
- // {
765
- // "code": "200000",
766
- // "data": {
767
- // "address": "0x78d3ad1c0aa1bf068e19c94a2d7b16c9c0fcd8b1",//Deposit address
768
- // "memo": null//Address tag. If the returned value is null, it means that the requested token has no memo. If you are to transfer funds from another platform to KuCoin Futures and if the token to be //transferred has memo(tag), you need to fill in the memo to ensure the transferred funds will be sent //to the address you specified.
769
- // }
770
- // }
771
- //
772
- const data = this.safeDict(response, 'data', {});
773
- const address = this.safeString(data, 'address');
774
- if (currencyId !== 'NIM') {
775
- // contains spaces
776
- this.checkAddress(address);
777
- }
778
- return {
779
- 'info': response,
780
- 'currency': currencyId,
781
- 'network': this.safeString(data, 'chain'),
782
- 'address': address,
783
- 'tag': this.safeString(data, 'memo'),
784
- };
785
- }
786
- /**
787
- * @method
788
- * @name kucoinfutures#fetchOrderBook
789
- * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
790
- * @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-part-order-book-level-2
791
- * @param {string} symbol unified symbol of the market to fetch the order book for
792
- * @param {int} [limit] the maximum amount of order book entries to return
793
- * @param {object} [params] extra parameters specific to the exchange API endpoint
794
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure} indexed by market symbols
795
- */
796
- async fetchOrderBook(symbol, limit = undefined, params = {}) {
797
- await this.loadMarkets();
798
- const level = this.safeNumber(params, 'level');
799
- if (level !== 2 && level !== undefined) {
800
- throw new BadRequest(this.id + ' fetchOrderBook() can only return level 2');
801
- }
802
- const market = this.market(symbol);
803
- const request = {
804
- 'symbol': market['id'],
805
- };
806
- if (limit !== undefined) {
807
- if ((limit === 20) || (limit === 100)) {
808
- request['limit'] = limit;
809
- }
810
- else {
811
- throw new BadRequest(this.id + ' fetchOrderBook() limit argument must be 20 or 100');
812
- }
813
- }
814
- else {
815
- request['limit'] = 20;
816
- }
817
- const response = await this.futuresPublicGetLevel2DepthLimit(this.extend(request, params));
818
- //
819
- // {
820
- // "code": "200000",
821
- // "data": {
822
- // "symbol": "XBTUSDM", //Symbol
823
- // "sequence": 100, //Ticker sequence number
824
- // "asks": [
825
- // ["5000.0", 1000], //Price, quantity
826
- // ["6000.0", 1983] //Price, quantity
827
- // ],
828
- // "bids": [
829
- // ["3200.0", 800], //Price, quantity
830
- // ["3100.0", 100] //Price, quantity
831
- // ],
832
- // "ts": 1604643655040584408 // timestamp
833
- // }
834
- // }
835
- //
836
- const data = this.safeDict(response, 'data', {});
837
- const timestamp = this.parseToInt(this.safeInteger(data, 'ts') / 1000000);
838
- const orderbook = this.parseOrderBook(data, market['symbol'], timestamp, 'bids', 'asks', 0, 1);
839
- orderbook['nonce'] = this.safeInteger(data, 'sequence');
840
- return orderbook;
841
- }
842
- /**
843
- * @method
844
- * @name kucoinfutures#fetchTicker
845
- * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
846
- * @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-ticker
847
- * @param {string} symbol unified symbol of the market to fetch the ticker for
848
- * @param {object} [params] extra parameters specific to the exchange API endpoint
849
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
850
- */
851
- async fetchTicker(symbol, params = {}) {
852
- await this.loadMarkets();
853
- const market = this.market(symbol);
854
- const request = {
855
- 'symbol': market['id'],
856
- };
857
- const response = await this.futuresPublicGetTicker(this.extend(request, params));
858
- //
859
- // {
860
- // "code": "200000",
861
- // "data": {
862
- // "sequence": 1638444978558,
863
- // "symbol": "ETHUSDTM",
864
- // "side": "sell",
865
- // "size": 4,
866
- // "price": "4229.35",
867
- // "bestBidSize": 2160,
868
- // "bestBidPrice": "4229.0",
869
- // "bestAskPrice": "4229.05",
870
- // "tradeId": "61aaa8b777a0c43055fe4851",
871
- // "ts": 1638574296209786785,
872
- // "bestAskSize": 36,
873
- // }
874
- // }
875
- //
876
- return this.parseTicker(response['data'], market);
877
- }
878
- /**
879
- * @method
880
- * @name kucoinfutures#fetchMarkPrice
881
- * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
882
- * @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-current-mark-price
883
- * @param {string} symbol unified symbol of the market to fetch the ticker for
884
- * @param {object} [params] extra parameters specific to the exchange API endpoint
885
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
886
- */
887
- async fetchMarkPrice(symbol, params = {}) {
888
- await this.loadMarkets();
889
- const market = this.market(symbol);
890
- const request = {
891
- 'symbol': market['id'],
892
- };
893
- const response = await this.futuresPublicGetMarkPriceSymbolCurrent(this.extend(request, params));
894
- //
895
- return this.parseTicker(response['data'], market);
896
- }
897
- /**
898
- * @method
899
- * @name kucoinfutures#fetchTickers
900
- * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
901
- * @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-symbols-list
902
- * @param {string[]} [symbols] unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
903
- * @param {object} [params] extra parameters specific to the exchange API endpoint
904
- * @param {string} [params.method] the method to use, futuresPublicGetAllTickers or futuresPublicGetContractsActive
905
- * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
906
- */
907
- async fetchTickers(symbols = undefined, params = {}) {
908
- await this.loadMarkets();
909
- symbols = this.marketSymbols(symbols);
910
- let method = undefined;
911
- [method, params] = this.handleOptionAndParams(params, 'fetchTickers', 'method', 'futuresPublicGetContractsActive');
912
- let response = undefined;
913
- if (method === 'futuresPublicGetAllTickers') {
914
- response = await this.futuresPublicGetAllTickers(params);
915
- }
916
- else {
917
- response = await this.futuresPublicGetContractsActive(params);
918
- }
919
- //
920
- // {
921
- // "code": "200000",
922
- // "data": {
923
- // "symbol": "ETHUSDTM",
924
- // "rootSymbol": "USDT",
925
- // "type": "FFWCSX",
926
- // "firstOpenDate": 1591086000000,
927
- // "expireDate": null,
928
- // "settleDate": null,
929
- // "baseCurrency": "ETH",
930
- // "quoteCurrency": "USDT",
931
- // "settleCurrency": "USDT",
932
- // "maxOrderQty": 1000000,
933
- // "maxPrice": 1000000.0000000000,
934
- // "lotSize": 1,
935
- // "tickSize": 0.05,
936
- // "indexPriceTickSize": 0.01,
937
- // "multiplier": 0.01,
938
- // "initialMargin": 0.01,
939
- // "maintainMargin": 0.005,
940
- // "maxRiskLimit": 1000000,
941
- // "minRiskLimit": 1000000,
942
- // "riskStep": 500000,
943
- // "makerFeeRate": 0.00020,
944
- // "takerFeeRate": 0.00060,
945
- // "takerFixFee": 0.0000000000,
946
- // "makerFixFee": 0.0000000000,
947
- // "settlementFee": null,
948
- // "isDeleverage": true,
949
- // "isQuanto": true,
950
- // "isInverse": false,
951
- // "markMethod": "FairPrice",
952
- // "fairMethod": "FundingRate",
953
- // "fundingBaseSymbol": ".ETHINT8H",
954
- // "fundingQuoteSymbol": ".USDTINT8H",
955
- // "fundingRateSymbol": ".ETHUSDTMFPI8H",
956
- // "indexSymbol": ".KETHUSDT",
957
- // "settlementSymbol": "",
958
- // "status": "Open",
959
- // "fundingFeeRate": 0.000535,
960
- // "predictedFundingFeeRate": 0.002197,
961
- // "openInterest": "8724443",
962
- // "turnoverOf24h": 341156641.03354263,
963
- // "volumeOf24h": 74833.54000000,
964
- // "markPrice": 4534.07,
965
- // "indexPrice":4531.92,
966
- // "lastTradePrice": 4545.4500000000,
967
- // "nextFundingRateTime": 25481884,
968
- // "maxLeverage": 100,
969
- // "sourceExchanges": [ "huobi", "Okex", "Binance", "Kucoin", "Poloniex", "Hitbtc" ],
970
- // "premiumsSymbol1M": ".ETHUSDTMPI",
971
- // "premiumsSymbol8H": ".ETHUSDTMPI8H",
972
- // "fundingBaseSymbol1M": ".ETHINT",
973
- // "fundingQuoteSymbol1M": ".USDTINT",
974
- // "lowPrice": 4456.90,
975
- // "highPrice": 4674.25,
976
- // "priceChgPct": 0.0046,
977
- // "priceChg": 21.15
978
- // }
979
- // }
980
- //
981
- const data = this.safeList(response, 'data');
982
- const tickers = this.parseTickers(data, symbols);
983
- return this.filterByArrayTickers(tickers, 'symbol', symbols);
984
- }
985
- parseTicker(ticker, market = undefined) {
986
- //
987
- // {
988
- // "symbol": "LTCUSDTM",
989
- // "granularity": 1000,
990
- // "timePoint": 1727967339000,
991
- // "value": 62.37, mark price
992
- // "indexPrice": 62.37
993
- // }
994
- //
995
- // {
996
- // "code": "200000",
997
- // "data": {
998
- // "sequence": 1629930362547,
999
- // "symbol": "ETHUSDTM",
1000
- // "side": "buy",
1001
- // "size": 130,
1002
- // "price": "4724.7",
1003
- // "bestBidSize": 5,
1004
- // "bestBidPrice": "4724.6",
1005
- // "bestAskPrice": "4724.65",
1006
- // "tradeId": "618d2a5a77a0c4431d2335f4",
1007
- // "ts": 1636641371963227600,
1008
- // "bestAskSize": 1789
1009
- // }
1010
- // }
1011
- //
1012
- // from fetchTickers
1013
- //
1014
- // {
1015
- // symbol: "XBTUSDTM",
1016
- // rootSymbol: "USDT",
1017
- // type: "FFWCSX",
1018
- // firstOpenDate: 1585555200000,
1019
- // expireDate: null,
1020
- // settleDate: null,
1021
- // baseCurrency: "XBT",
1022
- // quoteCurrency: "USDT",
1023
- // settleCurrency: "USDT",
1024
- // maxOrderQty: 1000000,
1025
- // maxPrice: 1000000,
1026
- // lotSize: 1,
1027
- // tickSize: 0.1,
1028
- // indexPriceTickSize: 0.01,
1029
- // multiplier: 0.001,
1030
- // initialMargin: 0.008,
1031
- // maintainMargin: 0.004,
1032
- // maxRiskLimit: 100000,
1033
- // minRiskLimit: 100000,
1034
- // riskStep: 50000,
1035
- // makerFeeRate: 0.0002,
1036
- // takerFeeRate: 0.0006,
1037
- // takerFixFee: 0,
1038
- // makerFixFee: 0,
1039
- // settlementFee: null,
1040
- // isDeleverage: true,
1041
- // isQuanto: true,
1042
- // isInverse: false,
1043
- // markMethod: "FairPrice",
1044
- // fairMethod: "FundingRate",
1045
- // fundingBaseSymbol: ".XBTINT8H",
1046
- // fundingQuoteSymbol: ".USDTINT8H",
1047
- // fundingRateSymbol: ".XBTUSDTMFPI8H",
1048
- // indexSymbol: ".KXBTUSDT",
1049
- // settlementSymbol: "",
1050
- // status: "Open",
1051
- // fundingFeeRate: 0.000297,
1052
- // predictedFundingFeeRate: 0.000327,
1053
- // fundingRateGranularity: 28800000,
1054
- // openInterest: "8033200",
1055
- // turnoverOf24h: 659795309.2524643,
1056
- // volumeOf24h: 9998.54,
1057
- // markPrice: 67193.51,
1058
- // indexPrice: 67184.81,
1059
- // lastTradePrice: 67191.8,
1060
- // nextFundingRateTime: 20022985,
1061
- // maxLeverage: 125,
1062
- // premiumsSymbol1M: ".XBTUSDTMPI",
1063
- // premiumsSymbol8H: ".XBTUSDTMPI8H",
1064
- // fundingBaseSymbol1M: ".XBTINT",
1065
- // fundingQuoteSymbol1M: ".USDTINT",
1066
- // lowPrice: 64041.6,
1067
- // highPrice: 67737.3,
1068
- // priceChgPct: 0.0447,
1069
- // priceChg: 2878.7
1070
- // }
1071
- //
1072
- const marketId = this.safeString(ticker, 'symbol');
1073
- market = this.safeMarket(marketId, market, '-');
1074
- const last = this.safeString2(ticker, 'price', 'lastTradePrice');
1075
- const timestamp = this.safeIntegerProduct(ticker, 'ts', 0.000001);
1076
- return this.safeTicker({
1077
- 'symbol': market['symbol'],
1078
- 'timestamp': timestamp,
1079
- 'datetime': this.iso8601(timestamp),
1080
- 'high': this.safeString(ticker, 'highPrice'),
1081
- 'low': this.safeString(ticker, 'lowPrice'),
1082
- 'bid': this.safeString(ticker, 'bestBidPrice'),
1083
- 'bidVolume': this.safeString(ticker, 'bestBidSize'),
1084
- 'ask': this.safeString(ticker, 'bestAskPrice'),
1085
- 'askVolume': this.safeString(ticker, 'bestAskSize'),
1086
- 'vwap': undefined,
1087
- 'open': undefined,
1088
- 'close': last,
1089
- 'last': last,
1090
- 'previousClose': undefined,
1091
- 'change': this.safeString(ticker, 'priceChg'),
1092
- 'percentage': this.safeString(ticker, 'priceChgPct'),
1093
- 'average': undefined,
1094
- 'baseVolume': this.safeString(ticker, 'volumeOf24h'),
1095
- 'quoteVolume': this.safeString(ticker, 'turnoverOf24h'),
1096
- 'markPrice': this.safeString2(ticker, 'markPrice', 'value'),
1097
- 'indexPrice': this.safeString(ticker, 'indexPrice'),
1098
- 'info': ticker,
1099
- }, market);
1100
- }
1101
35
  /**
1102
36
  * @method
1103
37
  * @name kucoinfutures#fetchBidsAsks
@@ -1112,1446 +46,10 @@ export default class kucoinfutures extends kucoin {
1112
46
  };
1113
47
  return await this.fetchTickers(symbols, this.extend(request, params));
1114
48
  }
1115
- /**
1116
- * @method
1117
- * @name kucoinfutures#fetchFundingHistory
1118
- * @description fetch the history of funding payments paid and received on this account
1119
- * @see https://www.kucoin.com/docs/rest/futures-trading/funding-fees/get-funding-history
1120
- * @param {string} symbol unified market symbol
1121
- * @param {int} [since] the earliest time in ms to fetch funding history for
1122
- * @param {int} [limit] the maximum number of funding history structures to retrieve
1123
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1124
- * @returns {object} a [funding history structure]{@link https://docs.ccxt.com/?id=funding-history-structure}
1125
- */
1126
- async fetchFundingHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1127
- if (symbol === undefined) {
1128
- throw new ArgumentsRequired(this.id + ' fetchFundingHistory() requires a symbol argument');
1129
- }
1130
- await this.loadMarkets();
1131
- const market = this.market(symbol);
1132
- const request = {
1133
- 'symbol': market['id'],
1134
- };
1135
- if (since !== undefined) {
1136
- request['startAt'] = since;
1137
- }
1138
- if (limit !== undefined) {
1139
- // * Since is ignored if limit is defined
1140
- request['maxCount'] = limit;
1141
- }
1142
- const response = await this.futuresPrivateGetFundingHistory(this.extend(request, params));
1143
- //
1144
- // {
1145
- // "code": "200000",
1146
- // "data": {
1147
- // "dataList": [
1148
- // {
1149
- // "id": 239471298749817,
1150
- // "symbol": "ETHUSDTM",
1151
- // "timePoint": 1638532800000,
1152
- // "fundingRate": 0.000100,
1153
- // "markPrice": 4612.8300000000,
1154
- // "positionQty": 12,
1155
- // "positionCost": 553.5396000000,
1156
- // "funding": -0.0553539600,
1157
- // "settleCurrency": "USDT"
1158
- // },
1159
- // ...
1160
- // ],
1161
- // "hasMore": true
1162
- // }
1163
- // }
1164
- //
1165
- const data = this.safeValue(response, 'data');
1166
- const dataList = this.safeList(data, 'dataList', []);
1167
- const fees = [];
1168
- for (let i = 0; i < dataList.length; i++) {
1169
- const listItem = dataList[i];
1170
- const timestamp = this.safeInteger(listItem, 'timePoint');
1171
- fees.push({
1172
- 'info': listItem,
1173
- 'symbol': symbol,
1174
- 'code': this.safeCurrencyCode(this.safeString(listItem, 'settleCurrency')),
1175
- 'timestamp': timestamp,
1176
- 'datetime': this.iso8601(timestamp),
1177
- 'id': this.safeNumber(listItem, 'id'),
1178
- 'amount': this.safeNumber(listItem, 'funding'),
1179
- 'fundingRate': this.safeNumber(listItem, 'fundingRate'),
1180
- 'markPrice': this.safeNumber(listItem, 'markPrice'),
1181
- 'positionQty': this.safeNumber(listItem, 'positionQty'),
1182
- 'positionCost': this.safeNumber(listItem, 'positionCost'),
1183
- });
1184
- }
1185
- return fees;
1186
- }
1187
- /**
1188
- * @method
1189
- * @name kucoinfutures#fetchPosition
1190
- * @see https://docs.kucoin.com/futures/#get-position-details
1191
- * @description fetch data on an open position
1192
- * @param {string} symbol unified market symbol of the market the position is held in
1193
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1194
- * @returns {object} a [position structure]{@link https://docs.ccxt.com/?id=position-structure}
1195
- */
1196
- async fetchPosition(symbol, params = {}) {
1197
- await this.loadMarkets();
1198
- const market = this.market(symbol);
1199
- const request = {
1200
- 'symbol': market['id'],
1201
- };
1202
- const response = await this.futuresPrivateGetPosition(this.extend(request, params));
1203
- //
1204
- // {
1205
- // "code": "200000",
1206
- // "data": {
1207
- // "id": "6505ee6eaff4070001f651c4",
1208
- // "symbol": "XBTUSDTM",
1209
- // "autoDeposit": false,
1210
- // "maintMarginReq": 0,
1211
- // "riskLimit": 200,
1212
- // "realLeverage": 0.0,
1213
- // "crossMode": false,
1214
- // "delevPercentage": 0.0,
1215
- // "currentTimestamp": 1694887534594,
1216
- // "currentQty": 0,
1217
- // "currentCost": 0.0,
1218
- // "currentComm": 0.0,
1219
- // "unrealisedCost": 0.0,
1220
- // "realisedGrossCost": 0.0,
1221
- // "realisedCost": 0.0,
1222
- // "isOpen": false,
1223
- // "markPrice": 26611.71,
1224
- // "markValue": 0.0,
1225
- // "posCost": 0.0,
1226
- // "posCross": 0,
1227
- // "posInit": 0.0,
1228
- // "posComm": 0.0,
1229
- // "posLoss": 0.0,
1230
- // "posMargin": 0.0,
1231
- // "posMaint": 0.0,
1232
- // "maintMargin": 0.0,
1233
- // "realisedGrossPnl": 0.0,
1234
- // "realisedPnl": 0.0,
1235
- // "unrealisedPnl": 0.0,
1236
- // "unrealisedPnlPcnt": 0,
1237
- // "unrealisedRoePcnt": 0,
1238
- // "avgEntryPrice": 0.0,
1239
- // "liquidationPrice": 0.0,
1240
- // "bankruptPrice": 0.0,
1241
- // "settleCurrency": "USDT",
1242
- // "maintainMargin": 0,
1243
- // "riskLimitLevel": 1
1244
- // }
1245
- // }
1246
- //
1247
- const data = this.safeDict(response, 'data', {});
1248
- return this.parsePosition(data, market);
1249
- }
1250
- /**
1251
- * @method
1252
- * @name kucoinfutures#fetchPositions
1253
- * @description fetch all open positions
1254
- * @see https://docs.kucoin.com/futures/#get-position-list
1255
- * @param {string[]|undefined} symbols list of unified market symbols
1256
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1257
- * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/?id=position-structure}
1258
- */
1259
- async fetchPositions(symbols = undefined, params = {}) {
1260
- await this.loadMarkets();
1261
- const response = await this.futuresPrivateGetPositions(params);
1262
- //
1263
- // {
1264
- // "code": "200000",
1265
- // "data": [
1266
- // {
1267
- // "id": "615ba79f83a3410001cde321",
1268
- // "symbol": "ETHUSDTM",
1269
- // "autoDeposit": false,
1270
- // "maintMarginReq": 0.005,
1271
- // "riskLimit": 1000000,
1272
- // "realLeverage": 18.61,
1273
- // "crossMode": false,
1274
- // "delevPercentage": 0.86,
1275
- // "openingTimestamp": 1638563515618,
1276
- // "currentTimestamp": 1638576872774,
1277
- // "currentQty": 2,
1278
- // "currentCost": 83.64200000,
1279
- // "currentComm": 0.05018520,
1280
- // "unrealisedCost": 83.64200000,
1281
- // "realisedGrossCost": 0.00000000,
1282
- // "realisedCost": 0.05018520,
1283
- // "isOpen": true,
1284
- // "markPrice": 4225.01,
1285
- // "markValue": 84.50020000,
1286
- // "posCost": 83.64200000,
1287
- // "posCross": 0.0000000000,
1288
- // "posInit": 3.63660870,
1289
- // "posComm": 0.05236717,
1290
- // "posLoss": 0.00000000,
1291
- // "posMargin": 3.68897586,
1292
- // "posMaint": 0.50637594,
1293
- // "maintMargin": 4.54717586,
1294
- // "realisedGrossPnl": 0.00000000,
1295
- // "realisedPnl": -0.05018520,
1296
- // "unrealisedPnl": 0.85820000,
1297
- // "unrealisedPnlPcnt": 0.0103,
1298
- // "unrealisedRoePcnt": 0.2360,
1299
- // "avgEntryPrice": 4182.10,
1300
- // "liquidationPrice": 4023.00,
1301
- // "bankruptPrice": 4000.25,
1302
- // "settleCurrency": "USDT",
1303
- // "isInverse": false
1304
- // }
1305
- // ]
1306
- // }
1307
- //
1308
- const data = this.safeList(response, 'data');
1309
- return this.parsePositions(data, symbols);
1310
- }
1311
- /**
1312
- * @method
1313
- * @name kucoinfutures#fetchPositionsHistory
1314
- * @description fetches historical positions
1315
- * @see https://www.kucoin.com/docs/rest/futures-trading/positions/get-positions-history
1316
- * @param {string[]} [symbols] list of unified market symbols
1317
- * @param {int} [since] the earliest time in ms to fetch position history for
1318
- * @param {int} [limit] the maximum number of entries to retrieve
1319
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1320
- * @param {int} [params.until] closing end time
1321
- * @param {int} [params.pageId] page id
1322
- * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/?id=position-structure}
1323
- */
1324
- async fetchPositionsHistory(symbols = undefined, since = undefined, limit = undefined, params = {}) {
1325
- await this.loadMarkets();
1326
- if (limit === undefined) {
1327
- limit = 200;
1328
- }
1329
- const request = {
1330
- 'limit': limit,
1331
- };
1332
- if (since !== undefined) {
1333
- request['from'] = since;
1334
- }
1335
- const until = this.safeInteger(params, 'until');
1336
- if (until !== undefined) {
1337
- params = this.omit(params, 'until');
1338
- request['to'] = until;
1339
- }
1340
- const response = await this.futuresPrivateGetHistoryPositions(this.extend(request, params));
1341
- //
1342
- // {
1343
- // "success": true,
1344
- // "code": "200",
1345
- // "msg": "success",
1346
- // "retry": false,
1347
- // "data": {
1348
- // "currentPage": 1,
1349
- // "pageSize": 10,
1350
- // "totalNum": 25,
1351
- // "totalPage": 3,
1352
- // "items": [
1353
- // {
1354
- // "closeId": "300000000000000030",
1355
- // "positionId": "300000000000000009",
1356
- // "uid": 99996908309485,
1357
- // "userId": "6527d4fc8c7f3d0001f40f5f",
1358
- // "symbol": "XBTUSDM",
1359
- // "settleCurrency": "XBT",
1360
- // "leverage": "0.0",
1361
- // "type": "LIQUID_LONG",
1362
- // "side": null,
1363
- // "closeSize": null,
1364
- // "pnl": "-1.0000003793999999",
1365
- // "realisedGrossCost": "0.9993849748999999",
1366
- // "withdrawPnl": "0.0",
1367
- // "roe": null,
1368
- // "tradeFee": "0.0006154045",
1369
- // "fundingFee": "0.0",
1370
- // "openTime": 1713785751181,
1371
- // "closeTime": 1713785752784,
1372
- // "openPrice": null,
1373
- // "closePrice": null
1374
- // }
1375
- // ]
1376
- // }
1377
- // }
1378
- //
1379
- const data = this.safeDict(response, 'data');
1380
- const items = this.safeList(data, 'items', []);
1381
- return this.parsePositions(items, symbols);
1382
- }
1383
- parsePosition(position, market = undefined) {
1384
- //
1385
- // {
1386
- // "code": "200000",
1387
- // "data": [
1388
- // {
1389
- // "id": "615ba79f83a3410001cde321", // Position ID
1390
- // "symbol": "ETHUSDTM", // Symbol
1391
- // "autoDeposit": false, // Auto deposit margin or not
1392
- // "maintMarginReq": 0.005, // Maintenance margin requirement
1393
- // "riskLimit": 1000000, // Risk limit
1394
- // "realLeverage": 25.92, // Leverage of the order
1395
- // "crossMode": false, // Cross mode or not
1396
- // "delevPercentage": 0.76, // ADL ranking percentile
1397
- // "openingTimestamp": 1638578546031, // Open time
1398
- // "currentTimestamp": 1638578563580, // Current timestamp
1399
- // "currentQty": 2, // Current postion quantity
1400
- // "currentCost": 83.787, // Current postion value
1401
- // "currentComm": 0.0167574, // Current commission
1402
- // "unrealisedCost": 83.787, // Unrealised value
1403
- // "realisedGrossCost": 0.0, // Accumulated realised gross profit value
1404
- // "realisedCost": 0.0167574, // Current realised position value
1405
- // "isOpen": true, // Opened position or not
1406
- // "markPrice": 4183.38, // Mark price
1407
- // "markValue": 83.6676, // Mark value
1408
- // "posCost": 83.787, // Position value
1409
- // "posCross": 0.0, // added margin
1410
- // "posInit": 3.35148, // Leverage margin
1411
- // "posComm": 0.05228309, // Bankruptcy cost
1412
- // "posLoss": 0.0, // Funding fees paid out
1413
- // "posMargin": 3.40376309, // Position margin
1414
- // "posMaint": 0.50707892, // Maintenance margin
1415
- // "maintMargin": 3.28436309, // Position margin
1416
- // "realisedGrossPnl": 0.0, // Accumulated realised gross profit value
1417
- // "realisedPnl": -0.0167574, // Realised profit and loss
1418
- // "unrealisedPnl": -0.1194, // Unrealised profit and loss
1419
- // "unrealisedPnlPcnt": -0.0014, // Profit-loss ratio of the position
1420
- // "unrealisedRoePcnt": -0.0356, // Rate of return on investment
1421
- // "avgEntryPrice": 4189.35, // Average entry price
1422
- // "liquidationPrice": 4044.55, // Liquidation price
1423
- // "bankruptPrice": 4021.75, // Bankruptcy price
1424
- // "settleCurrency": "USDT", // Currency used to clear and settle the trades
1425
- // "isInverse": false
1426
- // }
1427
- // ]
1428
- // }
1429
- // position history
1430
- // {
1431
- // "closeId": "300000000000000030",
1432
- // "positionId": "300000000000000009",
1433
- // "uid": 99996908309485,
1434
- // "userId": "6527d4fc8c7f3d0001f40f5f",
1435
- // "symbol": "XBTUSDM",
1436
- // "settleCurrency": "XBT",
1437
- // "leverage": "0.0",
1438
- // "type": "LIQUID_LONG",
1439
- // "side": null,
1440
- // "closeSize": null,
1441
- // "pnl": "-1.0000003793999999",
1442
- // "realisedGrossCost": "0.9993849748999999",
1443
- // "withdrawPnl": "0.0",
1444
- // "roe": null,
1445
- // "tradeFee": "0.0006154045",
1446
- // "fundingFee": "0.0",
1447
- // "openTime": 1713785751181,
1448
- // "closeTime": 1713785752784,
1449
- // "openPrice": null,
1450
- // "closePrice": null
1451
- // }
1452
- //
1453
- const symbol = this.safeString(position, 'symbol');
1454
- market = this.safeMarket(symbol, market);
1455
- const timestamp = this.safeInteger(position, 'currentTimestamp');
1456
- const size = this.safeString(position, 'currentQty');
1457
- let side = undefined;
1458
- const type = this.safeStringLower(position, 'type');
1459
- if (size !== undefined) {
1460
- if (Precise.stringGt(size, '0')) {
1461
- side = 'long';
1462
- }
1463
- else if (Precise.stringLt(size, '0')) {
1464
- side = 'short';
1465
- }
1466
- }
1467
- else if (type !== undefined) {
1468
- if (type.indexOf('long') > -1) {
1469
- side = 'long';
1470
- }
1471
- else {
1472
- side = 'short';
1473
- }
1474
- }
1475
- const notional = Precise.stringAbs(this.safeString(position, 'posCost'));
1476
- const initialMargin = this.safeString(position, 'posInit');
1477
- const initialMarginPercentage = Precise.stringDiv(initialMargin, notional);
1478
- // const marginRatio = Precise.stringDiv (maintenanceRate, collateral);
1479
- const unrealisedPnl = this.safeString(position, 'unrealisedPnl');
1480
- const crossMode = this.safeValue(position, 'crossMode');
1481
- // currently crossMode is always set to false and only isolated positions are supported
1482
- let marginMode = undefined;
1483
- if (crossMode !== undefined) {
1484
- marginMode = crossMode ? 'cross' : 'isolated';
1485
- }
1486
- return this.safePosition({
1487
- 'info': position,
1488
- 'id': this.safeString2(position, 'id', 'positionId'),
1489
- 'symbol': this.safeString(market, 'symbol'),
1490
- 'timestamp': timestamp,
1491
- 'datetime': this.iso8601(timestamp),
1492
- 'lastUpdateTimestamp': this.safeInteger(position, 'closeTime'),
1493
- 'initialMargin': this.parseNumber(initialMargin),
1494
- 'initialMarginPercentage': this.parseNumber(initialMarginPercentage),
1495
- 'maintenanceMargin': this.safeNumber(position, 'posMaint'),
1496
- 'maintenanceMarginPercentage': this.safeNumber(position, 'maintMarginReq'),
1497
- 'entryPrice': this.safeNumber2(position, 'avgEntryPrice', 'openPrice'),
1498
- 'notional': this.parseNumber(notional),
1499
- 'leverage': this.safeNumber2(position, 'realLeverage', 'leverage'),
1500
- 'unrealizedPnl': this.parseNumber(unrealisedPnl),
1501
- 'contracts': this.parseNumber(Precise.stringAbs(size)),
1502
- 'contractSize': this.safeValue(market, 'contractSize'),
1503
- 'realizedPnl': this.safeNumber2(position, 'realisedPnl', 'pnl'),
1504
- 'marginRatio': undefined,
1505
- 'liquidationPrice': this.safeNumber(position, 'liquidationPrice'),
1506
- 'markPrice': this.safeNumber(position, 'markPrice'),
1507
- 'lastPrice': undefined,
1508
- 'collateral': this.safeNumber(position, 'maintMargin'),
1509
- 'marginMode': marginMode,
1510
- 'side': side,
1511
- 'percentage': undefined,
1512
- 'stopLossPrice': undefined,
1513
- 'takeProfitPrice': undefined,
1514
- });
1515
- }
1516
- /**
1517
- * @method
1518
- * @name kucoinfutures#createOrder
1519
- * @description Create an order on the exchange
1520
- * @see https://www.kucoin.com/docs/rest/futures-trading/orders/place-order
1521
- * @see https://www.kucoin.com/docs/rest/futures-trading/orders/place-take-profit-and-stop-loss-order#http-request
1522
- * @param {string} symbol Unified CCXT market symbol
1523
- * @param {string} type 'limit' or 'market'
1524
- * @param {string} side 'buy' or 'sell'
1525
- * @param {float} amount the amount of currency to trade
1526
- * @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
1527
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1528
- * @param {object} [params.takeProfit] *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered and the triggerPriceType
1529
- * @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered and the triggerPriceType
1530
- * @param {float} [params.triggerPrice] The price a trigger order is triggered at
1531
- * @param {float} [params.stopLossPrice] price to trigger stop-loss orders
1532
- * @param {float} [params.takeProfitPrice] price to trigger take-profit orders
1533
- * @param {bool} [params.reduceOnly] A mark to reduce the position size only. Set to false by default. Need to set the position size when reduceOnly is true.
1534
- * @param {string} [params.timeInForce] GTC, GTT, IOC, or FOK, default is GTC, limit orders only
1535
- * @param {string} [params.postOnly] Post only flag, invalid when timeInForce is IOC or FOK
1536
- * @param {float} [params.cost] the cost of the order in units of USDT
1537
- * @param {string} [params.marginMode] 'cross' or 'isolated', default is 'isolated'
1538
- * @param {bool} [params.hedged] *swap and future only* true for hedged mode, false for one way mode, default is false
1539
- * ----------------- Exchange Specific Parameters -----------------
1540
- * @param {float} [params.leverage] Leverage size of the order (mandatory param in request, default is 1)
1541
- * @param {string} [params.clientOid] client order id, defaults to uuid if not passed
1542
- * @param {string} [params.remark] remark for the order, length cannot exceed 100 utf8 characters
1543
- * @param {string} [params.stop] 'up' or 'down', the direction the triggerPrice is triggered from, requires triggerPrice. down: Triggers when the price reaches or goes below the triggerPrice. up: Triggers when the price reaches or goes above the triggerPrice.
1544
- * @param {string} [params.triggerPriceType] "last", "mark", "index" - defaults to "mark"
1545
- * @param {string} [params.stopPriceType] exchange-specific alternative for triggerPriceType: TP, IP or MP
1546
- * @param {bool} [params.closeOrder] set to true to close position
1547
- * @param {bool} [params.test] set to true to use the test order endpoint (does not submit order, use to validate params)
1548
- * @param {bool} [params.forceHold] A mark to forcely hold the funds for an order, even though it's an order to reduce the position size. This helps the order stay on the order book and not get canceled when the position size changes. Set to false by default.\
1549
- * @param {string} [params.positionSide] *swap and future only* hedged two-way position side, LONG or SHORT
1550
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
1551
- */
1552
- async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1553
- await this.loadMarkets();
1554
- const market = this.market(symbol);
1555
- const testOrder = this.safeBool(params, 'test', false);
1556
- params = this.omit(params, 'test');
1557
- const hasTpOrSlOrder = (this.safeValue(params, 'stopLoss') !== undefined) || (this.safeValue(params, 'takeProfit') !== undefined);
1558
- const orderRequest = this.createContractOrderRequest(symbol, type, side, amount, price, params);
1559
- let response = undefined;
1560
- if (testOrder) {
1561
- response = await this.futuresPrivatePostOrdersTest(orderRequest);
1562
- }
1563
- else {
1564
- if (hasTpOrSlOrder) {
1565
- response = await this.futuresPrivatePostStOrders(orderRequest);
1566
- }
1567
- else {
1568
- response = await this.futuresPrivatePostOrders(orderRequest);
1569
- }
1570
- }
1571
- //
1572
- // {
1573
- // "code": "200000",
1574
- // "data": {
1575
- // "orderId": "619717484f1d010001510cde",
1576
- // },
1577
- // }
1578
- //
1579
- const data = this.safeDict(response, 'data', {});
1580
- return this.parseOrder(data, market);
1581
- }
1582
- /**
1583
- * @method
1584
- * @name kucoinfutures#createOrders
1585
- * @description create a list of trade orders
1586
- * @see https://www.kucoin.com/docs/rest/futures-trading/orders/place-multiple-orders
1587
- * @param {Array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
1588
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1589
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
1590
- */
1591
- async createOrders(orders, params = {}) {
1592
- await this.loadMarkets();
1593
- const ordersRequests = [];
1594
- for (let i = 0; i < orders.length; i++) {
1595
- const rawOrder = orders[i];
1596
- const symbol = this.safeString(rawOrder, 'symbol');
1597
- const market = this.market(symbol);
1598
- const type = this.safeString(rawOrder, 'type');
1599
- const side = this.safeString(rawOrder, 'side');
1600
- const amount = this.safeValue(rawOrder, 'amount');
1601
- const price = this.safeValue(rawOrder, 'price');
1602
- const orderParams = this.safeValue(rawOrder, 'params', {});
1603
- const orderRequest = this.createContractOrderRequest(market['id'], type, side, amount, price, orderParams);
1604
- ordersRequests.push(orderRequest);
1605
- }
1606
- const response = await this.futuresPrivatePostOrdersMulti(ordersRequests);
1607
- //
1608
- // {
1609
- // "code": "200000",
1610
- // "data": [
1611
- // {
1612
- // "orderId": "135241412609331200",
1613
- // "clientOid": "3d8fcc13-0b13-447f-ad30-4b3441e05213",
1614
- // "symbol": "LTCUSDTM",
1615
- // "code": "200000",
1616
- // "msg": "success"
1617
- // },
1618
- // {
1619
- // "orderId": "135241412747743234",
1620
- // "clientOid": "b878c7ee-ae3e-4d63-a20b-038acbb7306f",
1621
- // "symbol": "LTCUSDTM",
1622
- // "code": "200000",
1623
- // "msg": "success"
1624
- // }
1625
- // ]
1626
- // }
1627
- //
1628
- const data = this.safeList(response, 'data', []);
1629
- return this.parseOrders(data);
1630
- }
1631
- createContractOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
1632
- const market = this.market(symbol);
1633
- // required param, cannot be used twice
1634
- const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId', this.uuid());
1635
- params = this.omit(params, ['clientOid', 'clientOrderId']);
1636
- const request = {
1637
- 'clientOid': clientOrderId,
1638
- 'side': side,
1639
- 'symbol': market['id'],
1640
- 'type': type,
1641
- 'leverage': 1,
1642
- };
1643
- const marginModeUpper = this.safeStringUpper(params, 'marginMode');
1644
- if (marginModeUpper !== undefined) {
1645
- params = this.omit(params, 'marginMode');
1646
- request['marginMode'] = marginModeUpper;
1647
- }
1648
- const cost = this.safeString(params, 'cost');
1649
- params = this.omit(params, 'cost');
1650
- if (cost !== undefined) {
1651
- request['valueQty'] = this.costToPrecision(symbol, cost);
1652
- }
1653
- else {
1654
- if (amount < 1) {
1655
- throw new InvalidOrder(this.id + ' createOrder() minimum contract order amount is 1');
1656
- }
1657
- request['size'] = parseInt(this.amountToPrecision(symbol, amount));
1658
- }
1659
- const [triggerPrice, stopLossPrice, takeProfitPrice] = this.handleTriggerPrices(params);
1660
- const stopLoss = this.safeDict(params, 'stopLoss');
1661
- const takeProfit = this.safeDict(params, 'takeProfit');
1662
- const hasStopLoss = stopLoss !== undefined;
1663
- const hasTakeProfit = takeProfit !== undefined;
1664
- // const isTpAndSl = stopLossPrice && takeProfitPrice;
1665
- const triggerPriceTypes = {
1666
- 'mark': 'MP',
1667
- 'last': 'TP',
1668
- 'index': 'IP',
1669
- };
1670
- const triggerPriceType = this.safeString(params, 'triggerPriceType', 'mark');
1671
- const triggerPriceTypeValue = this.safeString(triggerPriceTypes, triggerPriceType, triggerPriceType);
1672
- params = this.omit(params, ['stopLossPrice', 'takeProfitPrice', 'triggerPrice', 'stopPrice', 'takeProfit', 'stopLoss']);
1673
- if (triggerPrice) {
1674
- request['stop'] = (side === 'buy') ? 'up' : 'down';
1675
- request['stopPrice'] = this.priceToPrecision(symbol, triggerPrice);
1676
- request['stopPriceType'] = triggerPriceTypeValue;
1677
- }
1678
- else if (hasStopLoss || hasTakeProfit) {
1679
- let priceType = triggerPriceTypeValue;
1680
- if (hasStopLoss) {
1681
- const slPrice = this.safeString2(stopLoss, 'triggerPrice', 'stopPrice');
1682
- request['triggerStopDownPrice'] = this.priceToPrecision(symbol, slPrice);
1683
- priceType = this.safeString(stopLoss, 'triggerPriceType', 'mark');
1684
- priceType = this.safeString(triggerPriceTypes, priceType, priceType);
1685
- }
1686
- if (hasTakeProfit) {
1687
- const tpPrice = this.safeString2(takeProfit, 'triggerPrice', 'takeProfitPrice');
1688
- request['triggerStopUpPrice'] = this.priceToPrecision(symbol, tpPrice);
1689
- priceType = this.safeString(takeProfit, 'triggerPriceType', 'mark');
1690
- priceType = this.safeString(triggerPriceTypes, priceType, priceType);
1691
- }
1692
- request['stopPriceType'] = priceType;
1693
- }
1694
- else if (stopLossPrice || takeProfitPrice) {
1695
- if (stopLossPrice) {
1696
- request['stop'] = (side === 'buy') ? 'up' : 'down';
1697
- request['stopPrice'] = this.priceToPrecision(symbol, stopLossPrice);
1698
- }
1699
- else {
1700
- request['stop'] = (side === 'buy') ? 'down' : 'up';
1701
- request['stopPrice'] = this.priceToPrecision(symbol, takeProfitPrice);
1702
- }
1703
- request['reduceOnly'] = true;
1704
- request['stopPriceType'] = triggerPriceTypeValue;
1705
- }
1706
- const uppercaseType = type.toUpperCase();
1707
- const timeInForce = this.safeStringUpper(params, 'timeInForce');
1708
- if (uppercaseType === 'LIMIT') {
1709
- if (price === undefined) {
1710
- throw new ArgumentsRequired(this.id + ' createOrder() requires a price argument for limit orders');
1711
- }
1712
- else {
1713
- request['price'] = this.priceToPrecision(symbol, price);
1714
- }
1715
- if (timeInForce !== undefined) {
1716
- request['timeInForce'] = timeInForce;
1717
- }
1718
- }
1719
- let postOnly = undefined;
1720
- [postOnly, params] = this.handlePostOnly(type === 'market', false, params);
1721
- if (postOnly) {
1722
- request['postOnly'] = true;
1723
- }
1724
- const hidden = this.safeValue(params, 'hidden');
1725
- if (postOnly && (hidden !== undefined)) {
1726
- throw new BadRequest(this.id + ' createOrder() does not support the postOnly parameter together with a hidden parameter');
1727
- }
1728
- const iceberg = this.safeValue(params, 'iceberg');
1729
- if (iceberg) {
1730
- const visibleSize = this.safeValue(params, 'visibleSize');
1731
- if (visibleSize === undefined) {
1732
- throw new ArgumentsRequired(this.id + ' createOrder() requires a visibleSize parameter for iceberg orders');
1733
- }
1734
- }
1735
- const reduceOnly = this.safeBool(params, 'reduceOnly', false);
1736
- let hedged = undefined;
1737
- [hedged, params] = this.handleParamBool(params, 'hedged', false);
1738
- if (reduceOnly) {
1739
- request['reduceOnly'] = reduceOnly;
1740
- if (hedged) {
1741
- const reduceOnlyPosSide = (side === 'sell') ? 'LONG' : 'SHORT';
1742
- request['positionSide'] = reduceOnlyPosSide;
1743
- }
1744
- }
1745
- else {
1746
- if (hedged) {
1747
- const posSide = (side === 'buy') ? 'LONG' : 'SHORT';
1748
- request['positionSide'] = posSide;
1749
- }
1750
- }
1751
- params = this.omit(params, ['timeInForce', 'stopPrice', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'reduceOnly', 'hedged']); // Time in force only valid for limit orders, exchange error when gtc for market orders
1752
- return this.extend(request, params);
1753
- }
1754
- /**
1755
- * @method
1756
- * @name kucoinfutures#cancelOrder
1757
- * @description cancels an open order
1758
- * @see https://www.kucoin.com/docs/rest/futures-trading/orders/cancel-futures-order-by-orderid
1759
- * @param {string} id order id
1760
- * @param {string} symbol unified symbol of the market the order was made in
1761
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1762
- * @param {string} [params.clientOrderId] cancel order by client order id
1763
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
1764
- */
1765
- async cancelOrder(id, symbol = undefined, params = {}) {
1766
- await this.loadMarkets();
1767
- const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId');
1768
- params = this.omit(params, ['clientOrderId']);
1769
- const request = {};
1770
- let response = undefined;
1771
- if (clientOrderId !== undefined) {
1772
- if (symbol === undefined) {
1773
- throw new ArgumentsRequired(this.id + ' cancelOrder() requires a symbol argument when cancelling by clientOrderId');
1774
- }
1775
- const market = this.market(symbol);
1776
- request['symbol'] = market['id'];
1777
- request['clientOid'] = clientOrderId;
1778
- response = await this.futuresPrivateDeleteOrdersClientOrderClientOid(this.extend(request, params));
1779
- }
1780
- else {
1781
- request['orderId'] = id;
1782
- response = await this.futuresPrivateDeleteOrdersOrderId(this.extend(request, params));
1783
- }
1784
- //
1785
- // {
1786
- // "code": "200000",
1787
- // "data": {
1788
- // "cancelledOrderIds": [
1789
- // "619714b8b6353000014c505a",
1790
- // ],
1791
- // },
1792
- // }
1793
- //
1794
- return this.safeOrder({ 'info': response });
1795
- }
1796
- /**
1797
- * @method
1798
- * @name kucoinfutures#cancelOrders
1799
- * @description cancel multiple orders
1800
- * @see https://www.kucoin.com/docs/rest/futures-trading/orders/batch-cancel-orders
1801
- * @param {string[]} ids order ids
1802
- * @param {string} symbol unified symbol of the market the order was made in
1803
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1804
- * @param {string[]} [params.clientOrderIds] client order ids
1805
- * @returns {object} an list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
1806
- */
1807
- async cancelOrders(ids, symbol = undefined, params = {}) {
1808
- await this.loadMarkets();
1809
- let market = undefined;
1810
- if (symbol !== undefined) {
1811
- market = this.market(symbol);
1812
- }
1813
- const ordersRequests = [];
1814
- const clientOrderIds = this.safeList2(params, 'clientOrderIds', 'clientOids', []);
1815
- params = this.omit(params, ['clientOrderIds', 'clientOids']);
1816
- let useClientorderId = false;
1817
- for (let i = 0; i < clientOrderIds.length; i++) {
1818
- useClientorderId = true;
1819
- if (symbol === undefined) {
1820
- throw new ArgumentsRequired(this.id + ' cancelOrders() requires a symbol argument when cancelling by clientOrderIds');
1821
- }
1822
- ordersRequests.push({
1823
- 'symbol': market['id'],
1824
- 'clientOid': this.safeString(clientOrderIds, i),
1825
- });
1826
- }
1827
- for (let i = 0; i < ids.length; i++) {
1828
- ordersRequests.push(ids[i]);
1829
- }
1830
- const requestKey = useClientorderId ? 'clientOidsList' : 'orderIdsList';
1831
- const request = {};
1832
- request[requestKey] = ordersRequests;
1833
- const response = await this.futuresPrivateDeleteOrdersMultiCancel(this.extend(request, params));
1834
- //
1835
- // {
1836
- // "code": "200000",
1837
- // "data":
1838
- // [
1839
- // {
1840
- // "orderId": "80465574458560512",
1841
- // "clientOid": null,
1842
- // "code": "200",
1843
- // "msg": "success"
1844
- // },
1845
- // {
1846
- // "orderId": "80465575289094144",
1847
- // "clientOid": null,
1848
- // "code": "200",
1849
- // "msg": "success"
1850
- // }
1851
- // ]
1852
- // }
1853
- //
1854
- const orders = this.safeList(response, 'data', []);
1855
- return this.parseOrders(orders, market);
1856
- }
1857
- /**
1858
- * @method
1859
- * @name kucoinfutures#cancelAllOrders
1860
- * @description cancel all open orders
1861
- * @see https://www.kucoin.com/docs/rest/futures-trading/orders/cancel-multiple-futures-limit-orders
1862
- * @see https://www.kucoin.com/docs/rest/futures-trading/orders/cancel-multiple-futures-stop-orders
1863
- * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
1864
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1865
- * @param {object} [params.trigger] When true, all the trigger orders will be cancelled
1866
- * @returns Response from the exchange
1867
- */
1868
- async cancelAllOrders(symbol = undefined, params = {}) {
1869
- await this.loadMarkets();
1870
- const request = {};
1871
- if (symbol !== undefined) {
1872
- request['symbol'] = this.marketId(symbol);
1873
- }
1874
- const trigger = this.safeValue2(params, 'stop', 'trigger');
1875
- params = this.omit(params, ['stop', 'trigger']);
1876
- let response = undefined;
1877
- if (trigger) {
1878
- response = await this.futuresPrivateDeleteStopOrders(this.extend(request, params));
1879
- }
1880
- else {
1881
- response = await this.futuresPrivateDeleteOrders(this.extend(request, params));
1882
- }
1883
- //
1884
- // {
1885
- // "code": "200000",
1886
- // "data": {
1887
- // "cancelledOrderIds": [
1888
- // "619714b8b6353000014c505a",
1889
- // ],
1890
- // },
1891
- // }
1892
- //
1893
- const data = this.safeDict(response, 'data');
1894
- return [this.safeOrder({ 'info': data })];
1895
- }
1896
- /**
1897
- * @method
1898
- * @name kucoinfutures#addMargin
1899
- * @description add margin
1900
- * @see https://www.kucoin.com/docs/rest/futures-trading/positions/add-margin-manually
1901
- * @param {string} symbol unified market symbol
1902
- * @param {float} amount amount of margin to add
1903
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1904
- * @returns {object} a [margin structure]{@link https://docs.ccxt.com/?id=margin-structure}
1905
- */
1906
- async addMargin(symbol, amount, params = {}) {
1907
- await this.loadMarkets();
1908
- const market = this.market(symbol);
1909
- const uuid = this.uuid();
1910
- const request = {
1911
- 'symbol': market['id'],
1912
- 'margin': this.amountToPrecision(symbol, amount),
1913
- 'bizNo': uuid,
1914
- };
1915
- const response = await this.futuresPrivatePostPositionMarginDepositMargin(this.extend(request, params));
1916
- //
1917
- // {
1918
- // "code": "200000",
1919
- // "data": {
1920
- // "id": "62311d26064e8f00013f2c6d",
1921
- // "symbol": "XRPUSDTM",
1922
- // "autoDeposit": false,
1923
- // "maintMarginReq": 0.01,
1924
- // "riskLimit": 200000,
1925
- // "realLeverage": 0.88,
1926
- // "crossMode": false,
1927
- // "delevPercentage": 0.4,
1928
- // "openingTimestamp": 1647385894798,
1929
- // "currentTimestamp": 1647414510672,
1930
- // "currentQty": -1,
1931
- // "currentCost": -7.658,
1932
- // "currentComm": 0.0053561,
1933
- // "unrealisedCost": -7.658,
1934
- // "realisedGrossCost": 0,
1935
- // "realisedCost": 0.0053561,
1936
- // "isOpen": true,
1937
- // "markPrice": 0.7635,
1938
- // "markValue": -7.635,
1939
- // "posCost": -7.658,
1940
- // "posCross": 1.00016084,
1941
- // "posInit": 7.658,
1942
- // "posComm": 0.00979006,
1943
- // "posLoss": 0,
1944
- // "posMargin": 8.6679509,
1945
- // "posMaint": 0.08637006,
1946
- // "maintMargin": 8.6909509,
1947
- // "realisedGrossPnl": 0,
1948
- // "realisedPnl": -0.0038335,
1949
- // "unrealisedPnl": 0.023,
1950
- // "unrealisedPnlPcnt": 0.003,
1951
- // "unrealisedRoePcnt": 0.003,
1952
- // "avgEntryPrice": 0.7658,
1953
- // "liquidationPrice": 1.6239,
1954
- // "bankruptPrice": 1.6317,
1955
- // "settleCurrency": "USDT"
1956
- // }
1957
- // }
1958
- //
1959
- //
1960
- // {
1961
- // "code":"200000",
1962
- // "msg":"Position does not exist"
1963
- // }
1964
- //
1965
- const data = this.safeValue(response, 'data');
1966
- return this.extend(this.parseMarginModification(data, market), {
1967
- 'amount': this.amountToPrecision(symbol, amount),
1968
- 'direction': 'in',
1969
- });
1970
- }
1971
- parseMarginModification(info, market = undefined) {
1972
- //
1973
- // {
1974
- // "id": "62311d26064e8f00013f2c6d",
1975
- // "symbol": "XRPUSDTM",
1976
- // "autoDeposit": false,
1977
- // "maintMarginReq": 0.01,
1978
- // "riskLimit": 200000,
1979
- // "realLeverage": 0.88,
1980
- // "crossMode": false,
1981
- // "delevPercentage": 0.4,
1982
- // "openingTimestamp": 1647385894798,
1983
- // "currentTimestamp": 1647414510672,
1984
- // "currentQty": -1,
1985
- // "currentCost": -7.658,
1986
- // "currentComm": 0.0053561,
1987
- // "unrealisedCost": -7.658,
1988
- // "realisedGrossCost": 0,
1989
- // "realisedCost": 0.0053561,
1990
- // "isOpen": true,
1991
- // "markPrice": 0.7635,
1992
- // "markValue": -7.635,
1993
- // "posCost": -7.658,
1994
- // "posCross": 1.00016084,
1995
- // "posInit": 7.658,
1996
- // "posComm": 0.00979006,
1997
- // "posLoss": 0,
1998
- // "posMargin": 8.6679509,
1999
- // "posMaint": 0.08637006,
2000
- // "maintMargin": 8.6909509,
2001
- // "realisedGrossPnl": 0,
2002
- // "realisedPnl": -0.0038335,
2003
- // "unrealisedPnl": 0.023,
2004
- // "unrealisedPnlPcnt": 0.003,
2005
- // "unrealisedRoePcnt": 0.003,
2006
- // "avgEntryPrice": 0.7658,
2007
- // "liquidationPrice": 1.6239,
2008
- // "bankruptPrice": 1.6317,
2009
- // "settleCurrency": "USDT"
2010
- // }
2011
- //
2012
- // {
2013
- // "code":"200000",
2014
- // "msg":"Position does not exist"
2015
- // }
2016
- //
2017
- const id = this.safeString(info, 'id');
2018
- market = this.safeMarket(id, market);
2019
- const currencyId = this.safeString(info, 'settleCurrency');
2020
- const crossMode = this.safeValue(info, 'crossMode');
2021
- const mode = crossMode ? 'cross' : 'isolated';
2022
- const marketId = this.safeString(market, 'symbol');
2023
- const timestamp = this.safeInteger(info, 'currentTimestamp');
2024
- return {
2025
- 'info': info,
2026
- 'symbol': this.safeSymbol(marketId, market),
2027
- 'type': undefined,
2028
- 'marginMode': mode,
2029
- 'amount': undefined,
2030
- 'total': undefined,
2031
- 'code': this.safeCurrencyCode(currencyId),
2032
- 'status': undefined,
2033
- 'timestamp': timestamp,
2034
- 'datetime': this.iso8601(timestamp),
2035
- };
2036
- }
2037
- /**
2038
- * @method
2039
- * @name kucoinfutures#fetchOrdersByStatus
2040
- * @description fetches a list of orders placed on the exchange
2041
- * @see https://docs.kucoin.com/futures/#get-order-list
2042
- * @see https://docs.kucoin.com/futures/#get-untriggered-stop-order-list
2043
- * @param {string} status 'active' or 'closed', only 'active' is valid for stop orders
2044
- * @param {string} symbol unified symbol for the market to retrieve orders from
2045
- * @param {int} [since] timestamp in ms of the earliest order to retrieve
2046
- * @param {int} [limit] The maximum number of orders to retrieve
2047
- * @param {object} [params] exchange specific parameters
2048
- * @param {bool} [params.trigger] set to true to retrieve untriggered stop orders
2049
- * @param {int} [params.until] End time in ms
2050
- * @param {string} [params.side] buy or sell
2051
- * @param {string} [params.type] limit or market
2052
- * @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)
2053
- * @returns An [array of order structures]{@link https://docs.ccxt.com/?id=order-structure}
2054
- */
2055
- async fetchOrdersByStatus(status, symbol = undefined, since = undefined, limit = undefined, params = {}) {
2056
- await this.loadMarkets();
2057
- let paginate = false;
2058
- [paginate, params] = this.handleOptionAndParams(params, 'fetchOrdersByStatus', 'paginate');
2059
- if (paginate) {
2060
- return await this.fetchPaginatedCallDynamic('fetchOrdersByStatus', symbol, since, limit, params);
2061
- }
2062
- const trigger = this.safeBool2(params, 'stop', 'trigger');
2063
- const until = this.safeInteger(params, 'until');
2064
- params = this.omit(params, ['stop', 'until', 'trigger']);
2065
- if (status === 'closed') {
2066
- status = 'done';
2067
- }
2068
- else if (status === 'open') {
2069
- status = 'active';
2070
- }
2071
- const request = {};
2072
- if (!trigger) {
2073
- request['status'] = status;
2074
- }
2075
- else if (status !== 'active') {
2076
- throw new BadRequest(this.id + ' fetchOrdersByStatus() can only fetch untriggered stop orders');
2077
- }
2078
- let market = undefined;
2079
- if (symbol !== undefined) {
2080
- market = this.market(symbol);
2081
- request['symbol'] = market['id'];
2082
- }
2083
- if (since !== undefined) {
2084
- request['startAt'] = since;
2085
- }
2086
- if (until !== undefined) {
2087
- request['endAt'] = until;
2088
- }
2089
- let response = undefined;
2090
- if (trigger) {
2091
- response = await this.futuresPrivateGetStopOrders(this.extend(request, params));
2092
- }
2093
- else {
2094
- response = await this.futuresPrivateGetOrders(this.extend(request, params));
2095
- }
2096
- //
2097
- // {
2098
- // "code": "200000",
2099
- // "data": {
2100
- // "currentPage": 1,
2101
- // "pageSize": 50,
2102
- // "totalNum": 4,
2103
- // "totalPage": 1,
2104
- // "items": [
2105
- // {
2106
- // "id": "64507d02921f1c0001ff6892",
2107
- // "symbol": "XBTUSDTM",
2108
- // "type": "market",
2109
- // "side": "buy",
2110
- // "price": null,
2111
- // "size": 1,
2112
- // "value": "27.992",
2113
- // "dealValue": "27.992",
2114
- // "dealSize": 1,
2115
- // "stp": "",
2116
- // "stop": "",
2117
- // "stopPriceType": "",
2118
- // "stopTriggered": false,
2119
- // "stopPrice": null,
2120
- // "timeInForce": "GTC",
2121
- // "postOnly": false,
2122
- // "hidden": false,
2123
- // "iceberg": false,
2124
- // "leverage": "17",
2125
- // "forceHold": false,
2126
- // "closeOrder": false,
2127
- // "visibleSize": null,
2128
- // "clientOid": null,
2129
- // "remark": null,
2130
- // "tags": null,
2131
- // "isActive": false,
2132
- // "cancelExist": false,
2133
- // "createdAt": 1682996482000,
2134
- // "updatedAt": 1682996483062,
2135
- // "endAt": 1682996483062,
2136
- // "orderTime": 1682996482953900677,
2137
- // "settleCurrency": "USDT",
2138
- // "status": "done",
2139
- // "filledValue": "27.992",
2140
- // "filledSize": 1,
2141
- // "reduceOnly": false
2142
- // }
2143
- // ]
2144
- // }
2145
- // }
2146
- //
2147
- const responseData = this.safeDict(response, 'data', {});
2148
- const orders = this.safeList(responseData, 'items', []);
2149
- return this.parseOrders(orders, market, since, limit);
2150
- }
2151
- /**
2152
- * @method
2153
- * @name kucoinfutures#fetchClosedOrders
2154
- * @description fetches information on multiple closed orders made by the user
2155
- * @see https://docs.kucoin.com/futures/#get-order-list
2156
- * @param {string} symbol unified market symbol of the market orders were made in
2157
- * @param {int} [since] the earliest time in ms to fetch orders for
2158
- * @param {int} [limit] the maximum number of order structures to retrieve
2159
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2160
- * @param {int} [params.until] end time in ms
2161
- * @param {string} [params.side] buy or sell
2162
- * @param {string} [params.type] limit, or market
2163
- * @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)
2164
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
2165
- */
2166
- async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2167
- await this.loadMarkets();
2168
- let paginate = false;
2169
- [paginate, params] = this.handleOptionAndParams(params, 'fetchClosedOrders', 'paginate');
2170
- if (paginate) {
2171
- return await this.fetchPaginatedCallDynamic('fetchClosedOrders', symbol, since, limit, params);
2172
- }
2173
- return await this.fetchOrdersByStatus('done', symbol, since, limit, params);
2174
- }
2175
- /**
2176
- * @method
2177
- * @name kucoinfutures#fetchOpenOrders
2178
- * @description fetches information on multiple open orders made by the user
2179
- * @see https://docs.kucoin.com/futures/#get-order-list
2180
- * @see https://docs.kucoin.com/futures/#get-untriggered-stop-order-list
2181
- * @param {string} symbol unified market symbol of the market orders were made in
2182
- * @param {int} [since] the earliest time in ms to fetch orders for
2183
- * @param {int} [limit] the maximum number of order structures to retrieve
2184
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2185
- * @param {int} [params.until] end time in ms
2186
- * @param {string} [params.side] buy or sell
2187
- * @param {string} [params.type] limit, or market
2188
- * @param {boolean} [params.trigger] set to true to retrieve untriggered stop orders
2189
- * @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)
2190
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
2191
- */
2192
- async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2193
- await this.loadMarkets();
2194
- let paginate = false;
2195
- [paginate, params] = this.handleOptionAndParams(params, 'fetchOpenOrders', 'paginate');
2196
- if (paginate) {
2197
- return await this.fetchPaginatedCallDynamic('fetchOpenOrders', symbol, since, limit, params);
2198
- }
2199
- return await this.fetchOrdersByStatus('open', symbol, since, limit, params);
2200
- }
2201
- /**
2202
- * @method
2203
- * @name kucoinfutures#fetchOrder
2204
- * @description fetches information on an order made by the user
2205
- * @see https://docs.kucoin.com/futures/#get-details-of-a-single-order
2206
- * @param {string} id order id
2207
- * @param {string} symbol unified symbol of the market the order was made in
2208
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2209
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
2210
- */
2211
- async fetchOrder(id, symbol = undefined, params = {}) {
2212
- await this.loadMarkets();
2213
- const request = {};
2214
- let response = undefined;
2215
- if (id === undefined) {
2216
- const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId');
2217
- if (clientOrderId === undefined) {
2218
- throw new InvalidOrder(this.id + ' fetchOrder() requires parameter id or params.clientOid');
2219
- }
2220
- request['clientOid'] = clientOrderId;
2221
- params = this.omit(params, ['clientOid', 'clientOrderId']);
2222
- response = await this.futuresPrivateGetOrdersByClientOid(this.extend(request, params));
2223
- }
2224
- else {
2225
- request['orderId'] = id;
2226
- response = await this.futuresPrivateGetOrdersOrderId(this.extend(request, params));
2227
- }
2228
- //
2229
- // {
2230
- // "code": "200000",
2231
- // "data": {
2232
- // "id": "64507d02921f1c0001ff6892",
2233
- // "symbol": "XBTUSDTM",
2234
- // "type": "market",
2235
- // "side": "buy",
2236
- // "price": null,
2237
- // "size": 1,
2238
- // "value": "27.992",
2239
- // "dealValue": "27.992",
2240
- // "dealSize": 1,
2241
- // "stp": "",
2242
- // "stop": "",
2243
- // "stopPriceType": "",
2244
- // "stopTriggered": false,
2245
- // "stopPrice": null,
2246
- // "timeInForce": "GTC",
2247
- // "postOnly": false,
2248
- // "hidden": false,
2249
- // "iceberg": false,
2250
- // "leverage": "17",
2251
- // "forceHold": false,
2252
- // "closeOrder": false,
2253
- // "visibleSize": null,
2254
- // "clientOid": null,
2255
- // "remark": null,
2256
- // "tags": null,
2257
- // "isActive": false,
2258
- // "cancelExist": false,
2259
- // "createdAt": 1682996482000,
2260
- // "updatedAt": 1682996483000,
2261
- // "endAt": 1682996483000,
2262
- // "orderTime": 1682996482953900677,
2263
- // "settleCurrency": "USDT",
2264
- // "status": "done",
2265
- // "filledSize": 1,
2266
- // "filledValue": "27.992",
2267
- // "reduceOnly": false
2268
- // }
2269
- // }
2270
- //
2271
- const market = (symbol !== undefined) ? this.market(symbol) : undefined;
2272
- const responseData = this.safeDict(response, 'data');
2273
- return this.parseOrder(responseData, market);
2274
- }
2275
- parseOrder(order, market = undefined) {
2276
- //
2277
- // fetchOrder, fetchOrdersByStatus
2278
- //
2279
- // {
2280
- // "id": "64507d02921f1c0001ff6892",
2281
- // "symbol": "XBTUSDTM",
2282
- // "type": "market",
2283
- // "side": "buy",
2284
- // "price": null,
2285
- // "size": 1,
2286
- // "value": "27.992",
2287
- // "dealValue": "27.992",
2288
- // "dealSize": 1,
2289
- // "stp": "",
2290
- // "stop": "",
2291
- // "stopPriceType": "",
2292
- // "stopTriggered": false,
2293
- // "stopPrice": null,
2294
- // "timeInForce": "GTC",
2295
- // "postOnly": false,
2296
- // "hidden": false,
2297
- // "iceberg": false,
2298
- // "leverage": "17",
2299
- // "forceHold": false,
2300
- // "closeOrder": false,
2301
- // "visibleSize": null,
2302
- // "clientOid": null,
2303
- // "remark": null,
2304
- // "tags": null,
2305
- // "isActive": false,
2306
- // "cancelExist": false,
2307
- // "createdAt": 1682996482000,
2308
- // "updatedAt": 1682996483062,
2309
- // "endAt": 1682996483062,
2310
- // "orderTime": 1682996482953900677,
2311
- // "settleCurrency": "USDT",
2312
- // "status": "done",
2313
- // "filledValue": "27.992",
2314
- // "filledSize": 1,
2315
- // "reduceOnly": false
2316
- // }
2317
- //
2318
- // createOrder
2319
- //
2320
- // {
2321
- // "orderId": "619717484f1d010001510cde"
2322
- // }
2323
- //
2324
- // createOrders
2325
- //
2326
- // {
2327
- // "orderId": "80465574458560512",
2328
- // "clientOid": "5c52e11203aa677f33e491",
2329
- // "symbol": "ETHUSDTM",
2330
- // "code": "200000",
2331
- // "msg": "success"
2332
- // }
2333
- //
2334
- const marketId = this.safeString(order, 'symbol');
2335
- market = this.safeMarket(marketId, market);
2336
- const symbol = market['symbol'];
2337
- const orderId = this.safeString2(order, 'id', 'orderId');
2338
- const type = this.safeString(order, 'type');
2339
- const timestamp = this.safeInteger(order, 'createdAt');
2340
- const datetime = this.iso8601(timestamp);
2341
- const price = this.safeString(order, 'price');
2342
- // price is zero for market order
2343
- // omitZero is called in safeOrder2
2344
- const side = this.safeString(order, 'side');
2345
- const feeCurrencyId = this.safeString(order, 'feeCurrency');
2346
- const feeCurrency = this.safeCurrencyCode(feeCurrencyId);
2347
- const feeCost = this.safeNumber(order, 'fee');
2348
- const amount = this.safeString(order, 'size');
2349
- const filled = this.safeString(order, 'filledSize');
2350
- const cost = this.safeString(order, 'filledValue');
2351
- let average = this.safeString(order, 'avgDealPrice');
2352
- if ((average === undefined) && Precise.stringGt(filled, '0')) {
2353
- const contractSize = this.safeString(market, 'contractSize');
2354
- if (market['linear']) {
2355
- average = Precise.stringDiv(cost, Precise.stringMul(contractSize, filled));
2356
- }
2357
- else {
2358
- average = Precise.stringDiv(Precise.stringMul(contractSize, filled), cost);
2359
- }
2360
- }
2361
- // precision reported by their api is 8 d.p.
2362
- // const average = Precise.stringDiv (cost, Precise.stringMul (filled, market['contractSize']));
2363
- // bool
2364
- const isActive = this.safeValue(order, 'isActive');
2365
- const cancelExist = this.safeBool(order, 'cancelExist', false);
2366
- let status = undefined;
2367
- if (isActive !== undefined) {
2368
- status = isActive ? 'open' : 'closed';
2369
- }
2370
- status = cancelExist ? 'canceled' : status;
2371
- let fee = undefined;
2372
- if (feeCost !== undefined) {
2373
- fee = {
2374
- 'currency': feeCurrency,
2375
- 'cost': feeCost,
2376
- };
2377
- }
2378
- const clientOrderId = this.safeString(order, 'clientOid');
2379
- const timeInForce = this.safeString(order, 'timeInForce');
2380
- const postOnly = this.safeValue(order, 'postOnly');
2381
- const reduceOnly = this.safeValue(order, 'reduceOnly');
2382
- const lastUpdateTimestamp = this.safeInteger(order, 'updatedAt');
2383
- return this.safeOrder({
2384
- 'id': orderId,
2385
- 'clientOrderId': clientOrderId,
2386
- 'symbol': symbol,
2387
- 'type': type,
2388
- 'timeInForce': timeInForce,
2389
- 'postOnly': postOnly,
2390
- 'reduceOnly': reduceOnly,
2391
- 'side': side,
2392
- 'amount': amount,
2393
- 'price': price,
2394
- 'triggerPrice': this.safeNumber(order, 'stopPrice'),
2395
- 'cost': cost,
2396
- 'filled': filled,
2397
- 'remaining': undefined,
2398
- 'timestamp': timestamp,
2399
- 'datetime': datetime,
2400
- 'fee': fee,
2401
- 'status': status,
2402
- 'info': order,
2403
- 'lastTradeTimestamp': undefined,
2404
- 'lastUpdateTimestamp': lastUpdateTimestamp,
2405
- 'average': average,
2406
- 'trades': undefined,
2407
- }, market);
2408
- }
2409
- /**
2410
- * @method
2411
- * @name kucoinfutures#fetchFundingRate
2412
- * @description fetch the current funding rate
2413
- * @see https://www.kucoin.com/docs/rest/futures-trading/funding-fees/get-current-funding-rate
2414
- * @param {string} symbol unified market symbol
2415
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2416
- * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/?id=funding-rate-structure}
2417
- */
2418
- async fetchFundingRate(symbol, params = {}) {
2419
- await this.loadMarkets();
2420
- const market = this.market(symbol);
2421
- const request = {
2422
- 'symbol': market['id'],
2423
- };
2424
- const response = await this.futuresPublicGetFundingRateSymbolCurrent(this.extend(request, params));
2425
- //
2426
- // {
2427
- // "code": "200000",
2428
- // "data": {
2429
- // "symbol": ".ETHUSDTMFPI8H",
2430
- // "granularity": 28800000,
2431
- // "timePoint": 1637380800000,
2432
- // "value": 0.0001,
2433
- // "predictedValue": 0.0001,
2434
- // },
2435
- // }
2436
- //
2437
- const data = this.safeDict(response, 'data', {});
2438
- // the website displayes the previous funding rate as "funding rate"
2439
- return this.parseFundingRate(data, market);
2440
- }
2441
- /**
2442
- * @method
2443
- * @name kucoinfutures#fetchFundingInterval
2444
- * @description fetch the current funding rate interval
2445
- * @see https://www.kucoin.com/docs/rest/futures-trading/funding-fees/get-current-funding-rate
2446
- * @param {string} symbol unified market symbol
2447
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2448
- * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/?id=funding-rate-structure}
2449
- */
2450
- async fetchFundingInterval(symbol, params = {}) {
2451
- return await this.fetchFundingRate(symbol, params);
2452
- }
2453
- parseFundingRate(data, market = undefined) {
2454
- //
2455
- // {
2456
- // "symbol": ".ETHUSDTMFPI8H",
2457
- // "granularity": 28800000,
2458
- // "timePoint": 1637380800000,
2459
- // "value": 0.0001,
2460
- // "predictedValue": 0.0001,
2461
- // }
2462
- //
2463
- const fundingTimestamp = this.safeInteger(data, 'timePoint');
2464
- const marketId = this.safeString(data, 'symbol');
2465
- return {
2466
- 'info': data,
2467
- 'symbol': this.safeSymbol(marketId, market, undefined, 'contract'),
2468
- 'markPrice': undefined,
2469
- 'indexPrice': undefined,
2470
- 'interestRate': undefined,
2471
- 'estimatedSettlePrice': undefined,
2472
- 'timestamp': undefined,
2473
- 'datetime': undefined,
2474
- 'fundingRate': this.safeNumber(data, 'value'),
2475
- 'fundingTimestamp': fundingTimestamp,
2476
- 'fundingDatetime': this.iso8601(fundingTimestamp),
2477
- 'nextFundingRate': this.safeNumber(data, 'predictedValue'),
2478
- 'nextFundingTimestamp': undefined,
2479
- 'nextFundingDatetime': undefined,
2480
- 'previousFundingRate': undefined,
2481
- 'previousFundingTimestamp': undefined,
2482
- 'previousFundingDatetime': undefined,
2483
- 'interval': this.parseFundingInterval(this.safeString(data, 'granularity')),
2484
- };
2485
- }
2486
- parseFundingInterval(interval) {
2487
- const intervals = {
2488
- '3600000': '1h',
2489
- '14400000': '4h',
2490
- '28800000': '8h',
2491
- '57600000': '16h',
2492
- '86400000': '24h',
2493
- };
2494
- return this.safeString(intervals, interval, interval);
2495
- }
2496
- parseBalance(response) {
2497
- const result = {
2498
- 'info': response,
2499
- 'timestamp': undefined,
2500
- 'datetime': undefined,
2501
- };
2502
- const data = this.safeValue(response, 'data');
2503
- const currencyId = this.safeString(data, 'currency');
2504
- const code = this.safeCurrencyCode(currencyId);
2505
- const account = this.account();
2506
- account['free'] = this.safeString(data, 'availableBalance');
2507
- account['total'] = this.safeString(data, 'accountEquity');
2508
- result[code] = account;
2509
- return this.safeBalance(result);
2510
- }
2511
- /**
2512
- * @method
2513
- * @name kucoinfutures#fetchBalance
2514
- * @description query for balance and get the amount of funds available for trading or funds locked in orders
2515
- * @see https://www.kucoin.com/docs/rest/funding/funding-overview/get-account-detail-futures
2516
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2517
- * @param {object} [params.code] the unified currency code to fetch the balance for, if not provided, the default .options['fetchBalance']['code'] will be used
2518
- * @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
2519
- */
2520
- async fetchBalance(params = {}) {
2521
- await this.loadMarkets();
2522
- // only fetches one balance at a time
2523
- let defaultCode = this.safeString(this.options, 'code');
2524
- const fetchBalanceOptions = this.safeValue(this.options, 'fetchBalance', {});
2525
- defaultCode = this.safeString(fetchBalanceOptions, 'code', defaultCode);
2526
- const code = this.safeString(params, 'code', defaultCode);
2527
- const currency = this.currency(code);
2528
- const request = {
2529
- 'currency': currency['id'],
2530
- };
2531
- const response = await this.futuresPrivateGetAccountOverview(this.extend(request, params));
2532
- //
2533
- // {
2534
- // "code": "200000",
2535
- // "data": {
2536
- // "accountEquity": 0.00005,
2537
- // "unrealisedPNL": 0,
2538
- // "marginBalance": 0.00005,
2539
- // "positionMargin": 0,
2540
- // "orderMargin": 0,
2541
- // "frozenFunds": 0,
2542
- // "availableBalance": 0.00005,
2543
- // "currency": "XBT"
2544
- // }
2545
- // }
2546
- //
2547
- return this.parseBalance(response);
2548
- }
2549
49
  /**
2550
50
  * @method
2551
51
  * @name kucoinfutures#transfer
2552
52
  * @description transfer currency internally between wallets on the same account
2553
- * @see https://www.kucoin.com/docs/rest/funding/transfer/transfer-to-main-or-trade-account
2554
- * @see https://www.kucoin.com/docs/rest/funding/transfer/transfer-to-futures-account
2555
53
  * @param {string} code unified currency code
2556
54
  * @param {float} amount amount to transfer
2557
55
  * @param {string} fromAccount account to transfer from
@@ -2619,55 +117,6 @@ export default class kucoinfutures extends kucoin {
2619
117
  'toAccount': toAccount,
2620
118
  });
2621
119
  }
2622
- parseTransfer(transfer, currency = undefined) {
2623
- //
2624
- // transfer to spot or funding account
2625
- //
2626
- // {
2627
- // "applyId": "5bffb63303aa675e8bbe18f9" // Transfer-out request ID
2628
- // }
2629
- //
2630
- // transfer to future account
2631
- //
2632
- // {
2633
- // "applyId": "6738754373ceee00011ec3f8",
2634
- // "bizNo": "6738754373ceee00011ec3f7",
2635
- // "payAccountType": "CONTRACT",
2636
- // "payTag": "DEFAULT",
2637
- // "remark": "",
2638
- // "recAccountType": "MAIN",
2639
- // "recTag": "DEFAULT",
2640
- // "recRemark": "",
2641
- // "recSystem": "KUCOIN",
2642
- // "status": "PROCESSING",
2643
- // "currency": "USDT",
2644
- // "amount": "5",
2645
- // "fee": "0",
2646
- // "sn": 1519769124846692,
2647
- // "reason": "",
2648
- // "createdAt": 1731753283000,
2649
- // "updatedAt": 1731753283000
2650
- // }
2651
- //
2652
- const timestamp = this.safeInteger(transfer, 'updatedAt');
2653
- return {
2654
- 'id': this.safeString(transfer, 'applyId'),
2655
- 'timestamp': timestamp,
2656
- 'datetime': this.iso8601(timestamp),
2657
- 'currency': this.safeCurrencyCode(undefined, currency),
2658
- 'amount': this.safeNumber(transfer, 'amount'),
2659
- 'fromAccount': undefined,
2660
- 'toAccount': undefined,
2661
- 'status': this.safeString(transfer, 'status'),
2662
- 'info': transfer,
2663
- };
2664
- }
2665
- parseTransferStatus(status) {
2666
- const statuses = {
2667
- 'PROCESSING': 'pending',
2668
- };
2669
- return this.safeString(statuses, status, status);
2670
- }
2671
120
  parseTransferType(transferType) {
2672
121
  const transferTypes = {
2673
122
  'spot': 'TRADE',
@@ -2675,873 +124,4 @@ export default class kucoinfutures extends kucoin {
2675
124
  };
2676
125
  return this.safeStringUpper(transferTypes, transferType, transferType);
2677
126
  }
2678
- /**
2679
- * @method
2680
- * @name kucoinfutures#fetchMyTrades
2681
- * @see https://docs.kucoin.com/futures/#get-fills
2682
- * @description fetch all trades made by the user
2683
- * @param {string} symbol unified market symbol
2684
- * @param {int} [since] the earliest time in ms to fetch trades for
2685
- * @param {int} [limit] the maximum number of trades structures to retrieve
2686
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2687
- * @param {int} [params.until] End time in ms
2688
- * @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)
2689
- * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
2690
- */
2691
- async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2692
- await this.loadMarkets();
2693
- let paginate = false;
2694
- [paginate, params] = this.handleOptionAndParams(params, 'fetchMyTrades', 'paginate');
2695
- if (paginate) {
2696
- return await this.fetchPaginatedCallDynamic('fetchMyTrades', symbol, since, limit, params);
2697
- }
2698
- let request = {
2699
- // orderId (String) [optional] Fills for a specific order (other parameters can be ignored if specified)
2700
- // symbol (String) [optional] Symbol of the contract
2701
- // side (String) [optional] buy or sell
2702
- // type (String) [optional] limit, market, limit_stop or market_stop
2703
- // startAt (long) [optional] Start time (millisecond)
2704
- // endAt (long) [optional] End time (millisecond)
2705
- };
2706
- let market = undefined;
2707
- if (symbol !== undefined) {
2708
- market = this.market(symbol);
2709
- request['symbol'] = market['id'];
2710
- }
2711
- if (since !== undefined) {
2712
- request['startAt'] = since;
2713
- }
2714
- if (limit !== undefined) {
2715
- request['pageSize'] = Math.min(1000, limit);
2716
- }
2717
- [request, params] = this.handleUntilOption('endAt', request, params);
2718
- const response = await this.futuresPrivateGetFills(this.extend(request, params));
2719
- //
2720
- // {
2721
- // "code": "200000",
2722
- // "data": {
2723
- // "currentPage": 1,
2724
- // "pageSize": 1,
2725
- // "totalNum": 251915,
2726
- // "totalPage": 251915,
2727
- // "items": [
2728
- // {
2729
- // "symbol": "XBTUSDM", // Ticker symbol of the contract
2730
- // "tradeId": "5ce24c1f0c19fc3c58edc47c", // Trade ID
2731
- // "orderId": "5ce24c16b210233c36ee321d", // Order ID
2732
- // "side": "sell", // Transaction side
2733
- // "liquidity": "taker", // Liquidity- taker or maker
2734
- // "price": "8302", // Filled price
2735
- // "size": 10, // Filled amount
2736
- // "value": "0.001204529", // Order value
2737
- // "feeRate": "0.0005", // Floating fees
2738
- // "fixFee": "0.00000006", // Fixed fees
2739
- // "feeCurrency": "XBT", // Charging currency
2740
- // "stop": "", // A mark to the stop order type
2741
- // "fee": "0.0000012022", // Transaction fee
2742
- // "orderType": "limit", // Order type
2743
- // "tradeType": "trade", // Trade type (trade, liquidation, ADL or settlement)
2744
- // "createdAt": 1558334496000, // Time the order created
2745
- // "settleCurrency": "XBT", // settlement currency
2746
- // "tradeTime": 1558334496000000000 // trade time in nanosecond
2747
- // }
2748
- // ]
2749
- // }
2750
- // }
2751
- //
2752
- const data = this.safeDict(response, 'data', {});
2753
- const trades = this.safeList(data, 'items', []);
2754
- return this.parseTrades(trades, market, since, limit);
2755
- }
2756
- /**
2757
- * @method
2758
- * @name kucoinfutures#fetchTrades
2759
- * @description get the list of most recent trades for a particular symbol
2760
- * @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-transaction-history
2761
- * @param {string} symbol unified symbol of the market to fetch trades for
2762
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
2763
- * @param {int} [limit] the maximum amount of trades to fetch
2764
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2765
- * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
2766
- */
2767
- async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
2768
- await this.loadMarkets();
2769
- const market = this.market(symbol);
2770
- const request = {
2771
- 'symbol': market['id'],
2772
- };
2773
- const response = await this.futuresPublicGetTradeHistory(this.extend(request, params));
2774
- //
2775
- // {
2776
- // "code": "200000",
2777
- // "data": [
2778
- // {
2779
- // "sequence": 32114961,
2780
- // "side": "buy",
2781
- // "size": 39,
2782
- // "price": "4001.6500000000",
2783
- // "takerOrderId": "61c20742f172110001e0ebe4",
2784
- // "makerOrderId": "61c2073fcfc88100010fcb5d",
2785
- // "tradeId": "61c2074277a0c473e69029b8",
2786
- // "ts": 1640105794099993896 // filled time
2787
- // }
2788
- // ]
2789
- // }
2790
- //
2791
- const trades = this.safeList(response, 'data', []);
2792
- return this.parseTrades(trades, market, since, limit);
2793
- }
2794
- parseTrade(trade, market = undefined) {
2795
- //
2796
- // fetchTrades (public)
2797
- //
2798
- // {
2799
- // "sequence": 32114961,
2800
- // "side": "buy",
2801
- // "size": 39,
2802
- // "price": "4001.6500000000",
2803
- // "takerOrderId": "61c20742f172110001e0ebe4",
2804
- // "makerOrderId": "61c2073fcfc88100010fcb5d",
2805
- // "tradeId": "61c2074277a0c473e69029b8",
2806
- // "ts": 1640105794099993896 // filled time
2807
- // }
2808
- //
2809
- // fetchMyTrades (private) v2
2810
- //
2811
- // {
2812
- // "symbol":"BTC-USDT",
2813
- // "tradeId":"5c35c02709e4f67d5266954e",
2814
- // "orderId":"5c35c02703aa673ceec2a168",
2815
- // "counterOrderId":"5c1ab46003aa676e487fa8e3",
2816
- // "side":"buy",
2817
- // "liquidity":"taker",
2818
- // "forceTaker":true,
2819
- // "price":"0.083",
2820
- // "size":"0.8424304",
2821
- // "funds":"0.0699217232",
2822
- // "fee":"0",
2823
- // "feeRate":"0",
2824
- // "feeCurrency":"USDT",
2825
- // "stop":"",
2826
- // "type":"limit",
2827
- // "createdAt":1547026472000
2828
- // }
2829
- //
2830
- // fetchMyTrades (private) v1
2831
- //
2832
- // {
2833
- // "symbol":"DOGEUSDTM",
2834
- // "tradeId":"620ec41a96bab27b5f4ced56",
2835
- // "orderId":"620ec41a0d1d8a0001560bd0",
2836
- // "side":"sell",
2837
- // "liquidity":"taker",
2838
- // "forceTaker":true,
2839
- // "price":"0.13969",
2840
- // "size":1,
2841
- // "value":"13.969",
2842
- // "feeRate":"0.0006",
2843
- // "fixFee":"0",
2844
- // "feeCurrency":"USDT",
2845
- // "stop":"",
2846
- // "tradeTime":1645134874858018058,
2847
- // "fee":"0.0083814",
2848
- // "settleCurrency":"USDT",
2849
- // "orderType":"market",
2850
- // "tradeType":"trade",
2851
- // "createdAt":1645134874858
2852
- // }
2853
- //
2854
- // watchTrades
2855
- //
2856
- // {
2857
- // "makerUserId": "62286a4d720edf0001e81961",
2858
- // "symbol": "ADAUSDTM",
2859
- // "sequence": 41320766,
2860
- // "side": "sell",
2861
- // "size": 2,
2862
- // "price": 0.35904,
2863
- // "takerOrderId": "636dd9da9857ba00010cfa44",
2864
- // "makerOrderId": "636dd9c8df149d0001e62bc8",
2865
- // "takerUserId": "6180be22b6ab210001fa3371",
2866
- // "tradeId": "636dd9da0000d400d477eca7",
2867
- // "ts": 1668143578987357700
2868
- // }
2869
- //
2870
- const marketId = this.safeString(trade, 'symbol');
2871
- market = this.safeMarket(marketId, market, '-');
2872
- const id = this.safeString2(trade, 'tradeId', 'id');
2873
- const orderId = this.safeString(trade, 'orderId');
2874
- const takerOrMaker = this.safeString(trade, 'liquidity');
2875
- let timestamp = this.safeInteger(trade, 'ts');
2876
- if (timestamp !== undefined) {
2877
- timestamp = this.parseToInt(timestamp / 1000000);
2878
- }
2879
- else {
2880
- timestamp = this.safeInteger(trade, 'createdAt');
2881
- // if it's a historical v1 trade, the exchange returns timestamp in seconds
2882
- if (('dealValue' in trade) && (timestamp !== undefined)) {
2883
- timestamp = timestamp * 1000;
2884
- }
2885
- }
2886
- const priceString = this.safeString2(trade, 'price', 'dealPrice');
2887
- const amountString = this.safeString2(trade, 'size', 'amount');
2888
- const side = this.safeString(trade, 'side');
2889
- let fee = undefined;
2890
- const feeCostString = this.safeString(trade, 'fee');
2891
- if (feeCostString !== undefined) {
2892
- const feeCurrencyId = this.safeString(trade, 'feeCurrency');
2893
- let feeCurrency = this.safeCurrencyCode(feeCurrencyId);
2894
- if (feeCurrency === undefined) {
2895
- feeCurrency = (side === 'sell') ? market['quote'] : market['base'];
2896
- }
2897
- fee = {
2898
- 'cost': feeCostString,
2899
- 'currency': feeCurrency,
2900
- 'rate': this.safeString(trade, 'feeRate'),
2901
- };
2902
- }
2903
- let type = this.safeString2(trade, 'type', 'orderType');
2904
- if (type === 'match') {
2905
- type = undefined;
2906
- }
2907
- let costString = this.safeString2(trade, 'funds', 'value');
2908
- if (costString === undefined) {
2909
- const contractSize = this.safeString(market, 'contractSize');
2910
- const contractCost = Precise.stringMul(priceString, amountString);
2911
- costString = Precise.stringMul(contractCost, contractSize);
2912
- }
2913
- return this.safeTrade({
2914
- 'info': trade,
2915
- 'id': id,
2916
- 'order': orderId,
2917
- 'timestamp': timestamp,
2918
- 'datetime': this.iso8601(timestamp),
2919
- 'symbol': market['symbol'],
2920
- 'type': type,
2921
- 'takerOrMaker': takerOrMaker,
2922
- 'side': side,
2923
- 'price': priceString,
2924
- 'amount': amountString,
2925
- 'cost': costString,
2926
- 'fee': fee,
2927
- }, market);
2928
- }
2929
- /**
2930
- * @method
2931
- * @name kucoinfutures#fetchDeposits
2932
- * @description fetch all deposits made to an account
2933
- * @param {string} code unified currency code
2934
- * @param {int} [since] the earliest time in ms to fetch deposits for
2935
- * @param {int} [limit] the maximum number of deposits structures to retrieve
2936
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2937
- * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
2938
- */
2939
- async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
2940
- await this.loadMarkets();
2941
- const request = {};
2942
- let currency = undefined;
2943
- if (code !== undefined) {
2944
- currency = this.currency(code);
2945
- request['currency'] = currency['id'];
2946
- }
2947
- if (limit !== undefined) {
2948
- request['pageSize'] = limit;
2949
- }
2950
- if (since !== undefined) {
2951
- request['startAt'] = since;
2952
- }
2953
- const response = await this.futuresPrivateGetDepositList(this.extend(request, params));
2954
- //
2955
- // {
2956
- // "code": "200000",
2957
- // "data": {
2958
- // "currentPage": 1,
2959
- // "pageSize": 5,
2960
- // "totalNum": 2,
2961
- // "totalPage": 1,
2962
- // "items": [
2963
- // {
2964
- // "address": "0x5f047b29041bcfdbf0e4478cdfa753a336ba6989",
2965
- // "memo": "5c247c8a03aa677cea2a251d",
2966
- // "amount": 1,
2967
- // "fee": 0.0001,
2968
- // "currency": "KCS",
2969
- // "isInner": false,
2970
- // "walletTxId": "5bbb57386d99522d9f954c5a@test004",
2971
- // "status": "SUCCESS",
2972
- // "createdAt": 1544178843000,
2973
- // "updatedAt": 1544178891000
2974
- // "remark":"foobar"
2975
- // },
2976
- // ...
2977
- // ]
2978
- // }
2979
- // }
2980
- //
2981
- const responseData = response['data']['items'];
2982
- return this.parseTransactions(responseData, currency, since, limit, { 'type': 'deposit' });
2983
- }
2984
- /**
2985
- * @method
2986
- * @name kucoinfutures#fetchWithdrawals
2987
- * @description fetch all withdrawals made from an account
2988
- * @param {string} code unified currency code
2989
- * @param {int} [since] the earliest time in ms to fetch withdrawals for
2990
- * @param {int} [limit] the maximum number of withdrawals structures to retrieve
2991
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2992
- * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
2993
- */
2994
- async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
2995
- await this.loadMarkets();
2996
- const request = {};
2997
- let currency = undefined;
2998
- if (code !== undefined) {
2999
- currency = this.currency(code);
3000
- request['currency'] = currency['id'];
3001
- }
3002
- if (limit !== undefined) {
3003
- request['pageSize'] = limit;
3004
- }
3005
- if (since !== undefined) {
3006
- request['startAt'] = since;
3007
- }
3008
- const response = await this.futuresPrivateGetWithdrawalList(this.extend(request, params));
3009
- //
3010
- // {
3011
- // "code": "200000",
3012
- // "data": {
3013
- // "currentPage": 1,
3014
- // "pageSize": 5,
3015
- // "totalNum": 2,
3016
- // "totalPage": 1,
3017
- // "items": [
3018
- // {
3019
- // "id": "5c2dc64e03aa675aa263f1ac",
3020
- // "address": "0x5bedb060b8eb8d823e2414d82acce78d38be7fe9",
3021
- // "memo": "",
3022
- // "currency": "ETH",
3023
- // "amount": 1.0000000,
3024
- // "fee": 0.0100000,
3025
- // "walletTxId": "3e2414d82acce78d38be7fe9",
3026
- // "isInner": false,
3027
- // "status": "FAILURE",
3028
- // "createdAt": 1546503758000,
3029
- // "updatedAt": 1546504603000
3030
- // },
3031
- // ...
3032
- // ]
3033
- // }
3034
- // }
3035
- //
3036
- const responseData = response['data']['items'];
3037
- return this.parseTransactions(responseData, currency, since, limit, { 'type': 'withdrawal' });
3038
- }
3039
- /**
3040
- * @method
3041
- * @name kucoinfutures#fetchMarketLeverageTiers
3042
- * @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes for a single market
3043
- * @see https://www.kucoin.com/docs/rest/futures-trading/risk-limit/get-futures-risk-limit-level
3044
- * @param {string} symbol unified market symbol
3045
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3046
- * @returns {object} a [leverage tiers structure]{@link https://docs.ccxt.com/?id=leverage-tiers-structure}
3047
- */
3048
- async fetchMarketLeverageTiers(symbol, params = {}) {
3049
- await this.loadMarkets();
3050
- const market = this.market(symbol);
3051
- if (!market['contract']) {
3052
- throw new BadRequest(this.id + ' fetchMarketLeverageTiers() supports contract markets only');
3053
- }
3054
- const request = {
3055
- 'symbol': market['id'],
3056
- };
3057
- const response = await this.futuresPublicGetContractsRiskLimitSymbol(this.extend(request, params));
3058
- //
3059
- // {
3060
- // "code": "200000",
3061
- // "data": [
3062
- // {
3063
- // "symbol": "ETHUSDTM",
3064
- // "level": 1,
3065
- // "maxRiskLimit": 300000,
3066
- // "minRiskLimit": 0,
3067
- // "maxLeverage": 100,
3068
- // "initialMargin": 0.0100000000,
3069
- // "maintainMargin": 0.0050000000
3070
- // },
3071
- // ...
3072
- // ]
3073
- // }
3074
- //
3075
- const data = this.safeList(response, 'data', []);
3076
- return this.parseMarketLeverageTiers(data, market);
3077
- }
3078
- parseMarketLeverageTiers(info, market = undefined) {
3079
- /**
3080
- * @ignore
3081
- * @method
3082
- * @name kucoinfutures#parseMarketLeverageTiers
3083
- * @param {object} info Exchange market response for 1 market
3084
- * @param {object} market CCXT market
3085
- */
3086
- //
3087
- // {
3088
- // "symbol": "ETHUSDTM",
3089
- // "level": 1,
3090
- // "maxRiskLimit": 300000,
3091
- // "minRiskLimit": 0,
3092
- // "maxLeverage": 100,
3093
- // "initialMargin": 0.0100000000,
3094
- // "maintainMargin": 0.0050000000
3095
- // }
3096
- //
3097
- const tiers = [];
3098
- for (let i = 0; i < info.length; i++) {
3099
- const tier = info[i];
3100
- const marketId = this.safeString(tier, 'symbol');
3101
- tiers.push({
3102
- 'tier': this.safeNumber(tier, 'level'),
3103
- 'symbol': this.safeSymbol(marketId, market, undefined, 'contract'),
3104
- 'currency': market['base'],
3105
- 'minNotional': this.safeNumber(tier, 'minRiskLimit'),
3106
- 'maxNotional': this.safeNumber(tier, 'maxRiskLimit'),
3107
- 'maintenanceMarginRate': this.safeNumber(tier, 'maintainMargin'),
3108
- 'maxLeverage': this.safeNumber(tier, 'maxLeverage'),
3109
- 'info': tier,
3110
- });
3111
- }
3112
- return tiers;
3113
- }
3114
- /**
3115
- * @method
3116
- * @name kucoinfutures#fetchFundingRateHistory
3117
- * @see https://www.kucoin.com/docs/rest/futures-trading/funding-fees/get-public-funding-history#request-url
3118
- * @description fetches historical funding rate prices
3119
- * @param {string} symbol unified symbol of the market to fetch the funding rate history for
3120
- * @param {int} [since] not used by kucuoinfutures
3121
- * @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure} to fetch
3122
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3123
- * @param {int} [params.until] end time in ms
3124
- * @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure}
3125
- */
3126
- async fetchFundingRateHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3127
- if (symbol === undefined) {
3128
- throw new ArgumentsRequired(this.id + ' fetchFundingRateHistory() requires a symbol argument');
3129
- }
3130
- await this.loadMarkets();
3131
- const market = this.market(symbol);
3132
- const request = {
3133
- 'symbol': market['id'],
3134
- 'from': 0,
3135
- 'to': this.milliseconds(),
3136
- };
3137
- const until = this.safeInteger(params, 'until');
3138
- params = this.omit(params, ['until']);
3139
- if (since !== undefined) {
3140
- request['from'] = since;
3141
- if (until === undefined) {
3142
- request['to'] = since + 1000 * 8 * 60 * 60 * 100;
3143
- }
3144
- }
3145
- if (until !== undefined) {
3146
- request['to'] = until;
3147
- if (since === undefined) {
3148
- request['to'] = until - 1000 * 8 * 60 * 60 * 100;
3149
- }
3150
- }
3151
- const response = await this.futuresPublicGetContractFundingRates(this.extend(request, params));
3152
- //
3153
- // {
3154
- // "code": "200000",
3155
- // "data": [
3156
- // {
3157
- // "symbol": "IDUSDTM",
3158
- // "fundingRate": 2.26E-4,
3159
- // "timepoint": 1702296000000
3160
- // }
3161
- // ]
3162
- // }
3163
- //
3164
- const data = this.safeList(response, 'data', []);
3165
- return this.parseFundingRateHistories(data, market, since, limit);
3166
- }
3167
- parseFundingRateHistory(info, market = undefined) {
3168
- const timestamp = this.safeInteger(info, 'timepoint');
3169
- const marketId = this.safeString(info, 'symbol');
3170
- return {
3171
- 'info': info,
3172
- 'symbol': this.safeSymbol(marketId, market),
3173
- 'fundingRate': this.safeNumber(info, 'fundingRate'),
3174
- 'timestamp': timestamp,
3175
- 'datetime': this.iso8601(timestamp),
3176
- };
3177
- }
3178
- /**
3179
- * @method
3180
- * @name kucoinfutures#closePosition
3181
- * @description closes open positions for a market
3182
- * @see https://www.kucoin.com/docs/rest/futures-trading/orders/place-order
3183
- * @param {string} symbol Unified CCXT market symbol
3184
- * @param {string} side not used by kucoinfutures closePositions
3185
- * @param {object} [params] extra parameters specific to the okx api endpoint
3186
- * @param {string} [params.clientOrderId] client order id of the order
3187
- * @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/?id=position-structure}
3188
- */
3189
- async closePosition(symbol, side = undefined, params = {}) {
3190
- await this.loadMarkets();
3191
- const market = this.market(symbol);
3192
- let clientOrderId = this.safeString(params, 'clientOrderId');
3193
- const testOrder = this.safeBool(params, 'test', false);
3194
- params = this.omit(params, ['test', 'clientOrderId']);
3195
- if (clientOrderId === undefined) {
3196
- clientOrderId = this.numberToString(this.nonce());
3197
- }
3198
- const request = {
3199
- 'symbol': market['id'],
3200
- 'closeOrder': true,
3201
- 'clientOid': clientOrderId,
3202
- 'type': 'market',
3203
- };
3204
- let response = undefined;
3205
- if (testOrder) {
3206
- response = await this.futuresPrivatePostOrdersTest(this.extend(request, params));
3207
- }
3208
- else {
3209
- response = await this.futuresPrivatePostOrders(this.extend(request, params));
3210
- }
3211
- return this.parseOrder(response, market);
3212
- }
3213
- /**
3214
- * @method
3215
- * @name kucoinfutures#fetchTradingFee
3216
- * @description fetch the trading fees for a market
3217
- * @see https://www.kucoin.com/docs/rest/funding/trade-fee/trading-pair-actual-fee-futures
3218
- * @param {string} symbol unified market symbol
3219
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3220
- * @returns {object} a [fee structure]{@link https://docs.ccxt.com/?id=fee-structure}
3221
- */
3222
- async fetchTradingFee(symbol, params = {}) {
3223
- await this.loadMarkets();
3224
- const market = this.market(symbol);
3225
- const request = {
3226
- 'symbols': market['id'],
3227
- };
3228
- const response = await this.privateGetTradeFees(this.extend(request, params));
3229
- //
3230
- // {
3231
- // "code": "200000",
3232
- // "data": {
3233
- // "symbol": "XBTUSDTM",
3234
- // "takerFeeRate": "0.0006",
3235
- // "makerFeeRate": "0.0002"
3236
- // }
3237
- // }
3238
- //
3239
- const data = this.safeList(response, 'data', []);
3240
- const first = this.safeDict(data, 0);
3241
- const marketId = this.safeString(first, 'symbol');
3242
- return {
3243
- 'info': response,
3244
- 'symbol': this.safeSymbol(marketId, market),
3245
- 'maker': this.safeNumber(first, 'makerFeeRate'),
3246
- 'taker': this.safeNumber(first, 'takerFeeRate'),
3247
- 'percentage': true,
3248
- 'tierBased': true,
3249
- };
3250
- }
3251
- /**
3252
- * @method
3253
- * @name kucoinfutures#fetchMarginMode
3254
- * @description fetches the margin mode of a trading pair
3255
- * @see https://www.kucoin.com/docs/rest/futures-trading/positions/get-margin-mode
3256
- * @param {string} symbol unified symbol of the market to fetch the margin mode for
3257
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3258
- * @returns {object} a [margin mode structure]{@link https://docs.ccxt.com/?id=margin-mode-structure}
3259
- */
3260
- async fetchMarginMode(symbol, params = {}) {
3261
- await this.loadMarkets();
3262
- const market = this.market(symbol);
3263
- const request = {
3264
- 'symbol': market['id'],
3265
- };
3266
- const response = await this.futuresPrivateGetPositionGetMarginMode(this.extend(request, params));
3267
- //
3268
- // {
3269
- // "code": "200000",
3270
- // "data": {
3271
- // "symbol": "XBTUSDTM",
3272
- // "marginMode": "ISOLATED"
3273
- // }
3274
- // }
3275
- //
3276
- const data = this.safeDict(response, 'data', {});
3277
- return this.parseMarginMode(data, market);
3278
- }
3279
- parseMarginMode(marginMode, market = undefined) {
3280
- let marginType = this.safeString(marginMode, 'marginMode');
3281
- marginType = (marginType === 'ISOLATED') ? 'isolated' : 'cross';
3282
- return {
3283
- 'info': marginMode,
3284
- 'symbol': market['symbol'],
3285
- 'marginMode': marginType,
3286
- };
3287
- }
3288
- /**
3289
- * @method
3290
- * @name kucoinfutures#setMarginMode
3291
- * @description set margin mode to 'cross' or 'isolated'
3292
- * @see https://www.kucoin.com/docs/rest/futures-trading/positions/modify-margin-mode
3293
- * @param {string} marginMode 'cross' or 'isolated'
3294
- * @param {string} symbol unified market symbol
3295
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3296
- * @returns {object} response from the exchange
3297
- */
3298
- async setMarginMode(marginMode, symbol = undefined, params = {}) {
3299
- if (symbol === undefined) {
3300
- throw new ArgumentsRequired(this.id + ' setMarginMode() requires a symbol argument');
3301
- }
3302
- this.checkRequiredArgument('setMarginMode', marginMode, 'marginMode', ['cross', 'isolated']);
3303
- await this.loadMarkets();
3304
- const market = this.market(symbol);
3305
- const request = {
3306
- 'symbol': market['id'],
3307
- 'marginMode': marginMode.toUpperCase(),
3308
- };
3309
- const response = await this.futuresPrivatePostPositionChangeMarginMode(this.extend(request, params));
3310
- //
3311
- // {
3312
- // "code": "200000",
3313
- // "data": {
3314
- // "symbol": "XBTUSDTM",
3315
- // "marginMode": "ISOLATED"
3316
- // }
3317
- // }
3318
- //
3319
- const data = this.safeDict(response, 'data', {});
3320
- return this.parseMarginMode(data, market);
3321
- }
3322
- /**
3323
- * @method
3324
- * @name kucoinfutures#setPositionMode
3325
- * @description set hedged to true or false for a market
3326
- * @see https://www.kucoin.com/docs-new/3475097e0
3327
- * @param {bool} hedged set to true to use two way position
3328
- * @param {string} [symbol] not used by bybit setPositionMode ()
3329
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3330
- * @returns {object} a response from the exchange
3331
- */
3332
- async setPositionMode(hedged, symbol = undefined, params = {}) {
3333
- await this.loadMarkets();
3334
- const posMode = hedged ? '1' : '0';
3335
- const request = {
3336
- 'positionMode': posMode,
3337
- };
3338
- const response = await this.futuresPrivatePostPositionSwitchPositionMode(this.extend(request, params));
3339
- //
3340
- // {
3341
- // "code": "200000",
3342
- // "data": {
3343
- // "positionMode": 1
3344
- // }
3345
- // }
3346
- //
3347
- return response;
3348
- }
3349
- /**
3350
- * @method
3351
- * @name kucoinfutures#fetchLeverage
3352
- * @description fetch the set leverage for a market
3353
- * @see https://www.kucoin.com/docs/rest/futures-trading/positions/get-cross-margin-leverage
3354
- * @param {string} symbol unified market symbol
3355
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3356
- * @returns {object} a [leverage structure]{@link https://docs.ccxt.com/?id=leverage-structure}
3357
- */
3358
- async fetchLeverage(symbol, params = {}) {
3359
- let marginMode = undefined;
3360
- [marginMode, params] = this.handleMarginModeAndParams(symbol, params);
3361
- if (marginMode !== 'cross') {
3362
- throw new NotSupported(this.id + ' fetchLeverage() currently supports only params["marginMode"] = "cross"');
3363
- }
3364
- await this.loadMarkets();
3365
- const market = this.market(symbol);
3366
- const request = {
3367
- 'symbol': market['id'],
3368
- };
3369
- const response = await this.futuresPrivateGetGetCrossUserLeverage(this.extend(request, params));
3370
- //
3371
- // {
3372
- // "code": "200000",
3373
- // "data": {
3374
- // "symbol": "XBTUSDTM",
3375
- // "leverage": "3"
3376
- // }
3377
- // }
3378
- //
3379
- const data = this.safeDict(response, 'data', {});
3380
- const parsed = this.parseLeverage(data, market);
3381
- return this.extend(parsed, {
3382
- 'marginMode': marginMode,
3383
- });
3384
- }
3385
- /**
3386
- * @method
3387
- * @name kucoinfutures#setLeverage
3388
- * @description set the level of leverage for a market
3389
- * @see https://www.kucoin.com/docs/rest/futures-trading/positions/modify-cross-margin-leverage
3390
- * @param {float} leverage the rate of leverage
3391
- * @param {string} symbol unified market symbol
3392
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3393
- * @returns {object} response from the exchange
3394
- */
3395
- async setLeverage(leverage, symbol = undefined, params = {}) {
3396
- let marginMode = undefined;
3397
- [marginMode, params] = this.handleMarginModeAndParams(symbol, params);
3398
- if (marginMode !== 'cross') {
3399
- throw new NotSupported(this.id + ' setLeverage() currently supports only params["marginMode"] = "cross"');
3400
- }
3401
- await this.loadMarkets();
3402
- const market = this.market(symbol);
3403
- const request = {
3404
- 'symbol': market['id'],
3405
- 'leverage': leverage.toString(),
3406
- };
3407
- const response = await this.futuresPrivatePostChangeCrossUserLeverage(this.extend(request, params));
3408
- //
3409
- // {
3410
- // "code": "200000",
3411
- // "data": true
3412
- // }
3413
- //
3414
- return this.parseLeverage(response, market);
3415
- }
3416
- parseLeverage(leverage, market = undefined) {
3417
- const marketId = this.safeString(leverage, 'symbol');
3418
- market = this.safeMarket(marketId, market);
3419
- const leverageNum = this.safeInteger(leverage, 'leverage');
3420
- return {
3421
- 'info': leverage,
3422
- 'symbol': market['symbol'],
3423
- 'marginMode': undefined,
3424
- 'longLeverage': leverageNum,
3425
- 'shortLeverage': leverageNum,
3426
- };
3427
- }
3428
- /**
3429
- * @method
3430
- * @name kucoinfutures#fetchPositionsADLRank
3431
- * @description fetches the auto deleveraging rank and risk percentage for a list of symbols
3432
- * @see https://www.kucoin.com/docs-new/rest/futures-trading/positions/get-position-list
3433
- * @param {string[]} [symbols] list of unified market symbols
3434
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3435
- * @returns {object[]} an array of [auto de leverage structures]{@link https://docs.ccxt.com/?id=auto-de-leverage-structure}
3436
- */
3437
- async fetchPositionsADLRank(symbols = undefined, params = {}) {
3438
- await this.loadMarkets();
3439
- symbols = this.marketSymbols(symbols, undefined, true, true, true);
3440
- const response = await this.futuresPrivateGetPositions(params);
3441
- //
3442
- // {
3443
- // "code": "200000",
3444
- // "data": [
3445
- // {
3446
- // "id": "600000000001260912",
3447
- // "symbol": "XBTUSDTM",
3448
- // "crossMode": true,
3449
- // "maintMarginReq": 0.0040000133,
3450
- // "delevPercentage": 0.0,
3451
- // "openingTimestamp": 1768481882915,
3452
- // "currentTimestamp": 1768481897988,
3453
- // "currentQty": 1,
3454
- // "currentCost": 96.9768,
3455
- // "currentComm": 0.05818608,
3456
- // "unrealisedCost": 96.9768,
3457
- // "realisedGrossCost": 0.0,
3458
- // "realisedCost": 0.05818608,
3459
- // "isOpen": true,
3460
- // "markPrice": 96985.6,
3461
- // "markValue": 96.9856,
3462
- // "posCost": 96.9768,
3463
- // "posInit": 4.84884,
3464
- // "posMargin": 4.84928,
3465
- // "posMaint": 0.38794369,
3466
- // "realisedGrossPnl": 0.0,
3467
- // "realisedPnl": -0.05818608,
3468
- // "unrealisedPnl": 0.0088,
3469
- // "unrealisedPnlPcnt": 1.0E-4,
3470
- // "unrealisedRoePcnt": 0.0018,
3471
- // "avgEntryPrice": 96976.8,
3472
- // "liquidationPrice": 52351.69,
3473
- // "bankruptPrice": 52110.87,
3474
- // "settleCurrency": "USDT",
3475
- // "isInverse": false,
3476
- // "maintainMargin": 0.0040000133,
3477
- // "marginMode": "CROSS",
3478
- // "positionSide": "LONG",
3479
- // "leverage": 20,
3480
- // "dealComm": -0.05818608,
3481
- // "fundingFee": 0,
3482
- // "tax": 0
3483
- // }
3484
- // ]
3485
- // }
3486
- //
3487
- const data = this.safeList(response, 'data', []);
3488
- return this.parseADLRanks(data, symbols);
3489
- }
3490
- parseADLRank(info, market = undefined) {
3491
- //
3492
- // fetchPositionsADLRank
3493
- //
3494
- // {
3495
- // "id": "600000000001260912",
3496
- // "symbol": "XBTUSDTM",
3497
- // "crossMode": true,
3498
- // "maintMarginReq": 0.0040000133,
3499
- // "delevPercentage": 0.0,
3500
- // "openingTimestamp": 1768481882915,
3501
- // "currentTimestamp": 1768481897988,
3502
- // "currentQty": 1,
3503
- // "currentCost": 96.9768,
3504
- // "currentComm": 0.05818608,
3505
- // "unrealisedCost": 96.9768,
3506
- // "realisedGrossCost": 0.0,
3507
- // "realisedCost": 0.05818608,
3508
- // "isOpen": true,
3509
- // "markPrice": 96985.6,
3510
- // "markValue": 96.9856,
3511
- // "posCost": 96.9768,
3512
- // "posInit": 4.84884,
3513
- // "posMargin": 4.84928,
3514
- // "posMaint": 0.38794369,
3515
- // "realisedGrossPnl": 0.0,
3516
- // "realisedPnl": -0.05818608,
3517
- // "unrealisedPnl": 0.0088,
3518
- // "unrealisedPnlPcnt": 1.0E-4,
3519
- // "unrealisedRoePcnt": 0.0018,
3520
- // "avgEntryPrice": 96976.8,
3521
- // "liquidationPrice": 52351.69,
3522
- // "bankruptPrice": 52110.87,
3523
- // "settleCurrency": "USDT",
3524
- // "isInverse": false,
3525
- // "maintainMargin": 0.0040000133,
3526
- // "marginMode": "CROSS",
3527
- // "positionSide": "LONG",
3528
- // "leverage": 20,
3529
- // "dealComm": -0.05818608,
3530
- // "fundingFee": 0,
3531
- // "tax": 0
3532
- // }
3533
- //
3534
- const marketId = this.safeString(info, 'symbol');
3535
- const timestamp = this.safeInteger(info, 'openingTimestamp');
3536
- const percentage = this.safeString(info, 'delevPercentage');
3537
- return {
3538
- 'info': info,
3539
- 'symbol': this.safeSymbol(marketId, market, undefined, 'contract'),
3540
- 'rank': undefined,
3541
- 'rating': undefined,
3542
- 'percentage': this.parseNumber(Precise.stringMul(percentage, '100')),
3543
- 'timestamp': timestamp,
3544
- 'datetime': this.iso8601(timestamp),
3545
- };
3546
- }
3547
127
  }