ccxt 4.5.44 → 4.5.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/README.md +9 -12
  2. package/dist/ccxt.browser.min.js +3 -3
  3. package/dist/cjs/ccxt.js +1 -12
  4. package/dist/cjs/src/abstract/kucoinfutures.js +1 -1
  5. package/dist/cjs/src/base/Exchange.js +39 -3
  6. package/dist/cjs/src/base/functions/encode.js +2 -2
  7. package/dist/cjs/src/base/functions/generic.js +8 -2
  8. package/dist/cjs/src/binance.js +11 -2
  9. package/dist/cjs/src/bitget.js +3 -1
  10. package/dist/cjs/src/bitmart.js +144 -21
  11. package/dist/cjs/src/bitrue.js +1 -1
  12. package/dist/cjs/src/bitteam.js +1 -1
  13. package/dist/cjs/src/btcbox.js +1 -1
  14. package/dist/cjs/src/bybit.js +58 -56
  15. package/dist/cjs/src/bydfi.js +102 -100
  16. package/dist/cjs/src/cex.js +1 -0
  17. package/dist/cjs/src/gate.js +264 -170
  18. package/dist/cjs/src/grvt.js +3 -2
  19. package/dist/cjs/src/hyperliquid.js +16 -5
  20. package/dist/cjs/src/kraken.js +4 -2
  21. package/dist/cjs/src/krakenfutures.js +1 -5
  22. package/dist/cjs/src/kucoin.js +4733 -972
  23. package/dist/cjs/src/kucoinfutures.js +14 -3434
  24. package/dist/cjs/src/lbank.js +1 -1
  25. package/dist/cjs/src/okx.js +75 -57
  26. package/dist/cjs/src/paradex.js +2 -6
  27. package/dist/cjs/src/poloniex.js +1 -1
  28. package/dist/cjs/src/pro/bydfi.js +19 -19
  29. package/dist/cjs/src/pro/gate.js +114 -53
  30. package/dist/cjs/src/pro/grvt.js +5 -3
  31. package/dist/cjs/src/pro/htx.js +4 -4
  32. package/dist/cjs/src/pro/kucoin.js +819 -178
  33. package/dist/cjs/src/pro/kucoinfutures.js +95 -1261
  34. package/dist/cjs/src/pro/mexc.js +10 -5
  35. package/dist/cjs/src/pro/okx.js +85 -40
  36. package/index.d.cts +2 -0
  37. package/js/ccxt.d.ts +2 -14
  38. package/js/ccxt.js +2 -10
  39. package/js/src/abstract/bitmart.d.ts +7 -0
  40. package/js/src/abstract/bydfi.d.ts +29 -29
  41. package/js/src/abstract/kraken.d.ts +1 -0
  42. package/js/src/abstract/kucoin.d.ts +46 -2
  43. package/js/src/abstract/kucoinfutures.d.ts +27 -11
  44. package/js/src/base/Exchange.d.ts +13 -1
  45. package/js/src/base/Exchange.js +39 -3
  46. package/js/src/base/functions/encode.js +2 -2
  47. package/js/src/base/functions/generic.js +9 -3
  48. package/js/src/binance.js +11 -2
  49. package/js/src/bitget.js +3 -1
  50. package/js/src/bitmart.d.ts +18 -4
  51. package/js/src/bitmart.js +144 -21
  52. package/js/src/bitrue.js +1 -1
  53. package/js/src/bitteam.js +1 -1
  54. package/js/src/btcbox.js +1 -1
  55. package/js/src/bybit.d.ts +1 -0
  56. package/js/src/bybit.js +58 -56
  57. package/js/src/bydfi.d.ts +31 -31
  58. package/js/src/bydfi.js +102 -100
  59. package/js/src/cex.js +2 -1
  60. package/js/src/gate.d.ts +125 -119
  61. package/js/src/gate.js +264 -170
  62. package/js/src/grvt.js +3 -2
  63. package/js/src/hyperliquid.d.ts +3 -1
  64. package/js/src/hyperliquid.js +16 -5
  65. package/js/src/kraken.js +4 -2
  66. package/js/src/krakenfutures.js +1 -5
  67. package/js/src/kucoin.d.ts +696 -100
  68. package/js/src/kucoin.js +4734 -973
  69. package/js/src/kucoinfutures.d.ts +4 -522
  70. package/js/src/kucoinfutures.js +14 -3434
  71. package/js/src/lbank.js +1 -1
  72. package/js/src/okx.d.ts +1 -0
  73. package/js/src/okx.js +75 -57
  74. package/js/src/paradex.d.ts +0 -1
  75. package/js/src/paradex.js +2 -6
  76. package/js/src/poloniex.js +1 -1
  77. package/js/src/pro/bydfi.d.ts +18 -18
  78. package/js/src/pro/bydfi.js +19 -19
  79. package/js/src/pro/gate.d.ts +30 -1
  80. package/js/src/pro/gate.js +114 -53
  81. package/js/src/pro/grvt.js +5 -3
  82. package/js/src/pro/htx.js +4 -4
  83. package/js/src/pro/kucoin.d.ts +70 -30
  84. package/js/src/pro/kucoin.js +821 -180
  85. package/js/src/pro/kucoinfutures.d.ts +17 -195
  86. package/js/src/pro/kucoinfutures.js +96 -1262
  87. package/js/src/pro/mexc.js +10 -5
  88. package/js/src/pro/okx.d.ts +1 -0
  89. package/js/src/pro/okx.js +85 -40
  90. package/package.json +2 -2
  91. package/dist/cjs/src/abstract/alp.js +0 -11
  92. package/dist/cjs/src/abstract/defx.js +0 -11
  93. package/dist/cjs/src/abstract/timex.js +0 -11
  94. package/dist/cjs/src/alp.js +0 -1059
  95. package/dist/cjs/src/defx.js +0 -2142
  96. package/dist/cjs/src/pro/defx.js +0 -866
  97. package/dist/cjs/src/timex.js +0 -1793
  98. package/js/src/abstract/alp.d.ts +0 -21
  99. package/js/src/abstract/alp.js +0 -5
  100. package/js/src/abstract/defx.d.ts +0 -72
  101. package/js/src/abstract/defx.js +0 -5
  102. package/js/src/abstract/timex.d.ts +0 -65
  103. package/js/src/abstract/timex.js +0 -5
  104. package/js/src/alp.d.ts +0 -209
  105. package/js/src/alp.js +0 -1052
  106. package/js/src/defx.d.ts +0 -348
  107. package/js/src/defx.js +0 -2135
  108. package/js/src/pro/defx.d.ts +0 -236
  109. package/js/src/pro/defx.js +0 -859
  110. package/js/src/timex.d.ts +0 -247
  111. package/js/src/timex.js +0 -1786
@@ -1,2142 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var defx$1 = require('./abstract/defx.js');
6
- var Precise = require('./base/Precise.js');
7
- var number = require('./base/functions/number.js');
8
- var sha256 = require('./static_dependencies/noble-hashes/sha256.js');
9
- var errors = require('./base/errors.js');
10
-
11
- // ---------------------------------------------------------------------------
12
- // ---------------------------------------------------------------------------
13
- /**
14
- * @class defx
15
- * @augments Exchange
16
- */
17
- class defx extends defx$1["default"] {
18
- describe() {
19
- return this.deepExtend(super.describe(), {
20
- 'id': 'defx',
21
- 'name': 'Defx X',
22
- // 'countries': [ '' ],
23
- 'rateLimit': 100,
24
- 'version': 'v1',
25
- 'certified': false,
26
- 'pro': false,
27
- 'hostname': 'defx.com',
28
- 'dex': true,
29
- 'has': {
30
- 'CORS': undefined,
31
- 'spot': false,
32
- 'margin': false,
33
- 'swap': true,
34
- 'future': false,
35
- 'option': false,
36
- 'addMargin': true,
37
- 'cancelAllOrders': true,
38
- 'cancelAllOrdersAfter': false,
39
- 'cancelOrder': true,
40
- 'cancelWithdraw': false,
41
- 'closeAllPositions': true,
42
- 'closePosition': true,
43
- 'createConvertTrade': false,
44
- 'createDepositAddress': false,
45
- 'createMarketBuyOrderWithCost': false,
46
- 'createMarketOrder': false,
47
- 'createMarketOrderWithCost': false,
48
- 'createMarketSellOrderWithCost': false,
49
- 'createOrder': true,
50
- 'createOrderWithTakeProfitAndStopLoss': true,
51
- 'createReduceOnlyOrder': true,
52
- 'createStopLimitOrder': false,
53
- 'createStopLossOrder': false,
54
- 'createStopMarketOrder': false,
55
- 'createStopOrder': false,
56
- 'createTakeProfitOrder': true,
57
- 'createTrailingAmountOrder': false,
58
- 'createTrailingPercentOrder': false,
59
- 'createTriggerOrder': true,
60
- 'fetchAccounts': false,
61
- 'fetchBalance': true,
62
- 'fetchCanceledOrders': true,
63
- 'fetchClosedOrder': false,
64
- 'fetchClosedOrders': true,
65
- 'fetchConvertCurrencies': false,
66
- 'fetchConvertQuote': false,
67
- 'fetchConvertTrade': false,
68
- 'fetchConvertTradeHistory': false,
69
- 'fetchCurrencies': false,
70
- 'fetchDepositAddress': false,
71
- 'fetchDepositAddresses': false,
72
- 'fetchDepositAddressesByNetwork': false,
73
- 'fetchDeposits': false,
74
- 'fetchDepositsWithdrawals': false,
75
- 'fetchFundingHistory': false,
76
- 'fetchFundingInterval': false,
77
- 'fetchFundingIntervals': false,
78
- 'fetchFundingRate': true,
79
- 'fetchFundingRateHistory': false,
80
- 'fetchFundingRates': false,
81
- 'fetchIndexOHLCV': false,
82
- 'fetchLedger': true,
83
- 'fetchLeverage': false,
84
- 'fetchMarginAdjustmentHistory': false,
85
- 'fetchMarginMode': false,
86
- 'fetchMarkets': true,
87
- 'fetchMarkOHLCV': false,
88
- 'fetchMarkPrice': false,
89
- 'fetchMarkPrices': false,
90
- 'fetchMyTrades': true,
91
- 'fetchOHLCV': true,
92
- 'fetchOpenInterestHistory': false,
93
- 'fetchOpenOrder': false,
94
- 'fetchOpenOrders': true,
95
- 'fetchOrder': true,
96
- 'fetchOrderBook': true,
97
- 'fetchOrders': true,
98
- 'fetchOrderTrades': false,
99
- 'fetchPosition': true,
100
- 'fetchPositionHistory': false,
101
- 'fetchPositionMode': false,
102
- 'fetchPositions': true,
103
- 'fetchPositionsHistory': false,
104
- 'fetchPremiumIndexOHLCV': false,
105
- 'fetchStatus': true,
106
- 'fetchTicker': true,
107
- 'fetchTickers': true,
108
- 'fetchTime': true,
109
- 'fetchTrades': true,
110
- 'fetchTradingFee': false,
111
- 'fetchTradingFees': false,
112
- 'fetchTransactions': false,
113
- 'fetchTransfers': false,
114
- 'fetchWithdrawals': false,
115
- 'reduceMargin': false,
116
- 'sandbox': true,
117
- 'setLeverage': true,
118
- 'setMargin': false,
119
- 'setPositionMode': false,
120
- 'transfer': false,
121
- 'withdraw': true,
122
- },
123
- 'timeframes': {
124
- '1m': '1m',
125
- '3m': '3m',
126
- '5m': '5m',
127
- '15m': '15m',
128
- '30m': '30m',
129
- '1h': '1h',
130
- '2h': '2h',
131
- '4h': '4h',
132
- '12h': '12h',
133
- '1d': '1d',
134
- '1w': '1w',
135
- '1M': '1M',
136
- },
137
- 'urls': {
138
- 'logo': 'https://github.com/user-attachments/assets/4e92bace-d7a9-45ea-92be-122168dc87e4',
139
- 'api': {
140
- 'public': 'https://api.{hostname}',
141
- 'private': 'https://api.{hostname}',
142
- },
143
- 'test': {
144
- 'public': 'https://api.testnet.{hostname}',
145
- 'private': 'https://api.testnet.{hostname}',
146
- },
147
- 'www': 'https://defx.com/home',
148
- 'doc': [
149
- 'https://docs.defx.com/docs',
150
- 'https://api-docs.defx.com/',
151
- ],
152
- 'fees': [
153
- '',
154
- ],
155
- 'referral': {
156
- 'url': 'https://app.defx.com/join/6I2CZ7',
157
- },
158
- },
159
- 'api': {
160
- 'v1': {
161
- 'public': {
162
- 'get': {
163
- 'healthcheck/ping': 1,
164
- 'symbols/{symbol}/ohlc': 1,
165
- 'symbols/{symbol}/trades': 1,
166
- 'symbols/{symbol}/prices': 1,
167
- 'symbols/{symbol}/ticker/24hr': 1,
168
- 'symbols/{symbol}/depth/{level}/{slab}': 1,
169
- 'ticker/24HrAgg': 1,
170
- 'c/markets': 1,
171
- 'c/markets/metadata': 1,
172
- 'analytics/market/stats/newUsers': 1,
173
- 'analytics/market/stats/tvl': 1,
174
- 'analytics/market/stats/volumeByInstrument': 1,
175
- 'analytics/market/stats/liquidation': 1,
176
- 'analytics/market/stats/totalVolume': 1,
177
- 'analytics/market/stats/openInterest': 1,
178
- 'analytics/market/stats/totalTrades': 1,
179
- 'analytics/market/stats/basis': 1,
180
- 'analytics/market/stats/insuranceFund': 1,
181
- 'analytics/market/stats/longAndShortRatio': 1,
182
- 'analytics/market/stats/fundingRate': 1,
183
- 'analytics/market/overview': 1,
184
- 'explorer/search': 1,
185
- 'explorer/transactions': 1,
186
- 'explorer/blocks': 1,
187
- },
188
- },
189
- 'private': {
190
- 'get': {
191
- 'api/order/{orderId}': 1,
192
- 'api/orders': 1,
193
- 'api/orders/oco/{parentOrderId}': 1,
194
- 'api/trades': 1,
195
- 'api/position/active': 1,
196
- 'api/users/metadata/leverage': 1,
197
- 'api/users/metadata/feeMultiplier': 1,
198
- 'api/users/metadata/slippage': 1,
199
- 'api/users/referral': 1,
200
- 'api/users/apikeys': 1,
201
- 'connection-signature-message/evm': 1,
202
- 'api/users/profile/wallets': 1,
203
- 'api/notifications': 1,
204
- 'api/wallet/balance': 1,
205
- 'api/wallet/transactions': 1,
206
- 'api/analytics/user/overview': 1,
207
- 'api/analytics/user/pnl': 1,
208
- 'api/analytics/points/overview': 1,
209
- 'api/analytics/points/history': 1,
210
- },
211
- 'post': {
212
- 'api/order': 1,
213
- 'api/position/oco': 1,
214
- 'api/users/socket/listenKeys': 1,
215
- 'api/users/metadata/leverage': 1,
216
- 'api/users/metadata/feeMultiplier': 1,
217
- 'api/users/metadata/slippage': 1,
218
- 'api/users/referral/recordReferralSignup': 1,
219
- 'api/users/apikeys': 1,
220
- 'api/users/profile/wallets': 1,
221
- 'api/transfers/withdrawal': 1,
222
- 'api/transfers/bridge/withdrawal': 1,
223
- },
224
- 'put': {
225
- 'api/position/updatePositionMargin': 1,
226
- 'api/users/socket/listenKeys/{listenKey}': 1,
227
- 'api/users/apikeys/{accessKey}/status': 1,
228
- 'api/users/referral': 1,
229
- },
230
- 'patch': {
231
- 'api/users/apikeys/{accessKey}': 1,
232
- },
233
- 'delete': {
234
- 'api/orders/allOpen': 1,
235
- 'api/order/{orderId}': 1,
236
- 'api/position/{positionId}': 1,
237
- 'api/position/all': 1,
238
- 'api/users/socket/listenKeys/{listenKey}': 1,
239
- 'api/users/apikeys/{accessKey}': 1,
240
- },
241
- },
242
- },
243
- },
244
- 'fees': {
245
- 'trading': {
246
- 'tierBased': true,
247
- 'percentage': true,
248
- 'maker': this.parseNumber('0.0002'),
249
- 'taker': this.parseNumber('0.0005'),
250
- },
251
- },
252
- 'options': {
253
- 'sandboxMode': false,
254
- },
255
- 'features': {
256
- 'spot': undefined,
257
- 'forDerivatives': {
258
- 'sandbox': true,
259
- 'createOrder': {
260
- 'marginMode': false,
261
- 'triggerPrice': true,
262
- // todo implement
263
- 'triggerPriceType': {
264
- 'last': true,
265
- 'mark': true,
266
- 'index': false,
267
- },
268
- 'triggerDirection': false,
269
- 'stopLossPrice': false,
270
- 'takeProfitPrice': false,
271
- 'attachedStopLossTakeProfit': undefined,
272
- 'timeInForce': {
273
- 'IOC': true,
274
- 'FOK': true,
275
- 'PO': true,
276
- 'GTD': false,
277
- },
278
- 'hedged': false,
279
- 'selfTradePrevention': false,
280
- 'trailing': false,
281
- 'iceberg': false,
282
- 'leverage': false,
283
- 'marketBuyByCost': false,
284
- 'marketBuyRequiresPrice': false,
285
- },
286
- 'createOrders': undefined,
287
- 'fetchMyTrades': {
288
- 'marginMode': false,
289
- 'limit': 1000,
290
- 'daysBack': undefined,
291
- 'untilDays': undefined,
292
- 'symbolRequired': false,
293
- },
294
- 'fetchOrder': {
295
- 'marginMode': false,
296
- 'trigger': false,
297
- 'trailing': false,
298
- 'symbolRequired': false,
299
- },
300
- 'fetchOpenOrders': {
301
- 'marginMode': true,
302
- 'limit': 100,
303
- 'trigger': false,
304
- 'trailing': false,
305
- 'symbolRequired': false,
306
- },
307
- 'fetchOrders': {
308
- 'marginMode': false,
309
- 'limit': 500,
310
- 'daysBack': 100000,
311
- 'untilDays': 100000,
312
- 'trigger': false,
313
- 'trailing': false,
314
- 'symbolRequired': false,
315
- },
316
- 'fetchClosedOrders': {
317
- 'marginMode': false,
318
- 'limit': 500,
319
- 'daysBack': 100000,
320
- 'daysBackCanceled': 1,
321
- 'untilDays': 100000,
322
- 'trigger': false,
323
- 'trailing': false,
324
- 'symbolRequired': false,
325
- },
326
- 'fetchOHLCV': {
327
- 'limit': 1000,
328
- },
329
- },
330
- 'swap': {
331
- 'linear': {
332
- 'extends': 'forDerivatives',
333
- },
334
- 'inverse': undefined,
335
- },
336
- 'future': {
337
- 'linear': undefined,
338
- 'inverse': undefined,
339
- },
340
- },
341
- 'commonCurrencies': {},
342
- 'exceptions': {
343
- 'exact': {
344
- '404': errors.BadRequest,
345
- 'missing_auth_signature': errors.AuthenticationError,
346
- 'leverage_higher_than_capped_leverage': errors.BadRequest,
347
- 'order_rejected': errors.InvalidOrder,
348
- 'invalid_order_id': errors.InvalidOrder,
349
- 'filter_lotsize_maxqty': errors.InvalidOrder,
350
- 'filter_notional_min': errors.InvalidOrder,
351
- 'failed_index_price_up_multiplier_filter': errors.InvalidOrder,
352
- 'no_open_orders': errors.InvalidOrder,
353
- 'active_position_not_found': errors.InvalidOrder,
354
- 'position_inactive': errors.InvalidOrder,
355
- 'invalid_position_id': errors.InvalidOrder,
356
- 'Internal server error': errors.ExchangeError, // {"msg":"Internal server error","code":"internal_server_error"}
357
- },
358
- 'broad': {
359
- 'Bad Request': errors.BadRequest, // {"errorMessage":"Bad Request","data":[{"param":"symbol","message":"\"symbol\" must be one of [ETH_USDC, BTC_USDC, BNB_USDC, SOL_USDC, DOGE_USDC, TON_USDC, AVAX_USDC, WIF_USDC, KPEPE_USDC, KSHIB_USDC, KBONK_USDC, MOODENG_USDC, POPCAT_USDC, MOTHER_USDC]"}]}
360
- },
361
- },
362
- 'precisionMode': number.TICK_SIZE,
363
- });
364
- }
365
- /**
366
- * @method
367
- * @name defx#fetchStatus
368
- * @description the latest known information on the availability of the exchange API
369
- * @see https://api-docs.defx.com/#4b03bb3b-a0fa-4dfb-b96c-237bde0ce9e6
370
- * @param {object} [params] extra parameters specific to the exchange API endpoint
371
- * @returns {object} a [status structure]{@link https://docs.ccxt.com/?id=exchange-status-structure}
372
- */
373
- async fetchStatus(params = {}) {
374
- const response = await this.v1PublicGetHealthcheckPing(params);
375
- //
376
- // {
377
- // "success": true,
378
- // "t": 1709705048323,
379
- // "v": "0.0.7",
380
- // "msg": "A programmer’s wife tells him, “While you’re at the grocery store, buy some eggs.” He never comes back."
381
- // }
382
- //
383
- let status = undefined;
384
- const success = this.safeBool(response, 'success');
385
- if (success) {
386
- status = 'ok';
387
- }
388
- else {
389
- status = 'error';
390
- }
391
- return {
392
- 'status': status,
393
- 'updated': undefined,
394
- 'eta': undefined,
395
- 'url': undefined,
396
- 'info': response,
397
- };
398
- }
399
- /**
400
- * @method
401
- * @name defx#fetchTime
402
- * @description fetches the current integer timestamp in milliseconds from the exchange server
403
- * @see https://api-docs.defx.com/#4b03bb3b-a0fa-4dfb-b96c-237bde0ce9e6
404
- * @param {object} [params] extra parameters specific to the exchange API endpoint
405
- * @returns {int} the current integer timestamp in milliseconds from the exchange server
406
- */
407
- async fetchTime(params = {}) {
408
- const response = await this.v1PublicGetHealthcheckPing(params);
409
- //
410
- // {
411
- // "success": true,
412
- // "t": 1709705048323,
413
- // "v": "0.0.7",
414
- // "msg": "A programmer’s wife tells him, “While you’re at the grocery store, buy some eggs.” He never comes back."
415
- // }
416
- //
417
- return this.safeInteger(response, 't');
418
- }
419
- /**
420
- * @method
421
- * @name defx#fetchMarkets
422
- * @description retrieves data on all markets for defx
423
- * @see https://api-docs.defx.com/#73cce0c8-f842-4891-9145-01bb6d61324d
424
- * @see https://api-docs.defx.com/#24fd4e5b-840e-451e-99e0-7fea47c7f371
425
- * @param {object} [params] extra parameters specific to the exchange API endpoint
426
- * @returns {object[]} an array of objects representing market data
427
- */
428
- async fetchMarkets(params = {}) {
429
- const request = {
430
- 'type': 'perps',
431
- };
432
- const promises = [
433
- this.v1PublicGetCMarkets(this.extend(request, params)),
434
- this.v1PublicGetCMarketsMetadata(this.extend(request, params)),
435
- ];
436
- const responses = await Promise.all(promises);
437
- //
438
- // {
439
- // "data": [
440
- // {
441
- // "market": "DOGE_USDC",
442
- // "candleWindows": [
443
- // "1m",
444
- // "3m",
445
- // "5m",
446
- // "15m",
447
- // "30m",
448
- // "1h",
449
- // "2h",
450
- // "4h",
451
- // "12h",
452
- // "1d",
453
- // "1w",
454
- // "1M"
455
- // ],
456
- // "depthSlabs": [
457
- // "0.00001",
458
- // "0.00005",
459
- // "0.0001",
460
- // "0.001",
461
- // "0.01"
462
- // ],
463
- // "filters": [
464
- // {
465
- // "filterType": "LOT_SIZE",
466
- // "minQty": "1.00000",
467
- // "maxQty": "1500000.00000",
468
- // "stepSize": "1.00000"
469
- // },
470
- // {
471
- // "filterType": "MARKET_LOT_SIZE",
472
- // "minQty": "1.00000",
473
- // "maxQty": "750000.00000",
474
- // "stepSize": "1.00000"
475
- // },
476
- // {
477
- // "filterType": "PRICE_FILTER",
478
- // "minPrice": "0.00244000",
479
- // "maxPrice": "30.00000000",
480
- // "tickSize": "0.00001"
481
- // },
482
- // {
483
- // "filterType": "NOTIONAL",
484
- // "minNotional": "100.00000000"
485
- // },
486
- // {
487
- // "filterType": "PERCENT_PRICE_BY_SIDE",
488
- // "bidMultiplierUp": "1.5",
489
- // "bidMultiplierDown": "0.5",
490
- // "askMultiplierUp": "1.5",
491
- // "askMultiplierDown": "0.5"
492
- // },
493
- // {
494
- // "filterType": "INDEX_PRICE_FILTER",
495
- // "multiplierUp": "1.3",
496
- // "multiplierDown": "0.7"
497
- // }
498
- // ],
499
- // "cappedLeverage": "25",
500
- // "maintenanceMarginTiers": [
501
- // {
502
- // "tier": "1",
503
- // "minMaintenanceMargin": "0",
504
- // "maxMaintenanceMargin": "2500",
505
- // "leverage": "25"
506
- // },
507
- // {
508
- // "tier": "2",
509
- // "minMaintenanceMargin": "2500",
510
- // "maxMaintenanceMargin": "12500",
511
- // "leverage": "20"
512
- // },
513
- // {
514
- // "tier": "3",
515
- // "minMaintenanceMargin": "12500",
516
- // "maxMaintenanceMargin": "25000",
517
- // "leverage": "15"
518
- // },
519
- // {
520
- // "tier": "4",
521
- // "minMaintenanceMargin": "25000",
522
- // "maxMaintenanceMargin": "50000",
523
- // "leverage": "10"
524
- // },
525
- // {
526
- // "tier": "5",
527
- // "minMaintenanceMargin": "50000",
528
- // "maxMaintenanceMargin": "75000",
529
- // "leverage": "8"
530
- // },
531
- // {
532
- // "tier": "6",
533
- // "minMaintenanceMargin": "75000",
534
- // "maxMaintenanceMargin": "125000",
535
- // "leverage": "7"
536
- // },
537
- // {
538
- // "tier": "7",
539
- // "minMaintenanceMargin": "125000",
540
- // "maxMaintenanceMargin": "187500",
541
- // "leverage": "5"
542
- // },
543
- // {
544
- // "tier": "8",
545
- // "minMaintenanceMargin": "187500",
546
- // "maxMaintenanceMargin": "250000",
547
- // "leverage": "3"
548
- // },
549
- // {
550
- // "tier": "9",
551
- // "minMaintenanceMargin": "250000",
552
- // "maxMaintenanceMargin": "375000",
553
- // "leverage": "2"
554
- // },
555
- // {
556
- // "tier": "10",
557
- // "minMaintenanceMargin": "375000",
558
- // "maxMaintenanceMargin": "500000",
559
- // "leverage": "1"
560
- // }
561
- // ],
562
- // "fees": {
563
- // "maker": "0.08",
564
- // "taker": "0.1"
565
- // }
566
- // },
567
- // ]
568
- // }
569
- //
570
- const activeMarkets = this.safeList(responses[0], 'data');
571
- const activeMarketsByType = this.indexBy(activeMarkets, 'market');
572
- const marketMetadatas = this.safeList(responses[1], 'data');
573
- for (let i = 0; i < marketMetadatas.length; i++) {
574
- const marketId = marketMetadatas[i]['market'];
575
- let status = undefined;
576
- if (marketId in activeMarketsByType) {
577
- status = activeMarketsByType[marketId]['status'];
578
- }
579
- marketMetadatas[i]['status'] = status;
580
- }
581
- return this.parseMarkets(marketMetadatas);
582
- }
583
- parseMarket(market) {
584
- const marketId = this.safeString(market, 'market');
585
- const parts = marketId.split('_');
586
- const baseId = this.safeString(parts, 0);
587
- const quoteId = this.safeString(parts, 1);
588
- const base = this.safeCurrencyCode(baseId);
589
- const quote = this.safeCurrencyCode(quoteId);
590
- const symbol = base + '/' + quote + ':' + quote;
591
- const filters = this.safeList(market, 'filters', []);
592
- const fees = this.safeDict(market, 'fees', {});
593
- const filtersByType = this.indexBy(filters, 'filterType');
594
- const priceFilter = this.safeDict(filtersByType, 'PRICE_FILTER', {});
595
- const lotFilter = this.safeDict(filtersByType, 'LOT_SIZE', {});
596
- const marketLotFilter = this.safeDict(filtersByType, 'MARKET_LOT_SIZE', {});
597
- const notionalFilter = this.safeDict(filtersByType, 'NOTIONAL', {});
598
- return {
599
- 'id': marketId,
600
- 'symbol': symbol,
601
- 'base': base,
602
- 'quote': quote,
603
- 'settle': quote,
604
- 'baseId': baseId,
605
- 'quoteId': quoteId,
606
- 'settleId': quoteId,
607
- 'type': 'swap',
608
- 'spot': false,
609
- 'margin': false,
610
- 'swap': true,
611
- 'future': false,
612
- 'option': false,
613
- 'active': this.safeString(market, 'status', '') === 'active',
614
- 'contract': true,
615
- 'linear': true,
616
- 'inverse': false,
617
- 'taker': this.safeNumber(fees, 'taker'),
618
- 'maker': this.safeNumber(fees, 'maker'),
619
- 'contractSize': this.parseNumber('1'),
620
- 'expiry': undefined,
621
- 'expiryDatetime': undefined,
622
- 'strike': undefined,
623
- 'optionType': undefined,
624
- 'precision': {
625
- 'amount': this.safeNumber(lotFilter, 'stepSize'),
626
- 'price': this.safeNumber(priceFilter, 'tickSize'),
627
- },
628
- 'limits': {
629
- 'leverage': {
630
- 'min': undefined,
631
- 'max': this.safeNumber(market, 'cappedLeverage'),
632
- },
633
- 'amount': {
634
- 'min': this.safeNumber(lotFilter, 'minQty'),
635
- 'max': this.safeNumber(lotFilter, 'maxQty'),
636
- },
637
- 'price': {
638
- 'min': this.safeNumber(priceFilter, 'minPrice'),
639
- 'max': this.safeNumber(priceFilter, 'maxPrice'),
640
- },
641
- 'cost': {
642
- 'min': this.safeNumber(notionalFilter, 'minNotional'),
643
- 'max': undefined,
644
- },
645
- 'market': {
646
- 'min': this.safeNumber(marketLotFilter, 'minQty'),
647
- 'max': this.safeNumber(marketLotFilter, 'maxQty'),
648
- },
649
- },
650
- 'created': undefined,
651
- 'info': market,
652
- };
653
- }
654
- /**
655
- * @method
656
- * @name defx#fetchTicker
657
- * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
658
- * @see https://api-docs.defx.com/#fe6f81d0-2f3a-4eee-976f-c8fc8f4c5d56
659
- * @param {string} symbol unified symbol of the market to fetch the ticker for
660
- * @param {object} [params] extra parameters specific to the exchange API endpoint
661
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
662
- */
663
- async fetchTicker(symbol, params = {}) {
664
- await this.loadMarkets();
665
- const market = this.market(symbol);
666
- const request = {
667
- 'symbol': market['id'],
668
- };
669
- const response = await this.v1PublicGetSymbolsSymbolTicker24hr(this.extend(request, params));
670
- //
671
- // {
672
- // "symbol": "BTC_USDC",
673
- // "priceChange": "0",
674
- // "priceChangePercent": "0",
675
- // "weightedAvgPrice": "0",
676
- // "lastPrice": "2.00",
677
- // "lastQty": "10.000",
678
- // "bestBidPrice": "1646.00",
679
- // "bestBidQty": "10.000",
680
- // "bestAskPrice": "1646.00",
681
- // "bestAskQty": "10.000",
682
- // "openPrice": "0.00",
683
- // "highPrice": "0.00",
684
- // "lowPrice": "0.00",
685
- // "volume": "0.000",
686
- // "quoteVolume": "0.00",
687
- // "openTime": 1700142658697,
688
- // "closeTime": 1700142658697,
689
- // "openInterestBase": "1.000",
690
- // "openInterestQuote": "0.43112300"
691
- // }
692
- //
693
- return this.parseTicker(response, market);
694
- }
695
- /**
696
- * @method
697
- * @name defx#fetchTickers
698
- * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
699
- * @see https://api-docs.defx.com/#8c61cfbd-40d9-410e-b014-f5b36eba51d1
700
- * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
701
- * @param {object} [params] extra parameters specific to the exchange API endpoint
702
- * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
703
- */
704
- async fetchTickers(symbols = undefined, params = {}) {
705
- await this.loadMarkets();
706
- let market = undefined;
707
- if (symbols !== undefined) {
708
- symbols = this.marketSymbols(symbols);
709
- const firstSymbol = this.safeString(symbols, 0);
710
- if (firstSymbol !== undefined) {
711
- market = this.market(firstSymbol);
712
- }
713
- }
714
- let type = undefined;
715
- [type, params] = this.handleMarketTypeAndParams('fetchTickers', market, params);
716
- if (type === 'spot') {
717
- throw new errors.NotSupported(this.id + ' fetchTickers() is not supported for ' + type + ' markets');
718
- }
719
- const response = await this.v1PublicGetTicker24HrAgg(params);
720
- //
721
- // {
722
- // "ETH_USDC": {
723
- // "priceChange": "0",
724
- // "priceChangePercent": "0",
725
- // "openPrice": "1646.15",
726
- // "highPrice": "1646.15",
727
- // "lowPrice": "1646.15",
728
- // "lastPrice": "1646.15",
729
- // "quoteVolume": "13.17",
730
- // "volume": "0.008",
731
- // "markPrice": "1645.15"
732
- // }
733
- // }
734
- //
735
- return this.parseTickers(response, symbols);
736
- }
737
- parseTicker(ticker, market = undefined) {
738
- //
739
- // fetchTicker
740
- //
741
- // {
742
- // "symbol": "BTC_USDC",
743
- // "priceChange": "0",
744
- // "priceChangePercent": "0",
745
- // "weightedAvgPrice": "0",
746
- // "lastPrice": "2.00",
747
- // "lastQty": "10.000",
748
- // "bestBidPrice": "1646.00",
749
- // "bestBidQty": "10.000",
750
- // "bestAskPrice": "1646.00",
751
- // "bestAskQty": "10.000",
752
- // "openPrice": "0.00",
753
- // "highPrice": "0.00",
754
- // "lowPrice": "0.00",
755
- // "volume": "0.000",
756
- // "quoteVolume": "0.00",
757
- // "openTime": 1700142658697,
758
- // "closeTime": 1700142658697,
759
- // "openInterestBase": "1.000",
760
- // "openInterestQuote": "0.43112300"
761
- // }
762
- //
763
- // fetchTickers
764
- //
765
- // "ETH_USDC": {
766
- // "priceChange": "0",
767
- // "priceChangePercent": "0",
768
- // "openPrice": "1646.15",
769
- // "highPrice": "1646.15",
770
- // "lowPrice": "1646.15",
771
- // "lastPrice": "1646.15",
772
- // "quoteVolume": "13.17",
773
- // "volume": "0.008",
774
- // "markPrice": "1645.15"
775
- // }
776
- //
777
- // fetchMarkPrice
778
- //
779
- // {
780
- // "markPrice": "100.00",
781
- // "indexPrice": "100.00",
782
- // "ltp": "101.34",
783
- // "movingFundingRate": "0.08",
784
- // "payoutFundingRate": "-0.03",
785
- // "nextFundingPayout": 1711555532146
786
- // }
787
- //
788
- const marketId = this.safeString(ticker, 'symbol');
789
- if (marketId !== undefined) {
790
- market = this.market(marketId);
791
- }
792
- const symbol = market['symbol'];
793
- const open = this.safeString(ticker, 'openPrice');
794
- const high = this.safeString(ticker, 'highPrice');
795
- const low = this.safeString(ticker, 'lowPrice');
796
- const close = this.safeString(ticker, 'lastPrice');
797
- const quoteVolume = this.safeString(ticker, 'quoteVolume');
798
- const baseVolume = this.safeString(ticker, 'volume');
799
- const percentage = this.safeString(ticker, 'priceChangePercent');
800
- const change = this.safeString(ticker, 'priceChange');
801
- let ts = this.safeInteger(ticker, 'closeTime');
802
- if (ts === 0) {
803
- ts = undefined;
804
- }
805
- const datetime = this.iso8601(ts);
806
- const bid = this.safeString(ticker, 'bestBidPrice');
807
- const bidVolume = this.safeString(ticker, 'bestBidQty');
808
- const ask = this.safeString(ticker, 'bestAskPrice');
809
- const askVolume = this.safeString(ticker, 'bestAskQty');
810
- return this.safeTicker({
811
- 'symbol': symbol,
812
- 'timestamp': ts,
813
- 'datetime': datetime,
814
- 'high': high,
815
- 'low': low,
816
- 'bid': bid,
817
- 'bidVolume': bidVolume,
818
- 'ask': ask,
819
- 'askVolume': askVolume,
820
- 'vwap': undefined,
821
- 'open': open,
822
- 'close': close,
823
- 'last': undefined,
824
- 'previousClose': undefined,
825
- 'change': change,
826
- 'percentage': percentage,
827
- 'average': undefined,
828
- 'baseVolume': baseVolume,
829
- 'quoteVolume': quoteVolume,
830
- 'markPrice': this.safeString(ticker, 'markPrice'),
831
- 'indexPrice': this.safeString(ticker, 'indexPrice'),
832
- 'info': ticker,
833
- }, market);
834
- }
835
- /**
836
- * @method
837
- * @name defx#fetchOHLCV
838
- * @see https://api-docs.defx.com/#54b71951-1472-4670-b5af-4c2dc41e73d0
839
- * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
840
- * @param {string} symbol unified symbol of the market to fetch OHLCV data for
841
- * @param {string} timeframe the length of time each candle represents
842
- * @param {int} [since] timestamp in ms of the earliest candle to fetch
843
- * @param {int} [limit] max=1000, max=100 when since is defined and is less than (now - (999 * (timeframe in ms)))
844
- * @param {object} [params] extra parameters specific to the exchange API endpoint
845
- * @param {int} [params.until] the latest time in ms to fetch orders for
846
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
847
- */
848
- async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
849
- await this.loadMarkets();
850
- const market = this.market(symbol);
851
- const maxLimit = 1000;
852
- if (limit === undefined) {
853
- limit = maxLimit;
854
- }
855
- limit = Math.min(maxLimit, limit);
856
- const request = {
857
- 'symbol': market['id'],
858
- 'interval': this.safeString(this.timeframes, timeframe, timeframe),
859
- 'limit': limit,
860
- };
861
- const until = this.safeInteger2(params, 'until', 'till');
862
- params = this.omit(params, ['until', 'till']);
863
- request['endTime'] = (until === undefined) ? this.milliseconds() : until;
864
- if (since === undefined) {
865
- request['startTime'] = 0;
866
- }
867
- else {
868
- request['startTime'] = since;
869
- if (until === undefined) {
870
- const timeframeInSeconds = this.parseTimeframe(timeframe);
871
- const timeframeInMilliseconds = timeframeInSeconds * 1000;
872
- const totalTimeframeInMilliseconds = limit * timeframeInMilliseconds;
873
- request['endTime'] = this.sum(since, totalTimeframeInMilliseconds);
874
- }
875
- }
876
- const response = await this.v1PublicGetSymbolsSymbolOhlc(this.extend(request, params));
877
- //
878
- // [
879
- // {
880
- // "symbol": "BTC_USDC",
881
- // "open": "0.00",
882
- // "high": "0.00",
883
- // "low": "0.00",
884
- // "close": "0.00",
885
- // "volume": "0.000",
886
- // "quoteAssetVolume": "0.00",
887
- // "takerBuyAssetVolume": "0.000",
888
- // "takerBuyQuoteAssetVolume": "0.00",
889
- // "numberOfTrades": 0,
890
- // "start": 1702453663894,
891
- // "end": 1702453663894,
892
- // "isClosed": true
893
- // }
894
- // ]
895
- //
896
- return this.parseOHLCVs(response, market, timeframe, since, limit);
897
- }
898
- parseOHLCV(ohlcv, market = undefined) {
899
- // example response in fetchOHLCV
900
- return [
901
- this.safeInteger(ohlcv, 'start'),
902
- this.safeNumber(ohlcv, 'open'),
903
- this.safeNumber(ohlcv, 'high'),
904
- this.safeNumber(ohlcv, 'low'),
905
- this.safeNumber(ohlcv, 'close'),
906
- this.safeNumber(ohlcv, 'volume'),
907
- ];
908
- }
909
- /**
910
- * @method
911
- * @name defx#fetchTrades
912
- * @description get the list of most recent trades for a particular symbol
913
- * @see https://api-docs.defx.com/#5865452f-ea32-4f13-bfbc-03af5f5574fd
914
- * @param {string} symbol unified symbol of the market to fetch trades for
915
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
916
- * @param {int} [limit] the maximum amount of trades to fetch
917
- * @param {object} [params] extra parameters specific to the exchange API endpoint
918
- * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
919
- */
920
- async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
921
- await this.loadMarkets();
922
- const market = this.market(symbol);
923
- const maxLimit = 50;
924
- if (limit === undefined) {
925
- limit = maxLimit;
926
- }
927
- limit = Math.min(maxLimit, limit);
928
- const request = {
929
- 'symbol': market['id'],
930
- 'limit': limit,
931
- };
932
- const response = await this.v1PublicGetSymbolsSymbolTrades(this.extend(request, params));
933
- //
934
- // [
935
- // {
936
- // "buyerMaker": "false",
937
- // "price": "2.0000",
938
- // "qty": "10.0000",
939
- // "symbol": "BTC_USDC",
940
- // "timestamp": "1702453663894"
941
- // }
942
- // ]
943
- //
944
- return this.parseTrades(response, market, since, limit);
945
- }
946
- /**
947
- * @method
948
- * @name defx#fetchMyTrades
949
- * @description fetch all trades made by the user
950
- * @see https://api-docs.defx.com/#06b5b33c-2fc6-48de-896c-fc316f5871a7
951
- * @param {string} symbol unified symbol of the market to fetch trades for
952
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
953
- * @param {int} [limit] the maximum amount of trades to fetch
954
- * @param {object} [params] extra parameters specific to the exchange API endpoint
955
- * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
956
- */
957
- async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
958
- await this.loadMarkets();
959
- const request = {};
960
- if (symbol !== undefined) {
961
- const market = this.market(symbol);
962
- request['symbols'] = market['id'];
963
- }
964
- if (limit !== undefined) {
965
- const maxLimit = 100;
966
- limit = Math.min(maxLimit, limit);
967
- request['pageSize'] = limit;
968
- }
969
- const response = await this.v1PrivateGetApiTrades(this.extend(request, params));
970
- //
971
- // {
972
- // "data": [
973
- // {
974
- // "id": "0192f665-c05b-7ba0-a080-8b6c99083489",
975
- // "orderId": "757730811259651728",
976
- // "time": "2024-11-04T08:58:36.474Z",
977
- // "symbol": "SOL_USDC",
978
- // "side": "SELL",
979
- // "price": "160.43600000",
980
- // "qty": "1.00",
981
- // "fee": "0.08823980",
982
- // "role": "TAKER",
983
- // "pnl": "0.00000000"
984
- // }
985
- // ]
986
- // }
987
- //
988
- const data = this.safeList(response, 'data', []);
989
- return this.parseTrades(data, undefined, since, limit);
990
- }
991
- parseTrade(trade, market = undefined) {
992
- //
993
- // fetchTrades
994
- // {
995
- // "buyerMaker": "false",
996
- // "price": "2.0000",
997
- // "qty": "10.0000",
998
- // "symbol": "BTC_USDC",
999
- // "timestamp": "1702453663894"
1000
- // }
1001
- //
1002
- // fetchMyTrades
1003
- // {
1004
- // "id": "0192f665-c05b-7ba0-a080-8b6c99083489",
1005
- // "orderId": "757730811259651728",
1006
- // "time": "2024-11-04T08:58:36.474Z",
1007
- // "symbol": "SOL_USDC",
1008
- // "side": "SELL",
1009
- // "price": "160.43600000",
1010
- // "qty": "1.00",
1011
- // "fee": "0.08823980",
1012
- // "role": "TAKER",
1013
- // "pnl": "0.00000000"
1014
- // }
1015
- //
1016
- const time = this.safeString(trade, 'time');
1017
- const timestamp = this.safeInteger(trade, 'timestamp', this.parse8601(time));
1018
- const marketId = this.safeString(trade, 'symbol');
1019
- market = this.safeMarket(marketId, market);
1020
- const symbol = market['symbol'];
1021
- const price = this.safeString(trade, 'price');
1022
- const amount = this.safeString(trade, 'qty');
1023
- const id = this.safeString(trade, 'id');
1024
- const oid = this.safeString(trade, 'orderId');
1025
- const takerOrMaker = this.safeStringLower(trade, 'role');
1026
- const buyerMaker = this.safeBool(trade, 'buyerMaker');
1027
- let side = this.safeStringLower(trade, 'side');
1028
- if (buyerMaker !== undefined) {
1029
- if (buyerMaker) {
1030
- side = 'sell';
1031
- }
1032
- else {
1033
- side = 'buy';
1034
- }
1035
- }
1036
- return this.safeTrade({
1037
- 'id': id,
1038
- 'timestamp': timestamp,
1039
- 'datetime': this.iso8601(timestamp),
1040
- 'symbol': symbol,
1041
- 'side': side,
1042
- 'price': price,
1043
- 'amount': amount,
1044
- 'cost': undefined,
1045
- 'order': oid,
1046
- 'takerOrMaker': takerOrMaker,
1047
- 'type': undefined,
1048
- 'fee': {
1049
- 'cost': this.safeString(trade, 'fee'),
1050
- 'currency': 'USDC',
1051
- },
1052
- 'info': trade,
1053
- }, market);
1054
- }
1055
- /**
1056
- * @method
1057
- * @name defx#fetchOrderBook
1058
- * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
1059
- * @see https://api-docs.defx.com/#6c1a2971-8325-4e7d-9962-e0bfcaacf9c4
1060
- * @param {string} symbol unified symbol of the market to fetch the order book for
1061
- * @param {int} [limit] the maximum amount of order book entries to return
1062
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1063
- * @param {string} [params.slab] slab from market.info.depthSlabs
1064
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure} indexed by market symbols
1065
- */
1066
- async fetchOrderBook(symbol, limit = undefined, params = {}) {
1067
- await this.loadMarkets();
1068
- const market = this.market(symbol);
1069
- if (limit === undefined) {
1070
- limit = 10; // limit must be one of [5, 10, 20]
1071
- }
1072
- const marketInfo = this.safeDict(market, 'info', {});
1073
- const slab = this.safeList(marketInfo, 'depthSlabs', []);
1074
- const request = {
1075
- 'symbol': market['id'],
1076
- 'level': limit,
1077
- 'slab': this.safeString(slab, 0),
1078
- };
1079
- const response = await this.v1PublicGetSymbolsSymbolDepthLevelSlab(this.extend(request, params));
1080
- //
1081
- // {
1082
- // "symbol": "ETH_USDC",
1083
- // "level": "5",
1084
- // "slab": "1",
1085
- // "lastTradeTimestamp": "1708313446812",
1086
- // "timestamp": "1708313446812",
1087
- // "bids": [
1088
- // {
1089
- // "price": "1646.16",
1090
- // "qty": "0.001"
1091
- // }
1092
- // ],
1093
- // "asks": [
1094
- // {
1095
- // "price": "1646.16",
1096
- // "qty": "0.001"
1097
- // }
1098
- // ]
1099
- // }
1100
- //
1101
- const timestamp = this.safeInteger(response, 'timestamp');
1102
- return this.parseOrderBook(response, symbol, timestamp, 'bids', 'asks', 'price', 'qty');
1103
- }
1104
- /**
1105
- * @method
1106
- * @name defx#fetchMarkPrice
1107
- * @description fetches mark price for the market
1108
- * @see https://api-docs.defx.com/#12168192-4e7b-4458-a001-e8b80961f0b7
1109
- * @param {string} symbol unified symbol of the market to fetch the ticker for
1110
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1111
- * @param {string} [params.subType] "linear" or "inverse"
1112
- * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
1113
- */
1114
- async fetchMarkPrice(symbol, params = {}) {
1115
- await this.loadMarkets();
1116
- const market = this.market(symbol);
1117
- const request = {
1118
- 'symbol': market['id'],
1119
- };
1120
- const response = await this.v1PublicGetSymbolsSymbolPrices(this.extend(request, params));
1121
- //
1122
- // {
1123
- // "markPrice": "100.00",
1124
- // "indexPrice": "100.00",
1125
- // "ltp": "101.34",
1126
- // "movingFundingRate": "0.08",
1127
- // "payoutFundingRate": "-0.03",
1128
- // "nextFundingPayout": 1711555532146
1129
- // }
1130
- //
1131
- return this.parseTicker(response, market);
1132
- }
1133
- /**
1134
- * @method
1135
- * @name defx#fetchFundingRate
1136
- * @description fetch the current funding rate
1137
- * @see https://api-docs.defx.com/#12168192-4e7b-4458-a001-e8b80961f0b7
1138
- * @param {string} symbol unified market symbol
1139
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1140
- * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/?id=funding-rate-structure}
1141
- */
1142
- async fetchFundingRate(symbol, params = {}) {
1143
- await this.loadMarkets();
1144
- const market = this.market(symbol);
1145
- const request = {
1146
- 'symbol': market['id'],
1147
- };
1148
- const response = await this.v1PublicGetSymbolsSymbolPrices(this.extend(request, params));
1149
- //
1150
- // {
1151
- // "markPrice": "100.00",
1152
- // "indexPrice": "100.00",
1153
- // "ltp": "101.34",
1154
- // "movingFundingRate": "0.08",
1155
- // "payoutFundingRate": "-0.03",
1156
- // "nextFundingPayout": 1711555532146
1157
- // }
1158
- //
1159
- return this.parseFundingRate(response, market);
1160
- }
1161
- parseFundingRate(contract, market = undefined) {
1162
- //
1163
- // {
1164
- // "markPrice": "100.00",
1165
- // "indexPrice": "100.00",
1166
- // "ltp": "101.34",
1167
- // "movingFundingRate": "0.08",
1168
- // "payoutFundingRate": "-0.03",
1169
- // "nextFundingPayout": 1711555532146
1170
- // }
1171
- //
1172
- const markPrice = this.safeNumber(contract, 'markPrice');
1173
- const indexPrice = this.safeNumber(contract, 'indexPrice');
1174
- const fundingRateRaw = this.safeString(contract, 'payoutFundingRate');
1175
- const fundingRate = Precise["default"].stringDiv(fundingRateRaw, '100');
1176
- const fundingTime = this.safeInteger(contract, 'nextFundingPayout');
1177
- return {
1178
- 'info': contract,
1179
- 'symbol': market['symbol'],
1180
- 'markPrice': markPrice,
1181
- 'indexPrice': indexPrice,
1182
- 'interestRate': undefined,
1183
- 'estimatedSettlePrice': undefined,
1184
- 'timestamp': undefined,
1185
- 'datetime': undefined,
1186
- 'fundingRate': this.parseNumber(fundingRate),
1187
- 'fundingTimestamp': fundingTime,
1188
- 'fundingDatetime': this.iso8601(fundingTime),
1189
- 'nextFundingRate': undefined,
1190
- 'nextFundingTimestamp': undefined,
1191
- 'nextFundingDatetime': undefined,
1192
- 'previousFundingRate': undefined,
1193
- 'previousFundingTimestamp': undefined,
1194
- 'previousFundingDatetime': undefined,
1195
- 'interval': undefined,
1196
- };
1197
- }
1198
- /**
1199
- * @method
1200
- * @name defx#fetchBalance
1201
- * @description query for balance and get the amount of funds available for trading or funds locked in orders
1202
- * @see https://api-docs.defx.com/#26414338-14f7-40a1-b246-f8ea8571493f
1203
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1204
- * @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
1205
- */
1206
- async fetchBalance(params = {}) {
1207
- await this.loadMarkets();
1208
- const response = await this.v1PrivateGetApiWalletBalance(params);
1209
- //
1210
- // {
1211
- // "assets": [
1212
- // {
1213
- // "asset": "USDC",
1214
- // "balance": "0.000"
1215
- // }
1216
- // ]
1217
- // }
1218
- //
1219
- const data = this.safeList(response, 'assets');
1220
- return this.parseBalance(data);
1221
- }
1222
- parseBalance(balances) {
1223
- const result = {
1224
- 'info': balances,
1225
- };
1226
- for (let i = 0; i < balances.length; i++) {
1227
- const balance = balances[i];
1228
- const code = this.safeCurrencyCode(this.safeString(balance, 'asset'));
1229
- const account = this.account();
1230
- account['total'] = this.safeString(balance, 'balance');
1231
- result[code] = account;
1232
- }
1233
- return this.safeBalance(result);
1234
- }
1235
- /**
1236
- * @method
1237
- * @name defx#createOrder
1238
- * @description create a trade order
1239
- * @see https://api-docs.defx.com/#ba222d88-8856-4d3c-87a9-7cec07bb2622
1240
- * @param {string} symbol unified symbol of the market to create an order in
1241
- * @param {string} type 'market' or 'limit'
1242
- * @param {string} side 'buy' or 'sell'
1243
- * @param {float} amount how much of currency you want to trade in units of base currency
1244
- * @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
1245
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1246
- * @param {float} [params.triggerPrice] The price a trigger order is triggered at
1247
- * @param {string} [params.reduceOnly] for swap and future reduceOnly is a string 'true' or 'false' that cant be sent with close position set to true or in hedge mode. For spot margin and option reduceOnly is a boolean.
1248
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
1249
- */
1250
- async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1251
- await this.loadMarkets();
1252
- const market = this.market(symbol);
1253
- const reduceOnly = this.safeBool2(params, 'reduceOnly', 'reduce_only');
1254
- params = this.omit(params, ['reduceOnly', 'reduce_only']);
1255
- const orderType = type.toUpperCase();
1256
- const orderSide = side.toUpperCase();
1257
- const request = {
1258
- 'symbol': market['id'],
1259
- 'side': orderSide,
1260
- 'type': orderType,
1261
- };
1262
- const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
1263
- const triggerPrice = this.safeString2(params, 'stopPrice', 'triggerPrice');
1264
- const isMarket = orderType === 'MARKET';
1265
- const isLimit = orderType === 'LIMIT';
1266
- const timeInForce = this.safeStringUpper(params, 'timeInForce');
1267
- if (timeInForce !== undefined) {
1268
- // GTC, IOC, FOK, AON
1269
- request['timeInForce'] = timeInForce;
1270
- }
1271
- else {
1272
- if (isLimit) {
1273
- request['timeInForce'] = 'GTC';
1274
- }
1275
- }
1276
- if (reduceOnly) {
1277
- request['reduceOnly'] = reduceOnly;
1278
- }
1279
- const clientOrderId = this.safeString(params, 'clientOrderId');
1280
- if (clientOrderId !== undefined) {
1281
- request['newClientOrderId'] = clientOrderId;
1282
- }
1283
- if (triggerPrice !== undefined || takeProfitPrice !== undefined) {
1284
- request['workingType'] = 'MARK_PRICE';
1285
- if (takeProfitPrice !== undefined) {
1286
- request['stopPrice'] = this.priceToPrecision(symbol, takeProfitPrice);
1287
- if (isMarket) {
1288
- request['type'] = 'TAKE_PROFIT_MARKET';
1289
- }
1290
- else {
1291
- request['type'] = 'TAKE_PROFIT_LIMIT';
1292
- }
1293
- }
1294
- else {
1295
- request['stopPrice'] = this.priceToPrecision(symbol, triggerPrice);
1296
- if (isMarket) {
1297
- request['type'] = 'STOP_MARKET';
1298
- }
1299
- else {
1300
- request['type'] = 'STOP_LIMIT';
1301
- }
1302
- }
1303
- }
1304
- if (isLimit && price !== undefined) {
1305
- request['price'] = this.priceToPrecision(symbol, price);
1306
- }
1307
- request['quantity'] = this.amountToPrecision(symbol, amount);
1308
- params = this.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id', 'postOnly', 'timeInForce', 'stopPrice', 'triggerPrice', 'takeProfitPrice']);
1309
- const response = await this.v1PrivatePostApiOrder(this.extend(request, params));
1310
- //
1311
- // {
1312
- // "success": true,
1313
- // "data": {
1314
- // "orderId": "",
1315
- // "clientOrderId": "",
1316
- // "cumulativeQty": "",
1317
- // "cumulativeQuote": "",
1318
- // "executedQty": "",
1319
- // "avgPrice": "",
1320
- // "origQty": "",
1321
- // "price": "",
1322
- // "reduceOnly": true,
1323
- // "side": "",
1324
- // "status": "",
1325
- // "symbol": "",
1326
- // "timeInForce": "",
1327
- // "type": "",
1328
- // "workingType": ""
1329
- // }
1330
- // }
1331
- //
1332
- const data = this.safeDict(response, 'data');
1333
- return this.parseOrder(data, market);
1334
- }
1335
- parseOrderStatus(status) {
1336
- if (status !== undefined) {
1337
- const statuses = {
1338
- 'NEW': 'open',
1339
- 'OPEN': 'open',
1340
- 'CANCELLED': 'canceled',
1341
- 'REJECTED': 'rejected',
1342
- 'FILLED': 'closed',
1343
- };
1344
- return this.safeString(statuses, status, status);
1345
- }
1346
- return status;
1347
- }
1348
- parseOrder(order, market = undefined) {
1349
- //
1350
- // {
1351
- // "orderId": "746472647227344528",
1352
- // "createdAt": "2024-10-25T16:49:31.077Z",
1353
- // "updatedAt": "2024-10-25T16:49:31.378Z",
1354
- // "clientOrderId": "0192c495-49c3-71ee-b3d3-7442a2090807",
1355
- // "reduceOnly": false,
1356
- // "side": "SELL",
1357
- // "status": "FILLED",
1358
- // "symbol": "SOL_USDC",
1359
- // "timeInForce": "GTC",
1360
- // "type": "MARKET",
1361
- // "origQty": "0.80",
1362
- // "executedQty": "0.80",
1363
- // "cumulativeQuote": "137.87440000",
1364
- // "avgPrice": "172.34300000",
1365
- // "totalPnL": "0.00000000",
1366
- // "totalFee": "0.07583092",
1367
- // "workingType": null,
1368
- // "postOnly": false,
1369
- // "linkedOrderParentType": null,
1370
- // "isTriggered": false,
1371
- // "slippagePercentage": "5"
1372
- // }
1373
- //
1374
- const orderId = this.safeString(order, 'orderId');
1375
- const clientOrderId = this.safeString(order, 'clientOrderId');
1376
- const marketId = this.safeString(order, 'symbol');
1377
- market = this.safeMarket(marketId, market);
1378
- const symbol = market['symbol'];
1379
- const price = this.safeString(order, 'price');
1380
- const amount = this.safeString(order, 'origQty');
1381
- const orderType = this.safeStringLower(order, 'type');
1382
- const status = this.safeString(order, 'status');
1383
- const side = this.safeStringLower(order, 'side');
1384
- const filled = this.omitZero(this.safeString(order, 'executedQty'));
1385
- const average = this.omitZero(this.safeString(order, 'avgPrice'));
1386
- const timeInForce = this.safeStringLower(order, 'timeInForce');
1387
- let takeProfitPrice = undefined;
1388
- let triggerPrice = undefined;
1389
- if (orderType !== undefined) {
1390
- if (orderType.indexOf('take_profit') >= 0) {
1391
- takeProfitPrice = this.safeString(order, 'stopPrice');
1392
- }
1393
- else {
1394
- triggerPrice = this.safeString(order, 'stopPrice');
1395
- }
1396
- }
1397
- const timestamp = this.parse8601(this.safeString(order, 'createdAt'));
1398
- const lastTradeTimestamp = this.parse8601(this.safeString(order, 'updatedAt'));
1399
- return this.safeOrder({
1400
- 'id': orderId,
1401
- 'clientOrderId': clientOrderId,
1402
- 'timestamp': timestamp,
1403
- 'datetime': this.iso8601(timestamp),
1404
- 'lastTradeTimestamp': lastTradeTimestamp,
1405
- 'lastUpdateTimestamp': lastTradeTimestamp,
1406
- 'status': this.parseOrderStatus(status),
1407
- 'symbol': symbol,
1408
- 'type': orderType,
1409
- 'timeInForce': timeInForce,
1410
- 'postOnly': this.safeBool(order, 'postOnly'),
1411
- 'reduceOnly': this.safeBool(order, 'reduceOnly'),
1412
- 'side': side,
1413
- 'price': price,
1414
- 'triggerPrice': triggerPrice,
1415
- 'takeProfitPrice': takeProfitPrice,
1416
- 'stopLossPrice': undefined,
1417
- 'average': average,
1418
- 'amount': amount,
1419
- 'filled': filled,
1420
- 'remaining': undefined,
1421
- 'cost': undefined,
1422
- 'trades': undefined,
1423
- 'fee': {
1424
- 'cost': this.safeString(order, 'totalFee'),
1425
- 'currency': 'USDC',
1426
- },
1427
- 'info': order,
1428
- }, market);
1429
- }
1430
- /**
1431
- * @method
1432
- * @name defx#cancelOrder
1433
- * @see https://api-docs.defx.com/#09186f23-f8d1-4993-acf4-9974d8a6ddb0
1434
- * @description cancels an open order
1435
- * @param {string} id order id
1436
- * @param {string} symbol unified symbol of the market the order was made in
1437
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1438
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
1439
- */
1440
- async cancelOrder(id, symbol = undefined, params = {}) {
1441
- await this.loadMarkets();
1442
- const request = {
1443
- 'orderId': id,
1444
- 'idType': 'orderId',
1445
- };
1446
- const clientOrderId = this.safeStringN(params, ['clOrdID', 'clientOrderId', 'client_order_id']);
1447
- const isByClientOrder = clientOrderId !== undefined;
1448
- if (isByClientOrder) {
1449
- if (symbol === undefined) {
1450
- throw new errors.ArgumentsRequired(this.id + ' cancelOrder() requires a symbol argument');
1451
- }
1452
- const market = this.market(symbol);
1453
- request['orderId'] = clientOrderId;
1454
- request['idType'] = 'clientOrderId';
1455
- request['symbol'] = market['id'];
1456
- }
1457
- params = this.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id']);
1458
- const response = await this.v1PrivateDeleteApiOrderOrderId(this.extend(request, params));
1459
- //
1460
- // {
1461
- // "success": true
1462
- // }
1463
- //
1464
- const extendParams = { 'symbol': symbol };
1465
- if (isByClientOrder) {
1466
- extendParams['clientOrderId'] = clientOrderId;
1467
- }
1468
- else {
1469
- extendParams['id'] = id;
1470
- }
1471
- return this.extend(this.parseOrder(response), extendParams);
1472
- }
1473
- /**
1474
- * @method
1475
- * @name defx#cancelAllOrders
1476
- * @description cancel all open orders
1477
- * @see https://api-docs.defx.com/#db5531da-3692-4a53-841f-6ad6495f823a
1478
- * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
1479
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1480
- * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
1481
- */
1482
- async cancelAllOrders(symbol = undefined, params = {}) {
1483
- await this.loadMarkets();
1484
- const market = this.market(symbol);
1485
- const request = {
1486
- 'symbols': [market['id']],
1487
- };
1488
- const response = await this.v1PrivateDeleteApiOrdersAllOpen(this.extend(request, params));
1489
- //
1490
- // {
1491
- // "data": {
1492
- // "msg": "The operation of cancel all open order is done."
1493
- // }
1494
- // }
1495
- //
1496
- return [this.safeOrder({ 'info': response })];
1497
- }
1498
- /**
1499
- * @method
1500
- * @name defx#fetchPosition
1501
- * @description fetch data on a single open contract trade position
1502
- * @see https://api-docs.defx.com/#d89dbb86-9aba-4f59-ac5d-a97ff25ea80e
1503
- * @param {string} symbol unified market symbol of the market the position is held in, default is undefined
1504
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1505
- * @returns {object} a [position structure]{@link https://docs.ccxt.com/?id=position-structure}
1506
- */
1507
- async fetchPosition(symbol, params = {}) {
1508
- if (symbol === undefined) {
1509
- throw new errors.ArgumentsRequired(this.id + ' fetchPosition() requires a symbol argument');
1510
- }
1511
- await this.loadMarkets();
1512
- const market = this.market(symbol);
1513
- const request = {
1514
- 'symbol': market['id'],
1515
- };
1516
- const response = await this.v1PrivateGetApiPositionActive(this.extend(request, params));
1517
- //
1518
- // {
1519
- // "data": [
1520
- // {
1521
- // "positionId": "0192c495-4a68-70ee-9081-9d368bd16dfc",
1522
- // "symbol": "SOL_USDC",
1523
- // "positionSide": "SHORT",
1524
- // "entryPrice": "172.34300000",
1525
- // "quantity": "0.80",
1526
- // "marginAmount": "20.11561173",
1527
- // "marginAsset": "USDC",
1528
- // "pnl": "0.00000000"
1529
- // }
1530
- // ]
1531
- // }
1532
- //
1533
- const data = this.safeList(response, 'data', []);
1534
- const first = this.safeDict(data, 0, {});
1535
- return this.parsePosition(first, market);
1536
- }
1537
- /**
1538
- * @method
1539
- * @name defx#fetchPositions
1540
- * @description fetch all open positions
1541
- * @see https://api-docs.defx.com/#d89dbb86-9aba-4f59-ac5d-a97ff25ea80e
1542
- * @param {string[]} [symbols] list of unified market symbols
1543
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1544
- * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/?id=position-structure}
1545
- */
1546
- async fetchPositions(symbols = undefined, params = {}) {
1547
- await this.loadMarkets();
1548
- const response = await this.v1PrivateGetApiPositionActive(params);
1549
- //
1550
- // {
1551
- // "data": [
1552
- // {
1553
- // "positionId": "0192c495-4a68-70ee-9081-9d368bd16dfc",
1554
- // "symbol": "SOL_USDC",
1555
- // "positionSide": "SHORT",
1556
- // "entryPrice": "172.34300000",
1557
- // "quantity": "0.80",
1558
- // "marginAmount": "20.11561173",
1559
- // "marginAsset": "USDC",
1560
- // "pnl": "0.00000000"
1561
- // }
1562
- // ]
1563
- // }
1564
- //
1565
- const positions = this.safeList(response, 'data', []);
1566
- return this.parsePositions(positions, symbols);
1567
- }
1568
- parsePosition(position, market = undefined) {
1569
- //
1570
- // {
1571
- // "positionId": "0192c495-4a68-70ee-9081-9d368bd16dfc",
1572
- // "symbol": "SOL_USDC",
1573
- // "positionSide": "SHORT",
1574
- // "entryPrice": "172.34300000",
1575
- // "quantity": "0.80",
1576
- // "marginAmount": "20.11561173",
1577
- // "marginAsset": "USDC",
1578
- // "pnl": "0.00000000"
1579
- // }
1580
- //
1581
- const marketId = this.safeString(position, 'symbol');
1582
- market = this.safeMarket(marketId, market);
1583
- const size = Precise["default"].stringAbs(this.safeString(position, 'quantity'));
1584
- const side = this.safeStringLower(position, 'positionSide');
1585
- const unrealisedPnl = this.omitZero(this.safeString(position, 'pnl'));
1586
- const entryPrice = this.omitZero(this.safeString(position, 'entryPrice'));
1587
- const initialMargin = this.safeString(position, 'marginAmount');
1588
- return this.safePosition({
1589
- 'info': position,
1590
- 'id': this.safeString(position, 'positionId'),
1591
- 'symbol': market['symbol'],
1592
- 'timestamp': undefined,
1593
- 'datetime': undefined,
1594
- 'lastUpdateTimestamp': undefined,
1595
- 'initialMargin': this.parseNumber(initialMargin),
1596
- 'initialMarginPercentage': undefined,
1597
- 'maintenanceMargin': undefined,
1598
- 'maintenanceMarginPercentage': undefined,
1599
- 'entryPrice': this.parseNumber(entryPrice),
1600
- 'notional': undefined,
1601
- 'leverage': undefined,
1602
- 'unrealizedPnl': this.parseNumber(unrealisedPnl),
1603
- 'realizedPnl': undefined,
1604
- 'contracts': this.parseNumber(size),
1605
- 'contractSize': this.safeNumber(market, 'contractSize'),
1606
- 'marginRatio': undefined,
1607
- 'liquidationPrice': undefined,
1608
- 'markPrice': undefined,
1609
- 'lastPrice': undefined,
1610
- 'collateral': undefined,
1611
- 'marginMode': undefined,
1612
- 'side': side,
1613
- 'percentage': undefined,
1614
- 'stopLossPrice': undefined,
1615
- 'takeProfitPrice': undefined,
1616
- 'hedged': undefined,
1617
- });
1618
- }
1619
- /**
1620
- * @method
1621
- * @name defx#fetchOrder
1622
- * @description fetches information on an order made by the user
1623
- * @see https://api-docs.defx.com/#44f82dd5-26b3-4e1f-b4aa-88ceddd65237
1624
- * @param {string} id the order id
1625
- * @param {string} symbol unified symbol of the market the order was made in
1626
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1627
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
1628
- */
1629
- async fetchOrder(id, symbol = undefined, params = {}) {
1630
- await this.loadMarkets();
1631
- const request = {
1632
- 'orderId': id,
1633
- 'idType': 'orderId',
1634
- };
1635
- const clientOrderId = this.safeStringN(params, ['clOrdID', 'clientOrderId', 'client_order_id']);
1636
- params = this.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id']);
1637
- if (clientOrderId !== undefined) {
1638
- if (symbol === undefined) {
1639
- throw new errors.ArgumentsRequired(this.id + ' fetchOrder() requires a symbol argument');
1640
- }
1641
- const market = this.market(symbol);
1642
- request['orderId'] = clientOrderId;
1643
- request['idType'] = 'clientOrderId';
1644
- request['symbol'] = market['id'];
1645
- }
1646
- const response = await this.v1PrivateGetApiOrderOrderId(this.extend(request, params));
1647
- //
1648
- // {
1649
- // "success": true,
1650
- // "data": {
1651
- // "orderId": "555068654076559792",
1652
- // "createdAt": "2024-05-08T05:45:42.148Z",
1653
- // "updatedAt": "2024-05-08T05:45:42.166Z",
1654
- // "clientOrderId": "dummyClientOrderId",
1655
- // "reduceOnly": false,
1656
- // "side": "SELL",
1657
- // "status": "REJECTED",
1658
- // "symbol": "BTC_USDC",
1659
- // "timeInForce": "GTC",
1660
- // "type": "TAKE_PROFIT_MARKET",
1661
- // "origQty": "1.000",
1662
- // "executedQty": "0.000",
1663
- // "cumulativeQuote": "0.00",
1664
- // "avgPrice": "0.00",
1665
- // "stopPrice": "65000.00",
1666
- // "totalPnL": "0.00",
1667
- // "workingType": "MARK_PRICE",
1668
- // "postOnly": false
1669
- // }
1670
- // }
1671
- //
1672
- const data = this.safeDict(response, 'data');
1673
- return this.parseOrder(data);
1674
- }
1675
- /**
1676
- * @method
1677
- * @name defx#fetchOrders
1678
- * @description fetches information on multiple orders made by the user
1679
- * @see https://api-docs.defx.com/#ab200038-8acb-4170-b05e-4fcb4cc13751
1680
- * @param {string} symbol unified market symbol
1681
- * @param {int} [since] the earliest time in ms to fetch open orders for
1682
- * @param {int} [limit] the maximum number of open order structures to retrieve
1683
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1684
- * @param {int} [params.until] the latest time in ms to fetch orders for
1685
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
1686
- */
1687
- async fetchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1688
- await this.loadMarkets();
1689
- const request = {};
1690
- if (symbol !== undefined) {
1691
- const market = this.market(symbol);
1692
- request['symbols'] = market['id'];
1693
- }
1694
- const until = this.safeInteger(params, 'until');
1695
- if (until !== undefined) {
1696
- params = this.omit(params, 'until');
1697
- request['end'] = this.iso8601(until);
1698
- }
1699
- if (since !== undefined) {
1700
- request['start'] = this.iso8601(since);
1701
- }
1702
- if (limit !== undefined) {
1703
- const maxLimit = 100;
1704
- limit = Math.min(maxLimit, limit);
1705
- request['pageSize'] = limit;
1706
- }
1707
- const response = await this.v1PrivateGetApiOrders(this.extend(request, params));
1708
- //
1709
- // {
1710
- // "data": [
1711
- // {
1712
- // "orderId": "746472647227344528",
1713
- // "createdAt": "2024-10-25T16:49:31.077Z",
1714
- // "updatedAt": "2024-10-25T16:49:31.378Z",
1715
- // "clientOrderId": "0192c495-49c3-71ee-b3d3-7442a2090807",
1716
- // "reduceOnly": false,
1717
- // "side": "SELL",
1718
- // "status": "FILLED",
1719
- // "symbol": "SOL_USDC",
1720
- // "timeInForce": "GTC",
1721
- // "type": "MARKET",
1722
- // "origQty": "0.80",
1723
- // "executedQty": "0.80",
1724
- // "cumulativeQuote": "137.87440000",
1725
- // "avgPrice": "172.34300000",
1726
- // "totalPnL": "0.00000000",
1727
- // "totalFee": "0.07583092",
1728
- // "workingType": null,
1729
- // "postOnly": false,
1730
- // "linkedOrderParentType": null,
1731
- // "isTriggered": false,
1732
- // "slippagePercentage": 5
1733
- // }
1734
- // ]
1735
- // }
1736
- //
1737
- const data = this.safeList(response, 'data', []);
1738
- return this.parseOrders(data, undefined, since, limit);
1739
- }
1740
- /**
1741
- * @method
1742
- * @name defx#fetchOpenOrders
1743
- * @description fetch all unfilled currently open orders
1744
- * @see https://api-docs.defx.com/#ab200038-8acb-4170-b05e-4fcb4cc13751
1745
- * @param {string} symbol unified market symbol
1746
- * @param {int} [since] the earliest time in ms to fetch open orders for
1747
- * @param {int} [limit] the maximum number of open order structures to retrieve
1748
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1749
- * @param {int} [params.until] the latest time in ms to fetch orders for
1750
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
1751
- */
1752
- async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1753
- const req = {
1754
- 'statuses': 'OPEN',
1755
- };
1756
- return await this.fetchOrders(symbol, since, limit, this.extend(req, params));
1757
- }
1758
- /**
1759
- * @method
1760
- * @name defx#fetchClosedOrders
1761
- * @description fetches information on multiple closed orders made by the user
1762
- * @see https://api-docs.defx.com/#ab200038-8acb-4170-b05e-4fcb4cc13751
1763
- * @param {string} symbol unified market symbol
1764
- * @param {int} [since] the earliest time in ms to fetch open orders for
1765
- * @param {int} [limit] the maximum number of open order structures to retrieve
1766
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1767
- * @param {int} [params.until] the latest time in ms to fetch orders for
1768
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
1769
- */
1770
- async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1771
- const req = {
1772
- 'statuses': 'FILLED',
1773
- };
1774
- return await this.fetchOrders(symbol, since, limit, this.extend(req, params));
1775
- }
1776
- /**
1777
- * @method
1778
- * @name defx#fetchCanceledOrders
1779
- * @description fetches information on multiple canceled orders made by the user
1780
- * @see https://api-docs.defx.com/#ab200038-8acb-4170-b05e-4fcb4cc13751
1781
- * @param {string} symbol unified market symbol
1782
- * @param {int} [since] the earliest time in ms to fetch open orders for
1783
- * @param {int} [limit] the maximum number of open order structures to retrieve
1784
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1785
- * @param {int} [params.until] the latest time in ms to fetch orders for
1786
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
1787
- */
1788
- async fetchCanceledOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1789
- const req = {
1790
- 'statuses': 'CANCELED',
1791
- };
1792
- return await this.fetchOrders(symbol, since, limit, this.extend(req, params));
1793
- }
1794
- /**
1795
- * @method
1796
- * @name defx#closePosition
1797
- * @description closes an open position for a market
1798
- * @see https://api-docs.defx.com/#b2c08074-c4d9-4e50-b637-0d6c498fa29e
1799
- * @param {string} symbol unified CCXT market symbol
1800
- * @param {string} [side] one-way mode: 'buy' or 'sell', hedge-mode: 'long' or 'short'
1801
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1802
- * @param {string} [params.positionId] the position id you want to close
1803
- * @param {string} [params.type] 'MARKET' or 'LIMIT'
1804
- * @param {string} [params.quantity] how much of currency you want to trade in units of base currency
1805
- * @param {string} [params.price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
1806
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
1807
- */
1808
- async closePosition(symbol, side = undefined, params = {}) {
1809
- await this.loadMarkets();
1810
- const positionId = this.safeString(params, 'positionId');
1811
- if (positionId === undefined) {
1812
- throw new errors.ArgumentsRequired(this.id + ' closePosition() requires a positionId');
1813
- }
1814
- const type = this.safeStringUpper(params, 'type');
1815
- if (type === undefined) {
1816
- throw new errors.ArgumentsRequired(this.id + ' closePosition() requires a type');
1817
- }
1818
- const quantity = this.safeString(params, 'quantity');
1819
- if (quantity === undefined) {
1820
- throw new errors.ArgumentsRequired(this.id + ' closePosition() requires a quantity');
1821
- }
1822
- const request = {
1823
- 'positionId': positionId,
1824
- 'type': type,
1825
- 'quantity': quantity,
1826
- };
1827
- if (type !== 'MARKET') {
1828
- const price = this.safeString(params, 'price');
1829
- if (price === undefined) {
1830
- throw new errors.ArgumentsRequired(this.id + ' closePosition() requires a price');
1831
- }
1832
- request['price'] = price;
1833
- }
1834
- params = this.omit(params, ['positionId', 'type', 'quantity', 'price']);
1835
- const response = await this.v1PrivateDeleteApiPositionPositionId(this.extend(request, params));
1836
- //
1837
- // {}
1838
- //
1839
- return response;
1840
- }
1841
- /**
1842
- * @method
1843
- * @name defx#closeAllPositions
1844
- * @description closes all open positions for a market type
1845
- * @see https://api-docs.defx.com/#d6f63b43-100e-47a9-998c-8b6c0c72d204
1846
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1847
- * @returns {object[]} A list of [position structures]{@link https://docs.ccxt.com/?id=position-structure}
1848
- */
1849
- async closeAllPositions(params = {}) {
1850
- await this.loadMarkets();
1851
- const response = await this.v1PrivateDeleteApiPositionAll(params);
1852
- //
1853
- // {
1854
- // "data": [
1855
- // {
1856
- // "positionId": "d6ca1a27-28ad-47ae-b244-0bda5ac37b2b",
1857
- // "success": true
1858
- // }
1859
- // ]
1860
- // }
1861
- //
1862
- const data = this.safeList(response, 'data', []);
1863
- return this.parsePositions(data, undefined, params);
1864
- }
1865
- /**
1866
- * @method
1867
- * @name defx#fetchLedger
1868
- * @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
1869
- * @see https://api-docs.defx.com/#38cc8974-794f-48c0-b959-db045a0ee565
1870
- * @param {string} [code] unified currency code
1871
- * @param {int} [since] timestamp in ms of the earliest ledger entry
1872
- * @param {int} [limit] max number of ledger entries to return
1873
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1874
- * @param {int} [params.until] timestamp in ms of the latest ledger entry
1875
- * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
1876
- * @returns {object} a [ledger structure]{@link https://docs.ccxt.com/?id=ledger-entry-structure}
1877
- */
1878
- async fetchLedger(code = undefined, since = undefined, limit = undefined, params = {}) {
1879
- await this.loadMarkets();
1880
- let paginate = false;
1881
- [paginate, params] = this.handleOptionAndParams(params, 'fetchLedger', 'paginate');
1882
- if (paginate) {
1883
- return await this.fetchPaginatedCallDynamic('fetchLedger', code, since, limit, params);
1884
- }
1885
- const request = {};
1886
- if (since !== undefined) {
1887
- request['start'] = since;
1888
- }
1889
- else {
1890
- request['start'] = 0;
1891
- }
1892
- const until = this.safeInteger(params, 'until');
1893
- if (until !== undefined) {
1894
- params = this.omit(params, 'until');
1895
- request['end'] = until;
1896
- }
1897
- else {
1898
- request['end'] = this.milliseconds();
1899
- }
1900
- const response = await this.v1PrivateGetApiWalletTransactions(this.extend(request, params));
1901
- const data = this.safeList(response, 'transactions', []);
1902
- return this.parseLedger(data, undefined, since, limit);
1903
- }
1904
- parseLedgerEntry(item, currency = undefined) {
1905
- //
1906
- // {
1907
- // "id": "01JCSZS6H5VQND3GF5P98SJ29C",
1908
- // "timestamp": 1731744012054,
1909
- // "type": "FundingFee",
1910
- // "amount": "0.02189287",
1911
- // "asset": "USDC",
1912
- // "operation": "CREDIT"
1913
- // }
1914
- //
1915
- const amount = this.safeString(item, 'amount');
1916
- const currencyId = this.safeString(item, 'asset');
1917
- const code = this.safeCurrencyCode(currencyId, currency);
1918
- currency = this.safeCurrency(currencyId, currency);
1919
- const timestamp = this.safeInteger(item, 'timestamp');
1920
- const type = this.safeString(item, 'type');
1921
- return this.safeLedgerEntry({
1922
- 'info': item,
1923
- 'id': this.safeString(item, 'id'),
1924
- 'direction': undefined,
1925
- 'account': undefined,
1926
- 'referenceAccount': undefined,
1927
- 'referenceId': undefined,
1928
- 'type': this.parseLedgerEntryType(type),
1929
- 'currency': code,
1930
- 'amount': this.parseNumber(amount),
1931
- 'timestamp': timestamp,
1932
- 'datetime': this.iso8601(timestamp),
1933
- 'before': undefined,
1934
- 'after': undefined,
1935
- 'status': undefined,
1936
- 'fee': undefined,
1937
- }, currency);
1938
- }
1939
- parseLedgerEntryType(type) {
1940
- const ledgerType = {
1941
- 'FundingFee': 'fee',
1942
- 'FeeRebate': 'fee',
1943
- 'FeeKickback': 'fee',
1944
- 'RealizedPnl': 'trade',
1945
- 'LiquidationClearance': 'trade',
1946
- 'Transfer': 'transfer',
1947
- 'ReferralPayout': 'referral',
1948
- 'Commission': 'commission',
1949
- };
1950
- return this.safeString(ledgerType, type, type);
1951
- }
1952
- /**
1953
- * @method
1954
- * @name defx#withdraw
1955
- * @description make a withdrawal
1956
- * @see https://api-docs.defx.com/#2600f503-63ed-4672-b8f6-69ea5f03203b
1957
- * @param {string} code unified currency code
1958
- * @param {float} amount the amount to withdraw
1959
- * @param {string} address the address to withdraw to
1960
- * @param {string} tag
1961
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1962
- * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/?id=transaction-structure}
1963
- */
1964
- async withdraw(code, amount, address, tag = undefined, params = {}) {
1965
- await this.loadMarkets();
1966
- const currency = this.currency(code);
1967
- const request = {
1968
- 'amount': this.currencyToPrecision(code, amount),
1969
- 'asset': currency['id'],
1970
- // 'network': 'ARB_SEPOLIA',
1971
- // 'chainId': '421614',
1972
- };
1973
- const response = await this.v1PrivatePostApiTransfersBridgeWithdrawal(this.extend(request, params));
1974
- //
1975
- // {
1976
- // "transactionId": "0x301e5851e5aefa733abfbc8b30817ca3b61601e0ddf1df8c59656fb888b0bc9c"
1977
- // }
1978
- //
1979
- return this.parseTransaction(response, currency);
1980
- }
1981
- parseTransaction(transaction, currency = undefined) {
1982
- //
1983
- // withdraw
1984
- //
1985
- // {
1986
- // "transactionId": "0x301e5851e5aefa733abfbc8b30817ca3b61601e0ddf1df8c59656fb888b0bc9c"
1987
- // }
1988
- //
1989
- const txid = this.safeString(transaction, 'transactionId');
1990
- return {
1991
- 'info': transaction,
1992
- 'id': undefined,
1993
- 'txid': txid,
1994
- 'timestamp': undefined,
1995
- 'datetime': undefined,
1996
- 'network': undefined,
1997
- 'address': undefined,
1998
- 'addressTo': undefined,
1999
- 'addressFrom': undefined,
2000
- 'tag': undefined,
2001
- 'tagTo': undefined,
2002
- 'tagFrom': undefined,
2003
- 'type': undefined,
2004
- 'amount': undefined,
2005
- 'currency': this.safeCurrencyCode(undefined, currency),
2006
- 'status': undefined,
2007
- 'updated': undefined,
2008
- 'internal': undefined,
2009
- 'comment': undefined,
2010
- 'fee': undefined,
2011
- };
2012
- }
2013
- /**
2014
- * @method
2015
- * @name defx#setLeverage
2016
- * @description set the level of leverage for a market
2017
- * @see https://api-docs.defx.com/#4cb4ecc4-6c61-4194-8353-be67faaf7ca7
2018
- * @param {float} leverage the rate of leverage
2019
- * @param {string} symbol unified market symbol
2020
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2021
- * @returns {object} response from the exchange
2022
- */
2023
- async setLeverage(leverage, symbol = undefined, params = {}) {
2024
- if (symbol === undefined) {
2025
- throw new errors.ArgumentsRequired(this.id + ' setLeverage() requires a symbol argument');
2026
- }
2027
- await this.loadMarkets();
2028
- const request = {
2029
- 'leverage': this.numberToString(leverage),
2030
- };
2031
- const market = this.market(symbol);
2032
- request['symbol'] = market['id'];
2033
- const response = await this.v1PrivatePostApiUsersMetadataLeverage(this.extend(request, params));
2034
- //
2035
- // {
2036
- // "success": true,
2037
- // "data": {
2038
- // "leverage": "11",
2039
- // "symbol": "BTC_USDC"
2040
- // }
2041
- // }
2042
- //
2043
- const data = this.safeDict(response, 'data', {});
2044
- return this.parseLeverage(data, market);
2045
- }
2046
- parseLeverage(leverage, market = undefined) {
2047
- //
2048
- // "data": {
2049
- // "leverage": "11",
2050
- // "symbol": "BTC_USDC"
2051
- // }
2052
- //
2053
- const marketId = this.safeString(leverage, 'symbol');
2054
- const leverageValue = this.safeInteger(leverage, 'leverage');
2055
- return {
2056
- 'info': leverage,
2057
- 'symbol': this.safeSymbol(marketId, market),
2058
- 'marginMode': undefined,
2059
- 'longLeverage': leverageValue,
2060
- 'shortLeverage': leverageValue,
2061
- };
2062
- }
2063
- nonce() {
2064
- return this.milliseconds();
2065
- }
2066
- sign(path, section = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
2067
- const version = section[0];
2068
- const access = section[1];
2069
- const pathWithParams = this.implodeParams(path, params);
2070
- let url = this.implodeHostname(this.urls['api'][access]);
2071
- url += '/' + version + '/';
2072
- params = this.omit(params, this.extractParams(path));
2073
- params = this.keysort(params);
2074
- if (access === 'public') {
2075
- url += 'open/' + pathWithParams;
2076
- if (Object.keys(params).length) {
2077
- url += '?' + this.rawencode(params);
2078
- }
2079
- }
2080
- else {
2081
- this.checkRequiredCredentials();
2082
- headers = { 'X-DEFX-SOURCE': 'ccxt' };
2083
- url += 'auth/' + pathWithParams;
2084
- const nonce = this.milliseconds().toString();
2085
- let payload = nonce;
2086
- if (method === 'GET' || path === 'api/order/{orderId}') {
2087
- payload += this.rawencode(params);
2088
- if (Object.keys(params).length) {
2089
- url += '?' + this.rawencode(params);
2090
- }
2091
- }
2092
- else {
2093
- if (params !== undefined) {
2094
- body = this.json(params);
2095
- payload += body;
2096
- }
2097
- headers['Content-Type'] = 'application/json';
2098
- }
2099
- const signature = this.hmac(this.encode(payload), this.encode(this.secret), sha256.sha256);
2100
- headers['X-DEFX-APIKEY'] = this.apiKey;
2101
- headers['X-DEFX-TIMESTAMP'] = nonce;
2102
- headers['X-DEFX-SIGNATURE'] = signature;
2103
- }
2104
- return { 'url': url, 'method': method, 'body': body, 'headers': headers };
2105
- }
2106
- handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
2107
- if (!response) {
2108
- return undefined; // fallback to default error handler
2109
- }
2110
- // {"errorCode":404,"errorMessage":"Not Found"}
2111
- // {"msg":"Missing auth signature","code":"missing_auth_signature"}
2112
- // {"success":false,"err":{"msg":"Invalid order id","code":"invalid_order_id"}}
2113
- const success = this.safeBool(response, 'success');
2114
- const err = this.safeDict(response, 'err', response);
2115
- const errorCode = this.safeString2(err, 'errorCode', 'code');
2116
- if (!success) {
2117
- const feedback = this.id + ' ' + this.json(response);
2118
- this.throwBroadlyMatchedException(this.exceptions['broad'], body, feedback);
2119
- this.throwExactlyMatchedException(this.exceptions['exact'], errorCode, feedback);
2120
- }
2121
- return undefined;
2122
- }
2123
- defaultNetworkCodeForCurrency(code) {
2124
- const currencyItem = this.currency(code);
2125
- const networks = currencyItem['networks'];
2126
- const networkKeys = Object.keys(networks);
2127
- for (let i = 0; i < networkKeys.length; i++) {
2128
- const network = networkKeys[i];
2129
- if (network === 'ETH') {
2130
- return network;
2131
- }
2132
- }
2133
- // if it was not returned according to above options, then return the first network of currency
2134
- return this.safeValue(networkKeys, 0);
2135
- }
2136
- setSandboxMode(enable) {
2137
- super.setSandboxMode(enable);
2138
- this.options['sandboxMode'] = enable;
2139
- }
2140
- }
2141
-
2142
- exports["default"] = defx;