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