forked from ccxt/ccxt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
btcalpha.js
823 lines (794 loc) · 32.8 KB
/
btcalpha.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
'use strict';
// ---------------------------------------------------------------------------
const Exchange = require ('./base/Exchange');
const { ExchangeError, AuthenticationError, DDoSProtection, InvalidOrder, InsufficientFunds } = require ('./base/errors');
const { TICK_SIZE } = require ('./base/functions/number');
const Precise = require ('./base/Precise');
// ---------------------------------------------------------------------------
module.exports = class btcalpha extends Exchange {
describe () {
return this.deepExtend (super.describe (), {
'id': 'btcalpha',
'name': 'BTC-Alpha',
'countries': [ 'US' ],
'version': 'v1',
'has': {
'CORS': undefined,
'spot': true,
'margin': false,
'swap': false,
'future': false,
'option': false,
'addMargin': false,
'cancelOrder': true,
'createOrder': true,
'createReduceOnlyOrder': false,
'createStopLimitOrder': false,
'createStopMarketOrder': false,
'createStopOrder': false,
'fetchBalance': true,
'fetchBorrowRate': false,
'fetchBorrowRateHistories': false,
'fetchBorrowRateHistory': false,
'fetchBorrowRates': false,
'fetchBorrowRatesPerSymbol': false,
'fetchClosedOrders': true,
'fetchDeposit': false,
'fetchDeposits': true,
'fetchFundingHistory': false,
'fetchFundingRate': false,
'fetchFundingRateHistory': false,
'fetchFundingRates': false,
'fetchIndexOHLCV': false,
'fetchLeverage': false,
'fetchMarginMode': false,
'fetchMarkets': true,
'fetchMarkOHLCV': false,
'fetchMyTrades': true,
'fetchOHLCV': true,
'fetchOpenInterestHistory': false,
'fetchOpenOrders': true,
'fetchOrder': true,
'fetchOrderBook': true,
'fetchOrders': true,
'fetchPosition': false,
'fetchPositionMode': false,
'fetchPositions': false,
'fetchPositionsRisk': false,
'fetchPremiumIndexOHLCV': false,
'fetchTicker': undefined,
'fetchTrades': true,
'fetchTradingFee': false,
'fetchTradingFees': false,
'fetchTransfer': false,
'fetchTransfers': false,
'fetchWithdrawal': false,
'fetchWithdrawals': true,
'reduceMargin': false,
'setLeverage': false,
'setMarginMode': false,
'setPositionMode': false,
'transfer': false,
'withdraw': false,
},
'timeframes': {
'1m': '1',
'5m': '5',
'15m': '15',
'30m': '30',
'1h': '60',
'4h': '240',
'1d': 'D',
},
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/42625213-dabaa5da-85cf-11e8-8f99-aa8f8f7699f0.jpg',
'api': {
'rest': 'https://btc-alpha.com/api',
},
'www': 'https://btc-alpha.com',
'doc': 'https://btc-alpha.github.io/api-docs',
'fees': 'https://btc-alpha.com/fees/',
'referral': 'https://btc-alpha.com/?r=123788',
},
'api': {
'public': {
'get': [
'currencies/',
'pairs/',
'orderbook/{pair_name}/',
'exchanges/',
'charts/{pair}/{type}/chart/',
],
},
'private': {
'get': [
'wallets/',
'orders/own/',
'order/{id}/',
'exchanges/own/',
'deposits/',
'withdraws/',
],
'post': [
'order/',
'order-cancel/',
],
},
},
'fees': {
'trading': {
'maker': this.parseNumber ('0.002'),
'taker': this.parseNumber ('0.002'),
},
'funding': {
'withdraw': {},
},
},
'commonCurrencies': {
'CBC': 'Cashbery',
},
'precisionMode': TICK_SIZE,
'exceptions': {
'exact': {},
'broad': {
'Out of balance': InsufficientFunds, // {"date":1570599531.4814300537,"error":"Out of balance -9.99243661 BTC"}
},
},
});
}
async fetchMarkets (params = {}) {
/**
* @method
* @name btcalpha#fetchMarkets
* @description retrieves data on all markets for btcalpha
* @param {dict} params extra parameters specific to the exchange api endpoint
* @returns {[dict]} an array of objects representing market data
*/
const response = await this.publicGetPairs (params);
//
// [
// {
// "name": "1INCH_USDT",
// "currency1": "1INCH",
// "currency2": "USDT",
// "price_precision": 4,
// "amount_precision": 2,
// "minimum_order_size": "0.01000000",
// "maximum_order_size": "900000.00000000",
// "minimum_order_value": "10.00000000",
// "liquidity_type": 10
// },
// ]
//
const result = [];
for (let i = 0; i < response.length; i++) {
const market = response[i];
const id = this.safeString (market, 'name');
const baseId = this.safeString (market, 'currency1');
const quoteId = this.safeString (market, 'currency2');
const base = this.safeCurrencyCode (baseId);
const quote = this.safeCurrencyCode (quoteId);
const pricePrecision = this.safeString (market, 'price_precision');
const priceLimit = this.parsePrecision (pricePrecision);
const amountLimit = this.safeString (market, 'minimum_order_size');
result.push ({
'id': id,
'symbol': base + '/' + quote,
'base': base,
'quote': quote,
'settle': undefined,
'baseId': baseId,
'quoteId': quoteId,
'settleId': undefined,
'type': 'spot',
'spot': true,
'margin': false,
'swap': false,
'future': false,
'option': false,
'active': true,
'contract': false,
'linear': undefined,
'inverse': undefined,
'contractSize': undefined,
'expiry': undefined,
'expiryDatetime': undefined,
'strike': undefined,
'optionType': undefined,
'precision': {
'amount': this.parseNumber (this.parsePrecision (this.safeString (market, 'amount_precision'))),
'price': this.parseNumber (this.parsePrecision ((pricePrecision))),
},
'limits': {
'leverage': {
'min': undefined,
'max': undefined,
},
'amount': {
'min': this.parseNumber (amountLimit),
'max': this.safeNumber (market, 'maximum_order_size'),
},
'price': {
'min': this.parseNumber (priceLimit),
'max': undefined,
},
'cost': {
'min': this.parseNumber (Precise.stringMul (priceLimit, amountLimit)),
'max': undefined,
},
},
'info': market,
});
}
return result;
}
async fetchOrderBook (symbol, limit = undefined, params = {}) {
/**
* @method
* @name btcalpha#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @param {str} symbol unified symbol of the market to fetch the order book for
* @param {int|undefined} limit the maximum amount of order book entries to return
* @param {dict} params extra parameters specific to the btcalpha api endpoint
* @returns {dict} A dictionary of [order book structures]{@link https://docs.ccxt.com/en/latest/manual.html#order-book-structure} indexed by market symbols
*/
await this.loadMarkets ();
const market = this.market (symbol);
const request = {
'pair_name': market['id'],
};
if (limit) {
request['limit_sell'] = limit;
request['limit_buy'] = limit;
}
const response = await this.publicGetOrderbookPairName (this.extend (request, params));
return this.parseOrderBook (response, market['symbol'], undefined, 'buy', 'sell', 'price', 'amount');
}
parseBidsAsks (bidasks, priceKey = 0, amountKey = 1) {
const result = [];
for (let i = 0; i < bidasks.length; i++) {
const bidask = bidasks[i];
if (bidask) {
result.push (this.parseBidAsk (bidask, priceKey, amountKey));
}
}
return result;
}
parseTrade (trade, market = undefined) {
//
// fetchTrades (public)
//
// {
// "id": "202203440",
// "timestamp": "1637856276.264215",
// "pair": "AAVE_USDT",
// "price": "320.79900000",
// "amount": "0.05000000",
// "type": "buy"
// }
//
// fetchMyTrades (private)
//
// {
// "id": "202203440",
// "timestamp": "1637856276.264215",
// "pair": "AAVE_USDT",
// "price": "320.79900000",
// "amount": "0.05000000",
// "type": "buy",
// "my_side": "buy"
// }
//
const marketId = this.safeString (trade, 'pair');
market = this.safeMarket (marketId, market, '_');
const timestamp = this.safeTimestamp (trade, 'timestamp');
const priceString = this.safeString (trade, 'price');
const amountString = this.safeString (trade, 'amount');
const id = this.safeString (trade, 'id');
const side = this.safeString2 (trade, 'my_side', 'type');
return this.safeTrade ({
'id': id,
'info': trade,
'timestamp': timestamp,
'datetime': this.iso8601 (timestamp),
'symbol': market['symbol'],
'order': id,
'type': 'limit',
'side': side,
'takerOrMaker': undefined,
'price': priceString,
'amount': amountString,
'cost': undefined,
'fee': undefined,
}, market);
}
async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
/**
* @method
* @name btcalpha#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @param {str} symbol unified symbol of the market to fetch trades for
* @param {int|undefined} since timestamp in ms of the earliest trade to fetch
* @param {int|undefined} limit the maximum amount of trades to fetch
* @param {dict} params extra parameters specific to the btcalpha api endpoint
* @returns {[dict]} a list of [trade structures]{@link https://docs.ccxt.com/en/latest/manual.html?#public-trades}
*/
await this.loadMarkets ();
let market = undefined;
const request = {};
if (symbol !== undefined) {
market = this.market (symbol);
request['pair'] = market['id'];
}
if (limit !== undefined) {
request['limit'] = limit;
}
const trades = await this.publicGetExchanges (this.extend (request, params));
return this.parseTrades (trades, market, since, limit);
}
async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) {
/**
* @method
* @name btcalpha#fetchDeposits
* @description fetch all deposits made to an account
* @param {str|undefined} code unified currency code
* @param {int|undefined} since the earliest time in ms to fetch deposits for
* @param {int|undefined} limit the maximum number of deposits structures to retrieve
* @param {dict} params extra parameters specific to the btcalpha api endpoint
* @returns {[dict]} a list of [transaction structures]{@link https://docs.ccxt.com/en/latest/manual.html#transaction-structure}
*/
await this.loadMarkets ();
const response = await this.privateGetDeposits (params);
//
// [
// {
// "timestamp": 1485363039.18359,
// "id": 317,
// "currency": "BTC",
// "amount": 530.00000000
// }
// ]
//
return this.parseTransactions (response, code, since, limit, { 'type': 'deposit' });
}
async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) {
/**
* @method
* @name btcalpha#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @param {str|undefined} code unified currency code
* @param {int|undefined} since the earliest time in ms to fetch withdrawals for
* @param {int|undefined} limit the maximum number of withdrawals structures to retrieve
* @param {dict} params extra parameters specific to the btcalpha api endpoint
* @returns {[dict]} a list of [transaction structures]{@link https://docs.ccxt.com/en/latest/manual.html#transaction-structure}
*/
await this.loadMarkets ();
let currency = undefined;
const request = {};
if (code !== undefined) {
currency = this.currency (code);
request['currency_id'] = currency['id'];
}
const response = await this.privateGetWithdraws (this.extend (request, params));
//
// [
// {
// "id": 403,
// "timestamp": 1485363466.868539,
// "currency": "BTC",
// "amount": 0.53000000,
// "status": 20
// }
// ]
//
return this.parseTransactions (response, code, since, limit, { 'type': 'withdrawal' });
}
parseTransaction (transaction, currency = undefined) {
//
// deposit
// {
// "timestamp": 1485363039.18359,
// "id": 317,
// "currency": "BTC",
// "amount": 530.00000000
// }
//
// withdrawal
// {
// "id": 403,
// "timestamp": 1485363466.868539,
// "currency": "BTC",
// "amount": 0.53000000,
// "status": 20
// }
//
const timestamp = this.safeTimestamp (transaction, 'timestamp');
const currencyId = this.safeString (transaction, 'currency');
const statusId = this.safeString (transaction, 'status');
return {
'id': this.safeString (transaction, 'id'),
'info': transaction,
'timestamp': timestamp,
'datetime': this.iso8601 (timestamp),
'network': undefined,
'address': undefined,
'addressTo': undefined,
'addressFrom': undefined,
'tag': undefined,
'tagTo': undefined,
'tagFrom': undefined,
'currency': this.safeCurrencyCode (currencyId, currency),
'amount': this.safeNumber (transaction, 'amount'),
'txid': undefined,
'type': undefined,
'status': this.parseTransactionStatus (statusId),
'comment': undefined,
'fee': undefined,
'updated': undefined,
};
}
parseTransactionStatus (status) {
const statuses = {
'10': 'pending', // New
'20': 'pending', // Verified, waiting for approving
'30': 'ok', // Approved by moderator
'40': 'failed', // Refused by moderator. See your email for more details
'50': 'canceled', // Cancelled by user
};
return this.safeString (statuses, status, status);
}
parseOHLCV (ohlcv, market = undefined) {
//
// {
// "time":1591296000,
// "open":0.024746,
// "close":0.024728,
// "low":0.024728,
// "high":0.024753,
// "volume":16.624
// }
//
return [
this.safeTimestamp (ohlcv, 'time'),
this.safeNumber (ohlcv, 'open'),
this.safeNumber (ohlcv, 'high'),
this.safeNumber (ohlcv, 'low'),
this.safeNumber (ohlcv, 'close'),
this.safeNumber (ohlcv, 'volume'),
];
}
async fetchOHLCV (symbol, timeframe = '5m', since = undefined, limit = undefined, params = {}) {
/**
* @method
* @name btcalpha#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @param {str} symbol unified symbol of the market to fetch OHLCV data for
* @param {str} timeframe the length of time each candle represents
* @param {int|undefined} since timestamp in ms of the earliest candle to fetch
* @param {int|undefined} limit the maximum amount of candles to fetch
* @param {dict} params extra parameters specific to the btcalpha api endpoint
* @returns {[[int]]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
await this.loadMarkets ();
const market = this.market (symbol);
const request = {
'pair': market['id'],
'type': this.timeframes[timeframe],
};
if (limit !== undefined) {
request['limit'] = limit;
}
if (since !== undefined) {
request['since'] = parseInt (since / 1000);
}
const response = await this.publicGetChartsPairTypeChart (this.extend (request, params));
//
// [
// {"time":1591296000,"open":0.024746,"close":0.024728,"low":0.024728,"high":0.024753,"volume":16.624},
// {"time":1591295700,"open":0.024718,"close":0.02475,"low":0.024711,"high":0.02475,"volume":31.645},
// {"time":1591295400,"open":0.024721,"close":0.024717,"low":0.024711,"high":0.02473,"volume":65.071}
// ]
//
return this.parseOHLCVs (response, market, timeframe, since, limit);
}
parseBalance (response) {
const result = { 'info': response };
for (let i = 0; i < response.length; i++) {
const balance = response[i];
const currencyId = this.safeString (balance, 'currency');
const code = this.safeCurrencyCode (currencyId);
const account = this.account ();
account['used'] = this.safeString (balance, 'reserve');
account['total'] = this.safeString (balance, 'balance');
result[code] = account;
}
return this.safeBalance (result);
}
async fetchBalance (params = {}) {
/**
* @method
* @name btcalpha#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @param {dict} params extra parameters specific to the btcalpha api endpoint
* @returns {dict} a [balance structure]{@link https://docs.ccxt.com/en/latest/manual.html?#balance-structure}
*/
await this.loadMarkets ();
const response = await this.privateGetWallets (params);
return this.parseBalance (response);
}
parseOrderStatus (status) {
const statuses = {
'1': 'open',
'2': 'canceled',
'3': 'closed',
};
return this.safeString (statuses, status, status);
}
parseOrder (order, market = undefined) {
//
// fetchClosedOrders / fetchOrder
// {
// "id": "923763073",
// "date": "1635451090368",
// "type": "sell",
// "pair": "XRP_USDT",
// "price": "1.00000000",
// "amount": "0.00000000",
// "status": "3",
// "amount_filled": "10.00000000",
// "amount_original": "10.0"
// "trades": [],
// }
//
// createOrder
// {
// "success": true,
// "date": "1635451754.497541",
// "type": "sell",
// "oid": "923776755",
// "price": "1.0",
// "amount": "10.0",
// "amount_filled": "0.0",
// "amount_original": "10.0",
// "trades": []
// }
//
const marketId = this.safeString (order, 'pair');
market = this.safeMarket (marketId, market, '_');
const symbol = market['symbol'];
const success = this.safeValue (order, 'success', false);
let timestamp = undefined;
if (success) {
timestamp = this.safeTimestamp (order, 'date');
} else {
timestamp = this.safeInteger (order, 'date');
}
const price = this.safeString (order, 'price');
const remaining = this.safeString (order, 'amount');
const filled = this.safeString (order, 'amount_filled');
const amount = this.safeString (order, 'amount_original');
const status = this.parseOrderStatus (this.safeString (order, 'status'));
const id = this.safeString2 (order, 'oid', 'id');
const trades = this.safeValue (order, 'trades');
const side = this.safeString2 (order, 'my_side', 'type');
return this.safeOrder ({
'id': id,
'clientOrderId': undefined,
'datetime': this.iso8601 (timestamp),
'timestamp': timestamp,
'status': status,
'symbol': symbol,
'type': 'limit',
'timeInForce': undefined,
'postOnly': undefined,
'side': side,
'price': price,
'stopPrice': undefined,
'cost': undefined,
'amount': amount,
'filled': filled,
'remaining': remaining,
'trades': trades,
'fee': undefined,
'info': order,
'lastTradeTimestamp': undefined,
'average': undefined,
}, market);
}
async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
/**
* @method
* @name btcalpha#createOrder
* @description create a trade order
* @param {str} symbol unified symbol of the market to create an order in
* @param {str} type 'market' or 'limit'
* @param {str} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float|undefined} price the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
* @param {dict} params extra parameters specific to the btcalpha api endpoint
* @returns {dict} an [order structure]{@link https://docs.ccxt.com/en/latest/manual.html#order-structure}
*/
await this.loadMarkets ();
const market = this.market (symbol);
const request = {
'pair': market['id'],
'type': side,
'amount': amount,
'price': this.priceToPrecision (symbol, price),
};
const response = await this.privatePostOrder (this.extend (request, params));
if (!response['success']) {
throw new InvalidOrder (this.id + ' ' + this.json (response));
}
const order = this.parseOrder (response, market);
amount = (order['amount'] > 0) ? order['amount'] : amount;
return this.extend (order, {
'amount': amount,
});
}
async cancelOrder (id, symbol = undefined, params = {}) {
/**
* @method
* @name btcalpha#cancelOrder
* @description cancels an open order
* @param {str} id order id
* @param {str|undefined} symbol unified symbol of the market the order was made in
* @param {dict} params extra parameters specific to the btcalpha api endpoint
* @returns {dict} An [order structure]{@link https://docs.ccxt.com/en/latest/manual.html#order-structure}
*/
const request = {
'order': id,
};
const response = await this.privatePostOrderCancel (this.extend (request, params));
return response;
}
async fetchOrder (id, symbol = undefined, params = {}) {
/**
* @method
* @name btcalpha#fetchOrder
* @description fetches information on an order made by the user
* @param {str|undefined} symbol not used by btcalpha fetchOrder
* @param {dict} params extra parameters specific to the btcalpha api endpoint
* @returns {dict} An [order structure]{@link https://docs.ccxt.com/en/latest/manual.html#order-structure}
*/
await this.loadMarkets ();
const request = {
'id': id,
};
const order = await this.privateGetOrderId (this.extend (request, params));
return this.parseOrder (order);
}
async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
/**
* @method
* @name btcalpha#fetchOrders
* @description fetches information on multiple orders made by the user
* @param {str|undefined} symbol unified market symbol of the market orders were made in
* @param {int|undefined} since the earliest time in ms to fetch orders for
* @param {int|undefined} limit the maximum number of orde structures to retrieve
* @param {dict} params extra parameters specific to the btcalpha api endpoint
* @returns {[dict]} a list of [order structures]{@link https://docs.ccxt.com/en/latest/manual.html#order-structure}
*/
await this.loadMarkets ();
const request = {};
let market = undefined;
if (symbol !== undefined) {
market = this.market (symbol);
request['pair'] = market['id'];
}
if (limit !== undefined) {
request['limit'] = limit;
}
const orders = await this.privateGetOrdersOwn (this.extend (request, params));
return this.parseOrders (orders, market, since, limit);
}
async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
/**
* @method
* @name btcalpha#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @param {str|undefined} symbol unified market symbol
* @param {int|undefined} since the earliest time in ms to fetch open orders for
* @param {int|undefined} limit the maximum number of open orders structures to retrieve
* @param {dict} params extra parameters specific to the btcalpha api endpoint
* @returns {[dict]} a list of [order structures]{@link https://docs.ccxt.com/en/latest/manual.html#order-structure}
*/
const request = {
'status': '1',
};
return await this.fetchOrders (symbol, since, limit, this.extend (request, params));
}
async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
/**
* @method
* @name btcalpha#fetchClosedOrders
* @description fetches information on multiple closed orders made by the user
* @param {str|undefined} symbol unified market symbol of the market orders were made in
* @param {int|undefined} since the earliest time in ms to fetch orders for
* @param {int|undefined} limit the maximum number of orde structures to retrieve
* @param {dict} params extra parameters specific to the btcalpha api endpoint
* @returns {[dict]} a list of [order structures]{@link https://docs.ccxt.com/en/latest/manual.html#order-structure}
*/
const request = {
'status': '3',
};
return await this.fetchOrders (symbol, since, limit, this.extend (request, params));
}
async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
/**
* @method
* @name btcalpha#fetchMyTrades
* @description fetch all trades made by the user
* @param {str|undefined} symbol unified market symbol
* @param {int|undefined} since the earliest time in ms to fetch trades for
* @param {int|undefined} limit the maximum number of trades structures to retrieve
* @param {dict} params extra parameters specific to the btcalpha api endpoint
* @returns {[dict]} a list of [trade structures]{@link https://docs.ccxt.com/en/latest/manual.html#trade-structure}
*/
await this.loadMarkets ();
const request = {};
if (symbol !== undefined) {
const market = this.market (symbol);
request['pair'] = market['id'];
}
if (limit !== undefined) {
request['limit'] = limit;
}
const trades = await this.privateGetExchangesOwn (this.extend (request, params));
return this.parseTrades (trades, undefined, since, limit);
}
nonce () {
return this.milliseconds ();
}
sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
const query = this.urlencode (this.keysort (this.omit (params, this.extractParams (path))));
let url = this.urls['api']['rest'] + '/';
if (path !== 'charts/{pair}/{type}/chart/') {
url += 'v1/';
}
url += this.implodeParams (path, params);
headers = { 'Accept': 'application/json' };
if (api === 'public') {
if (query.length) {
url += '?' + query;
}
} else {
this.checkRequiredCredentials ();
let payload = this.apiKey;
if (method === 'POST') {
headers['Content-Type'] = 'application/x-www-form-urlencoded';
body = query;
payload += body;
} else if (query.length) {
url += '?' + query;
}
headers['X-KEY'] = this.apiKey;
headers['X-SIGN'] = this.hmac (this.encode (payload), this.encode (this.secret));
headers['X-NONCE'] = this.nonce ().toString ();
}
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
}
handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
if (response === undefined) {
return; // fallback to default error handler
}
//
// {"date":1570599531.4814300537,"error":"Out of balance -9.99243661 BTC"}
//
const error = this.safeString (response, 'error');
const feedback = this.id + ' ' + body;
if (error !== undefined) {
this.throwExactlyMatchedException (this.exceptions['exact'], error, feedback);
this.throwBroadlyMatchedException (this.exceptions['broad'], error, feedback);
}
if (code === 401 || code === 403) {
throw new AuthenticationError (feedback);
} else if (code === 429) {
throw new DDoSProtection (feedback);
}
if (code < 400) {
return;
}
throw new ExchangeError (feedback);
}
};