ccxt-look 1.81.50
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.
- package/.cache/eslintcache +1 -0
- package/.dockerignore +6 -0
- package/.eslintignore +1 -0
- package/.gitattributes +5 -0
- package/.readthedocs.yaml +16 -0
- package/CONTRIBUTING.md +1049 -0
- package/LICENSE.txt +21 -0
- package/README.md +537 -0
- package/SECURITY.md +5 -0
- package/build/cleanup-old-tags.js +94 -0
- package/build/countries.js +256 -0
- package/build/export-exchanges.js +520 -0
- package/build/fs.js +51 -0
- package/build/transpile.js +1772 -0
- package/build/vss.js +78 -0
- package/ccxt.browser.js +7 -0
- package/ccxt.d.ts +692 -0
- package/ccxt.js +171 -0
- package/cleanup.sh +2 -0
- package/composer-install.sh +20 -0
- package/dist/ccxt.browser.js +208383 -0
- package/gource.sh +3 -0
- package/index.html +7 -0
- package/js/.eslintrc +87 -0
- package/js/aax.js +2686 -0
- package/js/ascendex.js +2584 -0
- package/js/base/.eslintrc.js +43 -0
- package/js/base/Exchange.js +2371 -0
- package/js/base/Precise.js +283 -0
- package/js/base/errorHierarchy.js +47 -0
- package/js/base/errors.js +55 -0
- package/js/base/functions/crypto.js +158 -0
- package/js/base/functions/encode.js +118 -0
- package/js/base/functions/generic.js +270 -0
- package/js/base/functions/misc.js +138 -0
- package/js/base/functions/number.js +329 -0
- package/js/base/functions/platform.js +38 -0
- package/js/base/functions/string.js +21 -0
- package/js/base/functions/throttle.js +79 -0
- package/js/base/functions/time.js +210 -0
- package/js/base/functions/type.js +66 -0
- package/js/base/functions.js +28 -0
- package/js/bequant.js +32 -0
- package/js/bibox.js +1407 -0
- package/js/bigone.js +1366 -0
- package/js/binance.js +5652 -0
- package/js/binancecoinm.js +46 -0
- package/js/binanceus.js +46 -0
- package/js/binanceusdm.js +49 -0
- package/js/bit2c.js +535 -0
- package/js/bitbank.js +842 -0
- package/js/bitbay.js +16 -0
- package/js/bitbns.js +1073 -0
- package/js/bitcoincom.js +15 -0
- package/js/bitfinex.js +1433 -0
- package/js/bitfinex2.js +2025 -0
- package/js/bitflyer.js +840 -0
- package/js/bitforex.js +614 -0
- package/js/bitget.js +2397 -0
- package/js/bithumb.js +980 -0
- package/js/bitmart.js +2516 -0
- package/js/bitmex.js +1809 -0
- package/js/bitopro.js +1443 -0
- package/js/bitpanda.js +1782 -0
- package/js/bitrue.js +1747 -0
- package/js/bitso.js +1062 -0
- package/js/bitstamp.js +1757 -0
- package/js/bitstamp1.js +343 -0
- package/js/bittrex.js +1876 -0
- package/js/bitvavo.js +1579 -0
- package/js/bkex.js +1233 -0
- package/js/bl3p.js +346 -0
- package/js/blockchaincom.js +969 -0
- package/js/btcalpha.js +680 -0
- package/js/btcbox.js +477 -0
- package/js/btcmarkets.js +1022 -0
- package/js/btctradeua.js +466 -0
- package/js/btcturk.js +734 -0
- package/js/buda.js +946 -0
- package/js/bw.js +1265 -0
- package/js/bybit.js +3372 -0
- package/js/bytetrade.js +1336 -0
- package/js/cdax.js +1646 -0
- package/js/cex.js +1410 -0
- package/js/coinbase.js +1342 -0
- package/js/coinbaseprime.js +31 -0
- package/js/coinbasepro.js +1466 -0
- package/js/coincheck.js +755 -0
- package/js/coinex.js +3400 -0
- package/js/coinfalcon.js +880 -0
- package/js/coinmate.js +794 -0
- package/js/coinone.js +816 -0
- package/js/coinspot.js +345 -0
- package/js/crex24.js +1636 -0
- package/js/cryptocom.js +1832 -0
- package/js/currencycom.js +1748 -0
- package/js/delta.js +1547 -0
- package/js/deribit.js +2148 -0
- package/js/digifinex.js +1585 -0
- package/js/eqonex.js +1660 -0
- package/js/exmo.js +1670 -0
- package/js/fairdesk.js +1231 -0
- package/js/flowbtc.js +35 -0
- package/js/fmfwio.js +34 -0
- package/js/ftx.js +2751 -0
- package/js/ftxus.js +38 -0
- package/js/gateio.js +4174 -0
- package/js/gemini.js +1397 -0
- package/js/hitbtc.js +1343 -0
- package/js/hitbtc3.js +2329 -0
- package/js/hollaex.js +1486 -0
- package/js/huobi.js +5706 -0
- package/js/huobijp.js +1710 -0
- package/js/huobipro.js +18 -0
- package/js/idex.js +1439 -0
- package/js/independentreserve.js +649 -0
- package/js/indodax.js +742 -0
- package/js/itbit.js +722 -0
- package/js/kraken.js +2179 -0
- package/js/kucoin.js +2571 -0
- package/js/kucoinfutures.js +1771 -0
- package/js/kuna.js +809 -0
- package/js/latoken.js +1445 -0
- package/js/lbank.js +760 -0
- package/js/liquid.js +1432 -0
- package/js/luno.js +873 -0
- package/js/lykke.js +1147 -0
- package/js/mercado.js +771 -0
- package/js/mexc.js +3151 -0
- package/js/ndax.js +2233 -0
- package/js/novadax.js +1318 -0
- package/js/oceanex.js +816 -0
- package/js/okcoin.js +3841 -0
- package/js/okex.js +16 -0
- package/js/okex5.js +16 -0
- package/js/okx.js +4795 -0
- package/js/paymium.js +498 -0
- package/js/phemex.js +2957 -0
- package/js/poloniex.js +1674 -0
- package/js/probit.js +1346 -0
- package/js/qtrade.js +1588 -0
- package/js/ripio.js +1061 -0
- package/js/static_dependencies/BN/bn.js +3526 -0
- package/js/static_dependencies/README.md +1 -0
- package/js/static_dependencies/crypto-js/crypto-js.js +5988 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/base.js +375 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/edwards.js +433 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/index.js +8 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/mont.js +180 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/short.js +938 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curves.js +204 -0
- package/js/static_dependencies/elliptic/lib/elliptic/ec/index.js +240 -0
- package/js/static_dependencies/elliptic/lib/elliptic/ec/key.js +119 -0
- package/js/static_dependencies/elliptic/lib/elliptic/ec/signature.js +24 -0
- package/js/static_dependencies/elliptic/lib/elliptic/eddsa/index.js +145 -0
- package/js/static_dependencies/elliptic/lib/elliptic/eddsa/key.js +100 -0
- package/js/static_dependencies/elliptic/lib/elliptic/eddsa/signature.js +65 -0
- package/js/static_dependencies/elliptic/lib/elliptic/precomputed/secp256k1.js +780 -0
- package/js/static_dependencies/elliptic/lib/elliptic/utils.js +214 -0
- package/js/static_dependencies/elliptic/lib/elliptic.js +22 -0
- package/js/static_dependencies/elliptic/lib/hmac-drbg/hmac-drbg.js +114 -0
- package/js/static_dependencies/fetch-ponyfill/fetch-node.js +39 -0
- package/js/static_dependencies/node-fetch/index.js +1564 -0
- package/js/static_dependencies/node-rsa/NodeRSA.js +223 -0
- package/js/static_dependencies/node-rsa/asn1/ber/errors.js +13 -0
- package/js/static_dependencies/node-rsa/asn1/ber/index.js +21 -0
- package/js/static_dependencies/node-rsa/asn1/ber/reader.js +262 -0
- package/js/static_dependencies/node-rsa/asn1/ber/types.js +36 -0
- package/js/static_dependencies/node-rsa/asn1/index.js +17 -0
- package/js/static_dependencies/node-rsa/encryptEngines/js.js +34 -0
- package/js/static_dependencies/node-rsa/formats/components.js +71 -0
- package/js/static_dependencies/node-rsa/formats/formats.js +31 -0
- package/js/static_dependencies/node-rsa/formats/pkcs1.js +148 -0
- package/js/static_dependencies/node-rsa/formats/pkcs8.js +187 -0
- package/js/static_dependencies/node-rsa/libs/jsbn.js +1252 -0
- package/js/static_dependencies/node-rsa/libs/rsa.js +147 -0
- package/js/static_dependencies/node-rsa/schemes/pkcs1.js +176 -0
- package/js/static_dependencies/node-rsa/schemes/schemes.js +21 -0
- package/js/static_dependencies/node-rsa/utils.js +98 -0
- package/js/static_dependencies/qs/formats.js +18 -0
- package/js/static_dependencies/qs/index.js +11 -0
- package/js/static_dependencies/qs/parse.js +242 -0
- package/js/static_dependencies/qs/stringify.js +269 -0
- package/js/static_dependencies/qs/utils.js +230 -0
- package/js/stex.js +1925 -0
- package/js/test/.eslintrc.js +42 -0
- package/js/test/Exchange/test.balance.js +61 -0
- package/js/test/Exchange/test.borrowRate.js +32 -0
- package/js/test/Exchange/test.currency.js +52 -0
- package/js/test/Exchange/test.fetchBalance.js +23 -0
- package/js/test/Exchange/test.fetchBorrowInterest.js +59 -0
- package/js/test/Exchange/test.fetchBorrowRate.js +32 -0
- package/js/test/Exchange/test.fetchBorrowRates.js +28 -0
- package/js/test/Exchange/test.fetchClosedOrders.js +32 -0
- package/js/test/Exchange/test.fetchCurrencies.js +35 -0
- package/js/test/Exchange/test.fetchDeposits.js +31 -0
- package/js/test/Exchange/test.fetchFundingFees.js +19 -0
- package/js/test/Exchange/test.fetchFundingRateHistory.js +40 -0
- package/js/test/Exchange/test.fetchL2OrderBook.js +23 -0
- package/js/test/Exchange/test.fetchLedger.js +42 -0
- package/js/test/Exchange/test.fetchLeverageTiers.js +33 -0
- package/js/test/Exchange/test.fetchMarketLeverageTiers.js +22 -0
- package/js/test/Exchange/test.fetchMarkets.js +33 -0
- package/js/test/Exchange/test.fetchMyTrades.js +42 -0
- package/js/test/Exchange/test.fetchOHLCV.js +46 -0
- package/js/test/Exchange/test.fetchOpenOrders.js +36 -0
- package/js/test/Exchange/test.fetchOrderBook.js +25 -0
- package/js/test/Exchange/test.fetchOrderBooks.js +35 -0
- package/js/test/Exchange/test.fetchOrders.js +41 -0
- package/js/test/Exchange/test.fetchPositions.js +47 -0
- package/js/test/Exchange/test.fetchStatus.js +35 -0
- package/js/test/Exchange/test.fetchTicker.js +38 -0
- package/js/test/Exchange/test.fetchTickers.js +49 -0
- package/js/test/Exchange/test.fetchTrades.js +39 -0
- package/js/test/Exchange/test.fetchTradingFee.js +18 -0
- package/js/test/Exchange/test.fetchTradingFees.js +22 -0
- package/js/test/Exchange/test.fetchTransactions.js +31 -0
- package/js/test/Exchange/test.fetchWithdrawals.js +31 -0
- package/js/test/Exchange/test.ledgerItem.js +46 -0
- package/js/test/Exchange/test.leverageTier.js +33 -0
- package/js/test/Exchange/test.loadMarkets.js +35 -0
- package/js/test/Exchange/test.market.js +129 -0
- package/js/test/Exchange/test.ohlcv.js +33 -0
- package/js/test/Exchange/test.order.js +62 -0
- package/js/test/Exchange/test.orderbook.js +61 -0
- package/js/test/Exchange/test.position.js +21 -0
- package/js/test/Exchange/test.throttle.js +94 -0
- package/js/test/Exchange/test.ticker.js +95 -0
- package/js/test/Exchange/test.trade.js +68 -0
- package/js/test/Exchange/test.tradingFee.js +34 -0
- package/js/test/Exchange/test.transaction.js +35 -0
- package/js/test/base/.eslintrc +38 -0
- package/js/test/base/functions/test.crypto.js +110 -0
- package/js/test/base/functions/test.datetime.js +62 -0
- package/js/test/base/functions/test.generic.js +152 -0
- package/js/test/base/functions/test.number.js +362 -0
- package/js/test/base/functions/test.time.js +56 -0
- package/js/test/base/functions/test.type.js +53 -0
- package/js/test/base/test.base.js +193 -0
- package/js/test/errors/test.InsufficientFunds.js +86 -0
- package/js/test/errors/test.InvalidNonce.js +64 -0
- package/js/test/errors/test.InvalidOrder.js +35 -0
- package/js/test/errors/test.OrderNotFound.js +39 -0
- package/js/test/test.js +426 -0
- package/js/test/test.timeout_hang.js +12 -0
- package/js/therock.js +1431 -0
- package/js/tidebit.js +632 -0
- package/js/tidex.js +939 -0
- package/js/timex.js +1283 -0
- package/js/upbit.js +1622 -0
- package/js/vcc.js +1353 -0
- package/js/wavesexchange.js +2185 -0
- package/js/wazirx.js +732 -0
- package/js/whitebit.js +1352 -0
- package/js/woo.js +1577 -0
- package/js/xena.js +1948 -0
- package/js/yobit.js +1129 -0
- package/js/zaif.js +647 -0
- package/js/zb.js +4088 -0
- package/js/zipmex.js +40 -0
- package/js/zonda.js +1497 -0
- package/multilang.sh +159 -0
- package/package.json +591 -0
- package/postinstall.js +103 -0
package/js/bitforex.js
ADDED
@@ -0,0 +1,614 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
// ---------------------------------------------------------------------------
|
4
|
+
|
5
|
+
const Exchange = require ('./base/Exchange');
|
6
|
+
const { ExchangeError, AuthenticationError, OrderNotFound, InsufficientFunds, DDoSProtection, PermissionDenied, BadSymbol, InvalidOrder } = require ('./base/errors');
|
7
|
+
|
8
|
+
// ---------------------------------------------------------------------------
|
9
|
+
|
10
|
+
module.exports = class bitforex extends Exchange {
|
11
|
+
describe () {
|
12
|
+
return this.deepExtend (super.describe (), {
|
13
|
+
'id': 'bitforex',
|
14
|
+
'name': 'Bitforex',
|
15
|
+
'countries': [ 'CN' ],
|
16
|
+
'rateLimit': 500, // https://github.com/ccxt/ccxt/issues/5054
|
17
|
+
'version': 'v1',
|
18
|
+
'has': {
|
19
|
+
'CORS': undefined,
|
20
|
+
'spot': true,
|
21
|
+
'margin': false,
|
22
|
+
'swap': undefined, // has but unimplemented
|
23
|
+
'future': false,
|
24
|
+
'option': false,
|
25
|
+
'cancelOrder': true,
|
26
|
+
'createOrder': true,
|
27
|
+
'fetchBalance': true,
|
28
|
+
'fetchBorrowRate': false,
|
29
|
+
'fetchBorrowRateHistories': false,
|
30
|
+
'fetchBorrowRateHistory': false,
|
31
|
+
'fetchBorrowRates': false,
|
32
|
+
'fetchBorrowRatesPerSymbol': false,
|
33
|
+
'fetchClosedOrders': true,
|
34
|
+
'fetchMarkets': true,
|
35
|
+
'fetchMyTrades': undefined,
|
36
|
+
'fetchOHLCV': true,
|
37
|
+
'fetchOpenOrders': true,
|
38
|
+
'fetchOrder': true,
|
39
|
+
'fetchOrderBook': true,
|
40
|
+
'fetchOrders': undefined,
|
41
|
+
'fetchTicker': true,
|
42
|
+
'fetchTickers': undefined,
|
43
|
+
'fetchTrades': true,
|
44
|
+
'fetchTransfer': false,
|
45
|
+
'fetchTransfers': false,
|
46
|
+
'fetchWithdrawal': false,
|
47
|
+
'fetchWithdrawals': false,
|
48
|
+
'transfer': false,
|
49
|
+
'withdraw': false,
|
50
|
+
},
|
51
|
+
'timeframes': {
|
52
|
+
'1m': '1min',
|
53
|
+
'5m': '5min',
|
54
|
+
'15m': '15min',
|
55
|
+
'30m': '30min',
|
56
|
+
'1h': '1hour',
|
57
|
+
'2h': '2hour',
|
58
|
+
'4h': '4hour',
|
59
|
+
'12h': '12hour',
|
60
|
+
'1d': '1day',
|
61
|
+
'1w': '1week',
|
62
|
+
'1M': '1month',
|
63
|
+
},
|
64
|
+
'urls': {
|
65
|
+
'logo': 'https://user-images.githubusercontent.com/51840849/87295553-1160ec00-c50e-11ea-8ea0-df79276a9646.jpg',
|
66
|
+
'api': 'https://api.bitforex.com',
|
67
|
+
'www': 'https://www.bitforex.com',
|
68
|
+
'doc': 'https://github.com/githubdev2020/API_Doc_en/wiki',
|
69
|
+
'fees': 'https://help.bitforex.com/en_us/?cat=13',
|
70
|
+
'referral': 'https://www.bitforex.com/en/invitationRegister?inviterId=1867438',
|
71
|
+
},
|
72
|
+
'api': {
|
73
|
+
'public': {
|
74
|
+
'get': {
|
75
|
+
'api/v1/market/symbols': 20,
|
76
|
+
'api/v1/market/ticker': 4,
|
77
|
+
'api/v1/market/depth': 4,
|
78
|
+
'api/v1/market/trades': 20,
|
79
|
+
'api/v1/market/kline': 20,
|
80
|
+
},
|
81
|
+
},
|
82
|
+
'private': {
|
83
|
+
'post': {
|
84
|
+
'api/v1/fund/mainAccount': 1,
|
85
|
+
'api/v1/fund/allAccount': 30,
|
86
|
+
'api/v1/trade/placeOrder': 1,
|
87
|
+
'api/v1/trade/placeMultiOrder': 10,
|
88
|
+
'api/v1/trade/cancelOrder': 1,
|
89
|
+
'api/v1/trade/cancelMultiOrder': 20,
|
90
|
+
'api/v1/trade/cancelAllOrder': 20,
|
91
|
+
'api/v1/trade/orderInfo': 1,
|
92
|
+
'api/v1/trade/multiOrderInfo': 10,
|
93
|
+
'api/v1/trade/orderInfos': 20,
|
94
|
+
},
|
95
|
+
},
|
96
|
+
},
|
97
|
+
'fees': {
|
98
|
+
'trading': {
|
99
|
+
'tierBased': false,
|
100
|
+
'percentage': true,
|
101
|
+
'maker': this.parseNumber ('0.001'),
|
102
|
+
'taker': this.parseNumber ('0.001'),
|
103
|
+
},
|
104
|
+
'funding': {
|
105
|
+
'tierBased': false,
|
106
|
+
'percentage': true,
|
107
|
+
'deposit': {},
|
108
|
+
'withdraw': {},
|
109
|
+
},
|
110
|
+
},
|
111
|
+
'commonCurrencies': {
|
112
|
+
'BKC': 'Bank Coin',
|
113
|
+
'CAPP': 'Crypto Application Token',
|
114
|
+
'CREDIT': 'TerraCredit',
|
115
|
+
'CTC': 'Culture Ticket Chain',
|
116
|
+
'EWT': 'EcoWatt Token',
|
117
|
+
'IQ': 'IQ.Cash',
|
118
|
+
'MIR': 'MIR COIN',
|
119
|
+
'NOIA': 'METANOIA',
|
120
|
+
'TON': 'To The Moon',
|
121
|
+
},
|
122
|
+
'exceptions': {
|
123
|
+
'1000': OrderNotFound, // {"code":"1000","success":false,"time":1643047898676,"message":"The order does not exist or the status is wrong"}
|
124
|
+
'1003': BadSymbol, // {"success":false,"code":"1003","message":"Param Invalid:param invalid -symbol:symbol error"}
|
125
|
+
'1013': AuthenticationError,
|
126
|
+
'1016': AuthenticationError,
|
127
|
+
'1017': PermissionDenied, // {"code":"1017","success":false,"time":1602670594367,"message":"IP not allow"}
|
128
|
+
'1019': BadSymbol, // {"code":"1019","success":false,"time":1607087743778,"message":"Symbol Invalid"}
|
129
|
+
'3002': InsufficientFunds,
|
130
|
+
'4002': InvalidOrder, // {"success":false,"code":"4002","message":"Price unreasonable"}
|
131
|
+
'4003': InvalidOrder, // {"success":false,"code":"4003","message":"amount too small"}
|
132
|
+
'4004': OrderNotFound,
|
133
|
+
'10204': DDoSProtection,
|
134
|
+
},
|
135
|
+
});
|
136
|
+
}
|
137
|
+
|
138
|
+
async fetchMarkets (params = {}) {
|
139
|
+
const response = await this.publicGetApiV1MarketSymbols (params);
|
140
|
+
//
|
141
|
+
// {
|
142
|
+
// "data": [
|
143
|
+
// {
|
144
|
+
// "amountPrecision":4,
|
145
|
+
// "minOrderAmount":3.0E-4,
|
146
|
+
// "pricePrecision":2,
|
147
|
+
// "symbol":"coin-usdt-btc"
|
148
|
+
// },
|
149
|
+
// ...
|
150
|
+
// ]
|
151
|
+
// }
|
152
|
+
//
|
153
|
+
const data = response['data'];
|
154
|
+
const result = [];
|
155
|
+
for (let i = 0; i < data.length; i++) {
|
156
|
+
const market = data[i];
|
157
|
+
const id = this.safeString (market, 'symbol');
|
158
|
+
const symbolParts = id.split ('-');
|
159
|
+
const baseId = symbolParts[2];
|
160
|
+
const quoteId = symbolParts[1];
|
161
|
+
const base = this.safeCurrencyCode (baseId);
|
162
|
+
const quote = this.safeCurrencyCode (quoteId);
|
163
|
+
result.push ({
|
164
|
+
'id': id,
|
165
|
+
'symbol': base + '/' + quote,
|
166
|
+
'base': base,
|
167
|
+
'quote': quote,
|
168
|
+
'settle': undefined,
|
169
|
+
'baseId': baseId,
|
170
|
+
'quoteId': quoteId,
|
171
|
+
'settleId': undefined,
|
172
|
+
'type': 'spot',
|
173
|
+
'spot': true,
|
174
|
+
'margin': false,
|
175
|
+
'swap': false,
|
176
|
+
'future': false,
|
177
|
+
'option': false,
|
178
|
+
'active': true,
|
179
|
+
'contract': false,
|
180
|
+
'linear': undefined,
|
181
|
+
'inverse': undefined,
|
182
|
+
'contractSize': undefined,
|
183
|
+
'expiry': undefined,
|
184
|
+
'expiryDateTime': undefined,
|
185
|
+
'strike': undefined,
|
186
|
+
'optionType': undefined,
|
187
|
+
'precision': {
|
188
|
+
'amount': this.safeInteger (market, 'amountPrecision'),
|
189
|
+
'price': this.safeInteger (market, 'pricePrecision'),
|
190
|
+
},
|
191
|
+
'limits': {
|
192
|
+
'leverage': {
|
193
|
+
'min': undefined,
|
194
|
+
'max': undefined,
|
195
|
+
},
|
196
|
+
'amount': {
|
197
|
+
'min': this.safeNumber (market, 'minOrderAmount'),
|
198
|
+
'max': undefined,
|
199
|
+
},
|
200
|
+
'price': {
|
201
|
+
'min': undefined,
|
202
|
+
'max': undefined,
|
203
|
+
},
|
204
|
+
'cost': {
|
205
|
+
'min': undefined,
|
206
|
+
'max': undefined,
|
207
|
+
},
|
208
|
+
},
|
209
|
+
'info': market,
|
210
|
+
});
|
211
|
+
}
|
212
|
+
return result;
|
213
|
+
}
|
214
|
+
|
215
|
+
parseTrade (trade, market = undefined) {
|
216
|
+
//
|
217
|
+
// fetchTrades (public) v1
|
218
|
+
//
|
219
|
+
// {
|
220
|
+
// "price":57594.53,
|
221
|
+
// "amount":0.3172,
|
222
|
+
// "time":1637329685322,
|
223
|
+
// "direction":1,
|
224
|
+
// "tid":"1131019666"
|
225
|
+
// }
|
226
|
+
//
|
227
|
+
// {
|
228
|
+
// "price":57591.33,
|
229
|
+
// "amount":0.002,
|
230
|
+
// "time":1637329685322,
|
231
|
+
// "direction":1,
|
232
|
+
// "tid":"1131019639"
|
233
|
+
// }
|
234
|
+
//
|
235
|
+
market = this.safeMarket (undefined, market);
|
236
|
+
const timestamp = this.safeInteger (trade, 'time');
|
237
|
+
const id = this.safeString (trade, 'tid');
|
238
|
+
const orderId = undefined;
|
239
|
+
const priceString = this.safeString (trade, 'price');
|
240
|
+
const amountString = this.safeString (trade, 'amount');
|
241
|
+
const sideId = this.safeInteger (trade, 'direction');
|
242
|
+
const side = this.parseSide (sideId);
|
243
|
+
return this.safeTrade ({
|
244
|
+
'info': trade,
|
245
|
+
'id': id,
|
246
|
+
'timestamp': timestamp,
|
247
|
+
'datetime': this.iso8601 (timestamp),
|
248
|
+
'symbol': market['symbol'],
|
249
|
+
'type': undefined,
|
250
|
+
'side': side,
|
251
|
+
'price': priceString,
|
252
|
+
'amount': amountString,
|
253
|
+
'cost': undefined,
|
254
|
+
'order': orderId,
|
255
|
+
'fee': undefined,
|
256
|
+
'takerOrMaker': undefined,
|
257
|
+
}, market);
|
258
|
+
}
|
259
|
+
|
260
|
+
async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
|
261
|
+
await this.loadMarkets ();
|
262
|
+
const request = {
|
263
|
+
'symbol': this.marketId (symbol),
|
264
|
+
};
|
265
|
+
if (limit !== undefined) {
|
266
|
+
request['size'] = limit;
|
267
|
+
}
|
268
|
+
const market = this.market (symbol);
|
269
|
+
const response = await this.publicGetApiV1MarketTrades (this.extend (request, params));
|
270
|
+
//
|
271
|
+
// {
|
272
|
+
// "data":
|
273
|
+
// [
|
274
|
+
// {
|
275
|
+
// "price":57594.53,
|
276
|
+
// "amount":0.3172,
|
277
|
+
// "time":1637329685322,
|
278
|
+
// "direction":1,
|
279
|
+
// "tid":"1131019666"
|
280
|
+
// }
|
281
|
+
// ],
|
282
|
+
// "success": true,
|
283
|
+
// "time": 1637329688475
|
284
|
+
// }
|
285
|
+
//
|
286
|
+
return this.parseTrades (response['data'], market, since, limit);
|
287
|
+
}
|
288
|
+
|
289
|
+
parseBalance (response) {
|
290
|
+
const data = response['data'];
|
291
|
+
const result = { 'info': response };
|
292
|
+
for (let i = 0; i < data.length; i++) {
|
293
|
+
const balance = data[i];
|
294
|
+
const currencyId = this.safeString (balance, 'currency');
|
295
|
+
const code = this.safeCurrencyCode (currencyId);
|
296
|
+
const account = this.account ();
|
297
|
+
account['used'] = this.safeString (balance, 'frozen');
|
298
|
+
account['free'] = this.safeString (balance, 'active');
|
299
|
+
account['total'] = this.safeString (balance, 'fix');
|
300
|
+
result[code] = account;
|
301
|
+
}
|
302
|
+
return this.safeBalance (result);
|
303
|
+
}
|
304
|
+
|
305
|
+
async fetchBalance (params = {}) {
|
306
|
+
await this.loadMarkets ();
|
307
|
+
const response = await this.privatePostApiV1FundAllAccount (params);
|
308
|
+
return this.parseBalance (response);
|
309
|
+
}
|
310
|
+
|
311
|
+
parseTicker (ticker, market = undefined) {
|
312
|
+
//
|
313
|
+
// {
|
314
|
+
// "buy":7.04E-7,
|
315
|
+
// "date":1643371198598,
|
316
|
+
// "high":7.48E-7,
|
317
|
+
// "last":7.28E-7,
|
318
|
+
// "low":7.10E-7,
|
319
|
+
// "sell":7.54E-7,
|
320
|
+
// "vol":9877287.2874
|
321
|
+
// }
|
322
|
+
//
|
323
|
+
const symbol = this.safeSymbol (undefined, market);
|
324
|
+
const timestamp = this.safeInteger (ticker, 'date');
|
325
|
+
return this.safeTicker ({
|
326
|
+
'symbol': symbol,
|
327
|
+
'timestamp': timestamp,
|
328
|
+
'datetime': this.iso8601 (timestamp),
|
329
|
+
'high': this.safeString (ticker, 'high'),
|
330
|
+
'low': this.safeString (ticker, 'low'),
|
331
|
+
'bid': this.safeString (ticker, 'buy'),
|
332
|
+
'bidVolume': undefined,
|
333
|
+
'ask': this.safeString (ticker, 'sell'),
|
334
|
+
'askVolume': undefined,
|
335
|
+
'vwap': undefined,
|
336
|
+
'open': undefined,
|
337
|
+
'close': this.safeString (ticker, 'last'),
|
338
|
+
'last': this.safeString (ticker, 'last'),
|
339
|
+
'previousClose': undefined,
|
340
|
+
'change': undefined,
|
341
|
+
'percentage': undefined,
|
342
|
+
'average': undefined,
|
343
|
+
'baseVolume': this.safeString (ticker, 'vol'),
|
344
|
+
'quoteVolume': undefined,
|
345
|
+
'info': ticker,
|
346
|
+
}, market, false);
|
347
|
+
}
|
348
|
+
|
349
|
+
async fetchTicker (symbol, params = {}) {
|
350
|
+
await this.loadMarkets ();
|
351
|
+
const market = this.markets[symbol];
|
352
|
+
const request = {
|
353
|
+
'symbol': market['id'],
|
354
|
+
};
|
355
|
+
const response = await this.publicGetApiV1MarketTicker (this.extend (request, params));
|
356
|
+
const ticker = this.safeValue (response, 'data');
|
357
|
+
//
|
358
|
+
// {
|
359
|
+
// "data":{
|
360
|
+
// "buy":37082.83,
|
361
|
+
// "date":1643388686660,
|
362
|
+
// "high":37487.83,
|
363
|
+
// "last":37086.79,
|
364
|
+
// "low":35544.44,
|
365
|
+
// "sell":37090.52,
|
366
|
+
// "vol":690.9776
|
367
|
+
// },
|
368
|
+
// "success":true,
|
369
|
+
// "time":1643388686660
|
370
|
+
// }
|
371
|
+
//
|
372
|
+
return this.parseTicker (ticker, market);
|
373
|
+
}
|
374
|
+
|
375
|
+
parseOHLCV (ohlcv, market = undefined) {
|
376
|
+
//
|
377
|
+
// {
|
378
|
+
// "close":0.02505143,
|
379
|
+
// "currencyVol":0,
|
380
|
+
// "high":0.02506422,
|
381
|
+
// "low":0.02505143,
|
382
|
+
// "open":0.02506095,
|
383
|
+
// "time":1591508940000,
|
384
|
+
// "vol":51.1869
|
385
|
+
// }
|
386
|
+
//
|
387
|
+
return [
|
388
|
+
this.safeInteger (ohlcv, 'time'),
|
389
|
+
this.safeNumber (ohlcv, 'open'),
|
390
|
+
this.safeNumber (ohlcv, 'high'),
|
391
|
+
this.safeNumber (ohlcv, 'low'),
|
392
|
+
this.safeNumber (ohlcv, 'close'),
|
393
|
+
this.safeNumber (ohlcv, 'vol'),
|
394
|
+
];
|
395
|
+
}
|
396
|
+
|
397
|
+
async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
|
398
|
+
await this.loadMarkets ();
|
399
|
+
const market = this.market (symbol);
|
400
|
+
const request = {
|
401
|
+
'symbol': market['id'],
|
402
|
+
'ktype': this.timeframes[timeframe],
|
403
|
+
};
|
404
|
+
if (limit !== undefined) {
|
405
|
+
request['size'] = limit; // default 1, max 600
|
406
|
+
}
|
407
|
+
const response = await this.publicGetApiV1MarketKline (this.extend (request, params));
|
408
|
+
//
|
409
|
+
// {
|
410
|
+
// "data":[
|
411
|
+
// {"close":0.02505143,"currencyVol":0,"high":0.02506422,"low":0.02505143,"open":0.02506095,"time":1591508940000,"vol":51.1869},
|
412
|
+
// {"close":0.02503914,"currencyVol":0,"high":0.02506687,"low":0.02503914,"open":0.02505358,"time":1591509000000,"vol":9.1082},
|
413
|
+
// {"close":0.02505172,"currencyVol":0,"high":0.02507466,"low":0.02503895,"open":0.02506371,"time":1591509060000,"vol":63.7431},
|
414
|
+
// ],
|
415
|
+
// "success":true,
|
416
|
+
// "time":1591509427131
|
417
|
+
// }
|
418
|
+
//
|
419
|
+
const data = this.safeValue (response, 'data', []);
|
420
|
+
return this.parseOHLCVs (data, market, timeframe, since, limit);
|
421
|
+
}
|
422
|
+
|
423
|
+
async fetchOrderBook (symbol, limit = undefined, params = {}) {
|
424
|
+
await this.loadMarkets ();
|
425
|
+
const marketId = this.marketId (symbol);
|
426
|
+
const request = {
|
427
|
+
'symbol': marketId,
|
428
|
+
};
|
429
|
+
if (limit !== undefined) {
|
430
|
+
request['size'] = limit;
|
431
|
+
}
|
432
|
+
const response = await this.publicGetApiV1MarketDepth (this.extend (request, params));
|
433
|
+
const data = this.safeValue (response, 'data');
|
434
|
+
const timestamp = this.safeInteger (response, 'time');
|
435
|
+
return this.parseOrderBook (data, symbol, timestamp, 'bids', 'asks', 'price', 'amount');
|
436
|
+
}
|
437
|
+
|
438
|
+
parseOrderStatus (status) {
|
439
|
+
const statuses = {
|
440
|
+
'0': 'open',
|
441
|
+
'1': 'open',
|
442
|
+
'2': 'closed',
|
443
|
+
'3': 'canceled',
|
444
|
+
'4': 'canceled',
|
445
|
+
};
|
446
|
+
return (status in statuses) ? statuses[status] : status;
|
447
|
+
}
|
448
|
+
|
449
|
+
parseSide (sideId) {
|
450
|
+
if (sideId === 1) {
|
451
|
+
return 'buy';
|
452
|
+
} else if (sideId === 2) {
|
453
|
+
return 'sell';
|
454
|
+
} else {
|
455
|
+
return undefined;
|
456
|
+
}
|
457
|
+
}
|
458
|
+
|
459
|
+
parseOrder (order, market = undefined) {
|
460
|
+
const id = this.safeString (order, 'orderId');
|
461
|
+
const timestamp = this.safeNumber (order, 'createTime');
|
462
|
+
const lastTradeTimestamp = this.safeNumber (order, 'lastTime');
|
463
|
+
const symbol = market['symbol'];
|
464
|
+
const sideId = this.safeInteger (order, 'tradeType');
|
465
|
+
const side = this.parseSide (sideId);
|
466
|
+
const type = undefined;
|
467
|
+
const price = this.safeString (order, 'orderPrice');
|
468
|
+
const average = this.safeString (order, 'avgPrice');
|
469
|
+
const amount = this.safeString (order, 'orderAmount');
|
470
|
+
const filled = this.safeString (order, 'dealAmount');
|
471
|
+
const status = this.parseOrderStatus (this.safeString (order, 'orderState'));
|
472
|
+
const feeSide = (side === 'buy') ? 'base' : 'quote';
|
473
|
+
const feeCurrency = market[feeSide];
|
474
|
+
const fee = {
|
475
|
+
'cost': this.safeNumber (order, 'tradeFee'),
|
476
|
+
'currency': feeCurrency,
|
477
|
+
};
|
478
|
+
return this.safeOrder ({
|
479
|
+
'info': order,
|
480
|
+
'id': id,
|
481
|
+
'clientOrderId': undefined,
|
482
|
+
'timestamp': timestamp,
|
483
|
+
'datetime': this.iso8601 (timestamp),
|
484
|
+
'lastTradeTimestamp': lastTradeTimestamp,
|
485
|
+
'symbol': symbol,
|
486
|
+
'type': type,
|
487
|
+
'timeInForce': undefined,
|
488
|
+
'postOnly': undefined,
|
489
|
+
'side': side,
|
490
|
+
'price': price,
|
491
|
+
'stopPrice': undefined,
|
492
|
+
'cost': undefined,
|
493
|
+
'average': average,
|
494
|
+
'amount': amount,
|
495
|
+
'filled': filled,
|
496
|
+
'remaining': undefined,
|
497
|
+
'status': status,
|
498
|
+
'fee': fee,
|
499
|
+
'trades': undefined,
|
500
|
+
}, market);
|
501
|
+
}
|
502
|
+
|
503
|
+
async fetchOrder (id, symbol = undefined, params = {}) {
|
504
|
+
await this.loadMarkets ();
|
505
|
+
const market = this.market (symbol);
|
506
|
+
const request = {
|
507
|
+
'symbol': this.marketId (symbol),
|
508
|
+
'orderId': id,
|
509
|
+
};
|
510
|
+
const response = await this.privatePostApiV1TradeOrderInfo (this.extend (request, params));
|
511
|
+
const order = this.parseOrder (response['data'], market);
|
512
|
+
return order;
|
513
|
+
}
|
514
|
+
|
515
|
+
async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
516
|
+
await this.loadMarkets ();
|
517
|
+
const market = this.market (symbol);
|
518
|
+
const request = {
|
519
|
+
'symbol': this.marketId (symbol),
|
520
|
+
'state': 0,
|
521
|
+
};
|
522
|
+
const response = await this.privatePostApiV1TradeOrderInfos (this.extend (request, params));
|
523
|
+
return this.parseOrders (response['data'], market, since, limit);
|
524
|
+
}
|
525
|
+
|
526
|
+
async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
527
|
+
await this.loadMarkets ();
|
528
|
+
const market = this.market (symbol);
|
529
|
+
const request = {
|
530
|
+
'symbol': this.marketId (symbol),
|
531
|
+
'state': 1,
|
532
|
+
};
|
533
|
+
const response = await this.privatePostApiV1TradeOrderInfos (this.extend (request, params));
|
534
|
+
return this.parseOrders (response['data'], market, since, limit);
|
535
|
+
}
|
536
|
+
|
537
|
+
async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
|
538
|
+
await this.loadMarkets ();
|
539
|
+
let sideId = undefined;
|
540
|
+
if (side === 'buy') {
|
541
|
+
sideId = 1;
|
542
|
+
} else if (side === 'sell') {
|
543
|
+
sideId = 2;
|
544
|
+
}
|
545
|
+
const request = {
|
546
|
+
'symbol': this.marketId (symbol),
|
547
|
+
'price': price,
|
548
|
+
'amount': amount,
|
549
|
+
'tradeType': sideId,
|
550
|
+
};
|
551
|
+
const response = await this.privatePostApiV1TradePlaceOrder (this.extend (request, params));
|
552
|
+
const data = response['data'];
|
553
|
+
return {
|
554
|
+
'info': response,
|
555
|
+
'id': this.safeString (data, 'orderId'),
|
556
|
+
};
|
557
|
+
}
|
558
|
+
|
559
|
+
async cancelOrder (id, symbol = undefined, params = {}) {
|
560
|
+
await this.loadMarkets ();
|
561
|
+
const request = {
|
562
|
+
'orderId': id,
|
563
|
+
};
|
564
|
+
if (symbol !== undefined) {
|
565
|
+
request['symbol'] = this.marketId (symbol);
|
566
|
+
}
|
567
|
+
const results = await this.privatePostApiV1TradeCancelOrder (this.extend (request, params));
|
568
|
+
const success = results['success'];
|
569
|
+
const returnVal = { 'info': results, 'success': success };
|
570
|
+
return returnVal;
|
571
|
+
}
|
572
|
+
|
573
|
+
sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
|
574
|
+
let url = this.urls['api'] + '/' + this.implodeParams (path, params);
|
575
|
+
const query = this.omit (params, this.extractParams (path));
|
576
|
+
if (api === 'public') {
|
577
|
+
if (Object.keys (query).length) {
|
578
|
+
url += '?' + this.urlencode (query);
|
579
|
+
}
|
580
|
+
} else {
|
581
|
+
this.checkRequiredCredentials ();
|
582
|
+
let payload = this.urlencode ({ 'accessKey': this.apiKey });
|
583
|
+
query['nonce'] = this.milliseconds ();
|
584
|
+
if (Object.keys (query).length) {
|
585
|
+
payload += '&' + this.urlencode (this.keysort (query));
|
586
|
+
}
|
587
|
+
// let message = '/' + 'api/' + this.version + '/' + path + '?' + payload;
|
588
|
+
const message = '/' + path + '?' + payload;
|
589
|
+
const signature = this.hmac (this.encode (message), this.encode (this.secret));
|
590
|
+
body = payload + '&signData=' + signature;
|
591
|
+
headers = {
|
592
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
593
|
+
};
|
594
|
+
}
|
595
|
+
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
|
596
|
+
}
|
597
|
+
|
598
|
+
handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
|
599
|
+
if (typeof body !== 'string') {
|
600
|
+
return; // fallback to default error handler
|
601
|
+
}
|
602
|
+
if ((body[0] === '{') || (body[0] === '[')) {
|
603
|
+
const feedback = this.id + ' ' + body;
|
604
|
+
const success = this.safeValue (response, 'success');
|
605
|
+
if (success !== undefined) {
|
606
|
+
if (!success) {
|
607
|
+
const code = this.safeString (response, 'code');
|
608
|
+
this.throwExactlyMatchedException (this.exceptions, code, feedback);
|
609
|
+
throw new ExchangeError (feedback);
|
610
|
+
}
|
611
|
+
}
|
612
|
+
}
|
613
|
+
}
|
614
|
+
};
|