ccxt 4.2.26 → 4.2.28

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