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/test/test.js
ADDED
@@ -0,0 +1,426 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
// ----------------------------------------------------------------------------
|
4
|
+
|
5
|
+
const [processPath, , exchangeId = null, exchangeSymbol = null] = process.argv.filter ((x) => !x.startsWith ('--'))
|
6
|
+
const verbose = process.argv.includes ('--verbose') || false
|
7
|
+
const debug = process.argv.includes ('--debug') || false
|
8
|
+
|
9
|
+
// ----------------------------------------------------------------------------
|
10
|
+
|
11
|
+
const fs = require ('fs')
|
12
|
+
, assert = require ('assert')
|
13
|
+
, { Agent } = require ('https')
|
14
|
+
, ccxt = require ('../../ccxt.js') // eslint-disable-line import/order
|
15
|
+
|
16
|
+
// ----------------------------------------------------------------------------
|
17
|
+
|
18
|
+
process.on ('uncaughtException', (e) => { console.log (e, e.stack); process.exit (1) })
|
19
|
+
process.on ('unhandledRejection', (e) => { console.log (e, e.stack); process.exit (1) })
|
20
|
+
|
21
|
+
// ----------------------------------------------------------------------------
|
22
|
+
|
23
|
+
console.log ('\nTESTING', { 'exchange': exchangeId, 'symbol': exchangeSymbol || 'all' }, '\n')
|
24
|
+
|
25
|
+
// ----------------------------------------------------------------------------
|
26
|
+
|
27
|
+
const proxies = [
|
28
|
+
'',
|
29
|
+
'https://cors-anywhere.herokuapp.com/'
|
30
|
+
]
|
31
|
+
|
32
|
+
//-----------------------------------------------------------------------------
|
33
|
+
|
34
|
+
const enableRateLimit = true
|
35
|
+
|
36
|
+
const httpsAgent = new Agent ({
|
37
|
+
'ecdhCurve': 'auto',
|
38
|
+
})
|
39
|
+
|
40
|
+
const timeout = 20000
|
41
|
+
|
42
|
+
const exchange = new (ccxt)[exchangeId] ({
|
43
|
+
httpsAgent,
|
44
|
+
verbose,
|
45
|
+
enableRateLimit,
|
46
|
+
debug,
|
47
|
+
timeout,
|
48
|
+
})
|
49
|
+
|
50
|
+
//-----------------------------------------------------------------------------
|
51
|
+
|
52
|
+
const tests = {}
|
53
|
+
const properties = Object.keys (exchange.has)
|
54
|
+
properties
|
55
|
+
// eslint-disable-next-line no-path-concat
|
56
|
+
.filter ((property) => fs.existsSync (__dirname + '/Exchange/test.' + property + '.js'))
|
57
|
+
.forEach ((property) => {
|
58
|
+
// eslint-disable-next-line global-require, import/no-dynamic-require, no-path-concat
|
59
|
+
tests[property] = require (__dirname + '/Exchange/test.' + property + '.js')
|
60
|
+
})
|
61
|
+
|
62
|
+
const errors = require ('../base/errors.js')
|
63
|
+
|
64
|
+
Object.keys (errors)
|
65
|
+
// eslint-disable-next-line no-path-concat
|
66
|
+
.filter ((error) => fs.existsSync (__dirname + '/errors/test.' + error + '.js'))
|
67
|
+
.forEach ((error) => {
|
68
|
+
// eslint-disable-next-line global-require, import/no-dynamic-require, no-path-concat
|
69
|
+
tests[error] = require (__dirname + '/errors/test.' + error + '.js')
|
70
|
+
})
|
71
|
+
|
72
|
+
//-----------------------------------------------------------------------------
|
73
|
+
|
74
|
+
const keysGlobal = 'keys.json'
|
75
|
+
const keysLocal = 'keys.local.json'
|
76
|
+
|
77
|
+
const keysFile = fs.existsSync (keysLocal) ? keysLocal : keysGlobal
|
78
|
+
// eslint-disable-next-line import/no-dynamic-require, no-path-concat
|
79
|
+
const settings = require (__dirname + '/../../' + keysFile)[exchangeId]
|
80
|
+
|
81
|
+
if (settings) {
|
82
|
+
const keys = Object.keys (settings)
|
83
|
+
for (let i = 0; i < keys.length; i++) {
|
84
|
+
const key = keys[i]
|
85
|
+
if (settings[key]) {
|
86
|
+
settings[key] = ccxt.deepExtend (exchange[key] || {}, settings[key])
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
Object.assign (exchange, settings)
|
92
|
+
|
93
|
+
if (settings && settings.skip) {
|
94
|
+
console.log ('[Skipped]', { 'exchange': exchangeId, 'symbol': exchangeSymbol || 'all' })
|
95
|
+
process.exit ()
|
96
|
+
}
|
97
|
+
|
98
|
+
//-----------------------------------------------------------------------------
|
99
|
+
|
100
|
+
async function test (methodName, exchange, ... args) {
|
101
|
+
console.log ('Testing', exchange.id, methodName, '(', ... args, ')')
|
102
|
+
return await (tests[methodName] (exchange, ... args))
|
103
|
+
}
|
104
|
+
|
105
|
+
async function testSymbol (exchange, symbol) {
|
106
|
+
|
107
|
+
await test ('loadMarkets', exchange);
|
108
|
+
await test ('fetchCurrencies', exchange);
|
109
|
+
await test ('fetchTicker', exchange, symbol);
|
110
|
+
await test ('fetchTickers', exchange, symbol);
|
111
|
+
await test ('fetchOHLCV', exchange, symbol);
|
112
|
+
await test ('fetchTrades', exchange, symbol);
|
113
|
+
|
114
|
+
if (exchange.id === 'coinbase') {
|
115
|
+
|
116
|
+
// nothing for now
|
117
|
+
|
118
|
+
} else {
|
119
|
+
|
120
|
+
await test ('fetchOrderBook', exchange, symbol);
|
121
|
+
await test ('fetchL2OrderBook', exchange, symbol);
|
122
|
+
await test ('fetchOrderBooks', exchange);
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
//-----------------------------------------------------------------------------
|
127
|
+
|
128
|
+
async function loadExchange (exchange) {
|
129
|
+
|
130
|
+
const markets = await exchange.loadMarkets ()
|
131
|
+
|
132
|
+
assert (typeof exchange.markets === 'object', '.markets is not an object')
|
133
|
+
assert (Array.isArray (exchange.symbols), '.symbols is not an array')
|
134
|
+
assert (exchange.symbols.length > 0, '.symbols.length <= 0 (less than or equal to zero)')
|
135
|
+
assert (Object.keys (exchange.markets).length > 0, 'Object.keys (.markets).length <= 0 (less than or equal to zero)')
|
136
|
+
assert (exchange.symbols.length === Object.keys (exchange.markets).length, 'number of .symbols is not equal to the number of .markets')
|
137
|
+
|
138
|
+
const symbols = [
|
139
|
+
'BTC/CNY',
|
140
|
+
'BTC/USD',
|
141
|
+
'BTC/USDT',
|
142
|
+
'BTC/EUR',
|
143
|
+
'BTC/ETH',
|
144
|
+
'ETH/BTC',
|
145
|
+
'BTC/JPY',
|
146
|
+
'ETH/EUR',
|
147
|
+
'ETH/JPY',
|
148
|
+
'ETH/CNY',
|
149
|
+
'ETH/USD',
|
150
|
+
'LTC/CNY',
|
151
|
+
'DASH/BTC',
|
152
|
+
'DOGE/BTC',
|
153
|
+
'BTC/AUD',
|
154
|
+
'BTC/PLN',
|
155
|
+
'USD/SLL',
|
156
|
+
'BTC/RUB',
|
157
|
+
'BTC/UAH',
|
158
|
+
'LTC/BTC',
|
159
|
+
'EUR/USD',
|
160
|
+
]
|
161
|
+
|
162
|
+
let result = exchange.symbols.filter ((symbol) => symbols.indexOf (symbol) >= 0)
|
163
|
+
|
164
|
+
if (result.length > 0) {
|
165
|
+
if (exchange.symbols.length > result.length) {
|
166
|
+
result = result.join (', ') + ' + more...'
|
167
|
+
} else {
|
168
|
+
result = result.join (', ')
|
169
|
+
}
|
170
|
+
}
|
171
|
+
|
172
|
+
console.log (exchange.symbols.length, 'symbols', result)
|
173
|
+
}
|
174
|
+
|
175
|
+
//-----------------------------------------------------------------------------
|
176
|
+
|
177
|
+
function getTestSymbol (exchange, symbols) {
|
178
|
+
let symbol = undefined
|
179
|
+
for (let i = 0; i < symbols.length; i++) {
|
180
|
+
const s = symbols[i]
|
181
|
+
const market = exchange.safeValue (exchange.markets, s)
|
182
|
+
if (market !== undefined) {
|
183
|
+
const active = exchange.safeValue (market, 'active')
|
184
|
+
if (active || (active === undefined)) {
|
185
|
+
symbol = s
|
186
|
+
break;
|
187
|
+
}
|
188
|
+
}
|
189
|
+
}
|
190
|
+
return symbol
|
191
|
+
}
|
192
|
+
|
193
|
+
async function testExchange (exchange) {
|
194
|
+
|
195
|
+
await loadExchange (exchange)
|
196
|
+
|
197
|
+
const codes = [
|
198
|
+
'BTC',
|
199
|
+
'ETH',
|
200
|
+
'XRP',
|
201
|
+
'LTC',
|
202
|
+
'BCH',
|
203
|
+
'EOS',
|
204
|
+
'BNB',
|
205
|
+
'BSV',
|
206
|
+
'USDT',
|
207
|
+
'ATOM',
|
208
|
+
'BAT',
|
209
|
+
'BTG',
|
210
|
+
'DASH',
|
211
|
+
'DOGE',
|
212
|
+
'ETC',
|
213
|
+
'IOTA',
|
214
|
+
'LSK',
|
215
|
+
'MKR',
|
216
|
+
'NEO',
|
217
|
+
'PAX',
|
218
|
+
'QTUM',
|
219
|
+
'TRX',
|
220
|
+
'TUSD',
|
221
|
+
'USD',
|
222
|
+
'USDC',
|
223
|
+
'WAVES',
|
224
|
+
'XEM',
|
225
|
+
'XMR',
|
226
|
+
'ZEC',
|
227
|
+
'ZRX',
|
228
|
+
]
|
229
|
+
|
230
|
+
let code = undefined
|
231
|
+
for (let i = 0; i < codes.length; i++) {
|
232
|
+
if (codes[i] in exchange.currencies) {
|
233
|
+
code = codes[i]
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
237
|
+
let symbol = getTestSymbol (exchange, [
|
238
|
+
'BTC/USD',
|
239
|
+
'BTC/USDT',
|
240
|
+
'BTC/CNY',
|
241
|
+
'BTC/EUR',
|
242
|
+
'BTC/ETH',
|
243
|
+
'ETH/BTC',
|
244
|
+
'ETH/USD',
|
245
|
+
'ETH/USDT',
|
246
|
+
'BTC/JPY',
|
247
|
+
'LTC/BTC',
|
248
|
+
'ZRX/WETH',
|
249
|
+
'EUR/USD',
|
250
|
+
])
|
251
|
+
|
252
|
+
if (symbol === undefined) {
|
253
|
+
for (let i = 0; i < codes.length; i++) {
|
254
|
+
const markets = Object.values (exchange.markets)
|
255
|
+
const activeMarkets = markets.filter ((market) => (market['base'] === codes[i]))
|
256
|
+
if (activeMarkets.length) {
|
257
|
+
const activeSymbols = activeMarkets.map (market => market['symbol'])
|
258
|
+
symbol = getTestSymbol (exchange, activeSymbols)
|
259
|
+
break;
|
260
|
+
}
|
261
|
+
}
|
262
|
+
}
|
263
|
+
|
264
|
+
if (symbol === undefined) {
|
265
|
+
const markets = Object.values (exchange.markets)
|
266
|
+
const activeMarkets = markets.filter ((market) => !exchange.safeValue (market, 'active', false))
|
267
|
+
const activeSymbols = activeMarkets.map (market => market['symbol'])
|
268
|
+
symbol = getTestSymbol (exchange, activeSymbols)
|
269
|
+
}
|
270
|
+
|
271
|
+
if (symbol === undefined) {
|
272
|
+
symbol = getTestSymbol (exchange, exchange.symbols)
|
273
|
+
}
|
274
|
+
|
275
|
+
if (symbol === undefined) {
|
276
|
+
symbol = exchange.symbols[0]
|
277
|
+
}
|
278
|
+
|
279
|
+
console.log ('SYMBOL:', symbol)
|
280
|
+
if ((symbol.indexOf ('.d') < 0)) {
|
281
|
+
await testSymbol (exchange, symbol)
|
282
|
+
}
|
283
|
+
|
284
|
+
if (!exchange.privateKey && (!exchange.apiKey || (exchange.apiKey.length < 1))) {
|
285
|
+
return true
|
286
|
+
}
|
287
|
+
|
288
|
+
exchange.checkRequiredCredentials ()
|
289
|
+
|
290
|
+
if (exchange['has']['signIn']) {
|
291
|
+
await exchange.signIn ()
|
292
|
+
}
|
293
|
+
|
294
|
+
// move to testnet/sandbox if possible before accessing the balance
|
295
|
+
// if (exchange.urls['test'])
|
296
|
+
// exchange.urls['api'] = exchange.urls['test']
|
297
|
+
|
298
|
+
const balance = await test ('fetchBalance', exchange)
|
299
|
+
|
300
|
+
await test ('fetchFundingFees', exchange)
|
301
|
+
await test ('fetchTradingFees', exchange)
|
302
|
+
await test ('fetchStatus', exchange)
|
303
|
+
|
304
|
+
await test ('fetchOrders', exchange, symbol)
|
305
|
+
await test ('fetchOpenOrders', exchange, symbol)
|
306
|
+
await test ('fetchClosedOrders', exchange, symbol)
|
307
|
+
await test ('fetchMyTrades', exchange, symbol)
|
308
|
+
await test ('fetchLeverageTiers', exchange, symbol)
|
309
|
+
|
310
|
+
await test ('fetchPositions', exchange, symbol)
|
311
|
+
|
312
|
+
if ('fetchLedger' in tests) {
|
313
|
+
await test ('fetchLedger', exchange, code)
|
314
|
+
}
|
315
|
+
|
316
|
+
await test ('fetchTransactions', exchange, code)
|
317
|
+
await test ('fetchDeposits', exchange, code)
|
318
|
+
await test ('fetchWithdrawals', exchange, code)
|
319
|
+
await test ('fetchBorrowRate', exchange, code)
|
320
|
+
await test ('fetchBorrowRates', exchange)
|
321
|
+
await test ('fetchBorrowInterest', exchange, code)
|
322
|
+
await test ('fetchBorrowInterest', exchange, code, symbol)
|
323
|
+
|
324
|
+
if (exchange.extendedTest) {
|
325
|
+
|
326
|
+
await test ('InvalidNonce', exchange, symbol)
|
327
|
+
await test ('OrderNotFound', exchange, symbol)
|
328
|
+
await test ('InvalidOrder', exchange, symbol)
|
329
|
+
await test ('InsufficientFunds', exchange, symbol, balance) // danger zone - won't execute with non-empty balance
|
330
|
+
}
|
331
|
+
|
332
|
+
// try {
|
333
|
+
// let marketSellOrder =
|
334
|
+
// await exchange.createMarketSellOrder (exchange.symbols[0], 1)
|
335
|
+
// console.log (exchange.id, 'ok', marketSellOrder)
|
336
|
+
// } catch (e) {
|
337
|
+
// console.log (exchange.id, 'error', 'market sell', e)
|
338
|
+
// }
|
339
|
+
//
|
340
|
+
// try {
|
341
|
+
// let marketBuyOrder = await exchange.createMarketBuyOrder (exchange.symbols[0], 1)
|
342
|
+
// console.log (exchange.id, 'ok', marketBuyOrder)
|
343
|
+
// } catch (e) {
|
344
|
+
// console.log (exchange.id, 'error', 'market buy', e)
|
345
|
+
// }
|
346
|
+
//
|
347
|
+
// try {
|
348
|
+
// let limitSellOrder = await exchange.createLimitSellOrder (exchange.symbols[0], 1, 3000)
|
349
|
+
// console.log (exchange.id, 'ok', limitSellOrder)
|
350
|
+
// } catch (e) {
|
351
|
+
// console.log (exchange.id, 'error', 'limit sell', e)
|
352
|
+
// }
|
353
|
+
//
|
354
|
+
// try {
|
355
|
+
// let limitBuyOrder = await exchange.createLimitBuyOrder (exchange.symbols[0], 1, 3000)
|
356
|
+
// console.log (exchange.id, 'ok', limitBuyOrder)
|
357
|
+
// } catch (e) {
|
358
|
+
// console.log (exchange.id, 'error', 'limit buy', e)
|
359
|
+
// }
|
360
|
+
}
|
361
|
+
|
362
|
+
//-----------------------------------------------------------------------------
|
363
|
+
|
364
|
+
async function tryAllProxies (exchange, proxies) {
|
365
|
+
|
366
|
+
const index = proxies.indexOf (exchange.proxy)
|
367
|
+
let currentProxy = (index >= 0) ? index : 0
|
368
|
+
const maxRetries = proxies.length
|
369
|
+
|
370
|
+
if (settings && ('proxy' in settings)) {
|
371
|
+
currentProxy = proxies.indexOf (settings.proxy)
|
372
|
+
}
|
373
|
+
|
374
|
+
for (let numRetries = 0; numRetries < maxRetries; numRetries++) {
|
375
|
+
|
376
|
+
try {
|
377
|
+
|
378
|
+
exchange.proxy = proxies[currentProxy]
|
379
|
+
|
380
|
+
// add random origin for proxies
|
381
|
+
if (exchange.proxy.length > 0) {
|
382
|
+
exchange.origin = exchange.uuid ()
|
383
|
+
}
|
384
|
+
|
385
|
+
await testExchange (exchange)
|
386
|
+
|
387
|
+
break
|
388
|
+
|
389
|
+
} catch (e) {
|
390
|
+
|
391
|
+
currentProxy = ++currentProxy % proxies.length
|
392
|
+
console.log ('[' + e.constructor.name + '] ' + e.message.slice (0, 200))
|
393
|
+
if (e instanceof ccxt.DDoSProtection) {
|
394
|
+
continue
|
395
|
+
} else if (e instanceof ccxt.RequestTimeout) {
|
396
|
+
continue
|
397
|
+
} else if (e instanceof ccxt.ExchangeNotAvailable) {
|
398
|
+
continue
|
399
|
+
} else if (e instanceof ccxt.AuthenticationError) {
|
400
|
+
return
|
401
|
+
} else if (e instanceof ccxt.InvalidNonce) {
|
402
|
+
return
|
403
|
+
} else {
|
404
|
+
throw e
|
405
|
+
}
|
406
|
+
}
|
407
|
+
}
|
408
|
+
}
|
409
|
+
|
410
|
+
//-----------------------------------------------------------------------------
|
411
|
+
|
412
|
+
async function main () {
|
413
|
+
|
414
|
+
if (exchangeSymbol) {
|
415
|
+
|
416
|
+
await loadExchange (exchange)
|
417
|
+
await testSymbol (exchange, exchangeSymbol)
|
418
|
+
|
419
|
+
} else {
|
420
|
+
|
421
|
+
await tryAllProxies (exchange, proxies)
|
422
|
+
}
|
423
|
+
|
424
|
+
}
|
425
|
+
|
426
|
+
main ()
|
@@ -0,0 +1,12 @@
|
|
1
|
+
// run with `node test_timeout_hang`
|
2
|
+
// TODO: integrate with CI tests somehow...
|
3
|
+
|
4
|
+
const { timeout } = require ('../base/functions')
|
5
|
+
|
6
|
+
;(async function () {
|
7
|
+
|
8
|
+
await timeout (10000, Promise.resolve ('foo'))
|
9
|
+
|
10
|
+
console.log ('Look ma, no hangs!') // should terminate the process immediately..
|
11
|
+
|
12
|
+
}) ()
|