ccxt 4.2.51 → 4.2.52

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.
@@ -1,884 +0,0 @@
1
- 'use strict';
2
-
3
- var bitforex$1 = require('./abstract/bitforex.js');
4
- var errors = require('./base/errors.js');
5
- var number = require('./base/functions/number.js');
6
- var sha256 = require('./static_dependencies/noble-hashes/sha256.js');
7
-
8
- // ---------------------------------------------------------------------------
9
- // ---------------------------------------------------------------------------
10
- /**
11
- * @class bitforex
12
- * @augments Exchange
13
- */
14
- class bitforex extends bitforex$1 {
15
- describe() {
16
- return this.deepExtend(super.describe(), {
17
- 'id': 'bitforex',
18
- 'name': 'Bitforex',
19
- 'countries': ['CN'],
20
- 'rateLimit': 500,
21
- 'version': 'v1',
22
- 'has': {
23
- 'CORS': undefined,
24
- 'spot': true,
25
- 'margin': false,
26
- 'swap': false,
27
- 'future': false,
28
- 'option': false,
29
- 'addMargin': false,
30
- 'cancelAllOrders': true,
31
- 'cancelOrder': true,
32
- 'createOrder': true,
33
- 'createReduceOnlyOrder': false,
34
- 'createStopLimitOrder': false,
35
- 'createStopMarketOrder': false,
36
- 'createStopOrder': false,
37
- 'fetchBalance': true,
38
- 'fetchBorrowInterest': false,
39
- 'fetchBorrowRateHistories': false,
40
- 'fetchBorrowRateHistory': false,
41
- 'fetchClosedOrders': true,
42
- 'fetchCrossBorrowRate': false,
43
- 'fetchCrossBorrowRates': false,
44
- 'fetchDepositAddress': false,
45
- 'fetchDepositAddresses': false,
46
- 'fetchDepositAddressesByNetwork': false,
47
- 'fetchFundingHistory': false,
48
- 'fetchFundingRate': false,
49
- 'fetchFundingRateHistory': false,
50
- 'fetchFundingRates': false,
51
- 'fetchIndexOHLCV': false,
52
- 'fetchIsolatedBorrowRate': false,
53
- 'fetchIsolatedBorrowRates': false,
54
- 'fetchIsolatedPositions': false,
55
- 'fetchLeverage': false,
56
- 'fetchLeverageTiers': false,
57
- 'fetchMarginMode': false,
58
- 'fetchMarketLeverageTiers': false,
59
- 'fetchMarkets': true,
60
- 'fetchMarkOHLCV': false,
61
- 'fetchMyTrades': true,
62
- 'fetchOHLCV': true,
63
- 'fetchOpenInterestHistory': false,
64
- 'fetchOpenOrders': true,
65
- 'fetchOrder': true,
66
- 'fetchOrderBook': true,
67
- 'fetchPosition': false,
68
- 'fetchPositionMode': false,
69
- 'fetchPositions': false,
70
- 'fetchPositionsRisk': false,
71
- 'fetchPremiumIndexOHLCV': false,
72
- 'fetchTicker': true,
73
- 'fetchTickers': false,
74
- 'fetchTrades': true,
75
- 'fetchTransactionFees': false,
76
- 'fetchTransfer': false,
77
- 'fetchTransfers': false,
78
- 'fetchWithdrawal': false,
79
- 'fetchWithdrawals': false,
80
- 'reduceMargin': false,
81
- 'repayCrossMargin': false,
82
- 'repayIsolatedMargin': false,
83
- 'setLeverage': false,
84
- 'setMargin': false,
85
- 'setMarginMode': false,
86
- 'setPositionMode': false,
87
- 'transfer': false,
88
- 'withdraw': false,
89
- },
90
- 'timeframes': {
91
- '1m': '1min',
92
- '5m': '5min',
93
- '15m': '15min',
94
- '30m': '30min',
95
- '1h': '1hour',
96
- '2h': '2hour',
97
- '4h': '4hour',
98
- '12h': '12hour',
99
- '1d': '1day',
100
- '1w': '1week',
101
- '1M': '1month',
102
- },
103
- 'urls': {
104
- 'logo': 'https://user-images.githubusercontent.com/51840849/87295553-1160ec00-c50e-11ea-8ea0-df79276a9646.jpg',
105
- 'api': {
106
- 'rest': 'https://api.bitforex.com',
107
- },
108
- 'www': 'https://www.bitforex.com',
109
- 'doc': 'https://github.com/githubdev2020/API_Doc_en/wiki',
110
- 'fees': 'https://help.bitforex.com/en_us/?cat=13',
111
- 'referral': 'https://www.bitforex.com/en/invitationRegister?inviterId=1867438',
112
- },
113
- 'api': {
114
- 'public': {
115
- 'get': {
116
- '/api/v1/ping': 0.2,
117
- '/api/v1/time': 0.2,
118
- 'api/v1/market/symbols': 20,
119
- 'api/v1/market/ticker': 4,
120
- 'api/v1/market/ticker-all': 4,
121
- 'api/v1/market/depth': 4,
122
- 'api/v1/market/depth-all': 4,
123
- 'api/v1/market/trades': 20,
124
- 'api/v1/market/kline': 20,
125
- },
126
- },
127
- 'private': {
128
- 'post': {
129
- 'api/v1/fund/mainAccount': 1,
130
- 'api/v1/fund/allAccount': 30,
131
- 'api/v1/trade/placeOrder': 1,
132
- 'api/v1/trade/placeMultiOrder': 10,
133
- 'api/v1/trade/cancelOrder': 1,
134
- 'api/v1/trade/cancelMultiOrder': 6.67,
135
- 'api/v1/trade/cancelAllOrder': 20,
136
- 'api/v1/trade/orderInfo': 1,
137
- 'api/v1/trade/multiOrderInfo': 10,
138
- 'api/v1/trade/orderInfos': 20,
139
- 'api/v1/trade/myTrades': 2,
140
- },
141
- },
142
- },
143
- 'fees': {
144
- 'trading': {
145
- 'tierBased': false,
146
- 'percentage': true,
147
- 'maker': this.parseNumber('0.001'),
148
- 'taker': this.parseNumber('0.001'),
149
- },
150
- 'funding': {
151
- 'tierBased': false,
152
- 'percentage': true,
153
- 'deposit': {},
154
- 'withdraw': {},
155
- },
156
- },
157
- 'commonCurrencies': {
158
- 'BKC': 'Bank Coin',
159
- 'CAPP': 'Crypto Application Token',
160
- 'CREDIT': 'TerraCredit',
161
- 'CTC': 'Culture Ticket Chain',
162
- 'EWT': 'EcoWatt Token',
163
- 'IQ': 'IQ.Cash',
164
- 'MIR': 'MIR COIN',
165
- 'NOIA': 'METANOIA',
166
- 'TON': 'To The Moon',
167
- },
168
- 'precisionMode': number.TICK_SIZE,
169
- 'exceptions': {
170
- '1000': errors.OrderNotFound,
171
- '1003': errors.BadSymbol,
172
- '1013': errors.AuthenticationError,
173
- '1016': errors.AuthenticationError,
174
- '1017': errors.PermissionDenied,
175
- '1019': errors.BadSymbol,
176
- '3002': errors.InsufficientFunds,
177
- '4002': errors.InvalidOrder,
178
- '4003': errors.InvalidOrder,
179
- '4004': errors.OrderNotFound,
180
- '10204': errors.DDoSProtection,
181
- },
182
- });
183
- }
184
- async fetchMarkets(params = {}) {
185
- /**
186
- * @method
187
- * @name bitforex#fetchMarkets
188
- * @description retrieves data on all markets for bitforex
189
- * @see https://apidoc.bitforex.com/#exchange-information
190
- * @param {object} [params] extra parameters specific to the exchange API endpoint
191
- * @returns {object[]} an array of objects representing market data
192
- */
193
- const response = await this.publicGetApiV1MarketSymbols(params);
194
- //
195
- // {
196
- // "data": [
197
- // {
198
- // "amountPrecision":4,
199
- // "minOrderAmount":3.0E-4,
200
- // "pricePrecision":2,
201
- // "symbol":"coin-usdt-btc"
202
- // },
203
- // ...
204
- // ]
205
- // }
206
- //
207
- const data = response['data'];
208
- const result = [];
209
- for (let i = 0; i < data.length; i++) {
210
- const market = data[i];
211
- const id = this.safeString(market, 'symbol');
212
- const symbolParts = id.split('-');
213
- const baseId = symbolParts[2];
214
- const quoteId = symbolParts[1];
215
- const base = this.safeCurrencyCode(baseId);
216
- const quote = this.safeCurrencyCode(quoteId);
217
- result.push({
218
- 'id': id,
219
- 'symbol': base + '/' + quote,
220
- 'base': base,
221
- 'quote': quote,
222
- 'settle': undefined,
223
- 'baseId': baseId,
224
- 'quoteId': quoteId,
225
- 'settleId': undefined,
226
- 'type': 'spot',
227
- 'spot': true,
228
- 'margin': false,
229
- 'swap': false,
230
- 'future': false,
231
- 'option': false,
232
- 'active': true,
233
- 'contract': false,
234
- 'linear': undefined,
235
- 'inverse': undefined,
236
- 'contractSize': undefined,
237
- 'expiry': undefined,
238
- 'expiryDateTime': undefined,
239
- 'strike': undefined,
240
- 'optionType': undefined,
241
- 'precision': {
242
- 'amount': this.parseNumber(this.parsePrecision(this.safeString(market, 'amountPrecision'))),
243
- 'price': this.parseNumber(this.parsePrecision(this.safeString(market, 'pricePrecision'))),
244
- },
245
- 'limits': {
246
- 'leverage': {
247
- 'min': undefined,
248
- 'max': undefined,
249
- },
250
- 'amount': {
251
- 'min': this.safeNumber(market, 'minOrderAmount'),
252
- 'max': undefined,
253
- },
254
- 'price': {
255
- 'min': undefined,
256
- 'max': undefined,
257
- },
258
- 'cost': {
259
- 'min': undefined,
260
- 'max': undefined,
261
- },
262
- },
263
- 'created': undefined,
264
- 'info': market,
265
- });
266
- }
267
- return result;
268
- }
269
- parseTrade(trade, market = undefined) {
270
- //
271
- // fetchTrades (public) v1
272
- //
273
- // {
274
- // "price":57594.53,
275
- // "amount":0.3172,
276
- // "time":1637329685322,
277
- // "direction":1,
278
- // "tid":"1131019666"
279
- // }
280
- //
281
- // fetchMyTrades (private)
282
- //
283
- // {
284
- // "symbol": "coin-usdt-babydoge",
285
- // "tid": 7289,
286
- // "orderId": "b6fe2b61-e5cb-4970-9bdc-8c7cd1fcb4d8",
287
- // "price": "0.000007",
288
- // "amount": "50000000",
289
- // "tradeFee": "50000",
290
- // "tradeFeeCurrency": "babydoge",
291
- // "time": "1684750536460",
292
- // "isBuyer": true,
293
- // "isMaker": true,
294
- // "isSelfTrade": true
295
- // }
296
- //
297
- const marketId = this.safeString(trade, 'symbol');
298
- market = this.safeMarket(marketId, market);
299
- const timestamp = this.safeInteger(trade, 'time');
300
- const id = this.safeString(trade, 'tid');
301
- const orderId = this.safeString(trade, 'orderId');
302
- const priceString = this.safeString(trade, 'price');
303
- const amountString = this.safeString(trade, 'amount');
304
- const sideId = this.safeInteger(trade, 'direction');
305
- let side = this.parseSide(sideId);
306
- if (side === undefined) {
307
- const isBuyer = this.safeValue(trade, 'isBuyer');
308
- side = isBuyer ? 'buy' : 'sell';
309
- }
310
- let takerOrMaker = undefined;
311
- const isMaker = this.safeValue(trade, 'isMaker');
312
- if (isMaker !== undefined) {
313
- takerOrMaker = (isMaker) ? 'maker' : 'taker';
314
- }
315
- let fee = undefined;
316
- const feeCostString = this.safeString(trade, 'tradeFee');
317
- if (feeCostString !== undefined) {
318
- const feeCurrencyId = this.safeString(trade, 'tradeFeeCurrency');
319
- const feeCurrencyCode = this.safeCurrencyCode(feeCurrencyId);
320
- fee = {
321
- 'cost': feeCostString,
322
- 'currency': feeCurrencyCode,
323
- };
324
- }
325
- return this.safeTrade({
326
- 'info': trade,
327
- 'id': id,
328
- 'timestamp': timestamp,
329
- 'datetime': this.iso8601(timestamp),
330
- 'symbol': market['symbol'],
331
- 'type': undefined,
332
- 'side': side,
333
- 'price': priceString,
334
- 'amount': amountString,
335
- 'cost': undefined,
336
- 'order': orderId,
337
- 'fee': fee,
338
- 'takerOrMaker': takerOrMaker,
339
- }, market);
340
- }
341
- async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
342
- /**
343
- * @method
344
- * @name bitforex#fetchTrades
345
- * @description get the list of most recent trades for a particular symbol
346
- * @see https://apidoc.bitforex.com/#recent-trades-list
347
- * @param {string} symbol unified symbol of the market to fetch trades for
348
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
349
- * @param {int} [limit] the maximum amount of trades to fetch
350
- * @param {object} [params] extra parameters specific to the exchange API endpoint
351
- * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
352
- */
353
- await this.loadMarkets();
354
- const request = {
355
- 'symbol': this.marketId(symbol),
356
- };
357
- if (limit !== undefined) {
358
- request['size'] = limit;
359
- }
360
- const market = this.market(symbol);
361
- const response = await this.publicGetApiV1MarketTrades(this.extend(request, params));
362
- //
363
- // {
364
- // "data":
365
- // [
366
- // {
367
- // "price":57594.53,
368
- // "amount":0.3172,
369
- // "time":1637329685322,
370
- // "direction":1,
371
- // "tid":"1131019666"
372
- // }
373
- // ],
374
- // "success": true,
375
- // "time": 1637329688475
376
- // }
377
- //
378
- return this.parseTrades(response['data'], market, since, limit);
379
- }
380
- async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
381
- /**
382
- * @method
383
- * @name bitforex#fetchMyTrades
384
- * @description fetch all trades made by the user
385
- * @see https://apidoc.bitforex.com/#spot-account-trade
386
- * @param {string} symbol unified market symbol
387
- * @param {int} [since] the earliest time in ms to fetch trades for
388
- * @param {int} [limit] the maximum number of trades structures to retrieve
389
- * @param {object} [params] extra parameters specific to the exchange API endpoint
390
- * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
391
- */
392
- if (symbol === undefined) {
393
- throw new errors.ArgumentsRequired(this.id + ' fetchMyTrades() requires a symbol argument');
394
- }
395
- await this.loadMarkets();
396
- const request = {
397
- // 'symbol': market['id'],
398
- // 'orderId': orderId,
399
- // 'startTime': timestamp,
400
- // 'endTime': timestamp,
401
- // 'limit': limit, // default 500, max 1000
402
- };
403
- const market = this.market(symbol);
404
- request['symbol'] = market['id'];
405
- if (limit !== undefined) {
406
- request['limit'] = limit;
407
- }
408
- if (since !== undefined) {
409
- request['startTime'] = Math.max(since - 1, 0);
410
- }
411
- const endTime = this.safeInteger2(params, 'until', 'endTime');
412
- if (endTime !== undefined) {
413
- request['endTime'] = endTime;
414
- }
415
- params = this.omit(params, ['until']);
416
- const response = await this.privatePostApiV1TradeMyTrades(this.extend(request, params));
417
- //
418
- // {
419
- // "data": [
420
- // {
421
- // "symbol": "coin-usdt-babydoge",
422
- // "tid": 7289,
423
- // "orderId": "a262d030-11a5-40fd-a07c-7ba84aa68752",
424
- // "price": "0.000007",
425
- // "amount": "50000000",
426
- // "tradeFee": "0.35",
427
- // "tradeFeeCurrency": "usdt",
428
- // "time": "1684750536460",
429
- // "isBuyer": false,
430
- // "isMaker": false,
431
- // "isSelfTrade": true
432
- // }
433
- // ],
434
- // "success": true,
435
- // "time": 1685009320042
436
- // }
437
- //
438
- const data = this.safeValue(response, 'data', []);
439
- return this.parseTrades(data, market, since, limit);
440
- }
441
- parseBalance(response) {
442
- const data = response['data'];
443
- const result = { 'info': response };
444
- for (let i = 0; i < data.length; i++) {
445
- const balance = data[i];
446
- const currencyId = this.safeString(balance, 'currency');
447
- const code = this.safeCurrencyCode(currencyId);
448
- const account = this.account();
449
- account['used'] = this.safeString(balance, 'frozen');
450
- account['free'] = this.safeString(balance, 'active');
451
- account['total'] = this.safeString(balance, 'fix');
452
- result[code] = account;
453
- }
454
- return this.safeBalance(result);
455
- }
456
- async fetchBalance(params = {}) {
457
- /**
458
- * @method
459
- * @name bitforex#fetchBalance
460
- * @description query for balance and get the amount of funds available for trading or funds locked in orders
461
- * @see https://apidoc.bitforex.com/#user-all-asset-information-user_data
462
- * @param {object} [params] extra parameters specific to the exchange API endpoint
463
- * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
464
- */
465
- await this.loadMarkets();
466
- const response = await this.privatePostApiV1FundAllAccount(params);
467
- return this.parseBalance(response);
468
- }
469
- parseTicker(ticker, market = undefined) {
470
- //
471
- // {
472
- // "buy":7.04E-7,
473
- // "date":1643371198598,
474
- // "high":7.48E-7,
475
- // "last":7.28E-7,
476
- // "low":7.10E-7,
477
- // "sell":7.54E-7,
478
- // "vol":9877287.2874
479
- // }
480
- //
481
- const symbol = this.safeSymbol(undefined, market);
482
- const timestamp = this.safeInteger(ticker, 'date');
483
- return this.safeTicker({
484
- 'symbol': symbol,
485
- 'timestamp': timestamp,
486
- 'datetime': this.iso8601(timestamp),
487
- 'high': this.safeString(ticker, 'high'),
488
- 'low': this.safeString(ticker, 'low'),
489
- 'bid': this.safeString(ticker, 'buy'),
490
- 'bidVolume': undefined,
491
- 'ask': this.safeString(ticker, 'sell'),
492
- 'askVolume': undefined,
493
- 'vwap': undefined,
494
- 'open': undefined,
495
- 'close': this.safeString(ticker, 'last'),
496
- 'last': this.safeString(ticker, 'last'),
497
- 'previousClose': undefined,
498
- 'change': undefined,
499
- 'percentage': undefined,
500
- 'average': undefined,
501
- 'baseVolume': this.safeString(ticker, 'vol'),
502
- 'quoteVolume': undefined,
503
- 'info': ticker,
504
- }, market);
505
- }
506
- async fetchTicker(symbol, params = {}) {
507
- /**
508
- * @method
509
- * @name bitforex#fetchTicker
510
- * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
511
- * @see https://apidoc.bitforex.com/#exchange-information
512
- * @param {string} symbol unified symbol of the market to fetch the ticker for
513
- * @param {object} [params] extra parameters specific to the exchange API endpoint
514
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
515
- */
516
- await this.loadMarkets();
517
- const market = this.markets[symbol];
518
- const request = {
519
- 'symbol': market['id'],
520
- };
521
- const response = await this.publicGetApiV1MarketTickerAll(this.extend(request, params));
522
- const ticker = this.safeValue(response, 'data');
523
- //
524
- // {
525
- // "data":{
526
- // "buy":37082.83,
527
- // "date":1643388686660,
528
- // "high":37487.83,
529
- // "last":37086.79,
530
- // "low":35544.44,
531
- // "sell":37090.52,
532
- // "vol":690.9776
533
- // },
534
- // "success":true,
535
- // "time":1643388686660
536
- // }
537
- //
538
- return this.parseTicker(ticker, market);
539
- }
540
- parseOHLCV(ohlcv, market = undefined) {
541
- //
542
- // {
543
- // "close":0.02505143,
544
- // "currencyVol":0,
545
- // "high":0.02506422,
546
- // "low":0.02505143,
547
- // "open":0.02506095,
548
- // "time":1591508940000,
549
- // "vol":51.1869
550
- // }
551
- //
552
- return [
553
- this.safeInteger(ohlcv, 'time'),
554
- this.safeNumber(ohlcv, 'open'),
555
- this.safeNumber(ohlcv, 'high'),
556
- this.safeNumber(ohlcv, 'low'),
557
- this.safeNumber(ohlcv, 'close'),
558
- this.safeNumber(ohlcv, 'vol'),
559
- ];
560
- }
561
- async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
562
- /**
563
- * @method
564
- * @name bitforex#fetchOHLCV
565
- * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
566
- * @see https://apidoc.bitforex.com/#kline
567
- * @param {string} symbol unified symbol of the market to fetch OHLCV data for
568
- * @param {string} timeframe the length of time each candle represents
569
- * @param {int} [since] timestamp in ms of the earliest candle to fetch
570
- * @param {int} [limit] the maximum amount of candles to fetch
571
- * @param {object} [params] extra parameters specific to the exchange API endpoint
572
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
573
- */
574
- await this.loadMarkets();
575
- const market = this.market(symbol);
576
- const request = {
577
- 'symbol': market['id'],
578
- 'ktype': this.safeString(this.timeframes, timeframe, timeframe),
579
- };
580
- if (limit !== undefined) {
581
- request['size'] = limit; // default 1, max 600
582
- }
583
- const response = await this.publicGetApiV1MarketKline(this.extend(request, params));
584
- //
585
- // {
586
- // "data":[
587
- // {"close":0.02505143,"currencyVol":0,"high":0.02506422,"low":0.02505143,"open":0.02506095,"time":1591508940000,"vol":51.1869},
588
- // {"close":0.02503914,"currencyVol":0,"high":0.02506687,"low":0.02503914,"open":0.02505358,"time":1591509000000,"vol":9.1082},
589
- // {"close":0.02505172,"currencyVol":0,"high":0.02507466,"low":0.02503895,"open":0.02506371,"time":1591509060000,"vol":63.7431},
590
- // ],
591
- // "success":true,
592
- // "time":1591509427131
593
- // }
594
- //
595
- const data = this.safeValue(response, 'data', []);
596
- return this.parseOHLCVs(data, market, timeframe, since, limit);
597
- }
598
- async fetchOrderBook(symbol, limit = undefined, params = {}) {
599
- /**
600
- * @method
601
- * @name bitforex#fetchOrderBook
602
- * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
603
- * @see https://apidoc.bitforex.com/#order-book
604
- * @param {string} symbol unified symbol of the market to fetch the order book for
605
- * @param {int} [limit] the maximum amount of order book entries to return
606
- * @param {object} [params] extra parameters specific to the exchange API endpoint
607
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
608
- */
609
- await this.loadMarkets();
610
- const market = this.market(symbol);
611
- const request = {
612
- 'symbol': market['id'],
613
- };
614
- if (limit !== undefined) {
615
- request['size'] = limit;
616
- }
617
- const response = await this.publicGetApiV1MarketDepthAll(this.extend(request, params));
618
- const data = this.safeValue(response, 'data');
619
- const timestamp = this.safeInteger(response, 'time');
620
- return this.parseOrderBook(data, market['symbol'], timestamp, 'bids', 'asks', 'price', 'amount');
621
- }
622
- parseOrderStatus(status) {
623
- const statuses = {
624
- '0': 'open',
625
- '1': 'open',
626
- '2': 'closed',
627
- '3': 'canceled',
628
- '4': 'canceled',
629
- };
630
- return (status in statuses) ? statuses[status] : status;
631
- }
632
- parseSide(sideId) {
633
- if (sideId === 1) {
634
- return 'buy';
635
- }
636
- else if (sideId === 2) {
637
- return 'sell';
638
- }
639
- else {
640
- return undefined;
641
- }
642
- }
643
- parseOrder(order, market = undefined) {
644
- const id = this.safeString(order, 'orderId');
645
- const timestamp = this.safeInteger(order, 'createTime');
646
- const lastTradeTimestamp = this.safeInteger(order, 'lastTime');
647
- const symbol = market['symbol'];
648
- const sideId = this.safeInteger(order, 'tradeType');
649
- const side = this.parseSide(sideId);
650
- const type = undefined;
651
- const price = this.safeString(order, 'orderPrice');
652
- const average = this.safeString(order, 'avgPrice');
653
- const amount = this.safeString(order, 'orderAmount');
654
- const filled = this.safeString(order, 'dealAmount');
655
- const status = this.parseOrderStatus(this.safeString(order, 'orderState'));
656
- const feeSide = (side === 'buy') ? 'base' : 'quote';
657
- const feeCurrency = market[feeSide];
658
- const fee = {
659
- 'cost': this.safeNumber(order, 'tradeFee'),
660
- 'currency': feeCurrency,
661
- };
662
- return this.safeOrder({
663
- 'info': order,
664
- 'id': id,
665
- 'clientOrderId': undefined,
666
- 'timestamp': timestamp,
667
- 'datetime': this.iso8601(timestamp),
668
- 'lastTradeTimestamp': lastTradeTimestamp,
669
- 'symbol': symbol,
670
- 'type': type,
671
- 'timeInForce': undefined,
672
- 'postOnly': undefined,
673
- 'side': side,
674
- 'price': price,
675
- 'stopPrice': undefined,
676
- 'triggerPrice': undefined,
677
- 'cost': undefined,
678
- 'average': average,
679
- 'amount': amount,
680
- 'filled': filled,
681
- 'remaining': undefined,
682
- 'status': status,
683
- 'fee': fee,
684
- 'trades': undefined,
685
- }, market);
686
- }
687
- async cancelAllOrders(symbol = undefined, params = {}) {
688
- /**
689
- * @method
690
- * @name bitforex#cancelAllOrders
691
- * @see https://github.com/githubdev2020/API_Doc_en/wiki/Cancle-all-orders
692
- * @description cancel all open orders in a market
693
- * @param {string} symbol unified market symbol of the market to cancel orders in
694
- * @param {object} [params] extra parameters specific to the exchange API endpoint
695
- * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
696
- */
697
- if (symbol === undefined) {
698
- throw new errors.ArgumentsRequired(this.id + ' cancelAllOrders () requires a symbol argument');
699
- }
700
- await this.loadMarkets();
701
- const market = this.market(symbol);
702
- const request = {
703
- 'symbol': market['id'],
704
- };
705
- const response = await this.privatePostApiV1TradeCancelAllOrder(this.extend(request, params));
706
- //
707
- // {
708
- // 'data': True,
709
- // 'success': True,
710
- // 'time': '1706542995252'
711
- // }
712
- //
713
- return response;
714
- }
715
- async fetchOrder(id, symbol = undefined, params = {}) {
716
- /**
717
- * @method
718
- * @name bitforex#fetchOrder
719
- * @description fetches information on an order made by the user
720
- * @see https://apidoc.bitforex.com/#order-information-user_data
721
- * @param {string} symbol unified symbol of the market the order was made in
722
- * @param {object} [params] extra parameters specific to the exchange API endpoint
723
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
724
- */
725
- await this.loadMarkets();
726
- const market = this.market(symbol);
727
- const request = {
728
- 'symbol': this.marketId(symbol),
729
- 'orderId': id,
730
- };
731
- const response = await this.privatePostApiV1TradeOrderInfo(this.extend(request, params));
732
- const order = this.parseOrder(response['data'], market);
733
- return order;
734
- }
735
- async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
736
- /**
737
- * @method
738
- * @name bitforex#fetchOpenOrders
739
- * @description fetch all unfilled currently open orders
740
- * @param {string} symbol unified market symbol
741
- * @param {int} [since] the earliest time in ms to fetch open orders for
742
- * @param {int} [limit] the maximum number of open order structures to retrieve
743
- * @param {object} [params] extra parameters specific to the exchange API endpoint
744
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
745
- */
746
- if (symbol === undefined) {
747
- throw new errors.ArgumentsRequired(this.id + ' fetchOpenOrders() requires a symbol argument');
748
- }
749
- await this.loadMarkets();
750
- const market = this.market(symbol);
751
- const request = {
752
- 'symbol': market['id'],
753
- 'state': 0,
754
- };
755
- const response = await this.privatePostApiV1TradeOrderInfos(this.extend(request, params));
756
- return this.parseOrders(response['data'], market, since, limit);
757
- }
758
- async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
759
- /**
760
- * @method
761
- * @name bitforex#fetchClosedOrders
762
- * @description fetches information on multiple closed orders made by the user
763
- * @param {string} symbol unified market symbol of the market orders were made in
764
- * @param {int} [since] the earliest time in ms to fetch orders for
765
- * @param {int} [limit] the maximum number of order structures to retrieve
766
- * @param {object} [params] extra parameters specific to the exchange API endpoint
767
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
768
- */
769
- if (symbol === undefined) {
770
- throw new errors.ArgumentsRequired(this.id + ' fetchClosedOrders() requires a symbol argument');
771
- }
772
- await this.loadMarkets();
773
- const market = this.market(symbol);
774
- const request = {
775
- 'symbol': market['id'],
776
- 'state': 1,
777
- };
778
- const response = await this.privatePostApiV1TradeOrderInfos(this.extend(request, params));
779
- return this.parseOrders(response['data'], market, since, limit);
780
- }
781
- async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
782
- /**
783
- * @method
784
- * @name bitforex#createOrder
785
- * @description create a trade order
786
- * @see https://apidoc.bitforex.com/#new-order-trade
787
- * @param {string} symbol unified symbol of the market to create an order in
788
- * @param {string} type 'market' or 'limit'
789
- * @param {string} side 'buy' or 'sell'
790
- * @param {float} amount how much of currency you want to trade in units of base currency
791
- * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
792
- * @param {object} [params] extra parameters specific to the exchange API endpoint
793
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
794
- */
795
- await this.loadMarkets();
796
- let sideId = undefined;
797
- if (side === 'buy') {
798
- sideId = 1;
799
- }
800
- else if (side === 'sell') {
801
- sideId = 2;
802
- }
803
- const market = this.market(symbol);
804
- const request = {
805
- 'symbol': market['id'],
806
- 'price': price,
807
- 'amount': amount,
808
- 'tradeType': sideId,
809
- };
810
- const response = await this.privatePostApiV1TradePlaceOrder(this.extend(request, params));
811
- const data = response['data'];
812
- return this.safeOrder({
813
- 'info': response,
814
- 'id': this.safeString(data, 'orderId'),
815
- }, market);
816
- }
817
- async cancelOrder(id, symbol = undefined, params = {}) {
818
- /**
819
- * @method
820
- * @name bitforex#cancelOrder
821
- * @description cancels an open order
822
- * @see https://apidoc.bitforex.com/#cancel-order-trade
823
- * @param {string} id order id
824
- * @param {string} symbol unified symbol of the market the order was made in
825
- * @param {object} [params] extra parameters specific to the exchange API endpoint
826
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
827
- */
828
- await this.loadMarkets();
829
- const request = {
830
- 'orderId': id,
831
- };
832
- if (symbol !== undefined) {
833
- request['symbol'] = this.marketId(symbol);
834
- }
835
- const results = await this.privatePostApiV1TradeCancelOrder(this.extend(request, params));
836
- const success = results['success'];
837
- const returnVal = { 'info': results, 'success': success };
838
- return returnVal;
839
- }
840
- sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
841
- let url = this.urls['api']['rest'] + '/' + this.implodeParams(path, params);
842
- const query = this.omit(params, this.extractParams(path));
843
- if (api === 'public') {
844
- if (Object.keys(query).length) {
845
- url += '?' + this.urlencode(query);
846
- }
847
- }
848
- else {
849
- this.checkRequiredCredentials();
850
- let payload = this.urlencode({ 'accessKey': this.apiKey });
851
- query['nonce'] = this.milliseconds();
852
- if (Object.keys(query).length) {
853
- payload += '&' + this.urlencode(this.keysort(query));
854
- }
855
- // let message = '/' + 'api/' + this.version + '/' + path + '?' + payload;
856
- const message = '/' + path + '?' + payload;
857
- const signature = this.hmac(this.encode(message), this.encode(this.secret), sha256.sha256);
858
- body = payload + '&signData=' + signature;
859
- headers = {
860
- 'Content-Type': 'application/x-www-form-urlencoded',
861
- };
862
- }
863
- return { 'url': url, 'method': method, 'body': body, 'headers': headers };
864
- }
865
- handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
866
- if (typeof body !== 'string') {
867
- return undefined; // fallback to default error handler
868
- }
869
- if ((body[0] === '{') || (body[0] === '[')) {
870
- const feedback = this.id + ' ' + body;
871
- const success = this.safeValue(response, 'success');
872
- if (success !== undefined) {
873
- if (!success) {
874
- const codeInner = this.safeString(response, 'code');
875
- this.throwExactlyMatchedException(this.exceptions, codeInner, feedback);
876
- throw new errors.ExchangeError(feedback);
877
- }
878
- }
879
- }
880
- return undefined;
881
- }
882
- }
883
-
884
- module.exports = bitforex;