ccxt 4.5.44 → 4.5.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +9 -12
  2. package/dist/ccxt.browser.min.js +3 -3
  3. package/dist/cjs/ccxt.js +1 -12
  4. package/dist/cjs/src/abstract/kucoinfutures.js +1 -1
  5. package/dist/cjs/src/base/Exchange.js +36 -3
  6. package/dist/cjs/src/base/functions/encode.js +2 -2
  7. package/dist/cjs/src/base/functions/generic.js +8 -2
  8. package/dist/cjs/src/bitrue.js +1 -1
  9. package/dist/cjs/src/bitteam.js +1 -1
  10. package/dist/cjs/src/btcbox.js +1 -1
  11. package/dist/cjs/src/cex.js +1 -0
  12. package/dist/cjs/src/gate.js +227 -168
  13. package/dist/cjs/src/grvt.js +3 -2
  14. package/dist/cjs/src/hyperliquid.js +16 -5
  15. package/dist/cjs/src/kraken.js +2 -2
  16. package/dist/cjs/src/krakenfutures.js +1 -5
  17. package/dist/cjs/src/kucoin.js +4729 -970
  18. package/dist/cjs/src/kucoinfutures.js +14 -3434
  19. package/dist/cjs/src/lbank.js +1 -1
  20. package/dist/cjs/src/poloniex.js +1 -1
  21. package/dist/cjs/src/pro/gate.js +37 -1
  22. package/dist/cjs/src/pro/kucoin.js +819 -178
  23. package/dist/cjs/src/pro/kucoinfutures.js +95 -1261
  24. package/dist/cjs/src/pro/mexc.js +10 -5
  25. package/dist/cjs/src/pro/okx.js +84 -39
  26. package/js/ccxt.d.ts +2 -14
  27. package/js/ccxt.js +2 -10
  28. package/js/src/abstract/kucoin.d.ts +46 -3
  29. package/js/src/abstract/kucoinfutures.d.ts +27 -12
  30. package/js/src/base/Exchange.d.ts +12 -1
  31. package/js/src/base/Exchange.js +36 -3
  32. package/js/src/base/functions/encode.js +2 -2
  33. package/js/src/base/functions/generic.js +9 -3
  34. package/js/src/bitrue.js +1 -1
  35. package/js/src/bitteam.js +1 -1
  36. package/js/src/btcbox.js +1 -1
  37. package/js/src/cex.js +2 -1
  38. package/js/src/gate.d.ts +125 -119
  39. package/js/src/gate.js +227 -168
  40. package/js/src/grvt.js +3 -2
  41. package/js/src/hyperliquid.d.ts +3 -1
  42. package/js/src/hyperliquid.js +16 -5
  43. package/js/src/kraken.js +2 -2
  44. package/js/src/krakenfutures.js +1 -5
  45. package/js/src/kucoin.d.ts +696 -100
  46. package/js/src/kucoin.js +4730 -971
  47. package/js/src/kucoinfutures.d.ts +4 -522
  48. package/js/src/kucoinfutures.js +14 -3434
  49. package/js/src/lbank.js +1 -1
  50. package/js/src/poloniex.js +1 -1
  51. package/js/src/pro/gate.d.ts +30 -1
  52. package/js/src/pro/gate.js +37 -1
  53. package/js/src/pro/kucoin.d.ts +70 -30
  54. package/js/src/pro/kucoin.js +821 -180
  55. package/js/src/pro/kucoinfutures.d.ts +17 -195
  56. package/js/src/pro/kucoinfutures.js +96 -1262
  57. package/js/src/pro/mexc.js +10 -5
  58. package/js/src/pro/okx.d.ts +1 -0
  59. package/js/src/pro/okx.js +84 -39
  60. package/package.json +1 -1
  61. package/dist/cjs/src/abstract/alp.js +0 -11
  62. package/dist/cjs/src/abstract/defx.js +0 -11
  63. package/dist/cjs/src/abstract/timex.js +0 -11
  64. package/dist/cjs/src/alp.js +0 -1059
  65. package/dist/cjs/src/defx.js +0 -2142
  66. package/dist/cjs/src/pro/defx.js +0 -866
  67. package/dist/cjs/src/timex.js +0 -1793
  68. package/js/src/abstract/alp.d.ts +0 -21
  69. package/js/src/abstract/alp.js +0 -5
  70. package/js/src/abstract/defx.d.ts +0 -72
  71. package/js/src/abstract/defx.js +0 -5
  72. package/js/src/abstract/timex.d.ts +0 -65
  73. package/js/src/abstract/timex.js +0 -5
  74. package/js/src/alp.d.ts +0 -209
  75. package/js/src/alp.js +0 -1052
  76. package/js/src/defx.d.ts +0 -348
  77. package/js/src/defx.js +0 -2135
  78. package/js/src/pro/defx.d.ts +0 -236
  79. package/js/src/pro/defx.js +0 -859
  80. package/js/src/timex.d.ts +0 -247
  81. package/js/src/timex.js +0 -1786
package/js/src/alp.js DELETED
@@ -1,1052 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- import Exchange from './abstract/alp.js';
3
- import { ExchangeError, InvalidOrder, InsufficientFunds } from './base/errors.js';
4
- import { Precise } from './base/Precise.js';
5
- import { TICK_SIZE } from './base/functions/number.js';
6
- import { sha256 } from './static_dependencies/noble-hashes/sha256.js';
7
- // ---------------------------------------------------------------------------
8
- /**
9
- * @class alp
10
- * @augments Exchange
11
- */
12
- export default class alp extends Exchange {
13
- describe() {
14
- return this.deepExtend(super.describe(), {
15
- 'id': 'alp',
16
- 'name': 'Alp',
17
- 'countries': ['US'],
18
- 'version': 'v1',
19
- 'rateLimit': 10,
20
- 'has': {
21
- 'CORS': undefined,
22
- 'spot': true,
23
- 'margin': false,
24
- 'swap': false,
25
- 'future': false,
26
- 'option': false,
27
- 'addMargin': false,
28
- 'borrowCrossMargin': false,
29
- 'borrowIsolatedMargin': false,
30
- 'borrowMargin': false,
31
- 'cancelOrder': true,
32
- 'closeAllPositions': false,
33
- 'closePosition': false,
34
- 'createDepositAddress': false,
35
- 'createOrder': true,
36
- 'createOrderWithTakeProfitAndStopLoss': false,
37
- 'createOrderWithTakeProfitAndStopLossWs': false,
38
- 'createPostOnlyOrder': false,
39
- 'createReduceOnlyOrder': false,
40
- 'createStopLimitOrder': false,
41
- 'createStopMarketOrder': false,
42
- 'createStopOrder': false,
43
- 'fetchBalance': true,
44
- 'fetchBorrowInterest': false,
45
- 'fetchBorrowRate': false,
46
- 'fetchBorrowRateHistories': false,
47
- 'fetchBorrowRateHistory': false,
48
- 'fetchBorrowRates': false,
49
- 'fetchBorrowRatesPerSymbol': false,
50
- 'fetchClosedOrders': true,
51
- 'fetchCrossBorrowRate': false,
52
- 'fetchCrossBorrowRates': false,
53
- 'fetchCurrencies': false,
54
- 'fetchDeposit': false,
55
- 'fetchDepositAddress': false,
56
- 'fetchDepositAddresses': false,
57
- 'fetchDepositAddressesByNetwork': false,
58
- 'fetchDeposits': true,
59
- 'fetchFundingHistory': false,
60
- 'fetchFundingInterval': false,
61
- 'fetchFundingIntervals': false,
62
- 'fetchFundingRate': false,
63
- 'fetchFundingRateHistory': false,
64
- 'fetchFundingRates': false,
65
- 'fetchGreeks': false,
66
- 'fetchIndexOHLCV': false,
67
- 'fetchIsolatedBorrowRate': false,
68
- 'fetchIsolatedBorrowRates': false,
69
- 'fetchIsolatedPositions': false,
70
- 'fetchL2OrderBook': true,
71
- 'fetchLeverage': false,
72
- 'fetchLeverages': false,
73
- 'fetchLeverageTiers': false,
74
- 'fetchLiquidations': false,
75
- 'fetchLongShortRatio': false,
76
- 'fetchLongShortRatioHistory': false,
77
- 'fetchMarginAdjustmentHistory': false,
78
- 'fetchMarginMode': false,
79
- 'fetchMarginModes': false,
80
- 'fetchMarketLeverageTiers': false,
81
- 'fetchMarkets': true,
82
- 'fetchMarkOHLCV': false,
83
- 'fetchMarkPrices': false,
84
- 'fetchMyLiquidations': false,
85
- 'fetchMySettlementHistory': false,
86
- 'fetchMyTrades': true,
87
- 'fetchOHLCV': true,
88
- 'fetchOpenInterest': false,
89
- 'fetchOpenInterestHistory': false,
90
- 'fetchOpenInterests': false,
91
- 'fetchOpenOrders': true,
92
- 'fetchOption': false,
93
- 'fetchOptionChain': false,
94
- 'fetchOrder': true,
95
- 'fetchOrderBook': true,
96
- 'fetchOrders': true,
97
- 'fetchPosition': false,
98
- 'fetchPositionHistory': false,
99
- 'fetchPositionMode': false,
100
- 'fetchPositions': false,
101
- 'fetchPositionsForSymbol': false,
102
- 'fetchPositionsHistory': false,
103
- 'fetchPositionsRisk': false,
104
- 'fetchPremiumIndexOHLCV': false,
105
- 'fetchSettlementHistory': false,
106
- 'fetchTicker': true,
107
- 'fetchTickers': true,
108
- 'fetchTrades': true,
109
- 'fetchTradingFee': false,
110
- 'fetchTradingFees': false,
111
- 'fetchTransfer': false,
112
- 'fetchTransfers': false,
113
- 'fetchVolatilityHistory': false,
114
- 'fetchWithdrawal': false,
115
- 'fetchWithdrawals': true,
116
- 'reduceMargin': false,
117
- 'repayCrossMargin': false,
118
- 'repayIsolatedMargin': false,
119
- 'repayMargin': false,
120
- 'setLeverage': false,
121
- 'setMargin': false,
122
- 'setMarginMode': false,
123
- 'setPositionMode': false,
124
- 'transfer': false,
125
- 'withdraw': false,
126
- },
127
- 'timeframes': {
128
- '5m': '5',
129
- '15m': '15',
130
- '30m': '30',
131
- '1h': '60',
132
- '4h': '240',
133
- '1d': 'D',
134
- },
135
- 'urls': {
136
- 'logo': 'https://github.com/user-attachments/assets/dce49f3a-61e5-4ba0-a2fe-41d192fd0e5d',
137
- 'api': {
138
- 'rest': 'https://alp.com/api',
139
- },
140
- 'www': 'https://alp.com',
141
- 'doc': 'https://alpcomdev.github.io/alp-api-docs/',
142
- 'fees': 'https://alp.com/fees/',
143
- 'referral': 'https://alp.com/?r=123788',
144
- },
145
- 'api': {
146
- 'public': {
147
- 'get': {
148
- 'currencies/': 1,
149
- 'pairs/': 1,
150
- 'orderbook/{pair_name}': 1,
151
- 'exchanges/': 1,
152
- 'charts/{pair}/{type}/chart/': 1,
153
- 'ticker/': 1,
154
- },
155
- },
156
- 'private': {
157
- 'get': {
158
- 'wallets/': 50,
159
- 'orders/own/': 50,
160
- 'order/{id}/': 50,
161
- 'exchanges/own/': 50,
162
- 'deposits/': 50,
163
- 'withdraws/': 50,
164
- },
165
- 'post': {
166
- 'order/': 50,
167
- 'order-cancel/': 50,
168
- },
169
- },
170
- },
171
- 'fees': {
172
- 'trading': {
173
- 'maker': this.parseNumber('0.002'),
174
- 'taker': this.parseNumber('0.002'),
175
- },
176
- 'funding': {
177
- 'withdraw': {},
178
- },
179
- },
180
- 'commonCurrencies': {
181
- 'CBC': 'Cashbery',
182
- },
183
- 'features': {
184
- 'spot': {
185
- 'sandbox': false,
186
- 'createOrder': {
187
- 'marginMode': false,
188
- 'triggerPrice': false,
189
- 'triggerPriceType': undefined,
190
- 'triggerDirection': false,
191
- 'stopLossPrice': false,
192
- 'takeProfitPrice': false,
193
- 'attachedStopLossTakeProfit': undefined,
194
- 'timeInForce': {
195
- 'IOC': false,
196
- 'FOK': false,
197
- 'PO': false,
198
- 'GTD': false,
199
- },
200
- 'hedged': false,
201
- 'leverage': false,
202
- 'marketBuyRequiresPrice': false,
203
- 'marketBuyByCost': false,
204
- 'selfTradePrevention': false,
205
- 'trailing': false,
206
- 'iceberg': false,
207
- },
208
- 'createOrders': undefined,
209
- 'fetchMyTrades': {
210
- 'marginMode': false,
211
- 'limit': 100,
212
- 'daysBack': undefined,
213
- 'untilDays': undefined,
214
- 'symbolRequired': false,
215
- },
216
- 'fetchOrder': {
217
- 'marginMode': false,
218
- 'trigger': false,
219
- 'trailing': false,
220
- 'symbolRequired': false,
221
- },
222
- 'fetchOpenOrders': {
223
- 'marginMode': false,
224
- 'limit': 2000,
225
- 'trigger': false,
226
- 'trailing': false,
227
- 'symbolRequired': false,
228
- },
229
- 'fetchOrders': {
230
- 'marginMode': false,
231
- 'limit': 2000,
232
- 'daysBack': undefined,
233
- 'untilDays': undefined,
234
- 'trigger': false,
235
- 'trailing': false,
236
- 'symbolRequired': false,
237
- },
238
- 'fetchClosedOrders': {
239
- 'marginMode': false,
240
- 'limit': 2000,
241
- 'daysBack': undefined,
242
- 'daysBackCanceled': undefined,
243
- 'untilDays': undefined,
244
- 'trigger': false,
245
- 'trailing': false,
246
- 'symbolRequired': false,
247
- },
248
- 'fetchOHLCV': {
249
- 'limit': 720,
250
- },
251
- },
252
- 'swap': {
253
- 'linear': undefined,
254
- 'inverse': undefined,
255
- },
256
- 'future': {
257
- 'linear': undefined,
258
- 'inverse': undefined,
259
- },
260
- },
261
- 'precisionMode': TICK_SIZE,
262
- 'exceptions': {
263
- 'exact': {},
264
- 'broad': {
265
- 'Out of balance': InsufficientFunds, // {"date":1570599531.4814300537,"error":"Out of balance -9.99243661 BTC"}
266
- },
267
- },
268
- });
269
- }
270
- /**
271
- * @method
272
- * @name alp#fetchMarkets
273
- * @description retrieves data on all markets for alp
274
- * @see https://alpcomdev.github.io/alp-api-docs/#list-all-currencies
275
- * @param {object} [params] extra parameters specific to the exchange API endpoint
276
- * @returns {object[]} an array of objects representing market data
277
- */
278
- async fetchMarkets(params = {}) {
279
- const response = await this.publicGetPairs(params);
280
- //
281
- // [
282
- // {
283
- // "name": "1INCH_USDT",
284
- // "currency1": "1INCH",
285
- // "currency2": "USDT",
286
- // "price_precision": 4,
287
- // "amount_precision": 2,
288
- // "minimum_order_size": "0.01000000",
289
- // "maximum_order_size": "900000.00000000",
290
- // "minimum_order_value": "10.00000000",
291
- // "liquidity_type": 10
292
- // },
293
- // ]
294
- //
295
- return this.parseMarkets(response);
296
- }
297
- parseMarket(market) {
298
- const id = this.safeString(market, 'name');
299
- const baseId = this.safeString(market, 'currency1');
300
- const quoteId = this.safeString(market, 'currency2');
301
- const base = this.safeCurrencyCode(baseId);
302
- const quote = this.safeCurrencyCode(quoteId);
303
- const pricePrecision = this.safeString(market, 'price_precision');
304
- const priceLimit = this.parsePrecision(pricePrecision);
305
- const amountLimit = this.safeString(market, 'minimum_order_size');
306
- return {
307
- 'id': id,
308
- 'symbol': base + '/' + quote,
309
- 'base': base,
310
- 'quote': quote,
311
- 'settle': undefined,
312
- 'baseId': baseId,
313
- 'quoteId': quoteId,
314
- 'settleId': undefined,
315
- 'type': 'spot',
316
- 'spot': true,
317
- 'margin': false,
318
- 'swap': false,
319
- 'future': false,
320
- 'option': false,
321
- 'active': true,
322
- 'contract': false,
323
- 'linear': undefined,
324
- 'inverse': undefined,
325
- 'contractSize': undefined,
326
- 'expiry': undefined,
327
- 'expiryDatetime': undefined,
328
- 'strike': undefined,
329
- 'optionType': undefined,
330
- 'precision': {
331
- 'amount': this.parseNumber(this.parsePrecision(this.safeString(market, 'amount_precision'))),
332
- 'price': this.parseNumber(this.parsePrecision((pricePrecision))),
333
- },
334
- 'limits': {
335
- 'leverage': {
336
- 'min': undefined,
337
- 'max': undefined,
338
- },
339
- 'amount': {
340
- 'min': this.parseNumber(amountLimit),
341
- 'max': this.safeNumber(market, 'maximum_order_size'),
342
- },
343
- 'price': {
344
- 'min': this.parseNumber(priceLimit),
345
- 'max': undefined,
346
- },
347
- 'cost': {
348
- 'min': this.parseNumber(Precise.stringMul(priceLimit, amountLimit)),
349
- 'max': undefined,
350
- },
351
- },
352
- 'created': undefined,
353
- 'info': market,
354
- };
355
- }
356
- /**
357
- * @method
358
- * @name alp#fetchTickers
359
- * @see https://alpcomdev.github.io/alp-api-docs/#tickers
360
- * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
361
- * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
362
- * @param {object} [params] extra parameters specific to the exchange API endpoint
363
- * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
364
- */
365
- async fetchTickers(symbols = undefined, params = {}) {
366
- await this.loadMarkets();
367
- const response = await this.publicGetTicker(params);
368
- //
369
- // [
370
- // {
371
- // "timestamp": "1674658.445272",
372
- // "pair": "BTC_USDT",
373
- // "last": "22476.85",
374
- // "diff": "458.96",
375
- // "vol": "6660.847784",
376
- // "high": "23106.08",
377
- // "low": "22348.29",
378
- // "buy": "22508.46",
379
- // "sell": "22521.11"
380
- // },
381
- // ...
382
- // ]
383
- //
384
- return this.parseTickers(response, symbols);
385
- }
386
- /**
387
- * @method
388
- * @name alp#fetchTicker
389
- * @see https://alpcomdev.github.io/alp-api-docs/#tickers
390
- * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
391
- * @param {string} symbol unified symbol of the market to fetch the ticker for
392
- * @param {object} [params] extra parameters specific to the exchange API endpoint
393
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
394
- */
395
- async fetchTicker(symbol, params = {}) {
396
- await this.loadMarkets();
397
- const market = this.market(symbol);
398
- const request = {
399
- 'pair': market['id'],
400
- };
401
- const response = await this.publicGetTicker(this.extend(request, params));
402
- //
403
- // {
404
- // "timestamp": "1674658.445272",
405
- // "pair": "BTC_USDT",
406
- // "last": "22476.85",
407
- // "diff": "458.96",
408
- // "vol": "6660.847784",
409
- // "high": "23106.08",
410
- // "low": "22348.29",
411
- // "buy": "22508.46",
412
- // "sell": "22521.11"
413
- // }
414
- //
415
- return this.parseTicker(response, market);
416
- }
417
- parseTicker(ticker, market = undefined) {
418
- //
419
- // {
420
- // "timestamp": "1674658.445272",
421
- // "pair": "BTC_USDT",
422
- // "last": "22476.85",
423
- // "diff": "458.96",
424
- // "vol": "6660.847784",
425
- // "high": "23106.08",
426
- // "low": "22348.29",
427
- // "buy": "22508.46",
428
- // "sell": "22521.11"
429
- // }
430
- //
431
- const timestampStr = this.safeString(ticker, 'timestamp');
432
- const timestamp = parseInt(Precise.stringMul(timestampStr, '1000000'));
433
- const marketId = this.safeString(ticker, 'pair');
434
- market = this.safeMarket(marketId, market, '_');
435
- const last = this.safeString(ticker, 'last');
436
- return this.safeTicker({
437
- 'info': ticker,
438
- 'symbol': market['symbol'],
439
- 'timestamp': timestamp,
440
- 'datetime': this.iso8601(timestamp),
441
- 'high': this.safeString(ticker, 'high'),
442
- 'low': this.safeString(ticker, 'low'),
443
- 'bid': this.safeString(ticker, 'buy'),
444
- 'bidVolume': undefined,
445
- 'ask': this.safeString(ticker, 'sell'),
446
- 'askVolume': undefined,
447
- 'vwap': undefined,
448
- 'open': undefined,
449
- 'close': last,
450
- 'last': last,
451
- 'previousClose': undefined,
452
- 'change': this.safeString(ticker, 'diff'),
453
- 'percentage': undefined,
454
- 'average': undefined,
455
- 'baseVolume': undefined,
456
- 'quoteVolume': this.safeString(ticker, 'vol'),
457
- }, market);
458
- }
459
- /**
460
- * @method
461
- * @name alp#fetchOrderBook
462
- * @see https://alpcomdev.github.io/alp-api-docs/#get-orderbook
463
- * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
464
- * @param {string} symbol unified symbol of the market to fetch the order book for
465
- * @param {int} [limit] the maximum amount of order book entries to return
466
- * @param {object} [params] extra parameters specific to the exchange API endpoint
467
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure} indexed by market symbols
468
- */
469
- async fetchOrderBook(symbol, limit = undefined, params = {}) {
470
- await this.loadMarkets();
471
- const market = this.market(symbol);
472
- const request = {
473
- 'pair_name': market['id'],
474
- };
475
- if (limit) {
476
- request['limit_sell'] = limit;
477
- request['limit_buy'] = limit;
478
- }
479
- const response = await this.publicGetOrderbookPairName(this.extend(request, params));
480
- return this.parseOrderBook(response, market['symbol'], undefined, 'buy', 'sell', 'price', 'amount');
481
- }
482
- parseBidsAsks(bidasks, priceKey = 0, amountKey = 1, countOrIdKey = 2) {
483
- const result = [];
484
- for (let i = 0; i < bidasks.length; i++) {
485
- const bidask = bidasks[i];
486
- if (bidask) {
487
- result.push(this.parseBidAsk(bidask, priceKey, amountKey));
488
- }
489
- }
490
- return result;
491
- }
492
- parseTrade(trade, market = undefined) {
493
- //
494
- // fetchTrades (public)
495
- //
496
- // {
497
- // "id": "202203440",
498
- // "timestamp": "1637856276.264215",
499
- // "pair": "AAVE_USDT",
500
- // "price": "320.79900000",
501
- // "amount": "0.05000000",
502
- // "type": "buy"
503
- // }
504
- //
505
- // fetchMyTrades (private)
506
- //
507
- // {
508
- // "id": "202203440",
509
- // "timestamp": "1637856276.264215",
510
- // "pair": "AAVE_USDT",
511
- // "price": "320.79900000",
512
- // "amount": "0.05000000",
513
- // "type": "buy",
514
- // "my_side": "buy"
515
- // }
516
- //
517
- const marketId = this.safeString(trade, 'pair');
518
- market = this.safeMarket(marketId, market, '_');
519
- const timestampRaw = this.safeString(trade, 'timestamp');
520
- const timestamp = this.parseToInt(Precise.stringMul(timestampRaw, '1000000'));
521
- const priceString = this.safeString(trade, 'price');
522
- const amountString = this.safeString(trade, 'amount');
523
- const id = this.safeString(trade, 'id');
524
- const side = this.safeString2(trade, 'my_side', 'type');
525
- return this.safeTrade({
526
- 'id': id,
527
- 'info': trade,
528
- 'timestamp': timestamp,
529
- 'datetime': this.iso8601(timestamp),
530
- 'symbol': market['symbol'],
531
- 'order': id,
532
- 'type': 'limit',
533
- 'side': side,
534
- 'takerOrMaker': undefined,
535
- 'price': priceString,
536
- 'amount': amountString,
537
- 'cost': undefined,
538
- 'fee': undefined,
539
- }, market);
540
- }
541
- /**
542
- * @method
543
- * @name alp#fetchTrades
544
- * @description get the list of most recent trades for a particular symbol
545
- * @see https://alpcomdev.github.io/alp-api-docs/#list-all-exchanges
546
- * @param {string} symbol unified symbol of the market to fetch trades for
547
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
548
- * @param {int} [limit] the maximum amount of trades to fetch
549
- * @param {object} [params] extra parameters specific to the exchange API endpoint
550
- * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
551
- */
552
- async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
553
- await this.loadMarkets();
554
- let market = undefined;
555
- const request = {};
556
- if (symbol !== undefined) {
557
- market = this.market(symbol);
558
- request['pair'] = market['id'];
559
- }
560
- if (limit !== undefined) {
561
- request['limit'] = limit;
562
- }
563
- const trades = await this.publicGetExchanges(this.extend(request, params));
564
- return this.parseTrades(trades, market, since, limit);
565
- }
566
- /**
567
- * @method
568
- * @name alp#fetchDeposits
569
- * @description fetch all deposits made to an account
570
- * @see https://alpcomdev.github.io/alp-api-docs/#list-own-deposits
571
- * @param {string} code unified currency code
572
- * @param {int} [since] the earliest time in ms to fetch deposits for
573
- * @param {int} [limit] the maximum number of deposits structures to retrieve
574
- * @param {object} [params] extra parameters specific to the exchange API endpoint
575
- * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
576
- */
577
- async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
578
- await this.loadMarkets();
579
- let currency = undefined;
580
- if (code !== undefined) {
581
- currency = this.currency(code);
582
- }
583
- const response = await this.privateGetDeposits(params);
584
- //
585
- // [
586
- // {
587
- // "timestamp": 1485363039.18359,
588
- // "id": 317,
589
- // "currency": "BTC",
590
- // "amount": 530.00000000
591
- // }
592
- // ]
593
- //
594
- return this.parseTransactions(response, currency, since, limit, { 'type': 'deposit' });
595
- }
596
- /**
597
- * @method
598
- * @name alp#fetchWithdrawals
599
- * @description fetch all withdrawals made from an account
600
- * @see https://alpcomdev.github.io/alp-api-docs/#list-own-made-withdraws
601
- * @param {string} code unified currency code
602
- * @param {int} [since] the earliest time in ms to fetch withdrawals for
603
- * @param {int} [limit] the maximum number of withdrawals structures to retrieve
604
- * @param {object} [params] extra parameters specific to the exchange API endpoint
605
- * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
606
- */
607
- async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
608
- await this.loadMarkets();
609
- let currency = undefined;
610
- const request = {};
611
- if (code !== undefined) {
612
- currency = this.currency(code);
613
- request['currency_id'] = currency['id'];
614
- }
615
- const response = await this.privateGetWithdraws(this.extend(request, params));
616
- //
617
- // [
618
- // {
619
- // "id": 403,
620
- // "timestamp": 1485363466.868539,
621
- // "currency": "BTC",
622
- // "amount": 0.53000000,
623
- // "status": 20
624
- // }
625
- // ]
626
- //
627
- return this.parseTransactions(response, currency, since, limit, { 'type': 'withdrawal' });
628
- }
629
- parseTransaction(transaction, currency = undefined) {
630
- //
631
- // deposit
632
- // {
633
- // "timestamp": 1485363039.18359,
634
- // "id": 317,
635
- // "currency": "BTC",
636
- // "amount": 530.00000000
637
- // }
638
- //
639
- // withdrawal
640
- // {
641
- // "id": 403,
642
- // "timestamp": 1485363466.868539,
643
- // "currency": "BTC",
644
- // "amount": 0.53000000,
645
- // "status": 20
646
- // }
647
- //
648
- const timestamp = this.safeTimestamp(transaction, 'timestamp');
649
- const currencyId = this.safeString(transaction, 'currency');
650
- const statusId = this.safeString(transaction, 'status');
651
- return {
652
- 'id': this.safeString(transaction, 'id'),
653
- 'info': transaction,
654
- 'timestamp': timestamp,
655
- 'datetime': this.iso8601(timestamp),
656
- 'network': undefined,
657
- 'address': undefined,
658
- 'addressTo': undefined,
659
- 'addressFrom': undefined,
660
- 'tag': undefined,
661
- 'tagTo': undefined,
662
- 'tagFrom': undefined,
663
- 'currency': this.safeCurrencyCode(currencyId, currency),
664
- 'amount': this.safeNumber(transaction, 'amount'),
665
- 'txid': undefined,
666
- 'type': undefined,
667
- 'status': this.parseTransactionStatus(statusId),
668
- 'comment': undefined,
669
- 'internal': undefined,
670
- 'fee': undefined,
671
- 'updated': undefined,
672
- };
673
- }
674
- parseTransactionStatus(status) {
675
- const statuses = {
676
- '10': 'pending',
677
- '20': 'pending',
678
- '30': 'ok',
679
- '40': 'failed',
680
- '50': 'canceled', // Cancelled by user
681
- };
682
- return this.safeString(statuses, status, status);
683
- }
684
- parseOHLCV(ohlcv, market = undefined) {
685
- //
686
- // {
687
- // "time":1591296000,
688
- // "open":0.024746,
689
- // "close":0.024728,
690
- // "low":0.024728,
691
- // "high":0.024753,
692
- // "volume":16.624
693
- // }
694
- //
695
- return [
696
- this.safeTimestamp(ohlcv, 'time'),
697
- this.safeNumber(ohlcv, 'open'),
698
- this.safeNumber(ohlcv, 'high'),
699
- this.safeNumber(ohlcv, 'low'),
700
- this.safeNumber(ohlcv, 'close'),
701
- this.safeNumber(ohlcv, 'volume'),
702
- ];
703
- }
704
- /**
705
- * @method
706
- * @name alp#fetchOHLCV
707
- * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
708
- * @see https://alpcomdev.github.io/alp-api-docs/#charts
709
- * @param {string} symbol unified symbol of the market to fetch OHLCV data for
710
- * @param {string} timeframe the length of time each candle represents
711
- * @param {int} [since] timestamp in ms of the earliest candle to fetch
712
- * @param {int} [limit] the maximum amount of candles to fetch
713
- * @param {object} [params] extra parameters specific to the exchange API endpoint
714
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
715
- */
716
- async fetchOHLCV(symbol, timeframe = '5m', since = undefined, limit = undefined, params = {}) {
717
- await this.loadMarkets();
718
- const market = this.market(symbol);
719
- const request = {
720
- 'pair': market['id'],
721
- 'type': this.safeString(this.timeframes, timeframe, timeframe),
722
- };
723
- if (limit !== undefined) {
724
- request['limit'] = limit;
725
- }
726
- if (since !== undefined) {
727
- request['since'] = this.parseToInt(since / 1000);
728
- }
729
- const response = await this.publicGetChartsPairTypeChart(this.extend(request, params));
730
- //
731
- // [
732
- // {"time":1591296000,"open":0.024746,"close":0.024728,"low":0.024728,"high":0.024753,"volume":16.624},
733
- // {"time":1591295700,"open":0.024718,"close":0.02475,"low":0.024711,"high":0.02475,"volume":31.645},
734
- // {"time":1591295400,"open":0.024721,"close":0.024717,"low":0.024711,"high":0.02473,"volume":65.071}
735
- // ]
736
- //
737
- return this.parseOHLCVs(response, market, timeframe, since, limit);
738
- }
739
- parseBalance(response) {
740
- const result = { 'info': response };
741
- for (let i = 0; i < response.length; i++) {
742
- const balance = response[i];
743
- const currencyId = this.safeString(balance, 'currency');
744
- const code = this.safeCurrencyCode(currencyId);
745
- const account = this.account();
746
- account['used'] = this.safeString(balance, 'reserve');
747
- account['total'] = this.safeString(balance, 'balance');
748
- result[code] = account;
749
- }
750
- return this.safeBalance(result);
751
- }
752
- /**
753
- * @method
754
- * @name alp#fetchBalance
755
- * @description query for balance and get the amount of funds available for trading or funds locked in orders
756
- * @see https://alpcomdev.github.io/alp-api-docs/#list-own-wallets
757
- * @param {object} [params] extra parameters specific to the exchange API endpoint
758
- * @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
759
- */
760
- async fetchBalance(params = {}) {
761
- await this.loadMarkets();
762
- const response = await this.privateGetWallets(params);
763
- return this.parseBalance(response);
764
- }
765
- parseOrderStatus(status) {
766
- const statuses = {
767
- '1': 'open',
768
- '2': 'canceled',
769
- '3': 'closed',
770
- };
771
- return this.safeString(statuses, status, status);
772
- }
773
- parseOrder(order, market = undefined) {
774
- //
775
- // fetchClosedOrders / fetchOrder
776
- // {
777
- // "id": "923763073",
778
- // "date": "1635451090368",
779
- // "type": "sell",
780
- // "pair": "XRP_USDT",
781
- // "price": "1.00000000",
782
- // "amount": "0.00000000",
783
- // "status": "3",
784
- // "amount_filled": "10.00000000",
785
- // "amount_original": "10.0"
786
- // "trades": [],
787
- // }
788
- //
789
- // createOrder
790
- // {
791
- // "success": true,
792
- // "date": "1635451754.497541",
793
- // "type": "sell",
794
- // "oid": "923776755",
795
- // "price": "1.0",
796
- // "amount": "10.0",
797
- // "amount_filled": "0.0",
798
- // "amount_original": "10.0",
799
- // "trades": []
800
- // }
801
- //
802
- const marketId = this.safeString(order, 'pair');
803
- market = this.safeMarket(marketId, market, '_');
804
- const symbol = market['symbol'];
805
- const success = this.safeBool(order, 'success', false);
806
- let timestamp = undefined;
807
- if (success) {
808
- timestamp = this.safeTimestamp(order, 'date');
809
- }
810
- else {
811
- timestamp = this.safeInteger(order, 'date');
812
- }
813
- const price = this.safeString(order, 'price');
814
- const remaining = this.safeString(order, 'amount');
815
- const filled = this.safeString(order, 'amount_filled');
816
- const amount = this.safeString(order, 'amount_original');
817
- const status = this.parseOrderStatus(this.safeString(order, 'status'));
818
- const id = this.safeStringN(order, ['oid', 'id', 'order']);
819
- const trades = this.safeValue(order, 'trades');
820
- const side = this.safeString2(order, 'my_side', 'type');
821
- return this.safeOrder({
822
- 'id': id,
823
- 'clientOrderId': undefined,
824
- 'datetime': this.iso8601(timestamp),
825
- 'timestamp': timestamp,
826
- 'status': status,
827
- 'symbol': symbol,
828
- 'type': 'limit',
829
- 'timeInForce': undefined,
830
- 'postOnly': undefined,
831
- 'side': side,
832
- 'price': price,
833
- 'triggerPrice': undefined,
834
- 'cost': undefined,
835
- 'amount': amount,
836
- 'filled': filled,
837
- 'remaining': remaining,
838
- 'trades': trades,
839
- 'fee': undefined,
840
- 'info': order,
841
- 'lastTradeTimestamp': undefined,
842
- 'average': undefined,
843
- }, market);
844
- }
845
- /**
846
- * @method
847
- * @name alp#createOrder
848
- * @see https://alpcomdev.github.io/alp-api-docs/#create-order
849
- * @description create a trade order
850
- * @param {string} symbol unified symbol of the market to create an order in
851
- * @param {string} type 'limit'
852
- * @param {string} side 'buy' or 'sell'
853
- * @param {float} amount how much of currency you want to trade in units of base currency
854
- * @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
855
- * @param {object} [params] extra parameters specific to the exchange API endpoint
856
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
857
- */
858
- async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
859
- if (type === 'market') {
860
- throw new InvalidOrder(this.id + ' only limits orders are supported');
861
- }
862
- await this.loadMarkets();
863
- const market = this.market(symbol);
864
- const request = {
865
- 'pair': market['id'],
866
- 'type': side,
867
- 'amount': amount,
868
- 'price': this.priceToPrecision(symbol, price),
869
- };
870
- const response = await this.privatePostOrder(this.extend(request, params));
871
- if (!response['success']) {
872
- throw new InvalidOrder(this.id + ' ' + this.json(response));
873
- }
874
- const order = this.parseOrder(response, market);
875
- const orderAmount = order['amount'].toString();
876
- amount = Precise.stringGt(orderAmount, '0') ? order['amount'] : amount;
877
- order['amount'] = this.parseNumber(amount);
878
- return order;
879
- }
880
- /**
881
- * @method
882
- * @name alp#cancelOrder
883
- * @see https://alpcomdev.github.io/alp-api-docs/#cancel-order
884
- * @description cancels an open order
885
- * @param {string} id order id
886
- * @param {string} symbol unified symbol of the market the order was made in
887
- * @param {object} [params] extra parameters specific to the exchange API endpoint
888
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
889
- */
890
- async cancelOrder(id, symbol = undefined, params = {}) {
891
- const request = {
892
- 'order': id,
893
- };
894
- const response = await this.privatePostOrderCancel(this.extend(request, params));
895
- //
896
- // {
897
- // "order": 63568
898
- // }
899
- //
900
- return this.parseOrder(response);
901
- }
902
- /**
903
- * @method
904
- * @name alp#fetchOrder
905
- * @see https://alpcomdev.github.io/alp-api-docs/#retrieve-single-order
906
- * @description fetches information on an order made by the user
907
- * @param {string} id the order id
908
- * @param {string} symbol not used by alp fetchOrder
909
- * @param {object} [params] extra parameters specific to the exchange API endpoint
910
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
911
- */
912
- async fetchOrder(id, symbol = undefined, params = {}) {
913
- await this.loadMarkets();
914
- const request = {
915
- 'id': id,
916
- };
917
- const order = await this.privateGetOrderId(this.extend(request, params));
918
- return this.parseOrder(order);
919
- }
920
- /**
921
- * @method
922
- * @name alp#fetchOrders
923
- * @see https://alpcomdev.github.io/alp-api-docs/#list-own-orders
924
- * @description fetches information on multiple orders made by the user
925
- * @param {string} symbol unified market symbol of the market orders were made in
926
- * @param {int} [since] the earliest time in ms to fetch orders for
927
- * @param {int} [limit] the maximum number of order structures to retrieve
928
- * @param {object} [params] extra parameters specific to the exchange API endpoint
929
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
930
- */
931
- async fetchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
932
- await this.loadMarkets();
933
- const request = {};
934
- let market = undefined;
935
- if (symbol !== undefined) {
936
- market = this.market(symbol);
937
- request['pair'] = market['id'];
938
- }
939
- if (limit !== undefined) {
940
- request['limit'] = limit;
941
- }
942
- const orders = await this.privateGetOrdersOwn(this.extend(request, params));
943
- return this.parseOrders(orders, market, since, limit);
944
- }
945
- /**
946
- * @method
947
- * @name alp#fetchOpenOrders
948
- * @description fetch all unfilled currently open orders
949
- * @see https://alpcomdev.github.io/alp-api-docs/#list-own-orders
950
- * @param {string} symbol unified market symbol
951
- * @param {int} [since] the earliest time in ms to fetch open orders for
952
- * @param {int} [limit] the maximum number of open orders structures to retrieve
953
- * @param {object} [params] extra parameters specific to the exchange API endpoint
954
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
955
- */
956
- async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
957
- const request = {
958
- 'status': '1',
959
- };
960
- return await this.fetchOrders(symbol, since, limit, this.extend(request, params));
961
- }
962
- /**
963
- * @method
964
- * @name alp#fetchClosedOrders
965
- * @description fetches information on multiple closed orders made by the user
966
- * @see https://alpcomdev.github.io/alp-api-docs/#list-own-orders
967
- * @param {string} symbol unified market symbol of the market orders were made in
968
- * @param {int} [since] the earliest time in ms to fetch orders for
969
- * @param {int} [limit] the maximum number of order structures to retrieve
970
- * @param {object} [params] extra parameters specific to the exchange API endpoint
971
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
972
- */
973
- async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
974
- const request = {
975
- 'status': '3',
976
- };
977
- return await this.fetchOrders(symbol, since, limit, this.extend(request, params));
978
- }
979
- /**
980
- * @method
981
- * @name alp#fetchMyTrades
982
- * @description fetch all trades made by the user
983
- * @see https://alpcomdev.github.io/alp-api-docs/#list-own-exchanges
984
- * @param {string} symbol unified market symbol
985
- * @param {int} [since] the earliest time in ms to fetch trades for
986
- * @param {int} [limit] the maximum number of trades structures to retrieve
987
- * @param {object} [params] extra parameters specific to the exchange API endpoint
988
- * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
989
- */
990
- async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
991
- await this.loadMarkets();
992
- const request = {};
993
- if (symbol !== undefined) {
994
- const market = this.market(symbol);
995
- request['pair'] = market['id'];
996
- }
997
- if (limit !== undefined) {
998
- request['limit'] = limit;
999
- }
1000
- const trades = await this.privateGetExchangesOwn(this.extend(request, params));
1001
- return this.parseTrades(trades, undefined, since, limit);
1002
- }
1003
- nonce() {
1004
- return this.milliseconds();
1005
- }
1006
- sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
1007
- const query = this.urlencode(this.keysort(this.omit(params, this.extractParams(path))));
1008
- let url = this.urls['api']['rest'] + '/';
1009
- if (path !== 'charts/{pair}/{type}/chart/') {
1010
- url += 'v1/';
1011
- }
1012
- url += this.implodeParams(path, params);
1013
- headers = { 'Accept': 'application/json' };
1014
- if (api === 'public') {
1015
- if (query.length) {
1016
- url += '?' + query;
1017
- }
1018
- }
1019
- else {
1020
- this.checkRequiredCredentials();
1021
- let payload = this.apiKey;
1022
- if (method === 'POST') {
1023
- headers['Content-Type'] = 'application/x-www-form-urlencoded';
1024
- body = query;
1025
- payload += body;
1026
- }
1027
- else if (query.length) {
1028
- url += '?' + query;
1029
- }
1030
- headers['X-KEY'] = this.apiKey;
1031
- headers['X-SIGN'] = this.hmac(this.encode(payload), this.encode(this.secret), sha256);
1032
- headers['X-NONCE'] = this.nonce().toString();
1033
- }
1034
- return { 'url': url, 'method': method, 'body': body, 'headers': headers };
1035
- }
1036
- handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
1037
- if (response === undefined) {
1038
- return undefined; // fallback to default error handler
1039
- }
1040
- //
1041
- // {"date":1570599531.4814300537,"error":"Out of balance -9.99243661 BTC"}
1042
- //
1043
- const error = this.safeString(response, 'error');
1044
- if (error !== undefined) {
1045
- const feedback = this.id + ' ' + body;
1046
- this.throwExactlyMatchedException(this.exceptions['exact'], error, feedback);
1047
- this.throwBroadlyMatchedException(this.exceptions['broad'], error, feedback);
1048
- throw new ExchangeError(feedback); // unknown error
1049
- }
1050
- return undefined;
1051
- }
1052
- }