ccxt 4.1.41 → 4.1.43

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.
@@ -0,0 +1,2328 @@
1
+ // ----------------------------------------------------------------------------
2
+
3
+ // PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
+ // https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
+ // EDIT THE CORRESPONDENT .ts FILE INSTEAD
6
+
7
+ import Exchange from './abstract/coinlist.js';
8
+ import { ArgumentsRequired, AuthenticationError, BadRequest, BadSymbol, ExchangeError, InsufficientFunds, InvalidAddress, InvalidOrder, NotSupported, OnMaintenance, OrderNotFound, PermissionDenied } from './base/errors.js';
9
+ import { TICK_SIZE } from './base/functions/number.js';
10
+ import { Precise } from './base/Precise.js';
11
+ import { sha256 } from './static_dependencies/noble-hashes/sha256.js';
12
+ /**
13
+ * @class coinlist
14
+ * @extends Exchange
15
+ */
16
+ export default class coinlist extends Exchange {
17
+ describe() {
18
+ return this.deepExtend(super.describe(), {
19
+ 'id': 'coinlist',
20
+ 'name': 'Coinlist',
21
+ 'countries': ['US'],
22
+ 'version': 'v1',
23
+ 'rateLimit': 300,
24
+ 'certified': false,
25
+ 'pro': false,
26
+ 'has': {
27
+ 'CORS': undefined,
28
+ 'spot': true,
29
+ 'margin': false,
30
+ 'swap': false,
31
+ 'future': false,
32
+ 'option': false,
33
+ 'addMargin': false,
34
+ 'borrowMargin': false,
35
+ 'cancelAllOrders': true,
36
+ 'cancelOrder': true,
37
+ 'cancelOrders': true,
38
+ 'createDepositAddress': false,
39
+ 'createOrder': true,
40
+ 'createPostOnlyOrder': true,
41
+ 'createReduceOnlyOrder': false,
42
+ 'createStopLimitOrder': true,
43
+ 'createStopMarketOrder': true,
44
+ 'createStopOrder': true,
45
+ 'deposit': false,
46
+ 'editOrder': true,
47
+ 'fetchAccounts': true,
48
+ 'fetchBalance': true,
49
+ 'fetchBidsAsks': false,
50
+ 'fetchBorrowInterest': false,
51
+ 'fetchBorrowRate': false,
52
+ 'fetchBorrowRateHistories': false,
53
+ 'fetchBorrowRateHistory': false,
54
+ 'fetchBorrowRates': false,
55
+ 'fetchBorrowRatesPerSymbol': false,
56
+ 'fetchCanceledOrders': true,
57
+ 'fetchClosedOrder': false,
58
+ 'fetchClosedOrders': true,
59
+ 'fetchCurrencies': true,
60
+ 'fetchDeposit': false,
61
+ 'fetchDepositAddress': false,
62
+ 'fetchDepositAddresses': false,
63
+ 'fetchDepositAddressesByNetwork': false,
64
+ 'fetchDeposits': false,
65
+ 'fetchDepositsWithdrawals': true,
66
+ 'fetchDepositWithdrawFee': false,
67
+ 'fetchDepositWithdrawFees': false,
68
+ 'fetchFundingHistory': false,
69
+ 'fetchFundingRate': false,
70
+ 'fetchFundingRateHistory': false,
71
+ 'fetchFundingRates': false,
72
+ 'fetchIndexOHLCV': 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': true,
89
+ 'fetchOrderTrades': true,
90
+ 'fetchPosition': false,
91
+ 'fetchPositions': false,
92
+ 'fetchPositionsRisk': false,
93
+ 'fetchPremiumIndexOHLCV': false,
94
+ 'fetchStatus': false,
95
+ 'fetchTicker': true,
96
+ 'fetchTickers': true,
97
+ 'fetchTime': true,
98
+ 'fetchTrades': true,
99
+ 'fetchTradingFee': false,
100
+ 'fetchTradingFees': true,
101
+ 'fetchTradingLimits': false,
102
+ 'fetchTransactionFee': false,
103
+ 'fetchTransactionFees': false,
104
+ 'fetchTransactions': true,
105
+ 'fetchTransfers': true,
106
+ 'fetchWithdrawal': false,
107
+ 'fetchWithdrawals': false,
108
+ 'fetchWithdrawalWhitelist': false,
109
+ 'reduceMargin': false,
110
+ 'repayMargin': false,
111
+ 'setLeverage': false,
112
+ 'setMargin': false,
113
+ 'setMarginMode': false,
114
+ 'setPositionMode': false,
115
+ 'signIn': false,
116
+ 'transfer': true,
117
+ 'withdraw': true,
118
+ 'ws': false,
119
+ },
120
+ 'timeframes': {
121
+ '1m': '1m',
122
+ '5m': '5m',
123
+ '30m': '30m',
124
+ },
125
+ 'urls': {
126
+ 'logo': 'https://github-production-user-asset-6210df.s3.amazonaws.com/1294454/281108917-eff2ae1d-ce8a-4b2a-950d-8678b12da965.jpg',
127
+ 'api': {
128
+ 'public': 'https://trade-api.coinlist.co',
129
+ 'private': 'https://trade-api.coinlist.co',
130
+ },
131
+ 'www': 'https://coinlist.co',
132
+ 'doc': [
133
+ 'https://trade-docs.coinlist.co',
134
+ ],
135
+ 'fees': 'https://coinlist.co/fees',
136
+ },
137
+ 'api': {
138
+ 'public': {
139
+ 'get': {
140
+ 'v1/symbols': 1,
141
+ 'v1/symbols/summary': 1,
142
+ 'v1/symbols/{symbol}': 1,
143
+ 'v1/symbols/{symbol}/summary': 1,
144
+ 'v1/symbols/{symbol}/book': 1,
145
+ 'v1/symbols/{symbol}/quote': 1,
146
+ 'v1/symbols/{symbol}/candles': 1,
147
+ 'v1/symbols/{symbol}/auctions': 1,
148
+ 'v1/symbols/{symbol}/auctions/{auction_code}': 1,
149
+ 'v1/time': 1,
150
+ 'v1/assets': 1,
151
+ },
152
+ },
153
+ 'private': {
154
+ 'get': {
155
+ 'v1/fees': 1,
156
+ 'v1/accounts': 1,
157
+ 'v1/accounts/{trader_id}': 1,
158
+ 'v1/accounts/{trader_id}/ledger': 1,
159
+ 'v1/accounts/{trader_id}/wallets': 1,
160
+ 'v1/accounts/{trader_id}/wallet-ledger': 1,
161
+ 'v1/accounts/{trader_id}/ledger-summary': 1,
162
+ 'v1/keys': 1,
163
+ 'v1/fills': 1,
164
+ 'v1/orders': 1,
165
+ 'v1/orders/{order_id}': 1,
166
+ 'v1/reports': 1,
167
+ 'v1/balances': 1,
168
+ 'v1/transfers': 1,
169
+ 'v1/user': 1,
170
+ 'v1/credits': 1, // not unified
171
+ },
172
+ 'post': {
173
+ 'v1/keys': 1,
174
+ 'v1/orders': 1,
175
+ 'v1/orders/cancel-all-after': 1,
176
+ 'v1/reports': 1,
177
+ 'v1/transfers/to-wallet': 1,
178
+ 'v1/transfers/from-wallet': 1,
179
+ 'v1/transfers/internal-transfer': 1,
180
+ 'v1/transfers/withdrawal-request': 1,
181
+ 'v1/orders/bulk': 1, // not unified
182
+ },
183
+ 'patch': {
184
+ 'v1/orders/{order_id}': 1,
185
+ 'v1/orders/bulk': 1, // not unified
186
+ },
187
+ 'delete': {
188
+ 'v1/keys/{key}': 1,
189
+ 'v1/orders': 1,
190
+ 'v1/orders/{order_id}': 1,
191
+ 'v1/orders/bulk': 1,
192
+ },
193
+ },
194
+ },
195
+ 'fees': {
196
+ 'trading': {
197
+ 'feeSide': 'get',
198
+ 'tierBased': true,
199
+ 'percentage': true,
200
+ 'taker': this.parseNumber('0.0045'),
201
+ 'maker': this.parseNumber('0.0025'),
202
+ 'tiers': {
203
+ 'taker': [
204
+ [this.parseNumber('0'), this.parseNumber('0.0045')],
205
+ [this.parseNumber('20000'), this.parseNumber('0.003')],
206
+ [this.parseNumber('50000'), this.parseNumber('0.0025')],
207
+ [this.parseNumber('100000'), this.parseNumber('0.002')],
208
+ [this.parseNumber('500000'), this.parseNumber('0.0018')],
209
+ [this.parseNumber('750000'), this.parseNumber('0.0018')],
210
+ [this.parseNumber('1000000'), this.parseNumber('0.0016')],
211
+ [this.parseNumber('2500000'), this.parseNumber('0.0013')],
212
+ [this.parseNumber('5000000'), this.parseNumber('0.0012')],
213
+ [this.parseNumber('10000000'), this.parseNumber('0.001')],
214
+ [this.parseNumber('50000000'), this.parseNumber('0.0005')],
215
+ [this.parseNumber('100000000'), this.parseNumber('0.0005')],
216
+ ],
217
+ 'maker': [
218
+ [this.parseNumber('0'), this.parseNumber('0.0025')],
219
+ [this.parseNumber('20000'), this.parseNumber('0.0025')],
220
+ [this.parseNumber('50000'), this.parseNumber('0.0025')],
221
+ [this.parseNumber('100000'), this.parseNumber('0.002')],
222
+ [this.parseNumber('500000'), this.parseNumber('0.0015')],
223
+ [this.parseNumber('750000'), this.parseNumber('0.0012')],
224
+ [this.parseNumber('1000000'), this.parseNumber('0.001')],
225
+ [this.parseNumber('2500000'), this.parseNumber('0.0008')],
226
+ [this.parseNumber('5000000'), this.parseNumber('0.0007')],
227
+ [this.parseNumber('10000000'), this.parseNumber('0.0006')],
228
+ [this.parseNumber('50000000'), this.parseNumber('0.0000')],
229
+ [this.parseNumber('100000000'), this.parseNumber('0.00')],
230
+ ],
231
+ },
232
+ },
233
+ },
234
+ 'precisionMode': TICK_SIZE,
235
+ // exchange-specific options
236
+ 'options': {
237
+ 'accountsByType': {
238
+ 'CoinList Pro': 'trading',
239
+ 'CoinList Pro trading account': 'trading',
240
+ 'Pro': 'trading',
241
+ 'pro': 'trading',
242
+ 'trade': 'trading',
243
+ 'trading': 'trading',
244
+ 'CoinList': 'funding',
245
+ 'CoinList wallet': 'funding',
246
+ 'Wallet': 'funding',
247
+ 'wallet': 'funding',
248
+ 'fund': 'funding',
249
+ 'funding': 'funding',
250
+ },
251
+ },
252
+ 'exceptions': {
253
+ // https://trade-docs.coinlist.co/?javascript--nodejs#message-codes
254
+ 'exact': {
255
+ 'AUTH_SIG_INVALID': AuthenticationError,
256
+ 'DENIED_MAINTENANCE': OnMaintenance,
257
+ 'ORDER_REJECT_BAD_STATUS': InvalidOrder,
258
+ 'ORDER_REJECT_INVALID_POST_ONLY': InvalidOrder,
259
+ 'ORDER_REJECT_INVALID_CLOSE_ONLY': InvalidOrder,
260
+ 'ORDER_REJECT_POST_ONLY_REQUIRED': InvalidOrder,
261
+ 'ORDER_REJECT_FROZEN_ORDER': InvalidOrder,
262
+ 'ORDER_REJECT_LIMIT_PRICE_PROTECTION_VIOLATION': InvalidOrder,
263
+ 'ORDER_REJECT_CLOSED': NotSupported,
264
+ 'ORDER_REJECT_MAX_ORDERS': BadRequest,
265
+ 'ORDER_REJECT_NOT_FOUND': OrderNotFound,
266
+ 'ORDER_REJECT_PARSE_ERROR': BadRequest,
267
+ 'ORDER_REJECT_PRICE_INVALID': InvalidOrder,
268
+ 'ORDER_REJECT_QUANTITY_ZERO': InvalidOrder,
269
+ 'ORDER_REJECT_TOKEN_LIMIT': InsufficientFunds,
270
+ 'ORDER_REJECT_TOKEN_LIMIT_OTHER': InvalidOrder,
271
+ 'ORDER_REJECT_SELF_TRADE': InvalidOrder,
272
+ 'ORDER_VALIDATE_BAD_SIZE_ALIGNMENT': InvalidOrder,
273
+ 'ORDER_VALIDATE_BAD_TICK_ALIGNMENT': InvalidOrder,
274
+ 'ORDER_VALIDATE_SYMBOL_NOT_FOUND': BadSymbol,
275
+ 'TRANSFERS_WITHDRAWAL_REQUEST_TOO_LARGE': InsufficientFunds,
276
+ 'WITHDRAWAL_REQUEST_NOT_ALLOWED': PermissionDenied, // {"message":"Withdrawal from CoinList not allowed for trader.","message_code":"WITHDRAWAL_REQUEST_NOT_ALLOWED","message_details":{"asset":"USDT","amount":"5","trader_id":"9c6f737e-a829-4843-87b1-b1ce86f2853b","destination_address":"0x9050dfA063D1bE7cA711c750b18D51fDD13e90Ee"}}
277
+ },
278
+ 'broad': {
279
+ 'A destinationAddress is required for non-USD withdrawals': InvalidAddress,
280
+ 'fails to match the JsonSchema date-time format pattern': BadRequest,
281
+ 'is required': ArgumentsRequired,
282
+ 'must be a string': BadRequest,
283
+ 'must be a valid GUID': BadRequest,
284
+ 'must be greater than or equal to': BadRequest,
285
+ 'must be less than or equal to': BadRequest,
286
+ 'must be one of': BadRequest,
287
+ 'Symbol not found': BadSymbol, // {"message":"Symbol not found: {symbol}"}
288
+ },
289
+ },
290
+ });
291
+ }
292
+ calculateRateLimiterCost(api, method, path, params, config = {}) {
293
+ if (Array.isArray(params)) {
294
+ const length = params.length;
295
+ return Math.ceil(length / 2);
296
+ }
297
+ return 1;
298
+ }
299
+ async fetchTime(params = {}) {
300
+ /**
301
+ * @method
302
+ * @name coinlist#fetchTime
303
+ * @description fetches the current integer timestamp in milliseconds from the exchange server
304
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#get-system-time
305
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
306
+ * @returns {int} the current integer timestamp in milliseconds from the exchange server
307
+ */
308
+ const response = await this.publicGetV1Time(params);
309
+ //
310
+ // {
311
+ // "epoch": 1698087996.039,
312
+ // "iso": "2023-10-23T19:06:36.039Z"
313
+ // }
314
+ //
315
+ const string = this.safeString(response, 'iso');
316
+ return this.parse8601(string);
317
+ }
318
+ async fetchCurrencies(params = {}) {
319
+ /**
320
+ * @method
321
+ * @name coinlist#fetchCurrencies
322
+ * @description fetches all available currencies on an exchange
323
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#list-supported-assets
324
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
325
+ * @returns {object} an associative dictionary of currencies
326
+ */
327
+ const response = await this.publicGetV1Assets(params);
328
+ //
329
+ // {
330
+ // "assets": [
331
+ // {
332
+ // "asset": "AAVE",
333
+ // "index_code": ".AAVEUSD",
334
+ // "decimal_places": 18,
335
+ // "min_withdrawal": "1.0000",
336
+ // "is_transferable": true,
337
+ // "is_visible": true
338
+ // },
339
+ // {
340
+ // "asset": "ALGO",
341
+ // "index_code": ".ALGOUSD",
342
+ // "decimal_places": 6,
343
+ // "min_withdrawal": "1.0000",
344
+ // "is_transferable": true,
345
+ // "is_visible": true
346
+ // }
347
+ // ]
348
+ // }
349
+ //
350
+ const currencies = this.safeValue(response, 'assets', []);
351
+ const result = {};
352
+ for (let i = 0; i < currencies.length; i++) {
353
+ const currency = currencies[i];
354
+ const id = this.safeString(currency, 'asset');
355
+ const code = this.safeCurrencyCode(id);
356
+ const isTransferable = this.safeValue(currency, 'is_transferable', false);
357
+ const withdrawEnabled = isTransferable;
358
+ const depositEnabled = isTransferable;
359
+ const active = isTransferable;
360
+ const decimalPlaces = this.safeString(currency, 'decimal_places');
361
+ const precision = this.parseNumber(this.parsePrecision(decimalPlaces));
362
+ const minWithdrawal = this.safeString(currency, 'min_withdrawal');
363
+ result[code] = {
364
+ 'id': id,
365
+ 'code': code,
366
+ 'name': code,
367
+ 'info': currency,
368
+ 'active': active,
369
+ 'deposit': depositEnabled,
370
+ 'withdraw': withdrawEnabled,
371
+ 'fee': undefined,
372
+ 'precision': precision,
373
+ 'limits': {
374
+ 'amount': { 'min': undefined, 'max': undefined },
375
+ 'withdraw': { 'min': minWithdrawal, 'max': undefined },
376
+ },
377
+ 'networks': {},
378
+ };
379
+ }
380
+ return result;
381
+ }
382
+ async fetchMarkets(params = {}) {
383
+ /**
384
+ * @method
385
+ * @name coinlist#fetchMarkets
386
+ * @description retrieves data on all markets for coinlist
387
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#list-symbols
388
+ * @param {object} [params] extra parameters specific to the exchange api endpoint
389
+ * @returns {object[]} an array of objects representing market data
390
+ */
391
+ const response = await this.publicGetV1Symbols(params);
392
+ //
393
+ // {
394
+ // symbols: [
395
+ // {
396
+ // symbol: 'CQT-USDT',
397
+ // base_currency: 'CQT',
398
+ // is_trader_geofenced: false,
399
+ // list_time: '2021-06-15T00:00:00.000Z',
400
+ // type: 'spot',
401
+ // series_code: 'CQT-USDT-SPOT',
402
+ // long_name: 'Covalent',
403
+ // asset_class: 'CRYPTO',
404
+ // minimum_price_increment: '0.0001',
405
+ // minimum_size_increment: '0.0001',
406
+ // quote_currency: 'USDT',
407
+ // index_code: null,
408
+ // price_band_threshold_market: '0.05',
409
+ // price_band_threshold_limit: '0.25',
410
+ // last_price: '0.12160000',
411
+ // fair_price: '0.12300000',
412
+ // index_price: null
413
+ // },
414
+ // ]
415
+ // }
416
+ //
417
+ const markets = this.safeValue(response, 'symbols', []);
418
+ const result = [];
419
+ for (let i = 0; i < markets.length; i++) {
420
+ const market = markets[i];
421
+ const id = this.safeString(market, 'symbol');
422
+ const baseId = this.safeString(market, 'base_currency');
423
+ const quoteId = this.safeString(market, 'quote_currency');
424
+ const base = this.safeCurrencyCode(baseId);
425
+ const quote = this.safeCurrencyCode(quoteId);
426
+ const amountPrecision = this.safeString(market, 'minimum_size_increment');
427
+ const pricePrecision = this.safeString(market, 'minimum_price_increment');
428
+ const created = this.safeString(market, 'list_time');
429
+ result.push({
430
+ 'id': id,
431
+ 'symbol': base + '/' + quote,
432
+ 'base': base,
433
+ 'quote': quote,
434
+ 'settle': undefined,
435
+ 'baseId': baseId,
436
+ 'quoteId': quoteId,
437
+ 'settleId': undefined,
438
+ 'type': 'spot',
439
+ 'spot': true,
440
+ 'margin': false,
441
+ 'swap': false,
442
+ 'future': false,
443
+ 'option': false,
444
+ 'active': true,
445
+ 'contract': false,
446
+ 'linear': undefined,
447
+ 'inverse': undefined,
448
+ 'contractSize': undefined,
449
+ 'expiry': undefined,
450
+ 'expiryDatetime': undefined,
451
+ 'strike': undefined,
452
+ 'optionType': undefined,
453
+ 'precision': {
454
+ 'amount': this.parseNumber(amountPrecision),
455
+ 'price': this.parseNumber(pricePrecision),
456
+ },
457
+ 'limits': {
458
+ 'leverage': {
459
+ 'min': undefined,
460
+ 'max': undefined,
461
+ },
462
+ 'amount': {
463
+ 'min': undefined,
464
+ 'max': undefined,
465
+ },
466
+ 'price': {
467
+ 'min': undefined,
468
+ 'max': undefined,
469
+ },
470
+ 'cost': {
471
+ 'min': undefined,
472
+ 'max': undefined,
473
+ },
474
+ },
475
+ 'created': this.parse8601(created),
476
+ 'info': market,
477
+ });
478
+ }
479
+ return result;
480
+ }
481
+ async fetchTickers(symbols = undefined, params = {}) {
482
+ /**
483
+ * @method
484
+ * @name coinlist#fetchTickers
485
+ * @description fetches price tickers for multiple markets, statistical calculations with the information calculated over the past 24 hours each market
486
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#get-symbol-summaries
487
+ * @param {string[]|} [symbols] unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
488
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
489
+ * @returns {object} a dictionary of [ticker structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#ticker-structure}
490
+ */
491
+ await this.loadMarkets();
492
+ const request = {};
493
+ const tickers = await this.publicGetV1SymbolsSummary(this.extend(request, params));
494
+ //
495
+ // {
496
+ // "MATIC-USD": {
497
+ // "type":"spot",
498
+ // "last_price":"0.60990000",
499
+ // "lowest_ask":"0.61190000",
500
+ // "highest_bid":"0.60790000",
501
+ // "last_trade": {
502
+ // "price":"0.60000000",
503
+ // "volume":"2.0000",
504
+ // "imbalance":"198.0000",
505
+ // "logicalTime":"2023-10-22T23:02:25.000Z",
506
+ // "auctionCode":"MATIC-USD-2023-10-22T23:02:25.000Z"
507
+ // },
508
+ // "volume_base_24h":"34.0555",
509
+ // "volume_quote_24h":"19.9282",
510
+ // "price_change_percent_24h":"7.50925436",
511
+ // "highest_price_24h":"0.68560000",
512
+ // "lowest_price_24h":"0.55500000"
513
+ // },
514
+ // }
515
+ //
516
+ return this.parseTickers(tickers, symbols, params);
517
+ }
518
+ async fetchTicker(symbol, params = {}) {
519
+ /**
520
+ * @method
521
+ * @name coinlist#fetchTicker
522
+ * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
523
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#get-market-summary
524
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
525
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
526
+ * @returns {object} a [ticker structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#ticker-structure}
527
+ */
528
+ await this.loadMarkets();
529
+ const market = this.market(symbol);
530
+ const request = {
531
+ 'symbol': market['id'],
532
+ };
533
+ const ticker = await this.publicGetV1SymbolsSymbolSummary(this.extend(request, params));
534
+ //
535
+ // {
536
+ // "type":"spot",
537
+ // "last_price":"31125.00000000",
538
+ // "lowest_ask":"31349.99000000",
539
+ // "highest_bid":"30900.00000000",
540
+ // "last_trade": {
541
+ // "price":"31000.00000000",
542
+ // "volume":"0.0003",
543
+ // "imbalance":"0.0000",
544
+ // "logicalTime":"2023-10-23T16:57:15.000Z",
545
+ // "auctionCode":"BTC-USDT-2023-10-23T16:57:15.000Z"
546
+ // },
547
+ // "volume_base_24h":"0.3752",
548
+ // "volume_quote_24h":"11382.7181",
549
+ // "price_change_percent_24h":"3.66264694",
550
+ // "highest_price_24h":"31225.12000000",
551
+ // "lowest_price_24h":"29792.81000000"
552
+ // }
553
+ //
554
+ return this.parseTicker(ticker, market);
555
+ }
556
+ parseTicker(ticker, market = undefined) {
557
+ //
558
+ // {
559
+ // "type":"spot",
560
+ // "last_price":"0.60990000",
561
+ // "lowest_ask":"0.61190000",
562
+ // "highest_bid":"0.60790000",
563
+ // "last_trade": {
564
+ // "price":"0.60000000",
565
+ // "volume":"2.0000",
566
+ // "imbalance":"198.0000",
567
+ // "logicalTime":"2023-10-22T23:02:25.000Z",
568
+ // "auctionCode":"MATIC-USD-2023-10-22T23:02:25.000Z"
569
+ // },
570
+ // "volume_base_24h":"34.0555",
571
+ // "volume_quote_24h":"19.9282",
572
+ // "price_change_percent_24h":"7.50925436",
573
+ // "highest_price_24h":"0.68560000",
574
+ // "lowest_price_24h":"0.55500000"
575
+ // }
576
+ //
577
+ const lastTrade = this.safeValue(ticker, 'last_trade', {});
578
+ const timestamp = this.parse8601(this.safeString(lastTrade, 'logicalTime'));
579
+ const bid = this.safeString(ticker, 'highest_bid');
580
+ const ask = this.safeString(ticker, 'lowest_ask');
581
+ const baseVolume = this.safeString(ticker, 'volume_base_24h');
582
+ const quoteVolume = this.safeString(ticker, 'volume_quote_24h');
583
+ const high = this.safeString(ticker, 'highest_price_24h');
584
+ const low = this.safeString(ticker, 'lowest_price_24h');
585
+ const close = this.safeString(ticker, 'last_price');
586
+ const changePcnt = this.safeString(ticker, 'price_change_percent_24h');
587
+ return this.safeTicker({
588
+ 'symbol': market['symbol'],
589
+ 'timestamp': timestamp,
590
+ 'datetime': this.iso8601(timestamp),
591
+ 'open': undefined,
592
+ 'high': high,
593
+ 'low': low,
594
+ 'close': close,
595
+ 'bid': bid,
596
+ 'bidVolume': undefined,
597
+ 'ask': ask,
598
+ 'askVolume': undefined,
599
+ 'vwap': undefined,
600
+ 'previousClose': undefined,
601
+ 'change': undefined,
602
+ 'percentage': changePcnt,
603
+ 'average': undefined,
604
+ 'baseVolume': baseVolume,
605
+ 'quoteVolume': quoteVolume,
606
+ 'info': ticker,
607
+ }, market);
608
+ }
609
+ async fetchOrderBook(symbol, limit = undefined, params = {}) {
610
+ /**
611
+ * @method
612
+ * @name coinlist#fetchOrderBook
613
+ * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
614
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#get-order-book-level-2
615
+ * @param {string} symbol unified symbol of the market to fetch the order book for
616
+ * @param {int} [limit] the maximum amount of order book entries to return (default 100, max 200)
617
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
618
+ * @returns {object} A dictionary of [order book structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-book-structure} indexed by market symbols
619
+ */
620
+ await this.loadMarkets();
621
+ const market = this.market(symbol);
622
+ const request = {
623
+ 'symbol': market['id'],
624
+ };
625
+ const response = await this.publicGetV1SymbolsSymbolBook(this.extend(request, params));
626
+ //
627
+ // {
628
+ // "bids": [
629
+ // [ "30900.00000000", "0.0001" ],
630
+ // [ "30664.21000000", "0.0172" ],
631
+ // [ "30664.20000000", "0.0906" ],
632
+ // ],
633
+ // "asks": [
634
+ // [ "31349.99000000", "0.0003" ],
635
+ // [ "31350.00000000", "0.0023" ],
636
+ // [ "31359.33000000", "0.0583" ],
637
+ // ],
638
+ // "after_auction_code": "BTC-USDT-2023-10-23T18:40:51.000Z",
639
+ // "call_time": "2023-10-23T18:40:51.068Z",
640
+ // "logical_time": "2023-10-23T18:40:51.000Z"
641
+ // }
642
+ //
643
+ const logical_time = this.parse8601(this.safeString(response, 'logical_time'));
644
+ const orderbook = this.parseOrderBook(response, symbol, logical_time);
645
+ orderbook['nonce'] = undefined;
646
+ return orderbook;
647
+ }
648
+ async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
649
+ /**
650
+ * @method
651
+ * @name coinlist#fetchOHLCV
652
+ * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
653
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#get-candles
654
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
655
+ * @param {string} timeframe the length of time each candle represents
656
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
657
+ * @param {int} [limit] the maximum amount of candles to fetch
658
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
659
+ * @param {int} [params.until] the latest time in ms to fetch entries for
660
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
661
+ */
662
+ await this.loadMarkets();
663
+ const market = this.market(symbol);
664
+ const granularity = this.safeString(this.timeframes, timeframe);
665
+ const request = {
666
+ 'symbol': market['id'],
667
+ 'granularity': granularity,
668
+ };
669
+ if (since !== undefined) {
670
+ request['start_time'] = this.iso8601(since);
671
+ if (limit !== undefined) {
672
+ const duration = this.parseTimeframe(timeframe) * 1000;
673
+ request['end_time'] = this.iso8601(this.sum(since, duration * (limit)));
674
+ }
675
+ else {
676
+ request['end_time'] = this.iso8601(this.milliseconds());
677
+ }
678
+ }
679
+ const until = this.safeInteger2(params, 'till', 'until');
680
+ if (until !== undefined) {
681
+ params = this.omit(params, ['till', 'until']);
682
+ request['end_time'] = this.iso8601(until);
683
+ }
684
+ const response = await this.publicGetV1SymbolsSymbolCandles(this.extend(request, params));
685
+ //
686
+ // {
687
+ // "candles": [
688
+ // [
689
+ // "2023-10-17T15:00:00.000Z",
690
+ // "28522.96000000",
691
+ // "28522.96000000",
692
+ // "28522.96000000",
693
+ // "28522.96000000",
694
+ // "0.1881",
695
+ // null
696
+ // ],
697
+ // [
698
+ // "2023-10-17T15:30:00.000Z",
699
+ // "28582.64000000",
700
+ // "28582.64000000",
701
+ // "28582.64000000",
702
+ // "28582.64000000",
703
+ // "0.0050",
704
+ // null
705
+ // ]
706
+ // ]
707
+ // }
708
+ //
709
+ const candles = this.safeValue(response, 'candles', []);
710
+ return this.parseOHLCVs(candles, market, timeframe, since, limit);
711
+ }
712
+ parseOHLCV(ohlcv, market = undefined) {
713
+ //
714
+ // [
715
+ // "2023-10-17T15:30:00.000Z",
716
+ // "28582.64000000",
717
+ // "28582.64000000",
718
+ // "28582.64000000",
719
+ // "28582.64000000",
720
+ // "0.0050",
721
+ // null
722
+ // ]
723
+ //
724
+ return [
725
+ this.parse8601(this.safeString(ohlcv, 0)),
726
+ this.safeNumber(ohlcv, 1),
727
+ this.safeNumber(ohlcv, 2),
728
+ this.safeNumber(ohlcv, 3),
729
+ this.safeNumber(ohlcv, 4),
730
+ this.safeNumber(ohlcv, 5),
731
+ ];
732
+ }
733
+ async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
734
+ /**
735
+ * @method
736
+ * @name coinlist#fetchTrades
737
+ * @description get the list of most recent trades for a particular symbol
738
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#list-auctions
739
+ * @param {string} symbol unified symbol of the market to fetch trades for
740
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
741
+ * @param {int} [limit] the maximum amount of trades to fetch (default 200, max 500)
742
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
743
+ * @param {int} [params.until] the latest time in ms to fetch entries for
744
+ * @returns {Trade[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#public-trades}
745
+ */
746
+ await this.loadMarkets();
747
+ const market = this.market(symbol);
748
+ const request = {
749
+ 'symbol': market['id'],
750
+ };
751
+ if (since !== undefined) {
752
+ request['start_time'] = this.iso8601(since);
753
+ }
754
+ if (limit !== undefined) {
755
+ request['count'] = limit;
756
+ }
757
+ const until = this.safeInteger2(params, 'till', 'until');
758
+ if (until !== undefined) {
759
+ params = this.omit(params, ['till', 'until']);
760
+ request['end_time'] = this.iso8601(until);
761
+ }
762
+ const response = await this.publicGetV1SymbolsSymbolAuctions(this.extend(request, params));
763
+ //
764
+ // {
765
+ // "auctions": [
766
+ // {
767
+ // "symbol":"BTC-USDT",
768
+ // "auction_code":"BTC-USDT-2023-10-01T08:05:56.000Z",
769
+ // "price":"27241.53000000",
770
+ // "volume":"0.0052",
771
+ // "imbalance":"-1.0983",
772
+ // "logical_time":"2023-10-01T08:05:56.000Z",
773
+ // "call_time":"2023-10-01T08:05:56.068Z"
774
+ // },
775
+ // {
776
+ // "symbol":"BTC-USDT",
777
+ // "auction_code":"BTC-USDT-2023-10-01T08:09:09.000Z",
778
+ // "price":"27236.83000000",
779
+ // "volume":"0.0283",
780
+ // "imbalance":"-1.0754",
781
+ // "logical_time":"2023-10-01T08:09:09.000Z",
782
+ // "call_time":"2023-10-01T08:09:09.078Z"
783
+ // }
784
+ // ]
785
+ // }
786
+ //
787
+ const auctions = this.safeValue(response, 'auctions', []);
788
+ return this.parseTrades(auctions, market, since, limit);
789
+ }
790
+ parseTrade(trade, market = undefined) {
791
+ //
792
+ // fetchTrades
793
+ // {
794
+ // "symbol": "BTC-USDT",
795
+ // "auction_code": "BTC-USDT-2023-10-01T08:05:56.000Z",
796
+ // "price": "27241.53000000",
797
+ // "volume": "0.0052",
798
+ // "imbalance": "-1.0983",
799
+ // "logical_time": "2023-10-01T08:05:56.000Z",
800
+ // "call_time": "2023-10-01T08:05:56.068Z"
801
+ // }
802
+ //
803
+ // fetchMyTrades
804
+ // {
805
+ // symbol: 'ETH-USDT',
806
+ // auction_code: 'ETH-USDT-2023-10-20T13:22:14.000Z',
807
+ // order_id: '83ed365f-497d-433b-96c1-9d08c1a12842',
808
+ // quantity: '0.0008',
809
+ // price: '1615.24000000',
810
+ // fee: '0.005815',
811
+ // fee_type: 'taker',
812
+ // fee_currency: 'USDT',
813
+ // logical_time: '2023-10-20T13:22:14.000Z'
814
+ // }
815
+ //
816
+ const marketId = this.safeString(trade, 'symbol');
817
+ market = this.safeMarket(marketId, market);
818
+ const symbol = market['symbol'];
819
+ const id = this.safeString(trade, 'auction_code');
820
+ const timestamp = this.parse8601(this.safeString(trade, 'logical_time'));
821
+ const priceString = this.safeString(trade, 'price');
822
+ let amountString = this.safeString2(trade, 'volume', 'quantity');
823
+ const order = this.safeString(trade, 'order_id');
824
+ let fee = undefined;
825
+ let side = undefined;
826
+ const feeCost = this.safeString(trade, 'fee');
827
+ if (feeCost !== undefined) {
828
+ // only in fetchMyTrades
829
+ const amountIsNegative = Precise.stringLt(amountString, '0');
830
+ if (amountIsNegative) {
831
+ side = 'sell';
832
+ amountString = Precise.stringNeg(amountString);
833
+ }
834
+ else {
835
+ side = 'buy';
836
+ }
837
+ fee = {
838
+ 'cost': feeCost,
839
+ 'currency': this.safeString(trade, 'fee_currency'),
840
+ };
841
+ }
842
+ else {
843
+ const imbalance = this.safeString(trade, 'imbalance');
844
+ if (Precise.stringLt(imbalance, '0')) {
845
+ side = 'buy';
846
+ }
847
+ else {
848
+ side = 'sell';
849
+ }
850
+ }
851
+ const takerOrMaker = this.safeString(trade, 'fee_type');
852
+ return this.safeTrade({
853
+ 'id': id,
854
+ 'order': order,
855
+ 'timestamp': timestamp,
856
+ 'datetime': this.iso8601(timestamp),
857
+ 'symbol': symbol,
858
+ 'type': undefined,
859
+ 'side': side,
860
+ 'takerOrMaker': takerOrMaker,
861
+ 'price': priceString,
862
+ 'amount': amountString,
863
+ 'cost': undefined,
864
+ 'fee': fee,
865
+ 'info': trade,
866
+ }, market);
867
+ }
868
+ async fetchTradingFees(params = {}) {
869
+ /**
870
+ * @method
871
+ * @name coinlist#fetchTradingFees
872
+ * @description fetch the trading fees for multiple markets
873
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#list-fees
874
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
875
+ * @returns {object} a dictionary of [fee structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#fee-structure} indexed by market symbols
876
+ */
877
+ await this.loadMarkets();
878
+ const response = await this.privateGetV1Fees(params);
879
+ //
880
+ // {
881
+ // fees_by_symbols: {
882
+ // 'BTC-USD,BTC-USDT,ETH-USD,ETH-USDT,ETH-BTC,AAVE-USD,AAVE-USDT,ALGO-USD,ALGO-USDT,AVAX-USD,AVAX-USDT,BICO-USD,BICO-USDT,BLD-USD,BLD-USDT,BTRST-USDT,BZZ-USDT,CELO-USD,CELO-BTC,CFG-USD,CFG-USDT,CLV-USDT,COMP-USD,COMP-USDT,CYBER-USDT,CQT-USDT,CSPR-USD,CSPR-USDT,CUSD-USD,CUSD-USDC,DOGE-USD,DOGE-USDT,DOT-USD,DOT-USDT,EFI-USDT,FIL-USD,FIL-USDT,FLOW-USD,FLOW-USDT,GAL-USD,GAL-USDT,GODS-USDT,GOG-USDT,HMT-USD,HMT-USDT,ICP-USD,ICP-USDT,IMX-USD,IMX-USDT,LINK-USD,LINK-USDT,MATIC-USD,MATIC-USDT,MINA-USD,MINA-USDT,MKR-USD,MKR-USDT,NEON-USDT,NYM-USD,NYM-USDT,OCEAN-USD,OXT-USD,ROSE-USD,ROSE-USDT,SKL-USD,SKL-USDT,SOL-USD,SOL-USDT,STX-USDT,SUI-USDT,T-USDT,UNI-USD,UNI-USDT,USDT-USD,VEGA-USDT,WAXL-USD,WAXL-USDT,WBTC-BTC,WCFG-USD,WCFG-USDT,XTZ-USD': {
883
+ // base: {
884
+ // fees: { maker: '0', taker: '0.0045', liquidation: '0' },
885
+ // floors: { maker: null, taker: null }
886
+ // },
887
+ // volume_tier_1: {
888
+ // fees: { maker: '0', taker: '0.003', liquidation: '0' },
889
+ // floors: { maker: null, taker: null }
890
+ // },
891
+ // volume_tier_2: {
892
+ // fees: { maker: '0', taker: '0.0025', liquidation: '0' },
893
+ // floors: { maker: null, taker: null }
894
+ // },
895
+ // volume_tier_3: {
896
+ // fees: { maker: '0', taker: '0.002', liquidation: '0' },
897
+ // floors: { maker: null, taker: null }
898
+ // },
899
+ // volume_tier_4: {
900
+ // fees: { maker: '0', taker: '0.0018', liquidation: '0' },
901
+ // floors: { maker: null, taker: null }
902
+ // },
903
+ // volume_tier_5: {
904
+ // fees: { maker: '0', taker: '0.0018', liquidation: '0' },
905
+ // floors: { maker: null, taker: null }
906
+ // },
907
+ // volume_tier_6: {
908
+ // fees: { maker: '0', taker: '0.0016', liquidation: '0' },
909
+ // floors: { maker: null, taker: null }
910
+ // },
911
+ // volume_tier_7: {
912
+ // fees: { maker: '0', taker: '0.0013', liquidation: '0' },
913
+ // floors: { maker: null, taker: null }
914
+ // },
915
+ // volume_tier_8: {
916
+ // fees: { maker: '0', taker: '0.0012', liquidation: '0' },
917
+ // floors: { maker: null, taker: null }
918
+ // },
919
+ // volume_tier_9: {
920
+ // fees: { maker: '0', taker: '0.001', liquidation: '0' },
921
+ // floors: { maker: null, taker: null }
922
+ // }
923
+ // volume_tier_10: {
924
+ // fees: { maker: '0', taker: '0.0005', liquidation: '0' },
925
+ // floors: { maker: null, taker: null }
926
+ // },
927
+ // volume_tier_11: {
928
+ // fees: { maker: '0', taker: '0.0005', liquidation: '0' },
929
+ // floors: { maker: null, taker: null }
930
+ // },
931
+ // }
932
+ // }
933
+ // }
934
+ //
935
+ const fees = this.safeValue(response, 'fees_by_symbols', {});
936
+ const result = {};
937
+ const groupsOfSymbols = Object.keys(fees);
938
+ for (let i = 0; i < groupsOfSymbols.length; i++) {
939
+ const group = groupsOfSymbols[i];
940
+ const feeTiers = this.safeValue(fees, group, {});
941
+ const tiers = this.parseFeeTiers(feeTiers);
942
+ const firstTier = this.safeValue(feeTiers, 'base', {});
943
+ const firstTierFees = this.safeValue(firstTier, 'fees', {});
944
+ const ids = group.split(',');
945
+ for (let j = 0; j < ids.length; j++) {
946
+ const id = ids[j];
947
+ const market = this.safeMarket(id);
948
+ const symbol = market['symbol'];
949
+ const info = {};
950
+ info[group] = feeTiers;
951
+ result[symbol] = {
952
+ 'info': info,
953
+ 'symbol': symbol,
954
+ 'maker': this.safeNumber(firstTierFees, 'maker'),
955
+ 'taker': this.safeNumber(firstTierFees, 'taker'),
956
+ 'percentage': true,
957
+ 'tierBased': true,
958
+ 'tiers': tiers,
959
+ };
960
+ }
961
+ }
962
+ return result;
963
+ }
964
+ parseFeeTiers(feeTiers, market = undefined) {
965
+ //
966
+ // base: {
967
+ // fees: { maker: '0', taker: '0.0045', liquidation: '0' },
968
+ // floors: { maker: null, taker: null }
969
+ // },
970
+ // volume_tier_1: {
971
+ // fees: { maker: '0', taker: '0.003', liquidation: '0' },
972
+ // floors: { maker: null, taker: null }
973
+ // },
974
+ // volume_tier_2: {
975
+ // fees: { maker: '0', taker: '0.0025', liquidation: '0' },
976
+ // floors: { maker: null, taker: null }
977
+ // },
978
+ // volume_tier_3: {
979
+ // fees: { maker: '0', taker: '0.002', liquidation: '0' },
980
+ // floors: { maker: null, taker: null }
981
+ // },
982
+ // volume_tier_4: {
983
+ // fees: { maker: '0', taker: '0.0018', liquidation: '0' },
984
+ // floors: { maker: null, taker: null }
985
+ // },
986
+ // volume_tier_5: {
987
+ // fees: { maker: '0', taker: '0.0018', liquidation: '0' },
988
+ // floors: { maker: null, taker: null }
989
+ // },
990
+ // volume_tier_6: {
991
+ // fees: { maker: '0', taker: '0.0016', liquidation: '0' },
992
+ // floors: { maker: null, taker: null }
993
+ // },
994
+ // volume_tier_7: {
995
+ // fees: { maker: '0', taker: '0.0013', liquidation: '0' },
996
+ // floors: { maker: null, taker: null }
997
+ // },
998
+ // volume_tier_8: {
999
+ // fees: { maker: '0', taker: '0.0012', liquidation: '0' },
1000
+ // floors: { maker: null, taker: null }
1001
+ // },
1002
+ // volume_tier_9: {
1003
+ // fees: { maker: '0', taker: '0.001', liquidation: '0' },
1004
+ // floors: { maker: null, taker: null }
1005
+ // }
1006
+ // volume_tier_10: {
1007
+ // fees: { maker: '0', taker: '0.0005', liquidation: '0' },
1008
+ // floors: { maker: null, taker: null }
1009
+ // },
1010
+ // volume_tier_11: {
1011
+ // fees: { maker: '0', taker: '0.0005', liquidation: '0' },
1012
+ // floors: { maker: null, taker: null }
1013
+ // },
1014
+ //
1015
+ let takerFees = [];
1016
+ let makerFees = [];
1017
+ const keys = Object.keys(feeTiers);
1018
+ const keysLength = keys.length;
1019
+ if (keysLength > 0) {
1020
+ for (let i = 0; i < keysLength; i++) {
1021
+ const key = keys[i];
1022
+ const tier = this.safeValue(feeTiers, key, {});
1023
+ const tierFees = this.safeValue(tier, 'fees', {});
1024
+ const taker = this.safeString(tierFees, 'taker');
1025
+ const maker = this.safeString(tierFees, 'maker');
1026
+ makerFees.push([undefined, this.parseNumber(maker)]);
1027
+ takerFees.push([undefined, this.parseNumber(taker)]);
1028
+ }
1029
+ takerFees = this.sortBy(takerFees, 1, true);
1030
+ makerFees = this.sortBy(makerFees, 1, true);
1031
+ const firstTier = this.safeValue(takerFees, 0, []);
1032
+ const exchangeFees = this.safeValue(this, 'fees', {});
1033
+ const exchangeFeesTrading = this.safeValue(exchangeFees, 'trading', {});
1034
+ const exchangeFeesTradingTiers = this.safeValue(exchangeFeesTrading, 'tiers', {});
1035
+ const exchangeFeesTradingTiersTaker = this.safeValue(exchangeFeesTradingTiers, 'taker', []);
1036
+ const exchangeFeesTradingTiersMaker = this.safeValue(exchangeFeesTradingTiers, 'maker', []);
1037
+ if ((keysLength === exchangeFeesTradingTiersTaker.length) && (firstTier.length > 0)) {
1038
+ for (let i = 0; i < keysLength; i++) {
1039
+ takerFees[i][0] = exchangeFeesTradingTiersTaker[i][0];
1040
+ makerFees[i][0] = exchangeFeesTradingTiersMaker[i][0];
1041
+ }
1042
+ }
1043
+ }
1044
+ return {
1045
+ 'maker': makerFees,
1046
+ 'taker': takerFees,
1047
+ };
1048
+ }
1049
+ async fetchAccounts(params = {}) {
1050
+ /**
1051
+ * @method
1052
+ * @name coinlist#fetchAccounts
1053
+ * @description fetch all the accounts associated with a profile
1054
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#list-accounts
1055
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
1056
+ * @returns {object} a dictionary of [account structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#account-structure} indexed by the account type
1057
+ */
1058
+ await this.loadMarkets();
1059
+ const response = await this.privateGetV1Accounts(params);
1060
+ //
1061
+ // {
1062
+ // "accounts": [
1063
+ // {
1064
+ // "trader_id": "b18507ce-7d55-4bf1-b12a-0ccca5b90936",
1065
+ // "name": "string"
1066
+ // }
1067
+ // ]
1068
+ // }
1069
+ //
1070
+ const accounts = this.safeValue(response, 'accounts', []);
1071
+ return this.parseAccounts(accounts, params);
1072
+ }
1073
+ parseAccount(account) {
1074
+ //
1075
+ // {
1076
+ // "trader_id": "b18507ce-7d55-4bf1-b12a-0ccca5b90936",
1077
+ // "name": "string"
1078
+ // }
1079
+ //
1080
+ return {
1081
+ 'id': this.safeString(account, 'trader_id'),
1082
+ 'type': 'trading',
1083
+ 'code': undefined,
1084
+ 'info': account,
1085
+ };
1086
+ }
1087
+ async fetchBalance(params = {}) {
1088
+ /**
1089
+ * @method
1090
+ * @name coinlist#fetchBalance
1091
+ * @description query for balance and get the amount of funds available for trading or funds locked in orders
1092
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#list-balances
1093
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
1094
+ * @returns {object} a [balance structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#balance-structure}
1095
+ */
1096
+ await this.loadMarkets();
1097
+ const response = await this.privateGetV1Balances(params);
1098
+ return this.parseBalance(response);
1099
+ }
1100
+ parseBalance(response) {
1101
+ //
1102
+ // {
1103
+ // "asset_balances": {
1104
+ // "BTC": "0.00308696",
1105
+ // "ETH": "20.000000000000000000"
1106
+ // },
1107
+ // "asset_holds": {
1108
+ // "BTC": "0.00000000",
1109
+ // "ETH": "1.000000000000000000"
1110
+ // },
1111
+ // "net_liquidation_value_usd": "string"
1112
+ // }
1113
+ //
1114
+ const timestamp = this.milliseconds();
1115
+ const result = {
1116
+ 'info': response,
1117
+ 'timestamp': timestamp,
1118
+ 'datetime': this.iso8601(timestamp),
1119
+ };
1120
+ const totalBalances = this.safeValue(response, 'asset_balances', {});
1121
+ const usedBalances = this.safeValue(response, 'asset_holds', {});
1122
+ const currencyIds = Object.keys(totalBalances);
1123
+ for (let i = 0; i < currencyIds.length; i++) {
1124
+ const currencyId = currencyIds[i];
1125
+ const code = this.safeCurrencyCode(currencyId);
1126
+ const account = this.account();
1127
+ account['total'] = this.safeString(totalBalances, currencyId);
1128
+ account['used'] = this.safeString(usedBalances, currencyId, '0');
1129
+ result[code] = account;
1130
+ }
1131
+ return this.safeBalance(result);
1132
+ }
1133
+ async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1134
+ /**
1135
+ * @method
1136
+ * @name coinlist#fetchMyTrades
1137
+ * @description fetch all trades made by the user
1138
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#list-fills
1139
+ * @param {string} symbol unified market symbol
1140
+ * @param {int} [since] the earliest time in ms to fetch trades for
1141
+ * @param {int} [limit] the maximum number of trades structures to retrieve (default 200, max 500)
1142
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
1143
+ * @param {int} [params.until] the latest time in ms to fetch entries for
1144
+ * @returns {Trade[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#trade-structure}
1145
+ */
1146
+ await this.loadMarkets();
1147
+ const request = {};
1148
+ let market = undefined;
1149
+ if (symbol !== undefined) {
1150
+ market = this.market(symbol);
1151
+ request['symbol'] = market['id'];
1152
+ }
1153
+ if (since !== undefined) {
1154
+ request['start_time'] = this.iso8601(since);
1155
+ }
1156
+ if (limit !== undefined) {
1157
+ request['count'] = limit;
1158
+ }
1159
+ const until = this.safeInteger2(params, 'till', 'until');
1160
+ if (until !== undefined) {
1161
+ params = this.omit(params, ['till', 'until']);
1162
+ request['end_time'] = this.iso8601(until);
1163
+ }
1164
+ const response = await this.privateGetV1Fills(this.extend(request, params));
1165
+ //
1166
+ // {
1167
+ // fills: [
1168
+ // {
1169
+ // symbol: 'ETH-USDT',
1170
+ // auction_code: 'ETH-USDT-2023-10-20T13:16:30.000Z',
1171
+ // order_id: '39911d5f-c789-4a7d-ad34-820a804d1da6',
1172
+ // quantity: '-0.0009',
1173
+ // price: '1608.83000000',
1174
+ // fee: '0.006516',
1175
+ // fee_type: 'taker',
1176
+ // fee_currency: 'USDT',
1177
+ // logical_time: '2023-10-20T13:16:30.000Z'
1178
+ // },
1179
+ // {
1180
+ // symbol: 'ETH-USDT',
1181
+ // auction_code: 'ETH-USDT-2023-10-20T13:22:14.000Z',
1182
+ // order_id: '83ed365f-497d-433b-96c1-9d08c1a12842',
1183
+ // quantity: '0.0008',
1184
+ // price: '1615.24000000',
1185
+ // fee: '0.005815',
1186
+ // fee_type: 'taker',
1187
+ // fee_currency: 'USDT',
1188
+ // logical_time: '2023-10-20T13:22:14.000Z'
1189
+ // },
1190
+ // ]
1191
+ // }
1192
+ //
1193
+ const fills = this.safeValue(response, 'fills', []);
1194
+ return this.parseTrades(fills, market, since, limit);
1195
+ }
1196
+ async fetchOrderTrades(id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
1197
+ /**
1198
+ * @method
1199
+ * @name coinlist#fetchOrderTrades
1200
+ * @description fetch all the trades made from a single order
1201
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#list-fills
1202
+ * @param {string} id order id
1203
+ * @param {string} symbol unified market symbol
1204
+ * @param {int} [since] the earliest time in ms to fetch trades for
1205
+ * @param {int} [limit] the maximum number of trades to retrieve
1206
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
1207
+ * @returns {object[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#trade-structure}
1208
+ */
1209
+ const request = {
1210
+ 'order_id': id,
1211
+ };
1212
+ return await this.fetchMyTrades(symbol, since, limit, this.extend(request, params));
1213
+ }
1214
+ async fetchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1215
+ /**
1216
+ * @method
1217
+ * @name coinlist#fetchOrders
1218
+ * @description fetches information on multiple orders made by the user
1219
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#list-orders
1220
+ * @param {string} symbol unified market symbol of the market orders were made in
1221
+ * @param {int} [since] the earliest time in ms to fetch orders for
1222
+ * @param {int} [limit] the maximum number of orde structures to retrieve (default 200, max 500)
1223
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
1224
+ * @param {int} [params.until] the latest time in ms to fetch entries for
1225
+ * @param {string|string[]} [params.status] the status of the order - 'accepted', 'done', 'canceled', 'rejected', 'pending' (default [ 'accepted', 'done', 'canceled', 'rejected', 'pending' ])
1226
+ * @returns {Order[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1227
+ */
1228
+ await this.loadMarkets();
1229
+ let status = this.safeString(params, 'status');
1230
+ if (status === undefined) {
1231
+ status = ['accepted', 'done', 'canceled', 'rejected', 'pending'];
1232
+ }
1233
+ const request = {
1234
+ 'status': status,
1235
+ };
1236
+ let market = undefined;
1237
+ if (symbol !== undefined) {
1238
+ market = this.market(symbol);
1239
+ request['symbol'] = market['id'];
1240
+ }
1241
+ if (since !== undefined) {
1242
+ request['start_time'] = this.iso8601(since);
1243
+ }
1244
+ if (limit !== undefined) {
1245
+ request['count'] = limit;
1246
+ }
1247
+ const until = this.safeInteger2(params, 'till', 'until');
1248
+ if (until !== undefined) {
1249
+ params = this.omit(params, ['till', 'until']);
1250
+ request['end_time'] = this.iso8601(until);
1251
+ }
1252
+ const response = await this.privateGetV1Orders(this.extend(request, params));
1253
+ //
1254
+ // {
1255
+ // "orders":[
1256
+ // {
1257
+ // "order_id":"913ea6e7-9fc9-43fb-9db1-f195d3baa93f",
1258
+ // "price":"35800.00000000",
1259
+ // "stop_price":null,
1260
+ // "cost":"0.00000000",
1261
+ // "fill_fees":"0.00000000",
1262
+ // "trader_id":"9c6f737e-a829-4843-87b1-b1ce86f2853b",
1263
+ // "status":"accepted",
1264
+ // "epoch_timestamp":"2023-10-26T08:20:56.307Z",
1265
+ // "origin":"web",
1266
+ // "self_trade_prevention":null,
1267
+ // "client_id":null,
1268
+ // "created_at":"2023-10-26T08:20:56.307Z",
1269
+ // "symbol":"BTC-USDT",
1270
+ // "size":"0.0003",
1271
+ // "side":"sell",
1272
+ // "type":"limit",
1273
+ // "post_only":false,
1274
+ // "size_filled":"0.0000"
1275
+ // }
1276
+ // ]
1277
+ // }
1278
+ //
1279
+ const orders = this.safeValue(response, 'orders', []);
1280
+ return this.parseOrders(orders, market, since, limit);
1281
+ }
1282
+ async fetchOrder(id, symbol = undefined, params = {}) {
1283
+ /**
1284
+ * @method
1285
+ * @name coinlist#fetchOrder
1286
+ * @description fetches information on an order made by the user
1287
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#get-specific-order-by-id
1288
+ * @param {int|string} id order id
1289
+ * @param {string} symbol not used by coinlist fetchOrder ()
1290
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
1291
+ * @returns {object} An [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1292
+ */
1293
+ await this.loadMarkets();
1294
+ const request = {
1295
+ 'order_id': id,
1296
+ };
1297
+ const response = await this.privateGetV1OrdersOrderId(this.extend(request, params));
1298
+ //
1299
+ // {
1300
+ // "order_id": "93101167-9065-4b9c-b98b-5d789a3ed9fe",
1301
+ // "client_id": "string",
1302
+ // "symbol": "string",
1303
+ // "type": "market",
1304
+ // "side": "buy",
1305
+ // "size": "string",
1306
+ // "price": "string",
1307
+ // "stop_price": "string",
1308
+ // "stop_trigger": "last",
1309
+ // "self_trade_prevention": "keep-newest",
1310
+ // "average_fill_price": "string",
1311
+ // "fill_fees": "string",
1312
+ // "size_filled": "string",
1313
+ // "created_at": "2019-08-24T14:15:22Z",
1314
+ // "epoch_timestamp": "2019-08-24T14:15:22Z",
1315
+ // "post_only": true,
1316
+ // "peg_price_type": "trailing-stop",
1317
+ // "peg_offset_value": "string",
1318
+ // "origin": "web",
1319
+ // "status": "pending"
1320
+ // }
1321
+ //
1322
+ return this.parseOrder(response);
1323
+ }
1324
+ async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1325
+ /**
1326
+ * @method
1327
+ * @name coinlist#fetchOpenOrders
1328
+ * @description fetch all unfilled currently open orders
1329
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#list-orders
1330
+ * @param {string} symbol unified market symbol
1331
+ * @param {int} [since] the earliest time in ms to fetch open orders for
1332
+ * @param {int} [limit] the maximum number of open order structures to retrieve (default 200, max 500)
1333
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
1334
+ * @param {int} [params.until] the latest time in ms to fetch entries for
1335
+ * @returns {Order[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1336
+ */
1337
+ await this.loadMarkets();
1338
+ const request = {
1339
+ 'status': 'accepted',
1340
+ };
1341
+ return this.fetchOrders(symbol, since, limit, this.extend(request, params));
1342
+ }
1343
+ async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1344
+ /**
1345
+ * @method
1346
+ * @name coinlist#fetchClosedOrders
1347
+ * @description fetches information on multiple closed orders made by the user
1348
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#list-orders
1349
+ * @param {string} symbol unified market symbol of the market orders were made in
1350
+ * @param {int} [since] the earliest time in ms to fetch orders for
1351
+ * @param {int} [limit] the maximum number of closed order structures to retrieve (default 200, max 500)
1352
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
1353
+ * @param {int} [params.until] the latest time in ms to fetch entries for
1354
+ * @returns {Order[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1355
+ */
1356
+ await this.loadMarkets();
1357
+ const request = {
1358
+ 'status': 'done',
1359
+ };
1360
+ return this.fetchOrders(symbol, since, limit, this.extend(request, params));
1361
+ }
1362
+ async fetchCanceledOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1363
+ /**
1364
+ * @method
1365
+ * @name coinlist#fetchCanceledOrders
1366
+ * @description fetches information on multiple canceled orders made by the user
1367
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#list-orders
1368
+ * @param {string} symbol unified market symbol of the market orders were made in
1369
+ * @param {int} [since] the earliest time in ms to fetch orders for
1370
+ * @param {int} [limit] the maximum number of canceled order structures to retrieve (default 200, max 500)
1371
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
1372
+ * @param {int} [params.until] the latest time in ms to fetch entries for
1373
+ * @returns {object} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1374
+ */
1375
+ await this.loadMarkets();
1376
+ const request = {
1377
+ 'status': 'canceled',
1378
+ };
1379
+ return this.fetchOrders(symbol, since, limit, this.extend(request, params));
1380
+ }
1381
+ async cancelAllOrders(symbol = undefined, params = {}) {
1382
+ /**
1383
+ * @method
1384
+ * @name coinlist#cancelAllOrders
1385
+ * @description cancel open orders of market
1386
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#cancel-all-orders
1387
+ * @param {string} symbol unified market symbol
1388
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
1389
+ * @returns {object[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1390
+ */
1391
+ await this.loadMarkets();
1392
+ let market = undefined;
1393
+ const request = {};
1394
+ if (symbol !== undefined) {
1395
+ market = this.market(symbol);
1396
+ request['symbol'] = market['id'];
1397
+ }
1398
+ const response = await this.privateDeleteV1Orders(this.extend(request, params));
1399
+ //
1400
+ // {
1401
+ // message: 'Order cancellation request received.',
1402
+ // timestamp: '2023-10-26T10:29:28.652Z'
1403
+ // }
1404
+ //
1405
+ const orders = [response];
1406
+ return this.parseOrders(orders, market);
1407
+ }
1408
+ async cancelOrder(id, symbol = undefined, params = {}) {
1409
+ /**
1410
+ * @method
1411
+ * @name coinlist#cancelOrder
1412
+ * @description cancels an open order
1413
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#cancel-specific-order-by-id
1414
+ * @param {string} id order id
1415
+ * @param {string} symbol not used by coinlist cancelOrder ()
1416
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
1417
+ * @returns {object} An [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1418
+ */
1419
+ await this.loadMarkets();
1420
+ const request = {
1421
+ 'order_id': id,
1422
+ };
1423
+ const response = await this.privateDeleteV1OrdersOrderId(this.extend(request, params));
1424
+ //
1425
+ // {
1426
+ // message: 'Cancel order request received.',
1427
+ // order_id: 'd36e7588-6525-485c-b768-8ad8b3f745f9',
1428
+ // timestamp: '2023-10-26T14:36:37.559Z'
1429
+ // }
1430
+ //
1431
+ return this.parseOrder(response);
1432
+ }
1433
+ async cancelOrders(ids, symbol = undefined, params = {}) {
1434
+ /**
1435
+ * @method
1436
+ * @name coinlist#cancelOrders
1437
+ * @description cancel multiple orders
1438
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#cancel-specific-orders
1439
+ * @param {string[]} ids order ids
1440
+ * @param {string} symbol not used by coinlist cancelOrders ()
1441
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
1442
+ * @returns {object} an list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1443
+ */
1444
+ await this.loadMarkets();
1445
+ params = ids;
1446
+ const response = await this.privateDeleteV1OrdersBulk(params);
1447
+ return response;
1448
+ }
1449
+ async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1450
+ /**
1451
+ * @method
1452
+ * @name coinlist#createOrder
1453
+ * @description create a trade order
1454
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#create-new-order
1455
+ * @param {string} symbol unified symbol of the market to create an order in
1456
+ * @param {string} type 'market' or 'limit' or 'stop_market' or 'stop_limit' or 'take_market' or 'take_limit'
1457
+ * @param {string} side 'buy' or 'sell'
1458
+ * @param {float} amount how much of currency you want to trade in units of base currency
1459
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1460
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
1461
+ * @param {bool} [params.postOnly] if true, the order will only be posted to the order book and not executed immediately (default false)
1462
+ * @param {float} [params.triggerPrice] only for the 'stop_market', 'stop_limit', 'take_market' or 'take_limit' orders (the price at which an order is triggered)
1463
+ * @param {string} [params.clientOrderId] client order id (default undefined)
1464
+ * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1465
+ */
1466
+ await this.loadMarkets();
1467
+ const market = this.market(symbol);
1468
+ const request = {
1469
+ 'symbol': market['id'],
1470
+ 'type': type,
1471
+ 'side': side,
1472
+ 'size': this.amountToPrecision(symbol, amount),
1473
+ };
1474
+ let isMarket = false;
1475
+ if ((type === 'limit') || (type === 'stop_limit') || (type === 'take_limit')) {
1476
+ if (price === undefined) {
1477
+ throw new ArgumentsRequired(this.id + ' createOrder() requires a price argument for a ' + type + ' order');
1478
+ }
1479
+ request['price'] = this.priceToPrecision(symbol, price);
1480
+ }
1481
+ else {
1482
+ isMarket = true;
1483
+ }
1484
+ let postOnly = undefined;
1485
+ [postOnly, params] = this.handlePostOnly(isMarket, false, params);
1486
+ if (postOnly) {
1487
+ request['post_only'] = true;
1488
+ }
1489
+ const triggerPrice = this.safeNumberN(params, ['triggerPrice', 'trigger_price', 'stopPrice', 'stop_price']);
1490
+ if (triggerPrice !== undefined) {
1491
+ params = this.omit(params, ['triggerPrice', 'trigger_price', 'stopPrice']);
1492
+ request['stop_price'] = this.priceToPrecision(symbol, triggerPrice);
1493
+ if (type === 'market') {
1494
+ request['type'] = 'stop_market';
1495
+ }
1496
+ else if (type === 'limit') {
1497
+ request['type'] = 'stop_limit';
1498
+ }
1499
+ }
1500
+ else if ((type === 'stop_market') || (type === 'stop_limit') || (type === 'take_market') || (type === 'take_limit')) {
1501
+ throw new ArgumentsRequired(this.id + ' createOrder() requires a stopPrice parameter for stop-loss and take-profit orders');
1502
+ }
1503
+ const clientOrderId = this.safeString2(params, 'clientOrderId', 'client_id');
1504
+ if (clientOrderId !== undefined) {
1505
+ request['client_id'] = clientOrderId;
1506
+ params = this.omit(params, ['clientOrderId', 'client_id']);
1507
+ }
1508
+ const response = await this.privatePostV1Orders(this.extend(request, params));
1509
+ //
1510
+ // {
1511
+ // "message": "New order request received.",
1512
+ // "order": {
1513
+ // "symbol": "BTC-USDT",
1514
+ // "type": "market",
1515
+ // "side": "sell",
1516
+ // "size": "0.0003",
1517
+ // "order_id": "cad67c0f-9aec-4ac8-ac03-aaf5db299ff7",
1518
+ // "trader_id": "9c6f737e-a829-4843-87b1-b1ce86f2853b"
1519
+ // },
1520
+ // "timestamp": "2023-10-26T11:30:55.376Z"
1521
+ // }
1522
+ //
1523
+ const order = this.safeValue(response, 'order', {});
1524
+ return this.parseOrder(order, market);
1525
+ }
1526
+ async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
1527
+ /**
1528
+ * @method
1529
+ * @name coinlist#editOrder
1530
+ * @description create a trade order
1531
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#modify-existing-order
1532
+ * @param {string} symbol unified symbol of the market to create an order in
1533
+ * @param {string} type 'market' or 'limit' or 'stop_market' or 'stop_limit' or 'take_market' or 'take_limit'
1534
+ * @param {string} side 'buy' or 'sell'
1535
+ * @param {float} amount how much of currency you want to trade in units of base currency
1536
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1537
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
1538
+ * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1539
+ */
1540
+ await this.loadMarkets();
1541
+ if (amount === undefined) {
1542
+ throw new ArgumentsRequired(this.id + ' editOrder() requires an amount argument');
1543
+ }
1544
+ const market = this.market(symbol);
1545
+ const request = {
1546
+ 'order_id': id,
1547
+ 'type': type,
1548
+ 'side': side,
1549
+ 'size': this.amountToPrecision(symbol, amount),
1550
+ };
1551
+ if (price !== undefined) {
1552
+ request['price'] = this.priceToPrecision(symbol, price);
1553
+ }
1554
+ const response = await this.privatePatchV1OrdersOrderId(this.extend(request, params));
1555
+ return this.parseOrder(response, market);
1556
+ }
1557
+ parseOrder(order, market = undefined) {
1558
+ //
1559
+ // fetchOrder
1560
+ // {
1561
+ // "order_id": "913ea6e7-9fc9-43fb-9db1-f195d3baa93f",
1562
+ // "price": "35800.00000000",
1563
+ // "stop_price":null,
1564
+ // "cost": "0.00000000",
1565
+ // "fill_fees": "0.00000000",
1566
+ // "trader_id": "9c6f737e-a829-4843-87b1-b1ce86f2853b",
1567
+ // "status": "canceled",
1568
+ // "epoch_timestamp": "2023-10-26T08:20:56.307Z",
1569
+ // "origin": "web",
1570
+ // "self_trade_prevention":null,
1571
+ // "client_id":null,
1572
+ // "symbol": "BTC-USDT",
1573
+ // "size": "0.0003",
1574
+ // "side": "sell",
1575
+ // "type": "limit",
1576
+ // "post_only":false,
1577
+ // "size_filled": "0.0000"
1578
+ // }
1579
+ //
1580
+ // fetchOrders
1581
+ // {
1582
+ // "order_id":"913ea6e7-9fc9-43fb-9db1-f195d3baa93f",
1583
+ // "price":"35800.00000000",
1584
+ // "stop_price":null,
1585
+ // "cost":"0.00000000",
1586
+ // "fill_fees":"0.00000000",
1587
+ // "trader_id":"9c6f737e-a829-4843-87b1-b1ce86f2853b",
1588
+ // "status":"accepted",
1589
+ // "epoch_timestamp":"2023-10-26T08:20:56.307Z",
1590
+ // "origin":"web",
1591
+ // "self_trade_prevention":null,
1592
+ // "client_id":null,
1593
+ // "created_at":"2023-10-26T08:20:56.307Z",
1594
+ // "symbol":"BTC-USDT",
1595
+ // "size":"0.0003",
1596
+ // "side":"sell",
1597
+ // "type":"limit",
1598
+ // "post_only":false,
1599
+ // "size_filled":"0.0000"
1600
+ // }
1601
+ //
1602
+ // createOrder
1603
+ // {
1604
+ // "symbol": "BTC-USDT",
1605
+ // "type": "market",
1606
+ // "side": "sell",
1607
+ // "size": "0.0003",
1608
+ // "order_id": "cad67c0f-9aec-4ac8-ac03-aaf5db299ff7",
1609
+ // "trader_id": "9c6f737e-a829-4843-87b1-b1ce86f2853b"
1610
+ // },
1611
+ //
1612
+ // cancelOrder
1613
+ // {
1614
+ // message: 'Cancel order request received.',
1615
+ // order_id: 'd36e7588-6525-485c-b768-8ad8b3f745f9',
1616
+ // timestamp: '2023-10-26T14:36:37.559Z'
1617
+ // }
1618
+ //
1619
+ // cancelOrders
1620
+ // {
1621
+ // message: 'Order cancellation request received.',
1622
+ // timestamp: '2023-10-26T10:29:28.652Z'
1623
+ // }
1624
+ //
1625
+ // cancelAllOrders
1626
+ // {
1627
+ // message: 'Order cancellation request received.',
1628
+ // timestamp: '2023-10-26T10:29:28.652Z'
1629
+ // }
1630
+ //
1631
+ const id = this.safeString(order, 'order_id');
1632
+ const marketId = this.safeString(order, 'symbol');
1633
+ market = this.safeMarket(marketId, market);
1634
+ const clientOrderId = this.safeString(order, 'client_id');
1635
+ let timestampString = this.safeString2(order, 'created_at', 'epoch_timestamp');
1636
+ if (timestampString === undefined) {
1637
+ timestampString = this.safeString(order, 'timestamp');
1638
+ }
1639
+ const timestamp = this.parse8601(timestampString);
1640
+ const status = this.parseOrderStatus(this.safeString(order, 'status'));
1641
+ const type = this.parseOrderType(this.safeString(order, 'type'));
1642
+ const side = this.safeString(order, 'side');
1643
+ const price = this.safeString(order, 'price');
1644
+ const stopPrice = this.safeString(order, 'stop_price');
1645
+ const average = this.safeString(order, 'average_fill_price'); // from documentation
1646
+ const amount = this.safeString(order, 'size');
1647
+ const filled = this.safeString(order, 'size_filled');
1648
+ const feeCost = this.safeString(order, 'fill_fees');
1649
+ const postOnly = this.safeValue(order, 'post_only');
1650
+ let fee = undefined;
1651
+ if (feeCost !== undefined) {
1652
+ fee = {
1653
+ 'currency': market['quote'],
1654
+ 'cost': feeCost,
1655
+ 'rate': undefined,
1656
+ };
1657
+ }
1658
+ return this.safeOrder({
1659
+ 'id': id,
1660
+ 'clientOrderId': clientOrderId,
1661
+ 'timestamp': timestamp,
1662
+ 'datetime': this.iso8601(timestamp),
1663
+ 'lastTradeTimestamp': undefined,
1664
+ 'status': status,
1665
+ 'symbol': market['symbol'],
1666
+ 'type': type,
1667
+ 'timeInForce': 'GTC',
1668
+ 'side': side,
1669
+ 'price': price,
1670
+ 'stopPrice': stopPrice,
1671
+ 'triggerPrice': stopPrice,
1672
+ 'average': average,
1673
+ 'amount': amount,
1674
+ 'cost': undefined,
1675
+ 'filled': filled,
1676
+ 'remaining': undefined,
1677
+ 'fee': fee,
1678
+ 'trades': undefined,
1679
+ 'info': order,
1680
+ 'postOnly': postOnly,
1681
+ }, market);
1682
+ }
1683
+ parseOrderStatus(status) {
1684
+ const statuses = {
1685
+ 'pending': 'open',
1686
+ 'accepted': 'open',
1687
+ 'rejected': 'rejected',
1688
+ 'done': 'closed',
1689
+ 'canceled': 'canceled',
1690
+ };
1691
+ return this.safeString(statuses, status, status);
1692
+ }
1693
+ parseOrderType(status) {
1694
+ const statuses = {
1695
+ 'market': 'market',
1696
+ 'limit': 'limit',
1697
+ 'stop_market': 'market',
1698
+ 'stop_limit': 'limit',
1699
+ 'take_market': 'market',
1700
+ 'take_limit': 'limit',
1701
+ };
1702
+ return this.safeString(statuses, status, status);
1703
+ }
1704
+ async transfer(code, amount, fromAccount, toAccount, params = {}) {
1705
+ /**
1706
+ * @method
1707
+ * @name coinlist#transfer
1708
+ * @description transfer currency internally between wallets on the same account
1709
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#transfer-funds-between-entities
1710
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#transfer-funds-from-wallet-to-pro
1711
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#transfer-funds-from-pro-to-wallet
1712
+ * @param {string} code unified currency code
1713
+ * @param {float} amount amount to transfer
1714
+ * @param {string} fromAccount account to transfer from
1715
+ * @param {string} toAccount account to transfer to
1716
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
1717
+ * @returns {object} a [transfer structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#transfer-structure}
1718
+ */
1719
+ await this.loadMarkets();
1720
+ const currency = this.currency(code);
1721
+ amount = this.currencyToPrecision(code, amount);
1722
+ const request = {
1723
+ 'asset': currency['id'],
1724
+ 'amount': amount,
1725
+ };
1726
+ const accountsByType = this.safeValue(this.options, 'accountsByType', {});
1727
+ const fromAcc = this.safeString(accountsByType, fromAccount, fromAccount);
1728
+ const toAcc = this.safeString(accountsByType, toAccount, toAccount);
1729
+ let response = undefined;
1730
+ if ((fromAcc === 'funding') && (toAcc === 'trading')) {
1731
+ response = await this.privatePostV1TransfersFromWallet(this.extend(request, params));
1732
+ }
1733
+ else if ((fromAcc === 'trading') && (toAcc === 'funding')) {
1734
+ response = await this.privatePostV1TransfersToWallet(this.extend(request, params));
1735
+ }
1736
+ else {
1737
+ request['from_trader_id'] = fromAcc;
1738
+ request['to_trader_id'] = toAcc;
1739
+ response = await this.privatePostV1TransfersInternalTransfer(this.extend(request, params));
1740
+ }
1741
+ //
1742
+ // privatePostV1TransfersInternalTransfer
1743
+ // {
1744
+ // "from_trader_id": "1f494ace-b3ed-4324-b202-55526ed06381",
1745
+ // "to_trader_id": "d32c7a40-cc24-44b0-8597-f9edb3da989f",
1746
+ // "asset": "string",
1747
+ // "amount": "string"
1748
+ // }
1749
+ //
1750
+ // privatePostV1TransfersFromWallet, privatePostV1TransfersToWallet
1751
+ // {
1752
+ // "transfer_id": "bb34f528-d9b0-47c6-b11f-4d4840b86ee3"
1753
+ // }
1754
+ //
1755
+ const transfer = this.parseTransfer(response, currency);
1756
+ return transfer;
1757
+ }
1758
+ async fetchTransfers(code = undefined, since = undefined, limit = undefined, params = {}) {
1759
+ /**
1760
+ * @method
1761
+ * @name coinlist#fetchTransfers
1762
+ * @description fetch a history of internal transfers between CoinList.co and CoinList Pro. It does not return external deposits or withdrawals
1763
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#list-transfers
1764
+ * @param {string} code unified currency code
1765
+ * @param {int} [since] the earliest time in ms to fetch transfers for
1766
+ * @param {int} [limit] the maximum number of transfer structures to retrieve (default 200, max 500)
1767
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
1768
+ * @param {int} [params.until] the latest time in ms to fetch entries for
1769
+ * @returns {object[]} a list of [transfer structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#transfer-structure}
1770
+ */
1771
+ await this.loadMarkets();
1772
+ let currency = undefined;
1773
+ if (code !== undefined) {
1774
+ currency = this.currency(code);
1775
+ }
1776
+ const request = {};
1777
+ if (since !== undefined) {
1778
+ request['start_time'] = this.iso8601(since);
1779
+ }
1780
+ if (limit !== undefined) {
1781
+ request['count'] = limit;
1782
+ }
1783
+ const until = this.safeInteger2(params, 'till', 'until');
1784
+ if (until !== undefined) {
1785
+ params = this.omit(params, ['till', 'until']);
1786
+ request['end_time'] = this.iso8601(until);
1787
+ }
1788
+ const response = await this.privateGetV1Transfers(this.extend(request, params));
1789
+ //
1790
+ // {
1791
+ // "transfers": [
1792
+ // {
1793
+ // "transfer_id": "2c02db25-e8f2-4271-8222-e110bfd0aa2a",
1794
+ // "created_at": "2023-10-20T13:15:37.000Z",
1795
+ // "confirmed_at": "2023-10-20T13:15:37.000Z",
1796
+ // "asset": "ETH",
1797
+ // "amount": "0.010000000000000000",
1798
+ // "status": "confirmed"
1799
+ // },
1800
+ // {
1801
+ // "transfer_id": "890694db-156c-4e93-a3ef-4db61685aca7",
1802
+ // "created_at": "2023-10-26T14:32:22.000Z",
1803
+ // "confirmed_at": "2023-10-26T14:32:22.000Z",
1804
+ // "asset": "USD",
1805
+ // "amount": "-3.00",
1806
+ // "status": "confirmed"
1807
+ // }
1808
+ // ]
1809
+ // }
1810
+ //
1811
+ const transfers = this.safeValue(response, 'transfers', []);
1812
+ return this.parseTransfers(transfers, currency, since, limit);
1813
+ }
1814
+ parseTransfer(transfer, currency = undefined) {
1815
+ //
1816
+ // fetchTransfers
1817
+ // {
1818
+ // "transfer_id": "890694db-156c-4e93-a3ef-4db61685aca7",
1819
+ // "created_at": "2023-10-26T14:32:22.000Z",
1820
+ // "confirmed_at": "2023-10-26T14:32:22.000Z",
1821
+ // "asset": "USD",
1822
+ // "amount": "-3.00",
1823
+ // "status": "confirmed"
1824
+ // }
1825
+ //
1826
+ // transfer - privatePostV1TransfersInternalTransfer
1827
+ // {
1828
+ // "from_trader_id": "1f494ace-b3ed-4324-b202-55526ed06381",
1829
+ // "to_trader_id": "d32c7a40-cc24-44b0-8597-f9edb3da989f",
1830
+ // "asset": "string",
1831
+ // "amount": "string"
1832
+ // }
1833
+ //
1834
+ // transfer - privatePostV1TransfersFromWallet, privatePostV1TransfersToWallet
1835
+ // {
1836
+ // "transfer_id": "bb34f528-d9b0-47c6-b11f-4d4840b86ee3"
1837
+ // }
1838
+ //
1839
+ const currencyId = this.safeString(transfer, 'asset');
1840
+ const confirmedAt = this.safeString(transfer, 'confirmed_at');
1841
+ const timetstamp = this.parse8601(confirmedAt);
1842
+ const status = this.safeString(transfer, 'status');
1843
+ let amountString = this.safeString(transfer, 'amount');
1844
+ let fromAccount = undefined;
1845
+ let toAccount = undefined;
1846
+ let amount = undefined;
1847
+ if (amountString !== undefined) {
1848
+ const amountIsNegative = Precise.stringLt(amountString, '0');
1849
+ if (amountIsNegative) {
1850
+ fromAccount = 'trading';
1851
+ toAccount = 'funding';
1852
+ amountString = Precise.stringNeg(amountString);
1853
+ }
1854
+ else {
1855
+ fromAccount = 'funding';
1856
+ toAccount = 'trading';
1857
+ }
1858
+ amount = this.parseNumber(amountString);
1859
+ }
1860
+ return {
1861
+ 'info': transfer,
1862
+ 'id': this.safeString(transfer, 'transfer_id'),
1863
+ 'timestamp': timetstamp,
1864
+ 'datetime': this.iso8601(timetstamp),
1865
+ 'currency': this.safeCurrencyCode(currencyId, currency),
1866
+ 'amount': amount,
1867
+ 'fromAccount': fromAccount,
1868
+ 'toAccount': toAccount,
1869
+ 'status': this.parseTransferStatus(status),
1870
+ };
1871
+ }
1872
+ parseTransferStatus(status) {
1873
+ const statuses = {
1874
+ 'confirmed': 'ok',
1875
+ };
1876
+ return this.safeString(statuses, status, status);
1877
+ }
1878
+ async fetchDepositsWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
1879
+ /**
1880
+ * @method
1881
+ * @name coinlist#fetchDepositsWithdrawals
1882
+ * @description fetch history of deposits and withdrawals from external wallets and between CoinList Pro trading account and CoinList wallet
1883
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#get-coinlist-wallet-ledger
1884
+ * @param {string} [code] unified currency code for the currency of the deposit/withdrawals
1885
+ * @param {int} [since] timestamp in ms of the earliest deposit/withdrawal
1886
+ * @param {int} [limit] max number of deposit/withdrawals to return (default 200, max 500)
1887
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
1888
+ * @returns {object} a list of [transaction structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#transaction-structure}
1889
+ */
1890
+ if (code === undefined) {
1891
+ throw new ArgumentsRequired(this.id + ' fetchDepositsWithdrawals() requires a code argument');
1892
+ }
1893
+ const traderId = this.safeString2(params, 'trader_id', 'traderId');
1894
+ if (traderId === undefined) {
1895
+ throw new ArgumentsRequired(this.id + ' fetchDepositsWithdrawals() requires a traderId argument in the params');
1896
+ }
1897
+ await this.loadMarkets();
1898
+ const currency = this.currency(code);
1899
+ const request = {
1900
+ 'asset': currency['id'],
1901
+ 'trader_id': traderId,
1902
+ };
1903
+ if (limit !== undefined) {
1904
+ request['count'] = limit;
1905
+ }
1906
+ params = this.omit(params, ['trader_id', 'traderId']);
1907
+ const response = await this.privateGetV1AccountsTraderIdWalletLedger(this.extend(request, params));
1908
+ //
1909
+ // [
1910
+ // {
1911
+ // "id": "2c02db25-e8f2-4271-8222-e110bfd0aa2a",
1912
+ // "asset": "ETH",
1913
+ // "amount": "0.01",
1914
+ // "created_at": "2023-10-20T13:15:37.000Z",
1915
+ // "description": "Transfer to CoinList Pro",
1916
+ // "type": "PRO_TRANSFER",
1917
+ // "delta": "-0.010000000000000000"
1918
+ // },
1919
+ // {
1920
+ // "id": "7139384d-6cec-479e-a19c-d498647ccb47",
1921
+ // "asset": "ETH",
1922
+ // "amount": "0.01",
1923
+ // "created_at": "2023-10-20T13:10:55.000Z",
1924
+ // "description": "CRYPTO_DEPOSIT",
1925
+ // "type": "CRYPTO_DEPOSIT",
1926
+ // "delta": "0.010000000000000000"
1927
+ // },
1928
+ //
1929
+ // ...
1930
+ //
1931
+ // {
1932
+ // "id": "91bbbb22-5ede-4e9a-81ef-3f9318aa83d2",
1933
+ // "asset": "USDT",
1934
+ // "amount": "4.169654",
1935
+ // "withdrawal_fee_amount": "8.830346000000000000",
1936
+ // "created_at": "2023-10-27T16:14:11.000Z",
1937
+ // "description": "CRYPTO_WITHDRAWAL",
1938
+ // "type": "CRYPTO_WITHDRAWAL",
1939
+ // "delta": "-4.169654000000000000"
1940
+ // },
1941
+ // {
1942
+ // "id": "830261bd-cda9-401f-b6df-105f4da3b37c",
1943
+ // "asset": "USDT",
1944
+ // "amount": "13",
1945
+ // "created_at": "2023-10-27T14:52:05.000Z",
1946
+ // "description": "Transfer from CoinList Pro",
1947
+ // "type": "PRO_TRANSFER",
1948
+ // "delta": "13.000000000000000000"
1949
+ // }
1950
+ // ]
1951
+ //
1952
+ // coinlist returns both internal transfers and blockchain transactions
1953
+ return this.parseTransactions(response, currency, since, limit);
1954
+ }
1955
+ async withdraw(code, amount, address, tag = undefined, params = {}) {
1956
+ /**
1957
+ * @method
1958
+ * @name coinlist#withdraw
1959
+ * @description request a withdrawal from CoinList wallet. (Disabled by default. Contact CoinList to apply for an exception.)
1960
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#request-withdrawal-from-wallet
1961
+ * @param {string} code unified currency code
1962
+ * @param {float} amount the amount to withdraw
1963
+ * @param {string} address the address to withdraw to
1964
+ * @param {string} tag
1965
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
1966
+ * @returns {object} a [transaction structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#transaction-structure}
1967
+ */
1968
+ await this.loadMarkets();
1969
+ const currency = this.currency(code);
1970
+ const request = {
1971
+ 'asset': currency['id'],
1972
+ 'amount': this.currencyToPrecision(code, amount),
1973
+ 'destination_address': address,
1974
+ };
1975
+ const response = await this.privatePostV1TransfersWithdrawalRequest(this.extend(request, params));
1976
+ //
1977
+ // {
1978
+ // "transfer_id": "d4a2d8dd-7def-4545-a062-761683b9aa05"
1979
+ // }
1980
+ //
1981
+ const data = this.safeValue(response, 'data', {});
1982
+ return this.parseTransaction(data, currency);
1983
+ }
1984
+ parseTransaction(transaction, currency = undefined) {
1985
+ // withdraw
1986
+ //
1987
+ // {
1988
+ // "transfer_id": "d4a2d8dd-7def-4545-a062-761683b9aa05"
1989
+ // }
1990
+ //
1991
+ // fetchDepositsWithdrawals
1992
+ // {
1993
+ // "id": "91bbbb22-5ede-4e9a-81ef-3f9318aa83d2",
1994
+ // "asset": "USDT",
1995
+ // "amount": "4.169654",
1996
+ // "withdrawal_fee_amount": "8.830346000000000000",
1997
+ // "created_at": "2023-10-27T16:14:11.000Z",
1998
+ // "description": "CRYPTO_WITHDRAWAL",
1999
+ // "type": "CRYPTO_WITHDRAWAL",
2000
+ // "delta": "-4.169654000000000000"
2001
+ // },
2002
+ //
2003
+ const currencyId = this.safeString(transaction, 'asset');
2004
+ const code = this.safeCurrencyCode(currencyId, currency);
2005
+ const id = this.safeString2(transaction, 'id', 'transfer_id');
2006
+ const amount = this.safeNumber(transaction, 'amount');
2007
+ const timestamp = this.parse8601(this.safeString(transaction, 'created_at'));
2008
+ let type = this.safeString(transaction, 'type', undefined);
2009
+ if (type === undefined) {
2010
+ type = 'withdrawal'; // undefined only in withdraw() method
2011
+ }
2012
+ else {
2013
+ type = this.parseTransactionType(type);
2014
+ }
2015
+ let fee = undefined;
2016
+ const feeCost = this.safeString(transaction, 'withdrawal_fee_amount');
2017
+ if (feeCost !== undefined) {
2018
+ fee = {
2019
+ 'cost': feeCost,
2020
+ 'currency': code,
2021
+ };
2022
+ }
2023
+ return {
2024
+ 'info': transaction,
2025
+ 'id': id,
2026
+ 'txid': undefined,
2027
+ 'timestamp': timestamp,
2028
+ 'datetime': this.iso8601(timestamp),
2029
+ 'network': undefined,
2030
+ 'addressFrom': undefined,
2031
+ 'address': undefined,
2032
+ 'addressTo': undefined,
2033
+ 'tagFrom': undefined,
2034
+ 'tag': undefined,
2035
+ 'tagTo': undefined,
2036
+ 'type': type,
2037
+ 'amount': amount,
2038
+ 'currency': code,
2039
+ 'status': undefined,
2040
+ 'updated': undefined,
2041
+ 'fee': fee,
2042
+ };
2043
+ }
2044
+ parseTransactionType(type) {
2045
+ const types = {
2046
+ 'CRYPTO_DEPOSIT': 'deposit',
2047
+ 'CRYPTO_WITHDRAWAL': 'withdrawal',
2048
+ 'PRO_TRANSFER': 'transfer',
2049
+ };
2050
+ return this.safeString(types, type, type);
2051
+ }
2052
+ async fetchLedger(code = undefined, since = undefined, limit = undefined, params = {}) {
2053
+ /**
2054
+ * @method
2055
+ * @name coinlist#fetchLedger
2056
+ * @description fetch the history of changes, actions done by the user or operations that altered balance of the user
2057
+ * @see https://trade-docs.coinlist.co/?javascript--nodejs#get-account-history
2058
+ * @param {string} code unified currency code, default is undefined
2059
+ * @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
2060
+ * @param {int} [limit] max number of ledger entrys to return (default 200, max 500)
2061
+ * @param {object} [params] extra parameters specific to the coinlist api endpoint
2062
+ * @param {int} [params.until] the latest time in ms to fetch entries for
2063
+ * @returns {object} a [ledger structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#ledger-structure}
2064
+ */
2065
+ const traderId = this.safeString2(params, 'trader_id', 'traderId');
2066
+ if (traderId === undefined) {
2067
+ throw new ArgumentsRequired(this.id + ' fetchLedger() requires a traderId argument in the params');
2068
+ }
2069
+ await this.loadMarkets();
2070
+ const request = {
2071
+ 'trader_id': traderId,
2072
+ };
2073
+ let currency = undefined;
2074
+ if (code !== undefined) {
2075
+ currency = this.currency(code);
2076
+ }
2077
+ if (since !== undefined) {
2078
+ request['start_time'] = this.iso8601(since);
2079
+ }
2080
+ if (limit !== undefined) {
2081
+ request['count'] = limit;
2082
+ }
2083
+ const until = this.safeInteger2(params, 'till', 'until');
2084
+ if (until !== undefined) {
2085
+ params = this.omit(params, ['till', 'until']);
2086
+ request['end_time'] = this.iso8601(until);
2087
+ }
2088
+ params = this.omit(params, ['trader_id', 'traderId']);
2089
+ const response = await this.privateGetV1AccountsTraderIdLedger(this.extend(request, params));
2090
+ //
2091
+ // {
2092
+ // transactions: [
2093
+ // {
2094
+ // transaction_id: '0288634e-49bd-494d-b04a-18fd1832d394',
2095
+ // transaction_type: 'XFER',
2096
+ // type: 'deposit',
2097
+ // asset: 'ETH',
2098
+ // symbol: null,
2099
+ // amount: '0.010000000000000000',
2100
+ // details: null,
2101
+ // created_at: '2023-10-20T13:15:39.443Z'
2102
+ // },
2103
+ // {
2104
+ // transaction_id: '47a45928-abcd-4c12-8bd6-587c3028025f',
2105
+ // transaction_type: 'SWAP',
2106
+ // type: 'atomic token swap',
2107
+ // asset: 'USDT',
2108
+ // symbol: 'ETH-USDT',
2109
+ // amount: '1.447947',
2110
+ // details: null,
2111
+ // created_at: '2023-10-20T13:16:30.373Z'
2112
+ // },
2113
+ // {
2114
+ // transaction_id: '1ffe3a54-916e-41f0-b957-3a01309eb009',
2115
+ // transaction_type: 'FEE',
2116
+ // type: 'fee',
2117
+ // asset: 'USDT',
2118
+ // symbol: 'ETH-USDT',
2119
+ // amount: '-0.006516',
2120
+ // details: {
2121
+ // fee_details: [
2122
+ // {
2123
+ // insurance_fee: '0',
2124
+ // order_id: '39911d5f-c789-4a7d-ad34-820a804d1da6',
2125
+ // fee_type: 'taker',
2126
+ // fee_currency: 'USDT'
2127
+ // }
2128
+ // ]
2129
+ // },
2130
+ // created_at: '2023-10-20T13:16:30.373Z'
2131
+ // },
2132
+ // {
2133
+ // transaction_id: '3930e8a3-2218-481f-8c3c-2219287e205e',
2134
+ // transaction_type: 'SWAP',
2135
+ // type: 'atomic token swap',
2136
+ // asset: 'ETH',
2137
+ // symbol: 'ETH-USDT',
2138
+ // amount: '-0.000900000000000000',
2139
+ // details: null,
2140
+ // created_at: '2023-10-20T13:16:30.373Z'
2141
+ // },
2142
+ // {
2143
+ // transaction_id: 'a6c65cb3-95d0-44e2-8202-f70581d6e55c',
2144
+ // transaction_type: 'XFER',
2145
+ // type: 'withdrawal',
2146
+ // asset: 'USD',
2147
+ // symbol: null,
2148
+ // amount: '-3.00',
2149
+ // details: null,
2150
+ // created_at: '2023-10-26T14:32:24.887Z'
2151
+ // }
2152
+ // ]
2153
+ // }
2154
+ //
2155
+ const ledger = this.safeValue(response, 'transactions', []);
2156
+ return this.parseLedger(ledger, currency, since, limit);
2157
+ }
2158
+ parseLedgerEntry(item, currency = undefined) {
2159
+ //
2160
+ // deposit transaction from wallet (funding) to pro (trading)
2161
+ // {
2162
+ // transaction_id: '0288634e-49bd-494d-b04a-18fd1832d394',
2163
+ // transaction_type: 'XFER',
2164
+ // type: 'deposit',
2165
+ // asset: 'ETH',
2166
+ // symbol: null,
2167
+ // amount: '0.010000000000000000',
2168
+ // details: null,
2169
+ // created_at: '2023-10-20T13:15:39.443Z'
2170
+ // }
2171
+ //
2172
+ // withdrawal transaction from pro (trading) to wallet (funding)
2173
+ // {
2174
+ // transaction_id: 'a6c65cb3-95d0-44e2-8202-f70581d6e55c',
2175
+ // transaction_type: 'XFER',
2176
+ // type: 'withdrawal',
2177
+ // asset: 'USD',
2178
+ // symbol: null,
2179
+ // amount: '-3.00',
2180
+ // details: null,
2181
+ // created_at: '2023-10-26T14:32:24.887Z'
2182
+ // }
2183
+ //
2184
+ // sell trade
2185
+ // {
2186
+ // transaction_id: '47a45928-abcd-4c12-8bd6-587c3028025f',
2187
+ // transaction_type: 'SWAP',
2188
+ // type: 'atomic token swap',
2189
+ // asset: 'USDT',
2190
+ // symbol: 'ETH-USDT',
2191
+ // amount: '1.447947',
2192
+ // details: null,
2193
+ // created_at: '2023-10-20T13:16:30.373Z'
2194
+ // }
2195
+ //
2196
+ // buy trade
2197
+ // {
2198
+ // transaction_id: '46d20a93-45c4-4441-a238-f89602eb8c8c',
2199
+ // transaction_type: 'SWAP',
2200
+ // type: 'atomic token swap',
2201
+ // asset: 'ETH',
2202
+ // symbol: 'ETH-USDT',
2203
+ // amount: '0.000800000000000000',
2204
+ // details: null,
2205
+ // created_at: '2023-10-20T13:22:14.256Z'
2206
+ // },
2207
+ //
2208
+ // fee
2209
+ // {
2210
+ // transaction_id: '57fd526c-36b1-4721-83ce-42aadcb1e953',
2211
+ // transaction_type: 'FEE',
2212
+ // type: 'fee',
2213
+ // asset: 'USDT',
2214
+ // symbol: 'BTC-USDT',
2215
+ // amount: '-0.047176',
2216
+ // details: {
2217
+ // fee_details: [
2218
+ // {
2219
+ // insurance_fee: '0',
2220
+ // order_id: 'c0bc33cd-eeb9-40a0-ab5f-2d99f323ef58',
2221
+ // fee_type: 'taker',
2222
+ // fee_currency: 'USDT'
2223
+ // }
2224
+ // ]
2225
+ // },
2226
+ // created_at: '2023-10-25T16:46:24.294Z'
2227
+ // }
2228
+ //
2229
+ const id = this.safeString(item, 'transaction_id');
2230
+ const createdAt = this.safeString(item, 'created_at');
2231
+ const timestamp = this.parse8601(createdAt);
2232
+ let amount = this.safeString(item, 'amount');
2233
+ const amountIsNegative = Precise.stringLt(amount, '0');
2234
+ let direction = undefined;
2235
+ if (amountIsNegative) {
2236
+ direction = 'out';
2237
+ amount = Precise.stringNeg(amount);
2238
+ }
2239
+ else {
2240
+ direction = 'in';
2241
+ }
2242
+ const currencyId = this.safeString(item, 'asset');
2243
+ const code = this.safeCurrencyCode(currencyId, currency);
2244
+ const type = this.parseLedgerEntryType(this.safeString(item, 'type'));
2245
+ return {
2246
+ 'info': item,
2247
+ 'id': id,
2248
+ 'timestamp': timestamp,
2249
+ 'datetime': this.iso8601(timestamp),
2250
+ 'direction': direction,
2251
+ 'account': 'trading',
2252
+ 'referenceId': undefined,
2253
+ 'referenceAccount': undefined,
2254
+ 'type': type,
2255
+ 'currency': code,
2256
+ 'amount': this.parseNumber(amount),
2257
+ 'before': undefined,
2258
+ 'after': undefined,
2259
+ 'status': 'ok',
2260
+ 'fee': undefined,
2261
+ };
2262
+ }
2263
+ parseLedgerEntryType(type) {
2264
+ const types = {
2265
+ 'atomic token swap': 'trade',
2266
+ 'fee': 'fee',
2267
+ 'deposit': 'transfer',
2268
+ 'withdrawal': 'transfer',
2269
+ };
2270
+ return this.safeString(types, type, type);
2271
+ }
2272
+ sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
2273
+ const request = this.omit(params, this.extractParams(path));
2274
+ const endpoint = '/' + this.implodeParams(path, params);
2275
+ let url = this.urls['api'][api] + endpoint;
2276
+ const query = this.urlencode(request);
2277
+ if (api === 'private') {
2278
+ this.checkRequiredCredentials();
2279
+ const timestamp = this.seconds().toString();
2280
+ let auth = timestamp + method + endpoint;
2281
+ const isBulk = Array.isArray(params);
2282
+ if ((method === 'POST') || (method === 'PATCH') || isBulk) {
2283
+ body = this.json(request);
2284
+ auth += body;
2285
+ }
2286
+ else if (query.length !== 0) {
2287
+ auth += '?' + query;
2288
+ url += '?' + query;
2289
+ }
2290
+ const signature = this.hmac(this.encode(auth), this.base64ToBinary(this.secret), sha256, 'base64');
2291
+ headers = {
2292
+ 'CL-ACCESS-KEY': this.apiKey,
2293
+ 'CL-ACCESS-SIG': signature,
2294
+ 'CL-ACCESS-TIMESTAMP': timestamp,
2295
+ 'Content-Type': 'application/json',
2296
+ };
2297
+ }
2298
+ else if (query.length !== 0) {
2299
+ url += '?' + query;
2300
+ }
2301
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
2302
+ }
2303
+ handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
2304
+ if (response === undefined) {
2305
+ // In some cases the exchange returns 202 Accepted for bad orders.
2306
+ // The body of that response contains order_id of the order.
2307
+ // Some bad orders will get status 'rejected' and could be fetched later (by using fetchOrders() or fetchOrder(order_id)).
2308
+ // While others don't get any status, they simply disappear, but the response is still 202 Accepted and contains their order_id.
2309
+ // When using fechOrder(order_id) for such disappeared orders, the exchange returns an empty response with code 404.
2310
+ if ((code === 404) && (url.indexOf('/orders/') >= 0) && (method === 'GET')) {
2311
+ const parts = url.split('/orders/');
2312
+ const orderId = this.safeString(parts, 1);
2313
+ throw new OrderNotFound(this.id + ' order ' + orderId + ' not found (or rejected on the exchange side)');
2314
+ }
2315
+ return undefined;
2316
+ }
2317
+ const responseCode = this.safeString(response, 'status');
2318
+ const messageCode = this.safeString(response, 'message_code');
2319
+ if ((messageCode !== undefined) || ((responseCode !== undefined) && (code !== 200) && (code !== 202) && (responseCode !== '200') && (responseCode !== '202'))) {
2320
+ const feedback = this.id + ' ' + body;
2321
+ const message = this.safeString(response, 'message');
2322
+ this.throwBroadlyMatchedException(this.exceptions['broad'], message, feedback);
2323
+ this.throwExactlyMatchedException(this.exceptions['exact'], messageCode, feedback);
2324
+ throw new ExchangeError(feedback);
2325
+ }
2326
+ return undefined;
2327
+ }
2328
+ }