ccxt 4.5.63 → 4.5.64

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 (124) hide show
  1. package/README.md +6 -8
  2. package/dist/ccxt.browser.min.js +4 -4
  3. package/dist/cjs/ccxt.js +6 -12
  4. package/dist/cjs/src/aster.js +2 -2
  5. package/dist/cjs/src/base/Exchange.js +34 -3
  6. package/dist/cjs/src/bitget.js +5 -3
  7. package/dist/cjs/src/bitmex.js +1 -1
  8. package/dist/cjs/src/bitstamp.js +2 -1
  9. package/dist/cjs/src/bitvavo.js +1 -0
  10. package/dist/cjs/src/btcbox.js +1 -1
  11. package/dist/cjs/src/bullish.js +1 -1
  12. package/dist/cjs/src/bybiteu.js +3 -0
  13. package/dist/cjs/src/coinbase.js +3 -2
  14. package/dist/cjs/src/coinbaseinternational.js +1 -1
  15. package/dist/cjs/src/delta.js +23 -1
  16. package/dist/cjs/src/derive.js +1 -1
  17. package/dist/cjs/src/digifinex.js +12 -0
  18. package/dist/cjs/src/dydx.js +2 -2
  19. package/dist/cjs/src/extended.js +1 -1
  20. package/dist/cjs/src/gateeu.js +1 -0
  21. package/dist/cjs/src/grvt.js +1 -1
  22. package/dist/cjs/src/hashkey.js +127 -6
  23. package/dist/cjs/src/hibachi.js +20 -10
  24. package/dist/cjs/src/hyperliquid.js +1 -1
  25. package/dist/cjs/src/kraken.js +2 -0
  26. package/dist/cjs/src/kucoin.js +1 -1
  27. package/dist/cjs/src/kucoineu.js +3 -0
  28. package/dist/cjs/src/lighter.js +6 -4
  29. package/dist/cjs/src/mudrex.js +1328 -0
  30. package/dist/cjs/src/myokx.js +3 -0
  31. package/dist/cjs/src/okxus.js +1 -5
  32. package/dist/cjs/src/onetrading.js +1 -0
  33. package/dist/cjs/src/pacifica.js +1 -1
  34. package/dist/cjs/src/poloniex.js +1 -1
  35. package/dist/cjs/src/pro/bingx.js +4 -2
  36. package/dist/cjs/src/pro/bitget.js +9 -7
  37. package/dist/cjs/src/pro/grvt.js +1 -1
  38. package/dist/cjs/src/pro/hashkey.js +1 -1
  39. package/dist/cjs/src/pro/kraken.js +1 -1
  40. package/dist/cjs/src/pro/mudrex.js +226 -0
  41. package/dist/cjs/src/pro/okxus.js +1 -1
  42. package/js/ccxt.d.ts +8 -14
  43. package/js/ccxt.js +6 -10
  44. package/js/src/abstract/binance.d.ts +3 -0
  45. package/js/src/abstract/binancecoinm.d.ts +3 -0
  46. package/js/src/abstract/binanceus.d.ts +3 -0
  47. package/js/src/abstract/binanceusdm.d.ts +3 -0
  48. package/js/src/abstract/bybit.d.ts +39 -0
  49. package/js/src/abstract/bybiteu.d.ts +39 -0
  50. package/js/src/abstract/coincheck.d.ts +3 -0
  51. package/js/src/abstract/coinsph.d.ts +8 -1
  52. package/js/src/abstract/kucoineu.js +0 -6
  53. package/js/src/abstract/mudrex.d.ts +33 -0
  54. package/js/src/aster.js +2 -2
  55. package/js/src/base/Exchange.d.ts +10 -1
  56. package/js/src/base/Exchange.js +34 -3
  57. package/js/src/bitget.js +5 -3
  58. package/js/src/bitmex.js +1 -1
  59. package/js/src/bitstamp.js +2 -1
  60. package/js/src/bitvavo.js +1 -0
  61. package/js/src/btcbox.js +1 -1
  62. package/js/src/bullish.js +1 -1
  63. package/js/src/bybiteu.js +3 -0
  64. package/js/src/coinbase.js +3 -2
  65. package/js/src/coinbaseinternational.js +1 -1
  66. package/js/src/delta.d.ts +12 -0
  67. package/js/src/delta.js +23 -1
  68. package/js/src/derive.js +1 -1
  69. package/js/src/digifinex.d.ts +12 -0
  70. package/js/src/digifinex.js +12 -0
  71. package/js/src/dydx.d.ts +2 -2
  72. package/js/src/dydx.js +2 -2
  73. package/js/src/extended.js +1 -1
  74. package/js/src/gateeu.js +1 -0
  75. package/js/src/grvt.d.ts +1 -1
  76. package/js/src/grvt.js +1 -1
  77. package/js/src/hashkey.d.ts +40 -3
  78. package/js/src/hashkey.js +127 -6
  79. package/js/src/hibachi.d.ts +9 -5
  80. package/js/src/hibachi.js +20 -10
  81. package/js/src/hyperliquid.js +1 -1
  82. package/js/src/kraken.js +2 -0
  83. package/js/src/kucoin.js +1 -1
  84. package/js/src/kucoineu.js +3 -0
  85. package/js/src/lighter.js +6 -4
  86. package/js/src/mudrex.d.ts +310 -0
  87. package/js/src/mudrex.js +1321 -0
  88. package/js/src/myokx.js +3 -0
  89. package/js/src/okxus.js +1 -5
  90. package/js/src/onetrading.js +1 -0
  91. package/js/src/pacifica.js +1 -1
  92. package/js/src/poloniex.js +1 -1
  93. package/js/src/pro/bingx.js +4 -2
  94. package/js/src/pro/bitget.js +9 -7
  95. package/js/src/pro/grvt.d.ts +1 -1
  96. package/js/src/pro/grvt.js +1 -1
  97. package/js/src/pro/hashkey.d.ts +1 -1
  98. package/js/src/pro/hashkey.js +1 -1
  99. package/js/src/pro/kraken.js +1 -1
  100. package/js/src/pro/mudrex.d.ts +23 -0
  101. package/js/src/pro/mudrex.js +219 -0
  102. package/js/src/pro/okxus.js +1 -1
  103. package/package.json +3 -3
  104. package/dist/cjs/src/abstract/coinmetro.js +0 -11
  105. package/dist/cjs/src/abstract/novadax.js +0 -11
  106. package/dist/cjs/src/ascendex.js +0 -3780
  107. package/dist/cjs/src/coinmetro.js +0 -2030
  108. package/dist/cjs/src/novadax.js +0 -1678
  109. package/dist/cjs/src/pro/ascendex.js +0 -1013
  110. package/js/src/abstract/ascendex.d.ts +0 -80
  111. package/js/src/abstract/coinmetro.d.ts +0 -37
  112. package/js/src/abstract/coinmetro.js +0 -5
  113. package/js/src/abstract/novadax.d.ts +0 -32
  114. package/js/src/abstract/novadax.js +0 -5
  115. package/js/src/ascendex.d.ts +0 -436
  116. package/js/src/ascendex.js +0 -3773
  117. package/js/src/coinmetro.d.ts +0 -245
  118. package/js/src/coinmetro.js +0 -2023
  119. package/js/src/novadax.d.ts +0 -279
  120. package/js/src/novadax.js +0 -1671
  121. package/js/src/pro/ascendex.d.ts +0 -99
  122. package/js/src/pro/ascendex.js +0 -1006
  123. /package/dist/cjs/src/abstract/{ascendex.js → mudrex.js} +0 -0
  124. /package/js/src/abstract/{ascendex.js → mudrex.js} +0 -0
@@ -1,2023 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- import Exchange from './abstract/coinmetro.js';
3
- import { ArgumentsRequired, BadRequest, BadSymbol, InsufficientFunds, InvalidOrder, ExchangeError, OrderNotFound, PermissionDenied, RateLimitExceeded } from './base/errors.js';
4
- import { TICK_SIZE } from './base/functions/number.js';
5
- import { Precise } from './base/Precise.js';
6
- // ---------------------------------------------------------------------------
7
- /**
8
- * @class coinmetro
9
- * @augments Exchange
10
- */
11
- export default class coinmetro extends Exchange {
12
- describe() {
13
- return this.deepExtend(super.describe(), {
14
- 'id': 'coinmetro',
15
- 'name': 'Coinmetro',
16
- 'countries': ['EE'], // Republic of Estonia
17
- 'version': 'v1',
18
- 'rateLimit': 200, // 1 request per 200 ms, 20 per minute, 300 per hour, 1k per day
19
- 'certified': false,
20
- 'pro': false,
21
- 'has': {
22
- 'CORS': undefined,
23
- 'spot': true,
24
- 'margin': true,
25
- 'swap': false,
26
- 'future': false,
27
- 'option': false,
28
- 'addMargin': false,
29
- 'borrowCrossMargin': true,
30
- 'borrowIsolatedMargin': false,
31
- 'cancelAllOrders': false,
32
- 'cancelOrder': true,
33
- 'cancelOrders': false,
34
- 'closeAllPositions': false,
35
- 'closePosition': true,
36
- 'createDepositAddress': false,
37
- 'createOrder': true,
38
- 'createPostOnlyOrder': false,
39
- 'createReduceOnlyOrder': false,
40
- 'createStopLimitOrder': true,
41
- 'createStopMarketOrder': true,
42
- 'createStopOrder': true,
43
- 'deposit': false,
44
- 'editOrder': false,
45
- 'fetchAccounts': false,
46
- 'fetchBalance': true,
47
- 'fetchBidsAsks': true,
48
- 'fetchBorrowInterest': false,
49
- 'fetchBorrowRateHistories': false,
50
- 'fetchBorrowRateHistory': false,
51
- 'fetchCanceledAndClosedOrders': true,
52
- 'fetchCanceledOrders': false,
53
- 'fetchClosedOrder': false,
54
- 'fetchClosedOrders': false,
55
- 'fetchCrossBorrowRate': false,
56
- 'fetchCrossBorrowRates': false,
57
- 'fetchCurrencies': true,
58
- 'fetchDeposit': false,
59
- 'fetchDepositAddress': false,
60
- 'fetchDepositAddresses': false,
61
- 'fetchDepositAddressesByNetwork': false,
62
- 'fetchDeposits': false,
63
- 'fetchDepositsWithdrawals': false,
64
- 'fetchDepositWithdrawFee': false,
65
- 'fetchDepositWithdrawFees': false,
66
- 'fetchFundingHistory': false,
67
- 'fetchFundingRate': false,
68
- 'fetchFundingRateHistory': false,
69
- 'fetchFundingRates': false,
70
- 'fetchIndexOHLCV': false,
71
- 'fetchIsolatedBorrowRate': false,
72
- 'fetchIsolatedBorrowRates': false,
73
- 'fetchL3OrderBook': false,
74
- 'fetchLedger': true,
75
- 'fetchLeverage': false,
76
- 'fetchLeverageTiers': false,
77
- 'fetchMarketLeverageTiers': false,
78
- 'fetchMarkets': true,
79
- 'fetchMarkOHLCV': false,
80
- 'fetchMyTrades': true,
81
- 'fetchOHLCV': true,
82
- 'fetchOpenInterestHistory': false,
83
- 'fetchOpenOrder': false,
84
- 'fetchOpenOrders': true,
85
- 'fetchOrder': true,
86
- 'fetchOrderBook': true,
87
- 'fetchOrderBooks': false,
88
- 'fetchOrders': false,
89
- 'fetchOrderTrades': false,
90
- 'fetchPosition': false,
91
- 'fetchPositions': false,
92
- 'fetchPositionsRisk': false,
93
- 'fetchPremiumIndexOHLCV': false,
94
- 'fetchStatus': false,
95
- 'fetchTicker': false,
96
- 'fetchTickers': true,
97
- 'fetchTime': false,
98
- 'fetchTrades': true,
99
- 'fetchTradingFee': false,
100
- 'fetchTradingFees': false,
101
- 'fetchTradingLimits': false,
102
- 'fetchTransactionFee': false,
103
- 'fetchTransactionFees': false,
104
- 'fetchTransactions': false,
105
- 'fetchTransfers': false,
106
- 'fetchWithdrawal': false,
107
- 'fetchWithdrawals': false,
108
- 'fetchWithdrawalWhitelist': false,
109
- 'reduceMargin': false,
110
- 'repayCrossMargin': false,
111
- 'repayIsolatedMargin': false,
112
- 'sandbox': true,
113
- 'setLeverage': false,
114
- 'setMargin': false,
115
- 'setMarginMode': false,
116
- 'setPositionMode': false,
117
- 'signIn': false,
118
- 'transfer': false,
119
- 'withdraw': false,
120
- 'ws': false,
121
- },
122
- 'timeframes': {
123
- '1m': '60000',
124
- '5m': '300000',
125
- '30m': '1800000',
126
- '4h': '14400000',
127
- '1d': '86400000',
128
- },
129
- 'urls': {
130
- 'logo': 'https://github.com/ccxt/ccxt/assets/43336371/e86f87ec-6ba3-4410-962b-f7988c5db539',
131
- 'api': {
132
- 'public': 'https://api.coinmetro.com',
133
- 'private': 'https://api.coinmetro.com',
134
- },
135
- 'test': {
136
- 'public': 'https://api.coinmetro.com/open',
137
- 'private': 'https://api.coinmetro.com/open',
138
- },
139
- 'www': 'https://coinmetro.com/',
140
- 'doc': [
141
- 'https://documenter.getpostman.com/view/3653795/SVfWN6KS',
142
- ],
143
- 'fees': 'https://help.coinmetro.com/hc/en-gb/articles/6844007317789-What-are-the-fees-on-Coinmetro-',
144
- 'referral': 'https://go.coinmetro.com/?ref=crypto24',
145
- },
146
- 'api': {
147
- 'public': {
148
- 'get': {
149
- 'demo/temp': 1,
150
- 'exchange/candles/{pair}/{timeframe}/{from}/{to}': 3,
151
- 'exchange/prices': 1,
152
- 'exchange/ticks/{pair}/{from}': 3,
153
- 'assets': 1,
154
- 'markets': 1,
155
- 'exchange/book/{pair}': 3,
156
- 'exchange/bookUpdates/{pair}/{from}': 1, // not unified
157
- },
158
- },
159
- 'private': {
160
- 'get': {
161
- 'users/balances': 1,
162
- 'users/wallets': 1,
163
- 'users/wallets/history/{since}': 1.67,
164
- 'exchange/orders/status/{orderID}': 1,
165
- 'exchange/orders/active': 1,
166
- 'exchange/orders/history/{since}': 1.67,
167
- 'exchange/fills/{since}': 1.67,
168
- 'exchange/margin': 1, // not unified
169
- },
170
- 'post': {
171
- 'jwt': 1, // not unified
172
- 'jwtDevice': 1, // not unified
173
- 'devices': 1, // not unified
174
- 'jwt-read-only': 1, // not unified
175
- 'exchange/orders/create': 1,
176
- 'exchange/orders/modify/{orderID}': 1, // not unified
177
- 'exchange/swap': 1, // not unified
178
- 'exchange/swap/confirm/{swapId}': 1, // not unified
179
- 'exchange/orders/close/{orderID}': 1,
180
- 'exchange/orders/hedge': 1, // not unified
181
- },
182
- 'put': {
183
- 'jwt': 1, // not unified
184
- 'exchange/orders/cancel/{orderID}': 1,
185
- 'users/margin/collateral': 1,
186
- 'users/margin/primary/{currency}': 1, // not unified
187
- },
188
- },
189
- },
190
- 'requiredCredentials': {
191
- 'apiKey': false,
192
- 'secret': false,
193
- 'uid': true,
194
- 'token': true,
195
- },
196
- 'fees': {
197
- 'trading': {
198
- 'feeSide': 'get',
199
- 'tierBased': false,
200
- 'percentage': true,
201
- 'taker': this.parseNumber('0.001'),
202
- 'maker': this.parseNumber('0'),
203
- },
204
- },
205
- 'precisionMode': TICK_SIZE,
206
- // exchange-specific options
207
- 'options': {
208
- 'currenciesByIdForParseMarket': undefined,
209
- 'currencyIdsListForParseMarket': ['QRDO'],
210
- },
211
- 'features': {
212
- 'spot': {
213
- 'sandbox': true,
214
- 'createOrder': {
215
- 'marginMode': true, // todo implement
216
- 'triggerPrice': true,
217
- 'triggerPriceType': undefined,
218
- 'triggerDirection': false,
219
- 'stopLossPrice': false, // todo
220
- 'takeProfitPrice': false, // todo
221
- 'attachedStopLossTakeProfit': {
222
- 'triggerPriceType': undefined,
223
- 'price': false,
224
- },
225
- 'timeInForce': {
226
- 'IOC': true,
227
- 'FOK': true,
228
- 'PO': false,
229
- 'GTD': true,
230
- },
231
- 'hedged': false,
232
- 'trailing': false,
233
- 'leverage': false,
234
- 'marketBuyByCost': true,
235
- 'marketBuyRequiresPrice': false,
236
- 'selfTradePrevention': false,
237
- 'iceberg': true,
238
- },
239
- 'createOrders': undefined,
240
- 'fetchMyTrades': {
241
- 'marginMode': false,
242
- 'limit': undefined,
243
- 'daysBack': 100000,
244
- 'untilDays': undefined,
245
- 'symbolRequired': false,
246
- },
247
- 'fetchOrder': {
248
- 'marginMode': false,
249
- 'trigger': false,
250
- 'trailing': false,
251
- 'symbolRequired': false,
252
- },
253
- 'fetchOpenOrders': {
254
- 'marginMode': false,
255
- 'limit': undefined,
256
- 'trigger': false,
257
- 'trailing': false,
258
- 'symbolRequired': false,
259
- },
260
- 'fetchOrders': {
261
- 'marginMode': false,
262
- 'limit': undefined,
263
- 'daysBack': 100000,
264
- 'untilDays': undefined,
265
- 'trigger': false,
266
- 'trailing': false,
267
- 'symbolRequired': false,
268
- },
269
- 'fetchClosedOrders': undefined,
270
- 'fetchOHLCV': {
271
- 'limit': 1000,
272
- },
273
- },
274
- 'swap': {
275
- 'linear': undefined,
276
- 'inverse': undefined,
277
- },
278
- 'future': {
279
- 'linear': undefined,
280
- 'inverse': undefined,
281
- },
282
- },
283
- 'exceptions': {
284
- // https://trade-docs.coinmetro.co/?javascript--nodejs#message-codes
285
- 'exact': {
286
- 'Both buyingCurrency and sellingCurrency are required': InvalidOrder, // 422 - "Both buyingCurrency and sellingCurrency are required"
287
- 'One and only one of buyingQty and sellingQty is required': InvalidOrder, // 422 - "One and only one of buyingQty and sellingQty is required"
288
- 'Invalid buyingCurrency': InvalidOrder, // 422 - "Invalid buyingCurrency"
289
- 'Invalid \'from\'': BadRequest, // 422 Unprocessable Entity {"message":"Invalid 'from'"}
290
- 'Invalid sellingCurrency': InvalidOrder, // 422 - "Invalid sellingCurrency"
291
- 'Invalid buyingQty': InvalidOrder, // 422 - "Invalid buyingQty"
292
- 'Invalid sellingQty': InvalidOrder, // 422 - "Invalid sellingQty"
293
- 'Insufficient balance': InsufficientFunds, // 422 - "Insufficient balance"
294
- 'Expiration date is in the past or too near in the future': InvalidOrder, // 422 Unprocessable Entity {"message":"Expiration date is in the past or too near in the future"}
295
- 'Forbidden': PermissionDenied, // 403 Forbidden {"message":"Forbidden"}
296
- 'Order Not Found': OrderNotFound, // 404 Not Found {"message":"Order Not Found"}
297
- 'since must be a millisecond timestamp': BadRequest, // 422 Unprocessable Entity {"message":"since must be a millisecond timestamp"}
298
- 'This pair is disabled on margin': BadSymbol, // 422 Unprocessable Entity {"message":"This pair is disabled on margin"}
299
- },
300
- 'broad': {
301
- 'accessing from a new IP': PermissionDenied, // 403 Forbidden {"message":"You're accessing from a new IP. Please check your email."}
302
- 'available to allocate as collateral': InsufficientFunds, // 403 Forbidden {"message":"Insufficient EUR available to allocate as collateral"}
303
- 'At least': BadRequest, // 422 Unprocessable Entity {"message":"At least 5 EUR per operation"}
304
- 'collateral is not allowed': BadRequest, // 422 Unprocessable Entity {"message":"DOGE collateral is not allowed"}
305
- 'Insufficient liquidity': InvalidOrder, // 503 Service Unavailable {"message":"Insufficient liquidity to fill the FOK order completely."}
306
- 'Insufficient order size': InvalidOrder, // 422 Unprocessable Entity {"message":"Insufficient order size - min 0.002 ETH"}
307
- 'Invalid quantity': InvalidOrder, // 422 Unprocessable Entity {"message":"Invalid quantity!"}
308
- 'Invalid Stop Loss': InvalidOrder, // 422 Unprocessable Entity {"message":"Invalid Stop Loss!"}
309
- 'Invalid stop price!': InvalidOrder, // 422 Unprocessable Entity {"message":"Invalid stop price!"}
310
- 'Not enough balance': InsufficientFunds, // 422 Unprocessable Entity {"message":"Not enough balance!"}
311
- 'Not enough margin': InsufficientFunds, // Unprocessable Entity {"message":"Not enough margin!"}
312
- 'orderType missing': BadRequest, // 422 Unprocessable Entity {"message":"orderType missing!"}
313
- 'Server Timeout': ExchangeError, // 503 Service Unavailable {"message":"Server Timeout!"}
314
- 'Time in force has to be IOC or FOK for market orders': InvalidOrder, // 422 Unprocessable Entity {"message":"Time in force has to be IOC or FOK for market orders!"}
315
- 'Too many attempts': RateLimitExceeded, // 429 Too Many Requests {"message":"Too many attempts. Try again in 3 seconds"}
316
- },
317
- },
318
- });
319
- }
320
- /**
321
- * @method
322
- * @name coinmetro#fetchCurrencies
323
- * @description fetches all available currencies on an exchange
324
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#d5876d43-a3fe-4479-8c58-24d0f044edfb
325
- * @param {object} [params] extra parameters specific to the exchange API endpoint
326
- * @returns {object} an associative dictionary of currencies
327
- */
328
- async fetchCurrencies(params = {}) {
329
- const response = await this.publicGetAssets(params);
330
- //
331
- // [
332
- // {
333
- // "symbol": "BTC",
334
- // "name": "Bitcoin",
335
- // "color": "#FFA500",
336
- // "type": "coin",
337
- // "canDeposit": true,
338
- // "canWithdraw": true,
339
- // "canTrade": true,
340
- // "notabeneDecimals": 8,
341
- // "canMarket": true,
342
- // "maxSwap": 10000,
343
- // "digits": 6,
344
- // "multiplier": 1000000,
345
- // "bookDigits": 8,
346
- // "bookMultiplier": 100000000,
347
- // "sentimentData": {
348
- // "sentiment": 51.59555555555555,
349
- // "interest": 1.127511216044664
350
- // },
351
- // "minQty": 0.0001
352
- // },
353
- // {
354
- // "symbol": "EUR",
355
- // "name": "Euro",
356
- // "color": "#1246FF",
357
- // "type": "fiat",
358
- // "canDeposit": true,
359
- // "canWithdraw": true,
360
- // "canTrade": true,
361
- // "canMarket": true,
362
- // "maxSwap": 10000,
363
- // "digits": 2,
364
- // "multiplier": 100,
365
- // "bookDigits": 3,
366
- // "bookMultiplier": 1000,
367
- // "minQty": 5
368
- // }
369
- // ...
370
- // ]
371
- //
372
- const result = this.parseCurrencies(response);
373
- const currenciesById = this.indexBy(result, 'id');
374
- this.options['currenciesByIdForParseMarket'] = currenciesById;
375
- const currentCurrencyIdsList = this.safeList(this.options, 'currencyIdsListForParseMarket', []);
376
- const currencyIdsList = Object.keys(currenciesById);
377
- for (let i = 0; i < currencyIdsList.length; i++) {
378
- currentCurrencyIdsList.push(currencyIdsList[i]);
379
- }
380
- this.options['currencyIdsListForParseMarket'] = currentCurrencyIdsList;
381
- return result;
382
- }
383
- parseCurrency(rawCurrency) {
384
- const id = this.safeString(rawCurrency, 'symbol');
385
- const code = this.safeCurrencyCode(id);
386
- const typeRaw = this.safeString(rawCurrency, 'type');
387
- let type = undefined;
388
- if (typeRaw === 'coin' || typeRaw === 'token' || typeRaw === 'erc20' || typeRaw === 'crypto') {
389
- type = 'crypto';
390
- }
391
- else if (typeRaw === 'fiat') {
392
- type = 'fiat';
393
- }
394
- let precisionDigits = this.safeString2(rawCurrency, 'digits', 'notabeneDecimals');
395
- if (code === 'RENDER') {
396
- // RENDER is an exception (with broken info)
397
- precisionDigits = '4';
398
- }
399
- return this.safeCurrencyStructure({
400
- 'id': id,
401
- 'code': code,
402
- 'name': code,
403
- 'type': type,
404
- 'info': rawCurrency,
405
- 'active': this.safeBool(rawCurrency, 'canTrade'),
406
- 'deposit': this.safeBool(rawCurrency, 'canDeposit'),
407
- 'withdraw': this.safeBool(rawCurrency, 'canWithdraw'),
408
- 'fee': undefined,
409
- 'precision': this.parseNumber(this.parsePrecision(precisionDigits)),
410
- 'limits': {
411
- 'amount': {
412
- 'min': this.safeNumber(rawCurrency, 'minQty'),
413
- 'max': undefined,
414
- },
415
- 'withdraw': {
416
- 'min': undefined,
417
- 'max': undefined,
418
- },
419
- },
420
- 'networks': {},
421
- });
422
- }
423
- /**
424
- * @method
425
- * @name coinmetro#fetchMarkets
426
- * @description retrieves data on all markets for coinmetro
427
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#9fd18008-338e-4863-b07d-722878a46832
428
- * @param {object} [params] extra parameters specific to the exchange API endpoint
429
- * @returns {object[]} an array of objects representing market data
430
- */
431
- async fetchMarkets(params = {}) {
432
- const promises = [];
433
- promises.push(this.publicGetMarkets(params));
434
- const responses = await Promise.all(promises);
435
- const response = responses[0];
436
- //
437
- // [
438
- // {
439
- // "pair": "YFIEUR",
440
- // "precision": 5,
441
- // "margin": false
442
- // },
443
- // {
444
- // "pair": "BTCEUR",
445
- // "precision": 2,
446
- // "margin": true
447
- // },
448
- // ...
449
- // ]
450
- //
451
- const result = [];
452
- for (let i = 0; i < response.length; i++) {
453
- const market = this.parseMarket(response[i]);
454
- // there are several broken (unavailable info) markets
455
- if (this.safeString(market, 'base') === undefined || this.safeString(market, 'quote') === undefined) {
456
- continue;
457
- }
458
- result.push(market);
459
- }
460
- return result;
461
- }
462
- parseMarket(market) {
463
- const id = this.safeString(market, 'pair');
464
- const parsedMarketId = this.parseMarketId(id);
465
- const baseId = this.safeString(parsedMarketId, 'baseId');
466
- const quoteId = this.safeString(parsedMarketId, 'quoteId');
467
- const base = this.safeCurrencyCode(baseId);
468
- const quote = this.safeCurrencyCode(quoteId);
469
- const basePrecisionAndLimits = this.parseMarketPrecisionAndLimits(baseId);
470
- const quotePrecisionAndLimits = this.parseMarketPrecisionAndLimits(quoteId);
471
- const margin = this.safeBool(market, 'margin', false);
472
- const tradingFees = this.safeValue(this.fees, 'trading', {});
473
- return this.safeMarketStructure({
474
- 'id': id,
475
- 'symbol': base + '/' + quote,
476
- 'base': base,
477
- 'quote': quote,
478
- 'settle': undefined,
479
- 'baseId': baseId,
480
- 'quoteId': quoteId,
481
- 'settleId': undefined,
482
- 'type': 'spot',
483
- 'spot': true,
484
- 'margin': margin,
485
- 'swap': false,
486
- 'future': false,
487
- 'option': false,
488
- 'active': true,
489
- 'contract': false,
490
- 'linear': undefined,
491
- 'inverse': undefined,
492
- 'taker': this.safeNumber(tradingFees, 'taker'),
493
- 'maker': this.safeNumber(tradingFees, 'maker'),
494
- 'contractSize': undefined,
495
- 'expiry': undefined,
496
- 'expiryDatetime': undefined,
497
- 'strike': undefined,
498
- 'optionType': undefined,
499
- 'precision': {
500
- 'amount': basePrecisionAndLimits['precision'],
501
- 'price': this.parseNumber(this.parsePrecision(this.safeString(market, 'precision'))),
502
- },
503
- 'limits': {
504
- 'leverage': {
505
- 'min': undefined,
506
- 'max': undefined,
507
- },
508
- 'amount': {
509
- 'min': basePrecisionAndLimits['minLimit'],
510
- 'max': undefined,
511
- },
512
- 'price': {
513
- 'min': undefined,
514
- 'max': undefined,
515
- },
516
- 'cost': {
517
- 'min': quotePrecisionAndLimits['minLimit'],
518
- 'max': undefined,
519
- },
520
- },
521
- 'created': undefined,
522
- 'info': market,
523
- });
524
- }
525
- parseMarketId(marketId) {
526
- let baseId = undefined;
527
- let quoteId = undefined;
528
- const currencyIds = this.safeValue(this.options, 'currencyIdsListForParseMarket', []);
529
- // Bubble sort by length (longest first)
530
- const currencyIdsLength = currencyIds.length;
531
- for (let i = 0; i < currencyIdsLength; i++) {
532
- for (let j = 0; j < currencyIdsLength - i - 1; j++) {
533
- const a = currencyIds[j];
534
- const b = currencyIds[j + 1];
535
- if (a.length < b.length) {
536
- currencyIds[j] = b;
537
- currencyIds[j + 1] = a;
538
- }
539
- }
540
- }
541
- for (let i = 0; i < currencyIds.length; i++) {
542
- const currencyId = currencyIds[i];
543
- const entryIndex = marketId.indexOf(currencyId);
544
- if (entryIndex === 0) {
545
- const restId = marketId.replace(currencyId, '');
546
- if (this.inArray(restId, currencyIds)) {
547
- if (entryIndex === 0) {
548
- baseId = currencyId;
549
- quoteId = restId;
550
- }
551
- else {
552
- baseId = restId;
553
- quoteId = currencyId;
554
- }
555
- break;
556
- }
557
- }
558
- }
559
- if (baseId === undefined || quoteId === undefined) {
560
- // https://github.com/ccxt/ccxt/issues/26820
561
- if (marketId.endsWith('USDT')) {
562
- baseId = marketId.replace('USDT', '');
563
- quoteId = 'USDT';
564
- }
565
- if (marketId.endsWith('USD')) {
566
- baseId = marketId.replace('USD', '');
567
- quoteId = 'USD';
568
- }
569
- }
570
- const result = {
571
- 'baseId': baseId,
572
- 'quoteId': quoteId,
573
- };
574
- return result;
575
- }
576
- parseMarketPrecisionAndLimits(currencyId) {
577
- const currencies = this.safeValue(this.options, 'currenciesByIdForParseMarket', {});
578
- const currency = this.safeValue(currencies, currencyId, {});
579
- const limits = this.safeValue(currency, 'limits', {});
580
- const amountLimits = this.safeValue(limits, 'amount', {});
581
- const minLimit = this.safeNumber(amountLimits, 'min');
582
- const result = {
583
- 'precision': this.safeNumber(currency, 'precision'),
584
- 'minLimit': minLimit,
585
- };
586
- return result;
587
- }
588
- /**
589
- * @method
590
- * @name coinmetro#fetchOHLCV
591
- * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
592
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#13cfb5bc-7bfb-4847-85e1-e0f35dfb3573
593
- * @param {string} symbol unified symbol of the market to fetch OHLCV data for
594
- * @param {string} timeframe the length of time each candle represents
595
- * @param {int} [since] timestamp in ms of the earliest candle to fetch
596
- * @param {int} [limit] the maximum amount of candles to fetch
597
- * @param {object} [params] extra parameters specific to the exchange API endpoint
598
- * @param {int} [params.until] the latest time in ms to fetch entries for
599
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
600
- */
601
- async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
602
- await this.loadMarkets();
603
- const market = this.market(symbol);
604
- const request = {
605
- 'pair': market['id'],
606
- 'timeframe': this.safeString(this.timeframes, timeframe, timeframe),
607
- };
608
- let until = undefined;
609
- if (since !== undefined) {
610
- request['from'] = since;
611
- if (limit !== undefined) {
612
- const duration = this.parseTimeframe(timeframe) * 1000;
613
- until = this.sum(since, duration * (limit));
614
- }
615
- }
616
- else {
617
- request['from'] = ':from'; // this endpoint doesn't accept empty from and to params (setting them into the value described in the documentation)
618
- }
619
- until = this.safeInteger(params, 'until', until);
620
- if (until !== undefined) {
621
- params = this.omit(params, ['until']);
622
- request['to'] = until;
623
- }
624
- else {
625
- request['to'] = ':to';
626
- }
627
- const response = await this.publicGetExchangeCandlesPairTimeframeFromTo(this.extend(request, params));
628
- //
629
- // {
630
- // "candleHistory": [
631
- // {
632
- // "pair": "ETHUSDT",
633
- // "timeframe": 86400000,
634
- // "timestamp": 1697673600000,
635
- // "c": 1567.4409353098604,
636
- // "h": 1566.7514068472303,
637
- // "l": 1549.4563666936847,
638
- // "o": 1563.4490341395904,
639
- // "v": 0
640
- // },
641
- // {
642
- // "pair": "ETHUSDT",
643
- // "timeframe": 86400000,
644
- // "timestamp": 1697760000000,
645
- // "c": 1603.7831363339324,
646
- // "h": 1625.0356823666407,
647
- // "l": 1565.4629390011505,
648
- // "o": 1566.8387619426028,
649
- // "v": 0
650
- // },
651
- // ...
652
- // ]
653
- // }
654
- //
655
- const candleHistory = this.safeList(response, 'candleHistory', []);
656
- return this.parseOHLCVs(candleHistory, market, timeframe, since, limit);
657
- }
658
- parseOHLCV(ohlcv, market = undefined) {
659
- return [
660
- this.safeInteger(ohlcv, 'timestamp'),
661
- this.safeNumber(ohlcv, 'o'),
662
- this.safeNumber(ohlcv, 'h'),
663
- this.safeNumber(ohlcv, 'l'),
664
- this.safeNumber(ohlcv, 'c'),
665
- this.safeNumber(ohlcv, 'v'),
666
- ];
667
- }
668
- /**
669
- * @method
670
- * @name coinmetro#fetchTrades
671
- * @description get the list of most recent trades for a particular symbol
672
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#6ee5d698-06da-4570-8c84-914185e05065
673
- * @param {string} symbol unified symbol of the market to fetch trades for
674
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
675
- * @param {int} [limit] the maximum amount of trades to fetch (default 200, max 500)
676
- * @param {object} [params] extra parameters specific to the exchange API endpoint
677
- * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
678
- */
679
- async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
680
- await this.loadMarkets();
681
- const market = this.market(symbol);
682
- const request = {
683
- 'pair': market['id'],
684
- };
685
- if (since !== undefined) {
686
- request['from'] = since;
687
- }
688
- else {
689
- // this endpoint accepts empty from param
690
- request['from'] = '';
691
- }
692
- const response = await this.publicGetExchangeTicksPairFrom(this.extend(request, params));
693
- //
694
- // {
695
- // "tickHistory": [
696
- // {
697
- // "pair": "ETHUSDT",
698
- // "price": 2077.5623,
699
- // "qty": 0.002888,
700
- // "timestamp": 1700684689420,
701
- // "seqNum": 10644554718
702
- // },
703
- // {
704
- // "pair": "ETHUSDT",
705
- // "price": 2078.3848,
706
- // "qty": 0.003368,
707
- // "timestamp": 1700684738410,
708
- // "seqNum": 10644559561
709
- // },
710
- // {
711
- // "pair": "ETHUSDT",
712
- // "price": 2077.1513,
713
- // "qty": 0.00337,
714
- // "timestamp": 1700684816853,
715
- // "seqNum": 10644567113
716
- // },
717
- // ...
718
- // ]
719
- // }
720
- //
721
- const tickHistory = this.safeList(response, 'tickHistory', []);
722
- return this.parseTrades(tickHistory, market, since, limit);
723
- }
724
- /**
725
- * @method
726
- * @name coinmetro#fetchMyTrades
727
- * @description fetch all trades made by the user
728
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#4d48ae69-8ee2-44d1-a268-71f84e557b7b
729
- * @param {string} symbol unified market symbol
730
- * @param {int} [since] the earliest time in ms to fetch trades for
731
- * @param {int} [limit] the maximum number of trades structures to retrieve (default 500, max 1000)
732
- * @param {object} [params] extra parameters specific to the exchange API endpoint
733
- * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
734
- */
735
- async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
736
- await this.loadMarkets();
737
- let market = undefined;
738
- if (symbol !== undefined) {
739
- market = this.market(symbol);
740
- }
741
- const request = {};
742
- if (since !== undefined) {
743
- request['since'] = since;
744
- }
745
- else {
746
- // the exchange requires a value for the since param
747
- request['since'] = 0;
748
- }
749
- const response = await this.privateGetExchangeFillsSince(this.extend(request, params));
750
- //
751
- // [
752
- // {
753
- // "pair": "ETHUSDC",
754
- // "seqNumber": 10873722343,
755
- // "timestamp": 1702570610747,
756
- // "qty": 0.002,
757
- // "price": 2282,
758
- // "side": "buy",
759
- // "orderID": "65671262d93d9525ac009e36170257061073952c6423a8c5b4d6c"
760
- // },
761
- // ...
762
- // ]
763
- //
764
- return this.parseTrades(response, market, since, limit);
765
- }
766
- parseTrade(trade, market = undefined) {
767
- //
768
- // fetchTrades
769
- // {
770
- // "pair": "ETHUSDT",
771
- // "price": 2077.1513,
772
- // "qty": 0.00337,
773
- // "timestamp": 1700684816853,
774
- // "seqNum": 10644567113
775
- // },
776
- //
777
- // fetchMyTrades
778
- // {
779
- // "pair": "ETHUSDC",
780
- // "seqNumber": 10873722343,
781
- // "timestamp": 1702570610747,
782
- // "qty": 0.002,
783
- // "price": 2282,
784
- // "side": "buy",
785
- // "orderID": "65671262d93d9525ac009e36170257061073952c6423a8c5b4d6c"
786
- // }
787
- //
788
- // fetchOrders
789
- // {
790
- // "_id": "657b31d360a9542449381bdc",
791
- // "seqNumber": 10873722343,
792
- // "timestamp": 1702570610747,
793
- // "qty": 0.002,
794
- // "price": 2282,
795
- // "side": "buy"
796
- // }
797
- //
798
- // {
799
- // "pair":"ETHUSDC",
800
- // "seqNumber":"10873722343",
801
- // "timestamp":"1702570610747",
802
- // "qty":"0.002",
803
- // "price":"2282",
804
- // "side":"buy",
805
- // "orderID":"65671262d93d9525ac009e36170257061073952c6423a8c5b4d6c",
806
- // "userID":"65671262d93d9525ac009e36"
807
- // }
808
- //
809
- const marketId = this.safeString2(trade, 'symbol', 'pair');
810
- market = this.safeMarket(marketId, market);
811
- const symbol = market['symbol'];
812
- const id = this.safeStringN(trade, ['_id', 'seqNum', 'seqNumber']);
813
- const timestamp = this.safeInteger(trade, 'timestamp');
814
- const priceString = this.safeString(trade, 'price');
815
- const amountString = this.safeString(trade, 'qty');
816
- const order = this.safeString(trade, 'orderID');
817
- const side = this.safeString(trade, 'side');
818
- return this.safeTrade({
819
- 'id': id,
820
- 'order': order,
821
- 'timestamp': timestamp,
822
- 'datetime': this.iso8601(timestamp),
823
- 'symbol': symbol,
824
- 'type': undefined,
825
- 'side': side,
826
- 'takerOrMaker': undefined,
827
- 'price': priceString,
828
- 'amount': amountString,
829
- 'cost': undefined,
830
- 'fee': undefined,
831
- 'info': trade,
832
- }, market);
833
- }
834
- /**
835
- * @method
836
- * @name coinmetro#fetchOrderBook
837
- * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
838
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#26ad80d7-8c46-41b5-9208-386f439a8b87
839
- * @param {string} symbol unified symbol of the market to fetch the order book for
840
- * @param {int} [limit] the maximum amount of order book entries to return (default 100, max 200)
841
- * @param {object} [params] extra parameters specific to the exchange API endpoint
842
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure}
843
- */
844
- async fetchOrderBook(symbol, limit = undefined, params = {}) {
845
- await this.loadMarkets();
846
- const market = this.market(symbol);
847
- const request = {
848
- 'pair': market['id'],
849
- };
850
- const response = await this.publicGetExchangeBookPair(this.extend(request, params));
851
- //
852
- // {
853
- // "book": {
854
- // "pair": "ETHUSDT",
855
- // "seqNumber": 10800409239,
856
- // "ask": {
857
- // "2354.2861": 3.75,
858
- // "2354.3138": 19,
859
- // "2354.7538": 80,
860
- // "2355.5430": 260,
861
- // "2356.4611": 950,
862
- // "2361.7150": 1500,
863
- // "206194.0000": 0.01
864
- // },
865
- // "bid": {
866
- // "2352.6339": 3.75,
867
- // "2352.6002": 19,
868
- // "2352.2402": 80,
869
- // "2351.4582": 260,
870
- // "2349.3111": 950,
871
- // "2343.8601": 1500,
872
- // "1.0000": 5
873
- // },
874
- // "checksum": 2108177337
875
- // }
876
- // }
877
- //
878
- const book = this.safeValue(response, 'book', {});
879
- const rawBids = this.safeValue(book, 'bid', {});
880
- const rawAsks = this.safeValue(book, 'ask', {});
881
- const rawOrderbook = {
882
- 'bids': rawBids,
883
- 'asks': rawAsks,
884
- };
885
- const orderbook = this.parseOrderBook(rawOrderbook, symbol);
886
- orderbook['nonce'] = this.safeInteger(book, 'seqNumber');
887
- return orderbook;
888
- }
889
- parseOrderBookBidsAsks(bidasks, priceKey = 0, amountKey = 1, countOrIdKey = 2) {
890
- const prices = Object.keys(bidasks);
891
- const result = [];
892
- for (let i = 0; i < prices.length; i++) {
893
- const priceString = this.safeString(prices, i);
894
- const price = this.safeNumber(prices, i);
895
- const volume = this.safeNumber(bidasks, priceString);
896
- (result).push([price, volume]);
897
- }
898
- return result;
899
- }
900
- /**
901
- * @method
902
- * @name coinmetro#fetchTickers
903
- * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
904
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#6ecd1cd1-f162-45a3-8b3b-de690332a485
905
- * @param {string[]} [symbols] unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
906
- * @param {object} [params] extra parameters specific to the exchange API endpoint
907
- * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
908
- */
909
- async fetchTickers(symbols = undefined, params = {}) {
910
- await this.loadMarkets();
911
- const response = await this.publicGetExchangePrices(params);
912
- //
913
- // {
914
- // "latestPrices": [
915
- // {
916
- // "pair": "PERPEUR",
917
- // "timestamp": 1702549840393,
918
- // "price": 0.7899997816001223,
919
- // "qty": 1e-12,
920
- // "ask": 0.8,
921
- // "bid": 0.7799995632002446
922
- // },
923
- // {
924
- // "pair": "PERPUSD",
925
- // "timestamp": 1702549841973,
926
- // "price": 0.8615317721366659,
927
- // "qty": 1e-12,
928
- // "ask": 0.8742333599999257,
929
- // "bid": 0.8490376365388491
930
- // },
931
- // ...
932
- // ],
933
- // "24hInfo": [
934
- // {
935
- // "delta": 0.25396444229149906,
936
- // "h": 0.78999978160012,
937
- // "l": 0.630001740844,
938
- // "v": 54.910000002833996,
939
- // "pair": "PERPEUR",
940
- // "sentimentData": {
941
- // "sentiment": 36.71333333333333,
942
- // "interest": 0.47430830039525695
943
- // }
944
- // },
945
- // {
946
- // "delta": 0.26915154078134096,
947
- // "h": 0.86220315458898,
948
- // "l": 0.67866757035154,
949
- // "v": 2.835000000000001e-9,
950
- // "pair": "PERPUSD",
951
- // "sentimentData": {
952
- // "sentiment": 36.71333333333333,
953
- // "interest": 0.47430830039525695
954
- // }
955
- // },
956
- // ...
957
- // ]
958
- // }
959
- //
960
- const latestPrices = this.safeValue(response, 'latestPrices', []);
961
- const twentyFourHInfos = this.safeValue(response, '24hInfo', []);
962
- const tickersObject = {};
963
- // merging info from two lists into one
964
- for (let i = 0; i < latestPrices.length; i++) {
965
- const latestPrice = latestPrices[i];
966
- const marketId = this.safeString(latestPrice, 'pair');
967
- if (marketId !== undefined) {
968
- tickersObject[marketId] = latestPrice;
969
- }
970
- }
971
- for (let i = 0; i < twentyFourHInfos.length; i++) {
972
- const twentyFourHInfo = twentyFourHInfos[i];
973
- const marketId = this.safeString(twentyFourHInfo, 'pair');
974
- if (marketId !== undefined) {
975
- const latestPrice = this.safeValue(tickersObject, marketId, {});
976
- tickersObject[marketId] = this.extend(twentyFourHInfo, latestPrice);
977
- }
978
- }
979
- const tickers = Object.values(tickersObject);
980
- return this.parseTickers(tickers, symbols);
981
- }
982
- /**
983
- * @method
984
- * @name coinmetro#fetchBidsAsks
985
- * @description fetches the bid and ask price and volume for multiple markets
986
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#6ecd1cd1-f162-45a3-8b3b-de690332a485
987
- * @param {string[]} [symbols] unified symbols of the markets to fetch the bids and asks for, all markets are returned if not assigned
988
- * @param {object} [params] extra parameters specific to the exchange API endpoint
989
- * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
990
- */
991
- async fetchBidsAsks(symbols = undefined, params = {}) {
992
- await this.loadMarkets();
993
- const response = await this.publicGetExchangePrices(params);
994
- const latestPrices = this.safeList(response, 'latestPrices', []);
995
- return this.parseTickers(latestPrices, symbols);
996
- }
997
- parseTicker(ticker, market = undefined) {
998
- //
999
- // {
1000
- // "pair": "PERPUSD",
1001
- // "timestamp": 1702549841973,
1002
- // "price": 0.8615317721366659,
1003
- // "qty": 1e-12,
1004
- // "ask": 0.8742333599999257,
1005
- // "bid": 0.8490376365388491
1006
- // "delta": 0.26915154078134096,
1007
- // "h": 0.86220315458898,
1008
- // "l": 0.67866757035154,
1009
- // "v": 2.835000000000001e-9,
1010
- // "sentimentData": {
1011
- // "sentiment": 36.71333333333333,
1012
- // "interest": 0.47430830039525695
1013
- // }
1014
- // }
1015
- //
1016
- const marketId = this.safeString(ticker, 'pair');
1017
- market = this.safeMarket(marketId, market);
1018
- const timestamp = this.safeInteger(ticker, 'timestamp');
1019
- const bid = this.safeString(ticker, 'bid');
1020
- const ask = this.safeString(ticker, 'ask');
1021
- const high = this.safeString(ticker, 'h');
1022
- const low = this.safeString(ticker, 'l');
1023
- const last = this.safeString(ticker, 'price');
1024
- const baseVolume = this.safeString(ticker, 'v');
1025
- const delta = this.safeString(ticker, 'delta');
1026
- const percentage = Precise.stringMul(delta, '100');
1027
- return this.safeTicker({
1028
- 'symbol': market['symbol'],
1029
- 'timestamp': timestamp,
1030
- 'datetime': this.iso8601(timestamp),
1031
- 'open': undefined,
1032
- 'high': high,
1033
- 'low': low,
1034
- 'close': undefined,
1035
- 'last': last,
1036
- 'bid': bid,
1037
- 'bidVolume': undefined,
1038
- 'ask': ask,
1039
- 'askVolume': undefined,
1040
- 'vwap': undefined,
1041
- 'previousClose': undefined,
1042
- 'change': undefined,
1043
- 'percentage': percentage,
1044
- 'average': undefined,
1045
- 'baseVolume': baseVolume,
1046
- 'quoteVolume': undefined,
1047
- 'info': ticker,
1048
- }, market);
1049
- }
1050
- /**
1051
- * @method
1052
- * @name coinmetro#fetchBalance
1053
- * @description query for balance and get the amount of funds available for trading or funds locked in orders
1054
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#741a1dcc-7307-40d0-acca-28d003d1506a
1055
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1056
- * @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
1057
- */
1058
- async fetchBalance(params = {}) {
1059
- await this.loadMarkets();
1060
- const response = await this.privateGetUsersWallets(params);
1061
- const list = this.safeList(response, 'list', []);
1062
- return this.parseBalance(list);
1063
- }
1064
- parseBalance(balances) {
1065
- //
1066
- // [
1067
- // {
1068
- // "xcmLocks": [],
1069
- // "xcmLockAmounts": [],
1070
- // "refList": [],
1071
- // "balanceHistory": [],
1072
- // "_id": "5fecd3c998e75c2e4d63f7c3",
1073
- // "currency": "BTC",
1074
- // "label": "BTC",
1075
- // "userId": "5fecd3c97fbfed1521db23bd",
1076
- // "__v": 0,
1077
- // "balance": 0.5,
1078
- // "createdAt": "2020-12-30T19:23:53.646Z",
1079
- // "disabled": false,
1080
- // "updatedAt": "2020-12-30T19:23:53.653Z",
1081
- // "reserved": 0,
1082
- // "id": "5fecd3c998e75c2e4d63f7c3"
1083
- // },
1084
- // ...
1085
- // ]
1086
- //
1087
- const result = {
1088
- 'info': balances,
1089
- };
1090
- for (let i = 0; i < balances.length; i++) {
1091
- const balanceEntry = this.safeDict(balances, i, {});
1092
- const currencyId = this.safeString(balanceEntry, 'currency');
1093
- const code = this.safeCurrencyCode(currencyId);
1094
- const account = this.account();
1095
- account['total'] = this.safeString(balanceEntry, 'balance');
1096
- account['used'] = this.safeString(balanceEntry, 'reserved');
1097
- result[code] = account;
1098
- }
1099
- return this.safeBalance(result);
1100
- }
1101
- /**
1102
- * @method
1103
- * @name coinmetro#fetchLedger
1104
- * @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
1105
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#4e7831f7-a0e7-4c3e-9336-1d0e5dcb15cf
1106
- * @param {string} [code] unified currency code, default is undefined
1107
- * @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
1108
- * @param {int} [limit] max number of ledger entries to return (default 200, max 500)
1109
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1110
- * @param {int} [params.until] the latest time in ms to fetch entries for
1111
- * @returns {object} a [ledger structure]{@link https://docs.ccxt.com/?id=ledger-entry-structure}
1112
- */
1113
- async fetchLedger(code = undefined, since = undefined, limit = undefined, params = {}) {
1114
- await this.loadMarkets();
1115
- const request = {};
1116
- if (since !== undefined) {
1117
- request['since'] = since;
1118
- }
1119
- else {
1120
- // this endpoint accepts empty since param
1121
- request['since'] = '';
1122
- }
1123
- let currency = undefined;
1124
- if (code !== undefined) {
1125
- currency = this.currency(code);
1126
- }
1127
- const response = await this.privateGetUsersWalletsHistorySince(this.extend(request, params));
1128
- //
1129
- // {
1130
- // "list": [
1131
- // {
1132
- // "currency": "USDC",
1133
- // "label": "USDC",
1134
- // "userId": "65671262d93d9525ac009e36",
1135
- // "balance": 0,
1136
- // "disabled": false,
1137
- // "balanceHistory": [
1138
- // {
1139
- // "description": "Deposit - 657973a9b6eadf0f33d70100",
1140
- // "JSONdata": {
1141
- // "fees": 0,
1142
- // "notes": "Via Crypto",
1143
- // "txHash": "0x2e4875185b0f312d8e24b2d26d46bf9877db798b608ad2ff97b2b8bc7d8134e5",
1144
- // "last4Digits": null,
1145
- // "IBAN": null,
1146
- // "alternativeChain": "polygon",
1147
- // "referenceId": "657973a9b6eadf0f33d70100",
1148
- // "status": "completed",
1149
- // "tracked": true
1150
- // },
1151
- // "amount": 99,
1152
- // "timestamp": "2023-12-13T09:04:51.270Z",
1153
- // "amountEUR": 91.79310117335974
1154
- // },
1155
- // {
1156
- // "description": "Order 65671262d93d9525ac009e36170257061073952c6423a8c5b4d6c SeqNum 10873722342",
1157
- // "JSONdata": {
1158
- // "price": "2282.00 ETH/USDC",
1159
- // "fees": 0,
1160
- // "notes": "Order 3a8c5b4d6c"
1161
- // },
1162
- // "amount": -4.564,
1163
- // "timestamp": "2023-12-14T16:16:50.760Z",
1164
- // "amountEUR": -4.150043849187587
1165
- // },
1166
- // ...
1167
- // ]
1168
- // },
1169
- // {
1170
- // "currency": "ETH",
1171
- // "label": "ETH",
1172
- // "userId": "65671262d93d9525ac009e36",
1173
- // "balance": 0,
1174
- // "disabled": false,
1175
- // "balanceHistory": [
1176
- // {
1177
- // "description": "Order 65671262d93d9525ac009e36170257061073952c6423a8c5b4d6c SeqNum 10873722342",
1178
- // "JSONdata": {
1179
- // "price": "2282.00 ETH/USDC",
1180
- // "fees": 0.000002,
1181
- // "notes": "Order 3a8c5b4d6c"
1182
- // },
1183
- // "amount": 0.001998,
1184
- // "timestamp": "2023-12-14T16:16:50.761Z",
1185
- // "amountEUR": 4.144849415806856
1186
- // },
1187
- // ...
1188
- // ]
1189
- // },
1190
- // {
1191
- // "currency": "DOGE",
1192
- // "label": "DOGE",
1193
- // "userId": "65671262d93d9525ac009e36",
1194
- // "balance": 0,
1195
- // "disabled": false,
1196
- // "balanceHistory": [
1197
- // {
1198
- // "description": "Order 65671262d93d9525ac009e361702905785319b5d9016dc20736034d13ca6a - Swap",
1199
- // "JSONdata": {
1200
- // "swap": true,
1201
- // "subtype": "swap",
1202
- // "fees": 0,
1203
- // "price": "0.0905469 DOGE/USDC",
1204
- // "notes": "Swap 034d13ca6a"
1205
- // },
1206
- // "amount": 70,
1207
- // "timestamp": "2023-12-18T13:23:05.836Z",
1208
- // "amountEUR": 5.643627624549227
1209
- // }
1210
- // ]
1211
- // },
1212
- // ...
1213
- // ]
1214
- // }
1215
- //
1216
- const ledgerByCurrencies = this.safeValue(response, 'list', []);
1217
- const ledger = [];
1218
- for (let i = 0; i < ledgerByCurrencies.length; i++) {
1219
- const currencyLedger = ledgerByCurrencies[i];
1220
- const currencyId = this.safeString(currencyLedger, 'currency');
1221
- const balanceHistory = this.safeValue(currencyLedger, 'balanceHistory', []);
1222
- for (let j = 0; j < balanceHistory.length; j++) {
1223
- const rawLedgerEntry = balanceHistory[j];
1224
- rawLedgerEntry['currencyId'] = currencyId;
1225
- ledger.push(rawLedgerEntry);
1226
- }
1227
- }
1228
- return this.parseLedger(ledger, currency, since, limit);
1229
- }
1230
- parseLedgerEntry(item, currency = undefined) {
1231
- const datetime = this.safeString(item, 'timestamp');
1232
- const currencyId = this.safeString(item, 'currencyId');
1233
- item = this.omit(item, 'currencyId');
1234
- currency = this.safeCurrency(currencyId, currency);
1235
- const description = this.safeString(item, 'description', '');
1236
- const [type, referenceId] = this.parseLedgerEntryDescription(description);
1237
- const JSONdata = this.safeValue(item, 'JSONdata', {});
1238
- const feeCost = this.safeString(JSONdata, 'fees');
1239
- const fee = {
1240
- 'cost': feeCost,
1241
- 'currency': undefined,
1242
- };
1243
- let amount = this.safeString(item, 'amount');
1244
- let direction = undefined;
1245
- if (amount !== undefined) {
1246
- if (Precise.stringLt(amount, '0')) {
1247
- direction = 'out';
1248
- amount = Precise.stringAbs(amount);
1249
- }
1250
- else if (Precise.stringGt(amount, '0')) {
1251
- direction = 'in';
1252
- }
1253
- }
1254
- return this.safeLedgerEntry({
1255
- 'info': item,
1256
- 'id': undefined,
1257
- 'timestamp': this.parse8601(datetime),
1258
- 'datetime': datetime,
1259
- 'direction': direction,
1260
- 'account': undefined,
1261
- 'referenceId': referenceId,
1262
- 'referenceAccount': undefined,
1263
- 'type': type,
1264
- 'currency': currency,
1265
- 'amount': amount,
1266
- 'before': undefined,
1267
- 'after': undefined,
1268
- 'status': undefined,
1269
- 'fee': fee,
1270
- }, currency);
1271
- }
1272
- parseLedgerEntryDescription(description) {
1273
- let descriptionArray = [];
1274
- if (description !== undefined) {
1275
- descriptionArray = description.split(' ');
1276
- }
1277
- let type = undefined;
1278
- let referenceId = undefined;
1279
- const length = descriptionArray.length;
1280
- if (length > 1) {
1281
- type = this.parseLedgerEntryType(descriptionArray[0]);
1282
- if (descriptionArray[1] !== '-') {
1283
- referenceId = descriptionArray[1];
1284
- }
1285
- else {
1286
- referenceId = this.safeString(descriptionArray, 2);
1287
- }
1288
- }
1289
- return [type, referenceId];
1290
- }
1291
- parseLedgerEntryType(type) {
1292
- const types = {
1293
- 'Deposit': 'transaction',
1294
- 'Withdraw': 'transaction',
1295
- 'Order': 'trade',
1296
- };
1297
- return this.safeString(types, type, type);
1298
- }
1299
- /**
1300
- * @method
1301
- * @name coinmetro#createOrder
1302
- * @description create a trade order
1303
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#a4895a1d-3f50-40ae-8231-6962ef06c771
1304
- * @param {string} symbol unified symbol of the market to create an order in
1305
- * @param {string} type 'market' or 'limit'
1306
- * @param {string} side 'buy' or 'sell'
1307
- * @param {float} amount how much of currency you want to trade in units of base currency
1308
- * @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
1309
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1310
- * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount in market orders
1311
- * @param {string} [params.timeInForce] "GTC", "IOC", "FOK", "GTD"
1312
- * @param {number} [params.expirationTime] timestamp in millisecond, for GTD orders only
1313
- * @param {float} [params.triggerPrice] the price at which a trigger order is triggered at
1314
- * @param {float} [params.stopLossPrice] *margin only* The price at which a stop loss order is triggered at
1315
- * @param {float} [params.takeProfitPrice] *margin only* The price at which a take profit order is triggered at
1316
- * @param {bool} [params.margin] true for creating a margin order
1317
- * @param {string} [params.fillStyle] fill style of the limit order: "sell" fulfills selling quantity "buy" fulfills buying quantity "base" fulfills base currency quantity "quote" fulfills quote currency quantity
1318
- * @param {string} [params.clientOrderId] client's comment
1319
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
1320
- */
1321
- async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1322
- await this.loadMarkets();
1323
- const market = this.market(symbol);
1324
- let request = {};
1325
- request['orderType'] = type;
1326
- let formattedAmount = undefined;
1327
- if (amount !== undefined) {
1328
- formattedAmount = this.amountToPrecision(symbol, amount);
1329
- }
1330
- let cost = this.safeValue(params, 'cost');
1331
- params = this.omit(params, 'cost');
1332
- if (type === 'limit') {
1333
- if ((price === undefined) && (cost === undefined)) {
1334
- throw new ArgumentsRequired(this.id + ' createOrder() requires a price or params.cost argument for a ' + type + ' order');
1335
- }
1336
- else if ((price !== undefined) && (amount !== undefined)) {
1337
- const costString = Precise.stringMul(this.numberToString(price), this.numberToString(formattedAmount));
1338
- cost = this.parseToNumeric(costString);
1339
- }
1340
- }
1341
- let precisedCost = undefined;
1342
- if (cost !== undefined) {
1343
- precisedCost = this.costToPrecision(symbol, cost);
1344
- }
1345
- if (side === 'sell') {
1346
- request = this.handleCreateOrderSide(market['baseId'], market['quoteId'], formattedAmount, precisedCost, request);
1347
- }
1348
- else if (side === 'buy') {
1349
- request = this.handleCreateOrderSide(market['quoteId'], market['baseId'], precisedCost, formattedAmount, request);
1350
- }
1351
- const timeInForce = this.safeValue(params, 'timeInForce');
1352
- if (timeInForce !== undefined) {
1353
- params = this.omit(params, 'timeInForce');
1354
- request['timeInForce'] = this.encodeOrderTimeInForce(timeInForce);
1355
- }
1356
- const triggerPrice = this.safeString2(params, 'triggerPrice', 'stopPrice');
1357
- if (triggerPrice !== undefined) {
1358
- params = this.omit(params, ['triggerPrice']);
1359
- request['stopPrice'] = this.priceToPrecision(symbol, triggerPrice);
1360
- }
1361
- const userData = this.safeValue(params, 'userData', {});
1362
- const comment = this.safeString2(params, 'clientOrderId', 'comment');
1363
- if (comment !== undefined) {
1364
- params = this.omit(params, ['clientOrderId']);
1365
- userData['comment'] = comment;
1366
- }
1367
- const stopLossPrice = this.safeString(params, 'stopLossPrice');
1368
- if (stopLossPrice !== undefined) {
1369
- params = this.omit(params, 'stopLossPrice');
1370
- userData['stopLoss'] = this.priceToPrecision(symbol, stopLossPrice);
1371
- }
1372
- const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
1373
- if (takeProfitPrice !== undefined) {
1374
- params = this.omit(params, 'takeProfitPrice');
1375
- userData['takeProfit'] = this.priceToPrecision(symbol, takeProfitPrice);
1376
- }
1377
- if (!this.isEmpty(userData)) {
1378
- request['userData'] = userData;
1379
- }
1380
- const response = await this.privatePostExchangeOrdersCreate(this.extend(request, params));
1381
- //
1382
- // {
1383
- // "userID": "65671262d93d9525ac009e36",
1384
- // "orderID": "65671262d93d9525ac009e36170257448481749b7ee2893bafec2",
1385
- // "orderType": "market",
1386
- // "buyingCurrency": "ETH",
1387
- // "sellingCurrency": "USDC",
1388
- // "buyingQty": 0.002,
1389
- // "timeInForce": 4,
1390
- // "boughtQty": 0.002,
1391
- // "soldQty": 4.587,
1392
- // "creationTime": 1702574484829,
1393
- // "seqNumber": 10874285330,
1394
- // "firstFillTime": 1702574484831,
1395
- // "lastFillTime": 1702574484831,
1396
- // "fills": [
1397
- // {
1398
- // "seqNumber": 10874285329,
1399
- // "timestamp": 1702574484831,
1400
- // "qty": 0.002,
1401
- // "price": 2293.5,
1402
- // "side": "buy"
1403
- // }
1404
- // ],
1405
- // "completionTime": 1702574484831,
1406
- // "takerQty": 0.002
1407
- // }
1408
- //
1409
- return this.parseOrder(response);
1410
- }
1411
- handleCreateOrderSide(sellingCurrency, buyingCurrency, sellingQty, buyingQty, request = {}) {
1412
- request['sellingCurrency'] = sellingCurrency;
1413
- request['buyingCurrency'] = buyingCurrency;
1414
- if (sellingQty !== undefined) {
1415
- request['sellingQty'] = sellingQty;
1416
- }
1417
- if (buyingQty !== undefined) {
1418
- request['buyingQty'] = buyingQty;
1419
- }
1420
- return request;
1421
- }
1422
- encodeOrderTimeInForce(timeInForce) {
1423
- const timeInForceTypes = {
1424
- 'GTC': 1,
1425
- 'IOC': 2,
1426
- 'GTD': 3,
1427
- 'FOK': 4,
1428
- };
1429
- return this.safeValue(timeInForceTypes, timeInForce, timeInForce);
1430
- }
1431
- /**
1432
- * @method
1433
- * @name coinmetro#cancelOrder
1434
- * @description cancels an open order
1435
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#eaea86da-16ca-4c56-9f00-5b1cb2ad89f8
1436
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#47f913fb-8cab-49f4-bc78-d980e6ced316
1437
- * @param {string} id order id
1438
- * @param {string} symbol not used by coinmetro cancelOrder ()
1439
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1440
- * @param {string} [params.margin] true for cancelling a margin order
1441
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
1442
- */
1443
- async cancelOrder(id, symbol = undefined, params = {}) {
1444
- await this.loadMarkets();
1445
- const request = {
1446
- 'orderID': id,
1447
- };
1448
- const marginMode = undefined;
1449
- [params, params] = this.handleMarginModeAndParams('cancelOrder', params);
1450
- const isMargin = this.safeBool(params, 'margin', false);
1451
- params = this.omit(params, 'margin');
1452
- let response = undefined;
1453
- if (isMargin || (marginMode !== undefined)) {
1454
- response = await this.privatePostExchangeOrdersCloseOrderID(this.extend(request, params));
1455
- }
1456
- else {
1457
- response = await this.privatePutExchangeOrdersCancelOrderID(this.extend(request, params));
1458
- }
1459
- //
1460
- // {
1461
- // "userID": "65671262d93d9525ac009e36",
1462
- // "orderID": "65671262d93d9525ac009e3617026635256739c996fe17d7cd5d4",
1463
- // "orderType": "limit",
1464
- // "buyingCurrency": "ETH",
1465
- // "sellingCurrency": "USDC",
1466
- // "fillStyle": "sell",
1467
- // "orderPlatform": "trade-v3",
1468
- // "timeInForce": 1,
1469
- // "buyingQty": 0.005655,
1470
- // "sellingQty": 11.31,
1471
- // "boughtQty": 0,
1472
- // "soldQty": 0,
1473
- // "creationTime": 1702663525713,
1474
- // "seqNumber": 10915220048,
1475
- // "completionTime": 1702928369053
1476
- // }
1477
- //
1478
- return this.parseOrder(response);
1479
- }
1480
- /**
1481
- * @method
1482
- * @name coinmetro#closePosition
1483
- * @description closes an open position
1484
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#47f913fb-8cab-49f4-bc78-d980e6ced316
1485
- * @param {string} symbol not used by coinmetro closePosition ()
1486
- * @param {string} [side] not used by coinmetro closePosition ()
1487
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1488
- * @param {string} [params.orderID] order id
1489
- * @param {number} [params.fraction] fraction of order to close, between 0 and 1 (defaults to 1)
1490
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
1491
- */
1492
- async closePosition(symbol, side = undefined, params = {}) {
1493
- await this.loadMarkets();
1494
- const orderId = this.safeString(params, 'orderId');
1495
- if (orderId === undefined) {
1496
- throw new ArgumentsRequired(this.id + ' closePosition() requires a orderId parameter');
1497
- }
1498
- const request = {
1499
- 'orderID': orderId,
1500
- };
1501
- const response = await this.privatePostExchangeOrdersCloseOrderID(this.extend(request, params));
1502
- //
1503
- // {
1504
- // "userID": "65671262d93d9525ac009e36",
1505
- // "orderID": "65671262d93d9525ac009e3617030152811996e5b352556d3d7d8_CL",
1506
- // "orderType": "market",
1507
- // "buyingCurrency": "ETH",
1508
- // "sellingCurrency": "EUR",
1509
- // "margin": true,
1510
- // "buyingQty": 0.03,
1511
- // "timeInForce": 4,
1512
- // "boughtQty": 0.03,
1513
- // "soldQty": 59.375,
1514
- // "creationTime": 1703015488482,
1515
- // "seqNumber": 10925321179,
1516
- // "firstFillTime": 1703015488483,
1517
- // "lastFillTime": 1703015488483,
1518
- // "fills": [
1519
- // {
1520
- // "seqNumber": 10925321178,
1521
- // "timestamp": 1703015488483,
1522
- // "qty": 0.03,
1523
- // "price": 1979.1666666666667,
1524
- // "side": "buy"
1525
- // }
1526
- // ],
1527
- // "completionTime": 1703015488483,
1528
- // "takerQty": 0.03
1529
- // }
1530
- //
1531
- return this.parseOrder(response);
1532
- }
1533
- /**
1534
- * @method
1535
- * @name coinmetro#fetchOpenOrders
1536
- * @description fetch all unfilled currently open orders
1537
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#518afd7a-4338-439c-a651-d4fdaa964138
1538
- * @param {string} symbol unified market symbol
1539
- * @param {int} [since] the earliest time in ms to fetch open orders for
1540
- * @param {int} [limit] the maximum number of open order structures to retrieve
1541
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1542
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
1543
- */
1544
- async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1545
- await this.loadMarkets();
1546
- let market = undefined;
1547
- if (symbol !== undefined) {
1548
- market = this.market(symbol);
1549
- }
1550
- const response = await this.privateGetExchangeOrdersActive(params);
1551
- const orders = this.parseOrders(response, market, since, limit);
1552
- for (let i = 0; i < orders.length; i++) {
1553
- const order = orders[i];
1554
- order['status'] = 'open';
1555
- }
1556
- return orders;
1557
- }
1558
- /**
1559
- * @method
1560
- * @name coinmetro#fetchCanceledAndClosedOrders
1561
- * @description fetches information on multiple canceled and closed orders made by the user
1562
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#4d48ae69-8ee2-44d1-a268-71f84e557b7b
1563
- * @param {string} symbol unified market symbol of the market orders were made in
1564
- * @param {int} [since] the earliest time in ms to fetch orders for
1565
- * @param {int} [limit] the maximum number of order structures to retrieve
1566
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1567
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
1568
- */
1569
- async fetchCanceledAndClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1570
- await this.loadMarkets();
1571
- let market = undefined;
1572
- if (symbol !== undefined) {
1573
- market = this.market(symbol);
1574
- }
1575
- const request = {};
1576
- if (since !== undefined) {
1577
- request['since'] = since;
1578
- }
1579
- const response = await this.privateGetExchangeOrdersHistorySince(this.extend(request, params));
1580
- return this.parseOrders(response, market, since, limit);
1581
- }
1582
- /**
1583
- * @method
1584
- * @name coinmetro#fetchOrder
1585
- * @description fetches information on an order made by the user
1586
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#95bbed87-db1c-47a7-a03e-aa247e91d5a6
1587
- * @param {int|string} id order id
1588
- * @param {string} symbol not used by coinmetro fetchOrder ()
1589
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1590
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
1591
- */
1592
- async fetchOrder(id, symbol = undefined, params = {}) {
1593
- await this.loadMarkets();
1594
- const request = {
1595
- 'orderID': id,
1596
- };
1597
- const response = await this.privateGetExchangeOrdersStatusOrderID(this.extend(request, params));
1598
- //
1599
- // {
1600
- // "_id": "657b4e6d60a954244939ac6f",
1601
- // "userID": "65671262d93d9525ac009e36",
1602
- // "orderID": "65671262d93d9525ac009e361702576531985b78465468b9cc544",
1603
- // "orderType": "market",
1604
- // "buyingCurrency": "ETH",
1605
- // "sellingCurrency": "USDC",
1606
- // "buyingQty": 0.004,
1607
- // "timeInForce": 4,
1608
- // "boughtQty": 0.004,
1609
- // "soldQty": 9.236,
1610
- // "creationTime": 1702576531995,
1611
- // "seqNumber": 10874644062,
1612
- // "firstFillTime": 1702576531995,
1613
- // "lastFillTime": 1702576531995,
1614
- // "fills": [
1615
- // {
1616
- // "_id": "657b4e6d60a954244939ac70",
1617
- // "seqNumber": 10874644061,
1618
- // "timestamp": 1702576531995,
1619
- // "qty": 0.004,
1620
- // "price": 2309,
1621
- // "side": "buy"
1622
- // }
1623
- // ],
1624
- // "completionTime": 1702576531995,
1625
- // "takerQty": 0.004,
1626
- // "fees": 0.000004,
1627
- // "isAncillary": false,
1628
- // "margin": false,
1629
- // "trade": false,
1630
- // "canceled": false
1631
- // }
1632
- //
1633
- return this.parseOrder(response);
1634
- }
1635
- parseOrder(order, market = undefined) {
1636
- //
1637
- // createOrder market
1638
- // {
1639
- // "userID": "65671262d93d9525ac009e36",
1640
- // "orderID": "65671262d93d9525ac009e36170257448481749b7ee2893bafec2",
1641
- // "orderType": "market",
1642
- // "buyingCurrency": "ETH",
1643
- // "sellingCurrency": "USDC",
1644
- // "buyingQty": 0.002,
1645
- // "timeInForce": 4,
1646
- // "boughtQty": 0.002,
1647
- // "soldQty": 4.587,
1648
- // "creationTime": 1702574484829,
1649
- // "seqNumber": 10874285330,
1650
- // "firstFillTime": 1702574484831,
1651
- // "lastFillTime": 1702574484831,
1652
- // "fills": [
1653
- // {
1654
- // "seqNumber": 10874285329,
1655
- // "timestamp": 1702574484831,
1656
- // "qty": 0.002,
1657
- // "price": 2293.5,
1658
- // "side": "buy"
1659
- // }
1660
- // ],
1661
- // "completionTime": 1702574484831,
1662
- // "takerQty": 0.002
1663
- // }
1664
- //
1665
- // createOrder limit
1666
- // {
1667
- // "userID": "65671262d93d9525ac009e36",
1668
- // "orderID": "65671262d93d9525ac009e3617026635256739c996fe17d7cd5d4",
1669
- // "orderType": "limit",
1670
- // "buyingCurrency": "ETH",
1671
- // "sellingCurrency": "USDC",
1672
- // "fillStyle": "sell",
1673
- // "orderPlatform": "trade-v3",
1674
- // "timeInForce": 1,
1675
- // "buyingQty": 0.005655,
1676
- // "sellingQty": 11.31,
1677
- // "boughtQty": 0,
1678
- // "soldQty": 0,
1679
- // "creationTime": 1702663525713,
1680
- // "seqNumber": 10885528683,
1681
- // "fees": 0,
1682
- // "fills": [],
1683
- // "isAncillary": false,
1684
- // "margin": false,
1685
- // "trade": false
1686
- // }
1687
- //
1688
- // fetchOrders market
1689
- // {
1690
- // "userID": "65671262d93d9525ac009e36",
1691
- // "orderID": "65671262d93d9525ac009e36170257061073952c6423a8c5b4d6c",
1692
- // "orderType": "market",
1693
- // "buyingCurrency": "ETH",
1694
- // "sellingCurrency": "USDC",
1695
- // "buyingQty": 0.002,
1696
- // "timeInForce": 4,
1697
- // "boughtQty": 0.002,
1698
- // "soldQty": 4.564,
1699
- // "creationTime": 1702570610746,
1700
- // "seqNumber": 10873722344,
1701
- // "firstFillTime": 1702570610747,
1702
- // "lastFillTime": 1702570610747,
1703
- // "fills": [
1704
- // {
1705
- // "_id": "657b31d360a9542449381bdc",
1706
- // "seqNumber": 10873722343,
1707
- // "timestamp": 1702570610747,
1708
- // "qty": 0.002,
1709
- // "price": 2282,
1710
- // "side": "buy"
1711
- // }
1712
- // ],
1713
- // "completionTime": 1702570610747,
1714
- // "takerQty": 0.002,
1715
- // "fees": 0.000002,
1716
- // "isAncillary": false,
1717
- // "margin": false,
1718
- // "trade": false,
1719
- // "canceled": false,
1720
- // "__v": 0
1721
- // }
1722
- //
1723
- // fetchOrders margin
1724
- // {
1725
- // "userData": {
1726
- // "takeProfit": 1700,
1727
- // "stopLoss": 2100
1728
- // },
1729
- // "_id": "658201d060a95424499394a2",
1730
- // "seqNumber": 10925300213,
1731
- // "orderType": "limit",
1732
- // "buyingCurrency": "EUR",
1733
- // "sellingCurrency": "ETH",
1734
- // "userID": "65671262d93d9525ac009e36",
1735
- // "closedQty": 0.03,
1736
- // "sellingQty": 0.03,
1737
- // "buyingQty": 58.8,
1738
- // "creationTime": 1703015281205,
1739
- // "margin": true,
1740
- // "timeInForce": 1,
1741
- // "boughtQty": 59.31,
1742
- // "orderID": "65671262d93d9525ac009e3617030152811996e5b352556d3d7d8",
1743
- // "lastFillTime": 1703015281206,
1744
- // "soldQty": 0.03,
1745
- // "closedTime": 1703015488488,
1746
- // "closedVal": 59.375,
1747
- // "trade": true,
1748
- // "takerQty": 59.31,
1749
- // "firstFillTime": 1703015281206,
1750
- // "completionTime": 1703015281206,
1751
- // "fills": [
1752
- // {
1753
- // "_id": "658201d060a95424499394a3",
1754
- // "seqNumber": 10925300212,
1755
- // "side": "sell",
1756
- // "price": 1977,
1757
- // "qty": 0.03,
1758
- // "timestamp": 1703015281206
1759
- // },
1760
- // {
1761
- // "_id": "658201d060a95424499394a4",
1762
- // "seqNumber": 10925321178,
1763
- // "timestamp": 1703015488483,
1764
- // "qty": 0.03,
1765
- // "price": 1979.1666666666667,
1766
- // "side": "buy"
1767
- // }
1768
- // ],
1769
- // "fees": 0.11875000200000001,
1770
- // "settledQtys": {
1771
- // "ETH": -0.000092842104710025
1772
- // },
1773
- // "isAncillary": false,
1774
- // "canceled": false
1775
- // }
1776
- //
1777
- // fetchOrder
1778
- // {
1779
- // "_id": "657b4e6d60a954244939ac6f",
1780
- // "userID": "65671262d93d9525ac009e36",
1781
- // "orderID": "65671262d93d9525ac009e361702576531985b78465468b9cc544",
1782
- // "orderType": "market",
1783
- // "buyingCurrency": "ETH",
1784
- // "sellingCurrency": "USDC",
1785
- // "buyingQty": 0.004,
1786
- // "timeInForce": 4,
1787
- // "boughtQty": 0.004,
1788
- // "soldQty": 9.236,
1789
- // "creationTime": 1702576531995,
1790
- // "seqNumber": 10874644062,
1791
- // "firstFillTime": 1702576531995,
1792
- // "lastFillTime": 1702576531995,
1793
- // "fills": [
1794
- // {
1795
- // "_id": "657b4e6d60a954244939ac70",
1796
- // "seqNumber": 10874644061,
1797
- // "timestamp": 1702576531995,
1798
- // "qty": 0.004,
1799
- // "price": 2309,
1800
- // "side": "buy"
1801
- // }
1802
- // ],
1803
- // "completionTime": 1702576531995,
1804
- // "takerQty": 0.004,
1805
- // "fees": 0.000004,
1806
- // "isAncillary": false,
1807
- // "margin": false,
1808
- // "trade": false,
1809
- // "canceled": false
1810
- // }
1811
- //
1812
- let timestamp = this.safeInteger(order, 'creationTime');
1813
- const isCanceled = this.safeValue(order, 'canceled');
1814
- let status = undefined;
1815
- if (isCanceled === true) {
1816
- if (timestamp === undefined) {
1817
- timestamp = this.safeInteger(order, 'completionTime'); // market orders with bad price gain IOC - we mark them as 'rejected'?
1818
- status = 'rejected'; // these orders don't have the 'creationTime` param and have 'canceled': true
1819
- }
1820
- else {
1821
- status = 'canceled';
1822
- }
1823
- }
1824
- else {
1825
- status = this.safeString(order, 'status');
1826
- order = this.omit(order, 'status'); // we mark orders from fetchOpenOrders with param 'status': 'open'
1827
- }
1828
- const type = this.safeString(order, 'orderType');
1829
- let buyingQty = this.safeString(order, 'buyingQty');
1830
- let sellingQty = this.safeString(order, 'sellingQty');
1831
- const boughtQty = this.safeString(order, 'boughtQty');
1832
- const soldQty = this.safeString(order, 'soldQty');
1833
- if (type === 'market') {
1834
- if ((buyingQty === undefined) && (boughtQty !== undefined) && (boughtQty !== '0')) {
1835
- buyingQty = boughtQty;
1836
- }
1837
- if ((sellingQty === undefined) && (soldQty !== undefined) && (soldQty !== '0')) {
1838
- sellingQty = soldQty;
1839
- }
1840
- }
1841
- const buyingCurrencyId = this.safeString(order, 'buyingCurrency', '');
1842
- const sellingCurrencyId = this.safeString(order, 'sellingCurrency', '');
1843
- const byuingIdPlusSellingId = buyingCurrencyId + sellingCurrencyId;
1844
- const sellingIdPlusBuyingId = sellingCurrencyId + buyingCurrencyId;
1845
- let side = undefined;
1846
- let marketId = undefined;
1847
- let baseAmount = buyingQty;
1848
- let quoteAmount = buyingQty;
1849
- let filled = undefined;
1850
- let cost = undefined;
1851
- let feeInBaseOrQuote = undefined;
1852
- const marketsById = this.indexBy(this.markets, 'id');
1853
- if (this.safeValue(marketsById, byuingIdPlusSellingId) !== undefined) {
1854
- side = 'buy';
1855
- marketId = byuingIdPlusSellingId;
1856
- quoteAmount = sellingQty;
1857
- filled = boughtQty;
1858
- cost = soldQty;
1859
- feeInBaseOrQuote = 'base';
1860
- }
1861
- else if (this.safeValue(marketsById, sellingIdPlusBuyingId) !== undefined) {
1862
- side = 'sell';
1863
- marketId = sellingIdPlusBuyingId;
1864
- baseAmount = sellingQty;
1865
- filled = soldQty;
1866
- cost = boughtQty;
1867
- feeInBaseOrQuote = 'quote';
1868
- }
1869
- let price = undefined;
1870
- if ((baseAmount !== undefined) && (quoteAmount !== undefined)) {
1871
- price = Precise.stringDiv(quoteAmount, baseAmount);
1872
- }
1873
- market = this.safeMarket(marketId, market);
1874
- let fee = undefined;
1875
- const feeCost = this.safeString(order, 'fees');
1876
- if ((feeCost !== undefined) && (feeInBaseOrQuote !== undefined)) {
1877
- fee = {
1878
- 'currency': market[feeInBaseOrQuote],
1879
- 'cost': feeCost,
1880
- 'rate': undefined,
1881
- };
1882
- }
1883
- const trades = this.safeValue(order, 'fills', []);
1884
- const userData = this.safeValue(order, 'userData', {});
1885
- const clientOrderId = this.safeString(userData, 'comment');
1886
- const takeProfitPrice = this.safeString(userData, 'takeProfit');
1887
- const stopLossPrice = this.safeString(userData, 'stopLoss');
1888
- return this.safeOrder({
1889
- 'id': this.safeString(order, 'orderID'),
1890
- 'clientOrderId': clientOrderId,
1891
- 'timestamp': timestamp,
1892
- 'datetime': this.iso8601(timestamp),
1893
- 'lastTradeTimestamp': this.safeInteger(order, 'lastFillTime'),
1894
- 'status': status,
1895
- 'symbol': market['symbol'],
1896
- 'type': type,
1897
- 'timeInForce': this.parseOrderTimeInForce(this.safeInteger(order, 'timeInForce')),
1898
- 'side': side,
1899
- 'price': price,
1900
- 'triggerPrice': this.safeString(order, 'stopPrice'),
1901
- 'takeProfitPrice': takeProfitPrice,
1902
- 'stopLossPrice': stopLossPrice,
1903
- 'average': undefined,
1904
- 'amount': baseAmount,
1905
- 'cost': cost,
1906
- 'filled': filled,
1907
- 'remaining': undefined,
1908
- 'fee': fee,
1909
- 'fees': undefined,
1910
- 'trades': trades,
1911
- 'info': order,
1912
- }, market);
1913
- }
1914
- parseOrderTimeInForce(timeInForce) {
1915
- const timeInForceTypes = [
1916
- undefined,
1917
- 'GTC',
1918
- 'IOC',
1919
- 'GTD',
1920
- 'FOK',
1921
- ];
1922
- return this.safeValue(timeInForceTypes, timeInForce, timeInForce);
1923
- }
1924
- /**
1925
- * @method
1926
- * @name coinmetro#borrowCrossMargin
1927
- * @description create a loan to borrow margin
1928
- * @see https://documenter.getpostman.com/view/3653795/SVfWN6KS#5b90b3b9-e5db-4d07-ac9d-d680a06fd110
1929
- * @param {string} code unified currency code of the currency to borrow
1930
- * @param {float} amount the amount to borrow
1931
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1932
- * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/?id=margin-loan-structure}
1933
- */
1934
- async borrowCrossMargin(code, amount, params = {}) {
1935
- await this.loadMarkets();
1936
- const currency = this.currency(code);
1937
- const currencyId = currency['id'];
1938
- const request = {};
1939
- request[currencyId] = this.currencyToPrecision(code, amount);
1940
- const response = await this.privatePutUsersMarginCollateral(this.extend(request, params));
1941
- //
1942
- // { "message": "OK" }
1943
- //
1944
- const result = this.safeValue(response, 'result', {});
1945
- const transaction = this.parseMarginLoan(result, currency);
1946
- return this.extend(transaction, {
1947
- 'amount': amount,
1948
- });
1949
- }
1950
- parseMarginLoan(info, currency = undefined) {
1951
- const currencyId = this.safeString(info, 'coin');
1952
- return {
1953
- 'id': undefined,
1954
- 'currency': this.safeCurrencyCode(currencyId, currency),
1955
- 'amount': undefined,
1956
- 'symbol': undefined,
1957
- 'timestamp': undefined,
1958
- 'datetime': undefined,
1959
- 'info': info,
1960
- };
1961
- }
1962
- sign(path, api = 'public', method = 'GET', params = {}, headers = {}, body = undefined) {
1963
- const request = this.omit(params, this.extractParams(path));
1964
- const endpoint = '/' + this.implodeParams(path, params);
1965
- let url = this.urls['api'][api] + endpoint;
1966
- const query = this.urlencode(request);
1967
- if (headers === undefined) {
1968
- headers = {};
1969
- }
1970
- headers['CCXT'] = 'true';
1971
- if (api === 'private') {
1972
- if ((this.uid === undefined) && (this.apiKey !== undefined)) {
1973
- this.uid = this.apiKey;
1974
- }
1975
- if ((this.token === undefined) && (this.secret !== undefined)) {
1976
- this.token = this.secret;
1977
- }
1978
- if (url === 'https://api.coinmetro.com/jwt') { // handle with headers for login endpoint
1979
- headers['X-Device-Id'] = 'bypass';
1980
- if (this.twofa !== undefined) {
1981
- headers['X-OTP'] = this.twofa;
1982
- }
1983
- }
1984
- else if (url === 'https://api.coinmetro.com/jwtDevice') { // handle with headers for long lived token login endpoint
1985
- headers['X-Device-Id'] = this.uid;
1986
- if (this.twofa !== undefined) {
1987
- headers['X-OTP'] = this.twofa;
1988
- }
1989
- }
1990
- else {
1991
- headers['Authorization'] = 'Bearer ' + this.token;
1992
- if (!url.startsWith('https://api.coinmetro.com/open')) { // if not sandbox endpoint
1993
- this.checkRequiredCredentials();
1994
- headers['X-Device-Id'] = this.uid;
1995
- }
1996
- }
1997
- if ((method === 'POST') || (method === 'PUT')) {
1998
- headers['Content-Type'] = 'application/x-www-form-urlencoded';
1999
- body = this.urlencode(request);
2000
- }
2001
- }
2002
- else if (query.length !== 0) {
2003
- url += '?' + query;
2004
- }
2005
- while (url.endsWith('/')) {
2006
- url = url.slice(0, url.length - 1);
2007
- }
2008
- return { 'url': url, 'method': method, 'body': body, 'headers': headers };
2009
- }
2010
- handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
2011
- if (response === undefined) {
2012
- return undefined;
2013
- }
2014
- if ((code !== 200) && (code !== 201) && (code !== 202)) {
2015
- const feedback = this.id + ' ' + body;
2016
- const message = this.safeString(response, 'message');
2017
- this.throwBroadlyMatchedException(this.exceptions['broad'], message, feedback);
2018
- this.throwExactlyMatchedException(this.exceptions['exact'], message, feedback);
2019
- throw new ExchangeError(feedback);
2020
- }
2021
- return undefined;
2022
- }
2023
- }