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
@@ -0,0 +1,193 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
global.log = require ('ololog') // for easier debugging
|
4
|
+
|
5
|
+
const { Exchange, index, aggregate } = require ('../../../ccxt')
|
6
|
+
const { strictEqual: equal, deepEqual } = require ('assert')
|
7
|
+
|
8
|
+
require ('./functions/test.generic')
|
9
|
+
require ('./functions/test.time')
|
10
|
+
require ('./functions/test.type')
|
11
|
+
require ('./functions/test.number')
|
12
|
+
require ('./functions/test.datetime')
|
13
|
+
require ('./functions/test.crypto')
|
14
|
+
|
15
|
+
function testCalculateFee() {
|
16
|
+
const price = 100.00
|
17
|
+
const amount = 10.00
|
18
|
+
const taker = 0.0025
|
19
|
+
const maker = 0.0010
|
20
|
+
const fees = { taker, maker }
|
21
|
+
const market = {
|
22
|
+
'id': 'foobar',
|
23
|
+
'symbol': 'FOO/BAR',
|
24
|
+
'base': 'FOO',
|
25
|
+
'quote': 'BAR',
|
26
|
+
'taker': taker,
|
27
|
+
'maker': maker,
|
28
|
+
'precision': {
|
29
|
+
'amount': 8,
|
30
|
+
'price': 8,
|
31
|
+
},
|
32
|
+
}
|
33
|
+
|
34
|
+
const exchange = new Exchange ({
|
35
|
+
'id': 'mock',
|
36
|
+
'markets': {
|
37
|
+
'FOO/BAR': market,
|
38
|
+
},
|
39
|
+
})
|
40
|
+
|
41
|
+
Object.keys (fees).forEach ((takerOrMaker) => {
|
42
|
+
|
43
|
+
const result = exchange.calculateFee (market['symbol'], 'limit', 'sell', amount, price, takerOrMaker, {})
|
44
|
+
|
45
|
+
deepEqual (result, {
|
46
|
+
'type': takerOrMaker,
|
47
|
+
'currency': 'BAR',
|
48
|
+
'rate': fees[takerOrMaker],
|
49
|
+
'cost': fees[takerOrMaker] * amount * price,
|
50
|
+
})
|
51
|
+
})
|
52
|
+
}
|
53
|
+
|
54
|
+
function testExchangeConfigExtension () {
|
55
|
+
|
56
|
+
|
57
|
+
const cost = { 'min': 0.001, 'max': 1000 }
|
58
|
+
const precision = { 'amount': 3 }
|
59
|
+
const exchange = new binance ({
|
60
|
+
'markets': {
|
61
|
+
'ETH/BTC': { 'limits': { cost }, precision },
|
62
|
+
},
|
63
|
+
})
|
64
|
+
|
65
|
+
deepEqual (exchange.markets['ETH/BTC'].limits.cost, cost)
|
66
|
+
deepEqual (exchange.markets['ETH/BTC'].precision, { 'price': 6, 'amount': 3 })
|
67
|
+
deepEqual (exchange.markets['ETH/BTC'].symbol, 'ETH/BTC')
|
68
|
+
}
|
69
|
+
|
70
|
+
function testAggregate () {
|
71
|
+
|
72
|
+
const bids = [
|
73
|
+
[ 789.1, 123.0 ],
|
74
|
+
[ 789.100, 123.0 ],
|
75
|
+
[ 123.0, 456.0 ],
|
76
|
+
[ 789.0, 123.0 ],
|
77
|
+
[ 789.10, 123.0 ],
|
78
|
+
]
|
79
|
+
|
80
|
+
const asks = [
|
81
|
+
[ 123.0, 456.0 ],
|
82
|
+
[ 789.0, 123.0 ],
|
83
|
+
[ 789.10, 123.0 ],
|
84
|
+
]
|
85
|
+
|
86
|
+
deepEqual (aggregate (bids.sort ()), [
|
87
|
+
[ 123.0, 456.0 ],
|
88
|
+
[ 789.0, 123.0 ],
|
89
|
+
[ 789.1, 369.0 ],
|
90
|
+
])
|
91
|
+
|
92
|
+
deepEqual (aggregate (asks.sort ()), [
|
93
|
+
[ 123.0, 456.0 ],
|
94
|
+
[ 789.0, 123.0 ],
|
95
|
+
[ 789.10, 123.0 ],
|
96
|
+
])
|
97
|
+
|
98
|
+
deepEqual (aggregate ([]), [])
|
99
|
+
}
|
100
|
+
|
101
|
+
function testSafeBalance () {
|
102
|
+
|
103
|
+
const exchange = new Exchange ({
|
104
|
+
'markets': {
|
105
|
+
'ETH/BTC': { 'id': 'ETH/BTC', 'symbol': 'ETH/BTC', 'base': 'ETH', 'quote': 'BTC', }
|
106
|
+
}
|
107
|
+
})
|
108
|
+
|
109
|
+
const input = {
|
110
|
+
'ETH': { 'free': 10, 'used': 10, 'total': 20 },
|
111
|
+
'ZEC': { 'free': 0, 'used': 0, 'total': 0 },
|
112
|
+
}
|
113
|
+
|
114
|
+
const expected = {
|
115
|
+
'ETH': { 'free': 10, 'used': 10, 'total': 20 },
|
116
|
+
'ZEC': { 'free': 0, 'used': 0, 'total': 0 },
|
117
|
+
'free': {
|
118
|
+
'ETH': 10,
|
119
|
+
'ZEC': 0,
|
120
|
+
},
|
121
|
+
'used': {
|
122
|
+
'ETH': 10,
|
123
|
+
'ZEC': 0,
|
124
|
+
},
|
125
|
+
'total': {
|
126
|
+
'ETH': 20,
|
127
|
+
'ZEC': 0,
|
128
|
+
},
|
129
|
+
}
|
130
|
+
|
131
|
+
const actual = exchange.safeBalance (input)
|
132
|
+
|
133
|
+
deepEqual (actual, expected)
|
134
|
+
}
|
135
|
+
|
136
|
+
function testCamelCasePropertyConversion () {
|
137
|
+
|
138
|
+
const exchange = new Exchange ({ 'id': 'mock' })
|
139
|
+
|
140
|
+
const propsSeenBefore = index (
|
141
|
+
["isNode", "empty", "keys", "values", "extend", "clone", "index", "ordered", "unique", "keysort", "indexBy", "groupBy", "filterBy", "sortBy", "flatten", "pluck", "omit", "sum", "deepExtend", "uuid", "unCamelCase", "capitalize", "isNumber", "isArray", "isObject", "isString", "isStringCoercible", "isDictionary", "hasProps", "prop", "asFloat", "asInteger", "safeFloat", "safeInteger", "safeValue", "safeString", "decimal", "toFixed", "truncate", "truncateToString", "precisionFromString", "stringToBinary", "stringToBase64", "base64ToBinary", "base64ToString", "binaryToString", "binaryConcat", "urlencode", "rawencode", "urlencodeBase64", "hash", "hmac", "jwt", "time", "setTimeout_safe", "sleep", "TimedOut", "timeout", "throttle", "json", "aggregate", "is_node", "index_by", "group_by", "filter_by", "sort_by", "deep_extend", "un_camel_case", "is_number", "is_array", "is_object", "is_string", "is_string_coercible", "is_dictionary", "has_props", "as_float", "as_integer", "safe_float", "safe_integer", "safe_value", "safe_string", "to_fixed", "truncate_to_string", "precision_from_string", "string_to_binary", "string_to_base64", "utf16To_base64", "base64To_binary", "base64To_string", "binary_to_string", "binary_concat", "urlencode_base64", "set_timeout_safe", "Timed_out", "encode", "decode", "userAgents", "headers", "proxy", "origin", "iso8601", "parse8601", "milliseconds", "microseconds", "seconds", "id", "enableRateLimit", "rateLimit", "parseJsonResponse", "substituteCommonCurrencyCodes", "verbose", "debug", "journal", "userAgent", "twofa", "timeframes", "hasPublicAPI", "hasPrivateAPI", "hasCORS", "hasDeposit", "hasFetchBalance", "hasFetchClosedOrders", "hasFetchCurrencies", "hasFetchMyTrades", "hasFetchOHLCV", "hasFetchOpenOrders", "hasFetchOrder", "hasFetchOrderBook", "hasFetchOrders", "hasFetchTicker", "hasFetchTickers", "hasFetchBidsAsks", "hasFetchTrades", "hasWithdraw", "hasCreateOrder", "hasCancelOrder", "apiKey", "secret", "uid", "login", "password", "requiredCredentials", "exceptions", "balance", "orderbooks", "tickers", "fees", "orders", "trades", "currencies", "last_http_response", "last_json_response", "arrayConcat", "market_id", "market_ids", "array_concat", "implode_params", "extract_params", "fetch_balance", "fetch_free_balance", "fetch_used_balance","fetch_total_balance", "fetch_l2_order_book", "fetch_order_book", "fetch_bids_asks", "fetch_tickers", "fetch_ticker", "fetch_trades", "fetch_order", "fetch_orders", "fetch_open_orders", "fetch_closed_orders", "fetch_order_status", "fetch_markets", "load_markets", "set_markets", "parse_balance", "parse_bid_ask", "parse_bids_asks", "parse_order_book", "parse_trades", "parse_orders", "parse_ohlcv", "parse_ohlcvs", "edit_limit_buy_order", "edit_limit_sell_order", "edit_limit_order", "edit_order", "create_limit_buy_order", "create_limit_sell_order", "create_market_buy_order", "create_market_sell_order", "create_order", "calculate_fee", "common_currency_code", "price_to_precision", "amount_to_precision", "amount_to_string", "fee_to_precision", "cost_to_precision", "constructor", "getMarket", "describe", "defaults", "nonce", "encodeURIComponent", "checkRequiredCredentials", "initRestRateLimiter", "defineRestApi", "fetch", "fetch2", "request", "handleErrors", "defaultErrorHandler", "handleRestErrors", "handleRestResponse", "setMarkets", "loadMarkets", "fetchBidsAsks", "fetchTickers", "fetchOrder", "fetchOrders", "fetchOpenOrders", "fetchClosedOrders", "fetchMyTrades", "fetchCurrencies", "fetchMarkets", "fetchOrderStatus", "account", "commonCurrencyCode", "currency", "market", "marketId", "marketIds", "symbol", "extractParams", "implodeParams", "url", "parseBidAsk", "parseBidsAsks", "fetchL2OrderBook", "parseOrderBook", "safeBalance", "fetchPartialBalance", "fetchFreeBalance", "fetchUsedBalance", "fetchTotalBalance", "filterBySinceLimit", "parseTrades", "parseOrders", "filterOrdersBySymbol", "parseOHLCV", "parseOHLCVs", "editLimitBuyOrder", "editLimitSellOrder", "editLimitOrder", "editOrder", "createLimitBuyOrder", "createLimitSellOrder", "createMarketBuyOrder", "createMarketSellOrder", "costToPrecision", "priceToPrecision", "amountToPrecision", "amountToLots", "feeToPrecision", "calculateFee", "Ymd", "YmdHMS"]
|
142
|
+
)
|
143
|
+
|
144
|
+
const props = index (Object.getOwnPropertyNames (exchange).concat (Object.getOwnPropertyNames (exchange.constructor.prototype)))
|
145
|
+
|
146
|
+
for (const k of Array.from (propsSeenBefore)) {
|
147
|
+
if (this[k] && !props.has (k)) {
|
148
|
+
throw new Error (`missing prop: ${k}`)
|
149
|
+
}
|
150
|
+
}
|
151
|
+
|
152
|
+
for (const k of Array.from (props)) {
|
153
|
+
if (!propsSeenBefore.has (k)) {
|
154
|
+
log.magenta.noLocate (`+ ${k}`)
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
}
|
159
|
+
|
160
|
+
function testCamelCasePropertyConversion2 () {
|
161
|
+
|
162
|
+
class Derived extends Exchange {}
|
163
|
+
const derived = new Derived ()
|
164
|
+
equal (typeof derived.load_markets, 'function')
|
165
|
+
}
|
166
|
+
|
167
|
+
function testLegacyHasSomething () {
|
168
|
+
|
169
|
+
const exchange = new Exchange ({
|
170
|
+
'id': 'mock',
|
171
|
+
'has': {
|
172
|
+
'CORS': true,
|
173
|
+
'publicAPI': false,
|
174
|
+
'fetchDepositAddress': 'emulated'
|
175
|
+
}
|
176
|
+
})
|
177
|
+
|
178
|
+
equal (exchange.hasCORS, true)
|
179
|
+
equal (exchange.hasPublicAPI, false)
|
180
|
+
equal (exchange.hasFetchDepositAddress, true)
|
181
|
+
}
|
182
|
+
|
183
|
+
// ----------------------------------------------------------------------------
|
184
|
+
|
185
|
+
function testBase () {
|
186
|
+
testCalculateFee ()
|
187
|
+
// testExchangeConfigExtension () // skipped
|
188
|
+
testAggregate ()
|
189
|
+
testSafeBalance ()
|
190
|
+
testCamelCasePropertyConversion ()
|
191
|
+
testCamelCasePropertyConversion2 ()
|
192
|
+
testLegacyHasSomething ()
|
193
|
+
}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
// ----------------------------------------------------------------------------
|
4
|
+
|
5
|
+
const assert = require ('assert')
|
6
|
+
, ccxt = require ('../../../ccxt.js')
|
7
|
+
|
8
|
+
// ----------------------------------------------------------------------------
|
9
|
+
// will try to place a buy order at the minimum price level on minimum amount possible
|
10
|
+
// will skip if balance is positive or market limits are not set
|
11
|
+
|
12
|
+
module.exports = async (exchange, symbol, balance) => {
|
13
|
+
|
14
|
+
if (!exchange.has.createOrder) {
|
15
|
+
console.log ('createOrder not supported')
|
16
|
+
return
|
17
|
+
}
|
18
|
+
|
19
|
+
const markets = await exchange.loadMarkets ()
|
20
|
+
const market = markets[symbol]
|
21
|
+
if (market.limits === undefined) {
|
22
|
+
console.log ('market.limits property is not set, will not test order creation')
|
23
|
+
return
|
24
|
+
}
|
25
|
+
|
26
|
+
const { price, amount, cost } = market.limits
|
27
|
+
|
28
|
+
if (price === undefined || amount === undefined || cost === undefined) {
|
29
|
+
console.log ('market.limits.[price|amount|cost] property is not set, will not test order creation')
|
30
|
+
return
|
31
|
+
}
|
32
|
+
|
33
|
+
let minPrice = price.min
|
34
|
+
let minAmount = amount.min // will be adjusted co cover minCost if needed
|
35
|
+
const minCost = cost.min
|
36
|
+
|
37
|
+
if (minPrice === undefined || minAmount === undefined || minCost === undefined) {
|
38
|
+
console.log ('min limits are not set, will not test order creation')
|
39
|
+
return
|
40
|
+
}
|
41
|
+
|
42
|
+
if (minCost > minPrice * minAmount) {
|
43
|
+
minAmount = minCost / minPrice
|
44
|
+
}
|
45
|
+
|
46
|
+
minPrice = exchange.priceToPrecision (symbol, minPrice)
|
47
|
+
minAmount = exchange.amountToPrecision (symbol, minAmount)
|
48
|
+
|
49
|
+
if (balance === undefined) {
|
50
|
+
console.log ('balance is not set, cannot ensure safety, will not test order creation')
|
51
|
+
return
|
52
|
+
}
|
53
|
+
|
54
|
+
const { base, quote } = market
|
55
|
+
if (balance[quote] !== undefined && balance[quote].total > 0) {
|
56
|
+
console.log ('balance is not empty, will not test order creation')
|
57
|
+
return
|
58
|
+
}
|
59
|
+
|
60
|
+
try {
|
61
|
+
|
62
|
+
console.log ('creating limit buy order...', symbol, minAmount, minPrice)
|
63
|
+
|
64
|
+
const order = await exchange.createLimitBuyOrder (symbol, minAmount, minPrice)
|
65
|
+
|
66
|
+
console.log ('order created although it should not had to - cleaning up')
|
67
|
+
|
68
|
+
console.log (order)
|
69
|
+
|
70
|
+
await exchange.cancelOrder (order.id, symbol)
|
71
|
+
|
72
|
+
assert.fail ()
|
73
|
+
|
74
|
+
} catch (e) {
|
75
|
+
|
76
|
+
if (e instanceof ccxt.InsufficientFunds) {
|
77
|
+
|
78
|
+
console.log ('InsufficientFunds thrown as expected')
|
79
|
+
|
80
|
+
} else {
|
81
|
+
|
82
|
+
console.log ('InsufficientFunds failed, exception follows:')
|
83
|
+
throw e
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
// ----------------------------------------------------------------------------
|
4
|
+
|
5
|
+
const assert = require ('assert')
|
6
|
+
, ccxt = require ('../../../ccxt.js')
|
7
|
+
|
8
|
+
// ----------------------------------------------------------------------------
|
9
|
+
|
10
|
+
module.exports = async (exchange, symbol) => {
|
11
|
+
|
12
|
+
console.log ('AuthenticationError (bad nonce) test...')
|
13
|
+
|
14
|
+
const hasFetchBalance = exchange.has.fetchBalance
|
15
|
+
const hasFetchMyTrades = exchange.has.fetchMyTrades
|
16
|
+
const hasFetchOrders = exchange.has.fetchOrders
|
17
|
+
|
18
|
+
if (hasFetchBalance || hasFetchMyTrades || hasFetchOrders) {
|
19
|
+
|
20
|
+
// save the nonce temporarily and replace it with a fake one
|
21
|
+
const nonce = exchange.nonce
|
22
|
+
exchange.nonce = () => 1
|
23
|
+
|
24
|
+
try {
|
25
|
+
|
26
|
+
// check if handleErrors() throws AuthenticationError if an exchange
|
27
|
+
// responds with an error on a bad nonce
|
28
|
+
// (still, some exchanges that require nonce silently eat bad nonce w/o an error)
|
29
|
+
|
30
|
+
if (hasFetchBalance) {
|
31
|
+
await exchange.fetchBalance ()
|
32
|
+
} else if (hasFetchMyTrades) {
|
33
|
+
await exchange.fetchMyTrades (symbol, 0)
|
34
|
+
} else {
|
35
|
+
await exchange.fetchOrders (symbol)
|
36
|
+
}
|
37
|
+
|
38
|
+
// restore the nonce so the caller may proceed in case bad nonce was accepted by an exchange
|
39
|
+
exchange.nonce = nonce
|
40
|
+
console.log (exchange.id + ': AuthenticationError: bad nonce swallowed')
|
41
|
+
|
42
|
+
} catch (e) {
|
43
|
+
|
44
|
+
// restore the nonce so the caller may proceed in case the test failed
|
45
|
+
exchange.nonce = nonce
|
46
|
+
|
47
|
+
if (e instanceof ccxt.AuthenticationError || e instanceof ccxt.InvalidNonce) {
|
48
|
+
|
49
|
+
// it has thrown the exception as expected
|
50
|
+
console.log ('AuthenticationError test passed')
|
51
|
+
|
52
|
+
} else {
|
53
|
+
|
54
|
+
// rethrow an unexpected error if any
|
55
|
+
throw e
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
} else {
|
60
|
+
|
61
|
+
console.log (exchange.id + ' has no means of testing for bad nonce')
|
62
|
+
|
63
|
+
}
|
64
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
// ----------------------------------------------------------------------------
|
4
|
+
|
5
|
+
const assert = require ('assert')
|
6
|
+
, ccxt = require ('../../../ccxt.js')
|
7
|
+
|
8
|
+
// ----------------------------------------------------------------------------
|
9
|
+
|
10
|
+
module.exports = async (exchange, symbol) => {
|
11
|
+
|
12
|
+
if (!exchange.has.createOrder) {
|
13
|
+
console.log ('createOrder not supported')
|
14
|
+
return
|
15
|
+
}
|
16
|
+
|
17
|
+
try {
|
18
|
+
|
19
|
+
await exchange.createLimitBuyOrder (symbol, 0, 0)
|
20
|
+
assert (false)
|
21
|
+
|
22
|
+
} catch (e) {
|
23
|
+
|
24
|
+
if (e instanceof ccxt.InvalidOrder) {
|
25
|
+
|
26
|
+
console.log ('InvalidOrder thrown as expected')
|
27
|
+
return
|
28
|
+
|
29
|
+
} else {
|
30
|
+
|
31
|
+
console.log ('InvalidOrder failed, exception follows:')
|
32
|
+
throw e
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
// ----------------------------------------------------------------------------
|
4
|
+
|
5
|
+
const assert = require ('assert')
|
6
|
+
, ccxt = require ('../../../ccxt.js')
|
7
|
+
|
8
|
+
// ----------------------------------------------------------------------------
|
9
|
+
|
10
|
+
module.exports = async (exchange, symbol) => {
|
11
|
+
|
12
|
+
if (!exchange.has.createOrder) {
|
13
|
+
console.log ('createOrder not supported -> test skipped')
|
14
|
+
return
|
15
|
+
}
|
16
|
+
|
17
|
+
const id = 1
|
18
|
+
|
19
|
+
try {
|
20
|
+
|
21
|
+
await exchange.cancelOrder (id, symbol)
|
22
|
+
|
23
|
+
console.log ('test failed')
|
24
|
+
|
25
|
+
assert (false)
|
26
|
+
|
27
|
+
} catch (e) {
|
28
|
+
|
29
|
+
if (e instanceof ccxt.OrderNotFound) {
|
30
|
+
|
31
|
+
console.log ('OrderNotFound thrown as expected')
|
32
|
+
|
33
|
+
} else {
|
34
|
+
|
35
|
+
console.log ('OrderNotFound test failed')
|
36
|
+
throw e
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|