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,362 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
const { numberToString, decimalToPrecision, ROUND, TRUNCATE, DECIMAL_PLACES, TICK_SIZE, PAD_WITH_ZERO, SIGNIFICANT_DIGITS } = require ('../../../../ccxt');
|
4
|
+
const Precise = require ('../../../base/Precise')
|
5
|
+
const assert = require ('assert');
|
6
|
+
|
7
|
+
// ----------------------------------------------------------------------------
|
8
|
+
// numberToString
|
9
|
+
|
10
|
+
assert (numberToString (-7.8e-7) === '-0.00000078');
|
11
|
+
assert (numberToString (7.8e-7) === '0.00000078');
|
12
|
+
assert (numberToString (-17.805e-7) === '-0.0000017805');
|
13
|
+
assert (numberToString (17.805e-7) === '0.0000017805');
|
14
|
+
assert (numberToString (-7.0005e27) === '-7000500000000000000000000000');
|
15
|
+
assert (numberToString (7.0005e27) === '7000500000000000000000000000');
|
16
|
+
assert (numberToString (-7.9e27) === '-7900000000000000000000000000');
|
17
|
+
assert (numberToString (7e27) === '7000000000000000000000000000');
|
18
|
+
assert (numberToString (7.9e27) === '7900000000000000000000000000');
|
19
|
+
assert (numberToString (-12.345) === '-12.345');
|
20
|
+
assert (numberToString (12.345) === '12.345');
|
21
|
+
assert (numberToString (0) === '0');
|
22
|
+
assert (numberToString (7.35946e21) === '7359460000000000000000');
|
23
|
+
assert (numberToString (0.00000001) === '0.00000001');
|
24
|
+
assert (numberToString (1e-7) === '0.0000001');
|
25
|
+
assert (numberToString (-1e-7) === '-0.0000001');
|
26
|
+
|
27
|
+
// ----------------------------------------------------------------------------
|
28
|
+
// testDecimalToPrecisionTruncationToNDigitsAfterDot
|
29
|
+
|
30
|
+
assert (decimalToPrecision ('12.3456000', TRUNCATE, 100, DECIMAL_PLACES) === '12.3456');
|
31
|
+
assert (decimalToPrecision ('12.3456', TRUNCATE, 100, DECIMAL_PLACES) === '12.3456');
|
32
|
+
assert (decimalToPrecision ('12.3456', TRUNCATE, 4, DECIMAL_PLACES) === '12.3456');
|
33
|
+
assert (decimalToPrecision ('12.3456', TRUNCATE, 3, DECIMAL_PLACES) === '12.345');
|
34
|
+
assert (decimalToPrecision ('12.3456', TRUNCATE, 2, DECIMAL_PLACES) === '12.34');
|
35
|
+
assert (decimalToPrecision ('12.3456', TRUNCATE, 1, DECIMAL_PLACES) === '12.3');
|
36
|
+
assert (decimalToPrecision ('12.3456', TRUNCATE, 0, DECIMAL_PLACES) === '12');
|
37
|
+
|
38
|
+
assert (decimalToPrecision ('0.0000001', TRUNCATE, 8, DECIMAL_PLACES) === '0.0000001');
|
39
|
+
assert (decimalToPrecision ('0.00000001', TRUNCATE, 8, DECIMAL_PLACES) === '0.00000001');
|
40
|
+
|
41
|
+
assert (decimalToPrecision ('0.000000000', TRUNCATE, 9, DECIMAL_PLACES, PAD_WITH_ZERO) === '0.000000000');
|
42
|
+
assert (decimalToPrecision ('0.000000001', TRUNCATE, 9, DECIMAL_PLACES, PAD_WITH_ZERO) === '0.000000001');
|
43
|
+
|
44
|
+
assert (decimalToPrecision ('12.3456', TRUNCATE, -1, DECIMAL_PLACES) === '10');
|
45
|
+
assert (decimalToPrecision ('123.456', TRUNCATE, -1, DECIMAL_PLACES) === '120');
|
46
|
+
assert (decimalToPrecision ('123.456', TRUNCATE, -2, DECIMAL_PLACES) === '100');
|
47
|
+
assert (decimalToPrecision ('9.99999', TRUNCATE, -1, DECIMAL_PLACES) === '0');
|
48
|
+
assert (decimalToPrecision ('99.9999', TRUNCATE, -1, DECIMAL_PLACES) === '90');
|
49
|
+
assert (decimalToPrecision ('99.9999', TRUNCATE, -2, DECIMAL_PLACES) === '0');
|
50
|
+
|
51
|
+
assert (decimalToPrecision ('0', TRUNCATE, 0, DECIMAL_PLACES) === '0');
|
52
|
+
assert (decimalToPrecision ('-0.9', TRUNCATE, 0, DECIMAL_PLACES) === '0');
|
53
|
+
|
54
|
+
// ----------------------------------------------------------------------------
|
55
|
+
// testDecimalToPrecisionTruncationToNSignificantDigits
|
56
|
+
|
57
|
+
assert (decimalToPrecision ('0.000123456700', TRUNCATE, 100, SIGNIFICANT_DIGITS) === '0.0001234567');
|
58
|
+
assert (decimalToPrecision ('0.0001234567', TRUNCATE, 100, SIGNIFICANT_DIGITS) === '0.0001234567');
|
59
|
+
assert (decimalToPrecision ('0.0001234567', TRUNCATE, 7, SIGNIFICANT_DIGITS) === '0.0001234567');
|
60
|
+
|
61
|
+
assert (decimalToPrecision ('0.000123456', TRUNCATE, 6, SIGNIFICANT_DIGITS) === '0.000123456');
|
62
|
+
assert (decimalToPrecision ('0.000123456', TRUNCATE, 5, SIGNIFICANT_DIGITS) === '0.00012345');
|
63
|
+
assert (decimalToPrecision ('0.000123456', TRUNCATE, 2, SIGNIFICANT_DIGITS) === '0.00012');
|
64
|
+
assert (decimalToPrecision ('0.000123456', TRUNCATE, 1, SIGNIFICANT_DIGITS) === '0.0001');
|
65
|
+
|
66
|
+
assert (decimalToPrecision ('123.0000987654', TRUNCATE, 10, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) === '123.0000987');
|
67
|
+
assert (decimalToPrecision ('123.0000987654', TRUNCATE, 8, SIGNIFICANT_DIGITS) === '123.00009');
|
68
|
+
assert (decimalToPrecision ('123.0000987654', TRUNCATE, 7, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) === '123.0000');
|
69
|
+
assert (decimalToPrecision ('123.0000987654', TRUNCATE, 6, SIGNIFICANT_DIGITS) === '123');
|
70
|
+
assert (decimalToPrecision ('123.0000987654', TRUNCATE, 5, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) === '123.00');
|
71
|
+
assert (decimalToPrecision ('123.0000987654', TRUNCATE, 4, SIGNIFICANT_DIGITS) === '123');
|
72
|
+
assert (decimalToPrecision ('123.0000987654', TRUNCATE, 4, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) === '123.0');
|
73
|
+
assert (decimalToPrecision ('123.0000987654', TRUNCATE, 3, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) === '123');
|
74
|
+
assert (decimalToPrecision ('123.0000987654', TRUNCATE, 2, SIGNIFICANT_DIGITS) === '120');
|
75
|
+
assert (decimalToPrecision ('123.0000987654', TRUNCATE, 1, SIGNIFICANT_DIGITS) === '100');
|
76
|
+
assert (decimalToPrecision ('123.0000987654', TRUNCATE, 1, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) === '100');
|
77
|
+
|
78
|
+
assert (decimalToPrecision ('1234', TRUNCATE, 5, SIGNIFICANT_DIGITS) === '1234');
|
79
|
+
assert (decimalToPrecision ('1234', TRUNCATE, 5, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) === '1234.0');
|
80
|
+
assert (decimalToPrecision ('1234', TRUNCATE, 4, SIGNIFICANT_DIGITS) === '1234');
|
81
|
+
assert (decimalToPrecision ('1234', TRUNCATE, 4, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) === '1234');
|
82
|
+
assert (decimalToPrecision ('1234.69', TRUNCATE, 0, SIGNIFICANT_DIGITS) === '0');
|
83
|
+
assert (decimalToPrecision ('1234.69', TRUNCATE, 0, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) === '0');
|
84
|
+
|
85
|
+
// ----------------------------------------------------------------------------
|
86
|
+
// testDecimalToPrecisionRoundingToNDigitsAfterDot
|
87
|
+
|
88
|
+
assert (decimalToPrecision ('12.3456000', ROUND, 100, DECIMAL_PLACES) === '12.3456');
|
89
|
+
assert (decimalToPrecision ('12.3456', ROUND, 100, DECIMAL_PLACES) === '12.3456');
|
90
|
+
assert (decimalToPrecision ('12.3456', ROUND, 4, DECIMAL_PLACES) === '12.3456');
|
91
|
+
assert (decimalToPrecision ('12.3456', ROUND, 3, DECIMAL_PLACES) === '12.346');
|
92
|
+
assert (decimalToPrecision ('12.3456', ROUND, 2, DECIMAL_PLACES) === '12.35');
|
93
|
+
assert (decimalToPrecision ('12.3456', ROUND, 1, DECIMAL_PLACES) === '12.3');
|
94
|
+
assert (decimalToPrecision ('12.3456', ROUND, 0, DECIMAL_PLACES) === '12');
|
95
|
+
|
96
|
+
// a problematic case in PHP
|
97
|
+
assert (decimalToPrecision ('10000', ROUND, 6, DECIMAL_PLACES) === '10000');
|
98
|
+
assert (decimalToPrecision ('0.00003186', ROUND, 8, DECIMAL_PLACES) === '0.00003186');
|
99
|
+
|
100
|
+
assert (decimalToPrecision ('12.3456', ROUND, -1, DECIMAL_PLACES) === '10');
|
101
|
+
assert (decimalToPrecision ('123.456', ROUND, -1, DECIMAL_PLACES) === '120');
|
102
|
+
assert (decimalToPrecision ('123.456', ROUND, -2, DECIMAL_PLACES) === '100');
|
103
|
+
assert (decimalToPrecision ('9.99999', ROUND, -1, DECIMAL_PLACES) === '10');
|
104
|
+
assert (decimalToPrecision ('99.9999', ROUND, -1, DECIMAL_PLACES) === '100');
|
105
|
+
assert (decimalToPrecision ('99.9999', ROUND, -2, DECIMAL_PLACES) === '100');
|
106
|
+
|
107
|
+
assert (decimalToPrecision ('9.999', ROUND, 3, DECIMAL_PLACES) === '9.999');
|
108
|
+
assert (decimalToPrecision ('9.999', ROUND, 2, DECIMAL_PLACES) === '10');
|
109
|
+
assert (decimalToPrecision ('9.999', ROUND, 2, DECIMAL_PLACES, PAD_WITH_ZERO) === '10.00');
|
110
|
+
assert (decimalToPrecision ('99.999', ROUND, 2, DECIMAL_PLACES, PAD_WITH_ZERO) === '100.00');
|
111
|
+
assert (decimalToPrecision ('-99.999', ROUND, 2, DECIMAL_PLACES, PAD_WITH_ZERO) === '-100.00');
|
112
|
+
|
113
|
+
// ----------------------------------------------------------------------------
|
114
|
+
// testDecimalToPrecisionRoundingToNSignificantDigits
|
115
|
+
|
116
|
+
assert (decimalToPrecision ('0.000123456700', ROUND, 100, SIGNIFICANT_DIGITS) === '0.0001234567');
|
117
|
+
assert (decimalToPrecision ('0.0001234567', ROUND, 100, SIGNIFICANT_DIGITS) === '0.0001234567');
|
118
|
+
assert (decimalToPrecision ('0.0001234567', ROUND, 7, SIGNIFICANT_DIGITS) === '0.0001234567');
|
119
|
+
|
120
|
+
assert (decimalToPrecision ('0.000123456', ROUND, 6, SIGNIFICANT_DIGITS) === '0.000123456');
|
121
|
+
assert (decimalToPrecision ('0.000123456', ROUND, 5, SIGNIFICANT_DIGITS) === '0.00012346');
|
122
|
+
assert (decimalToPrecision ('0.000123456', ROUND, 4, SIGNIFICANT_DIGITS) === '0.0001235');
|
123
|
+
assert (decimalToPrecision ('0.00012', ROUND, 2, SIGNIFICANT_DIGITS) === '0.00012');
|
124
|
+
assert (decimalToPrecision ('0.0001', ROUND, 1, SIGNIFICANT_DIGITS) === '0.0001');
|
125
|
+
|
126
|
+
assert (decimalToPrecision ('123.0000987654', ROUND, 7, SIGNIFICANT_DIGITS) === '123.0001');
|
127
|
+
assert (decimalToPrecision ('123.0000987654', ROUND, 6, SIGNIFICANT_DIGITS) === '123');
|
128
|
+
|
129
|
+
assert (decimalToPrecision ('0.00098765', ROUND, 2, SIGNIFICANT_DIGITS) === '0.00099');
|
130
|
+
assert (decimalToPrecision ('0.00098765', ROUND, 2, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) === '0.00099');
|
131
|
+
|
132
|
+
assert (decimalToPrecision ('0.00098765', ROUND, 1, SIGNIFICANT_DIGITS) === '0.001');
|
133
|
+
assert (decimalToPrecision ('0.00098765', ROUND, 10, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) === '0.0009876500000');
|
134
|
+
|
135
|
+
assert (decimalToPrecision ('0.098765', ROUND, 1, SIGNIFICANT_DIGITS, PAD_WITH_ZERO) === '0.1');
|
136
|
+
|
137
|
+
assert (decimalToPrecision ('0', ROUND, 0, SIGNIFICANT_DIGITS) === '0');
|
138
|
+
assert (decimalToPrecision ('-0.123', ROUND, 0, SIGNIFICANT_DIGITS) === '0');
|
139
|
+
|
140
|
+
assert (decimalToPrecision ('0.00000044', ROUND, 5, SIGNIFICANT_DIGITS) === '0.00000044');
|
141
|
+
|
142
|
+
// ----------------------------------------------------------------------------
|
143
|
+
// testDecimalToPrecisionRoundingToTickSize
|
144
|
+
|
145
|
+
assert (decimalToPrecision ('0.000123456700', ROUND, 0.00012, TICK_SIZE) === '0.00012');
|
146
|
+
assert (decimalToPrecision ('0.0001234567', ROUND, 0.00013, TICK_SIZE) === '0.00013');
|
147
|
+
assert (decimalToPrecision ('0.0001234567', TRUNCATE, 0.00013, TICK_SIZE) === '0');
|
148
|
+
assert (decimalToPrecision ('101.000123456700', ROUND, 100, TICK_SIZE) === '100');
|
149
|
+
assert (decimalToPrecision ('0.000123456700', ROUND, 100, TICK_SIZE) === '0');
|
150
|
+
assert (decimalToPrecision ('165', TRUNCATE, 110, TICK_SIZE) === '110');
|
151
|
+
assert (decimalToPrecision ('3210', TRUNCATE, 1110, TICK_SIZE) === '2220');
|
152
|
+
assert (decimalToPrecision ('165', ROUND, 110, TICK_SIZE) === '220');
|
153
|
+
assert (decimalToPrecision ('0.000123456789', ROUND, 0.00000012, TICK_SIZE) === '0.00012348');
|
154
|
+
assert (decimalToPrecision ('0.000123456789', TRUNCATE, 0.00000012, TICK_SIZE) === '0.00012336');
|
155
|
+
assert (decimalToPrecision ('0.000273398', ROUND, 1e-7, TICK_SIZE) === '0.0002734');
|
156
|
+
|
157
|
+
assert (decimalToPrecision ('0.00005714', TRUNCATE, 0.00000001, TICK_SIZE) === '0.00005714');
|
158
|
+
// this line causes problems in JS, fix with Precise
|
159
|
+
// assert (decimalToPrecision ('0.0000571495257361', TRUNCATE, 0.00000001, TICK_SIZE) === '0.00005714');
|
160
|
+
|
161
|
+
assert (decimalToPrecision ('0.01', ROUND, 0.0001, TICK_SIZE, PAD_WITH_ZERO) === '0.0100');
|
162
|
+
assert (decimalToPrecision ('0.01', TRUNCATE, 0.0001, TICK_SIZE, PAD_WITH_ZERO) === '0.0100');
|
163
|
+
|
164
|
+
assert (decimalToPrecision ('-0.000123456789', ROUND, 0.00000012, TICK_SIZE) === '-0.00012348');
|
165
|
+
assert (decimalToPrecision ('-0.000123456789', TRUNCATE, 0.00000012, TICK_SIZE) === '-0.00012336');
|
166
|
+
assert (decimalToPrecision ('-165', TRUNCATE, 110, TICK_SIZE) === '-110');
|
167
|
+
assert (decimalToPrecision ('-165', ROUND, 110, TICK_SIZE) === '-220');
|
168
|
+
assert (decimalToPrecision ('-1650', TRUNCATE, 1100, TICK_SIZE) === '-1100');
|
169
|
+
assert (decimalToPrecision ('-1650', ROUND, 1100, TICK_SIZE) === '-2200');
|
170
|
+
|
171
|
+
assert (decimalToPrecision ('0.0006', TRUNCATE, 0.0001, TICK_SIZE) === '0.0006');
|
172
|
+
assert (decimalToPrecision ('-0.0006', TRUNCATE, 0.0001, TICK_SIZE) === '-0.0006');
|
173
|
+
assert (decimalToPrecision ('0.6', TRUNCATE, 0.2, TICK_SIZE) === '0.6');
|
174
|
+
assert (decimalToPrecision ('-0.6', TRUNCATE, 0.2, TICK_SIZE) === '-0.6');
|
175
|
+
assert (decimalToPrecision ('1.2', ROUND, 0.4, TICK_SIZE) === '1.2');
|
176
|
+
assert (decimalToPrecision ('-1.2', ROUND, 0.4, TICK_SIZE) === '-1.2');
|
177
|
+
assert (decimalToPrecision ('1.2', ROUND, 0.02, TICK_SIZE) === '1.2');
|
178
|
+
assert (decimalToPrecision ('-1.2', ROUND, 0.02, TICK_SIZE) === '-1.2');
|
179
|
+
assert (decimalToPrecision ('44', ROUND, 4.4, TICK_SIZE) === '44');
|
180
|
+
assert (decimalToPrecision ('-44', ROUND, 4.4, TICK_SIZE) === '-44');
|
181
|
+
assert (decimalToPrecision ('44.00000001', ROUND, 4.4, TICK_SIZE) === '44');
|
182
|
+
assert (decimalToPrecision ('-44.00000001', ROUND, 4.4, TICK_SIZE) === '-44');
|
183
|
+
|
184
|
+
// https://github.com/ccxt/ccxt/issues/6731
|
185
|
+
assert (decimalToPrecision ('20', TRUNCATE, 0.00000001, TICK_SIZE) === '20');
|
186
|
+
|
187
|
+
// ----------------------------------------------------------------------------
|
188
|
+
// testDecimalToPrecisionNegativeNumbers
|
189
|
+
|
190
|
+
assert (decimalToPrecision ('-0.123456', TRUNCATE, 5, DECIMAL_PLACES) === '-0.12345');
|
191
|
+
assert (decimalToPrecision ('-0.123456', ROUND, 5, DECIMAL_PLACES) === '-0.12346');
|
192
|
+
|
193
|
+
// ----------------------------------------------------------------------------
|
194
|
+
// decimalToPrecision: without dot / trailing dot
|
195
|
+
|
196
|
+
assert (decimalToPrecision ('123', TRUNCATE, 0) === '123');
|
197
|
+
|
198
|
+
assert (decimalToPrecision ('123', TRUNCATE, 5, DECIMAL_PLACES) === '123');
|
199
|
+
assert (decimalToPrecision ('123', TRUNCATE, 5, DECIMAL_PLACES, PAD_WITH_ZERO) === '123.00000');
|
200
|
+
|
201
|
+
assert (decimalToPrecision ('123.', TRUNCATE, 0, DECIMAL_PLACES) === '123');
|
202
|
+
assert (decimalToPrecision ('123.', TRUNCATE, 5, DECIMAL_PLACES, PAD_WITH_ZERO) === '123.00000');
|
203
|
+
|
204
|
+
assert (decimalToPrecision ('0.', TRUNCATE, 0) === '0');
|
205
|
+
assert (decimalToPrecision ('0.', TRUNCATE, 5, DECIMAL_PLACES, PAD_WITH_ZERO) === '0.00000');
|
206
|
+
|
207
|
+
// ----------------------------------------------------------------------------
|
208
|
+
// decimalToPrecision: rounding for equidistant digits
|
209
|
+
|
210
|
+
assert (decimalToPrecision ('1.44', ROUND, 1, DECIMAL_PLACES) === '1.4');
|
211
|
+
assert (decimalToPrecision ('1.45', ROUND, 1, DECIMAL_PLACES) === '1.5');
|
212
|
+
assert (decimalToPrecision ('1.45', ROUND, 0, DECIMAL_PLACES) === '1'); // not 2
|
213
|
+
|
214
|
+
// ----------------------------------------------------------------------------
|
215
|
+
// negative precision only implemented so far in python
|
216
|
+
// pretty useless for decimal applications as anything |x| < 5 === 0
|
217
|
+
// NO_PADDING and PAD_WITH_ZERO are ignored
|
218
|
+
|
219
|
+
assert (decimalToPrecision ('5', ROUND, -1, DECIMAL_PLACES) === '10');
|
220
|
+
assert (decimalToPrecision ('4.999', ROUND, -1, DECIMAL_PLACES) === '0');
|
221
|
+
assert (decimalToPrecision ('0.0431531423', ROUND, -1, DECIMAL_PLACES) === '0');
|
222
|
+
assert (decimalToPrecision ('-69.3', ROUND, -1, DECIMAL_PLACES) === '-70');
|
223
|
+
assert (decimalToPrecision ('5001', ROUND, -4, DECIMAL_PLACES) === '10000');
|
224
|
+
assert (decimalToPrecision ('4999.999', ROUND, -4, DECIMAL_PLACES) === '0');
|
225
|
+
|
226
|
+
assert (decimalToPrecision ('69.3', TRUNCATE, -2, DECIMAL_PLACES) === '0');
|
227
|
+
assert (decimalToPrecision ('-69.3', TRUNCATE, -2, DECIMAL_PLACES) === '0');
|
228
|
+
assert (decimalToPrecision ('69.3', TRUNCATE, -1, SIGNIFICANT_DIGITS) === '60');
|
229
|
+
assert (decimalToPrecision ('-69.3', TRUNCATE, -1, SIGNIFICANT_DIGITS) === '-60');
|
230
|
+
assert (decimalToPrecision ('69.3', TRUNCATE, -2, SIGNIFICANT_DIGITS) === '0');
|
231
|
+
assert (decimalToPrecision ('1602000000000000000000', TRUNCATE, 3, SIGNIFICANT_DIGITS) === '1600000000000000000000');
|
232
|
+
|
233
|
+
// ----------------------------------------------------------------------------
|
234
|
+
// testDecimalToPrecisionErrorHandling (todo)
|
235
|
+
//
|
236
|
+
// throws (() =>
|
237
|
+
// decimalToPrecision ('123456.789', TRUNCATE, -2, DECIMAL_PLACES),
|
238
|
+
// 'negative precision is not yet supported')
|
239
|
+
//
|
240
|
+
// throws (() =>
|
241
|
+
// decimalToPrecision ('foo'),
|
242
|
+
// "invalid number (contains an illegal character 'f')")
|
243
|
+
//
|
244
|
+
// throws (() =>
|
245
|
+
// decimalToPrecision ('0.01', TRUNCATE, -1, TICK_SIZE),
|
246
|
+
// "TICK_SIZE cant be used with negative numPrecisionDigits")
|
247
|
+
|
248
|
+
// ----------------------------------------------------------------------------
|
249
|
+
|
250
|
+
const w = '-1.123e-6';
|
251
|
+
const x = '0.00000002';
|
252
|
+
const y = '69696900000';
|
253
|
+
const z = '0';
|
254
|
+
const a = '1e8';
|
255
|
+
|
256
|
+
assert (Precise.stringMul (x, y) === '1393.938');
|
257
|
+
assert (Precise.stringMul (y, x) === '1393.938');
|
258
|
+
assert (Precise.stringAdd (x, y) === '69696900000.00000002');
|
259
|
+
assert (Precise.stringAdd (y, x) === '69696900000.00000002');
|
260
|
+
assert (Precise.stringSub (x, y) === '-69696899999.99999998');
|
261
|
+
assert (Precise.stringSub (y, x) === '69696899999.99999998');
|
262
|
+
assert (Precise.stringDiv (x, y, 1) === '0');
|
263
|
+
assert (Precise.stringDiv (x, y) === '0');
|
264
|
+
assert (Precise.stringDiv (x, y, 19) === '0.0000000000000000002');
|
265
|
+
assert (Precise.stringDiv (x, y, 20) === '0.00000000000000000028');
|
266
|
+
assert (Precise.stringDiv (x, y, 21) === '0.000000000000000000286');
|
267
|
+
assert (Precise.stringDiv (x, y, 22) === '0.0000000000000000002869');
|
268
|
+
assert (Precise.stringDiv (y, x) === '3484845000000000000');
|
269
|
+
|
270
|
+
assert (Precise.stringMul (x, w) === '-0.00000000000002246');
|
271
|
+
assert (Precise.stringMul (w, x) === '-0.00000000000002246');
|
272
|
+
assert (Precise.stringAdd (x, w) === '-0.000001103');
|
273
|
+
assert (Precise.stringAdd (w, x) === '-0.000001103');
|
274
|
+
assert (Precise.stringSub (x, w) === '0.000001143');
|
275
|
+
assert (Precise.stringSub (w, x) === '-0.000001143');
|
276
|
+
assert (Precise.stringDiv (x, w) === '-0.017809439002671415');
|
277
|
+
assert (Precise.stringDiv (w, x) === '-56.15');
|
278
|
+
|
279
|
+
assert (Precise.stringMul (z, w) === '0');
|
280
|
+
assert (Precise.stringMul (z, x) === '0');
|
281
|
+
assert (Precise.stringMul (z, y) === '0');
|
282
|
+
assert (Precise.stringMul (w, z) === '0');
|
283
|
+
assert (Precise.stringMul (x, z) === '0');
|
284
|
+
assert (Precise.stringMul (y, z) === '0');
|
285
|
+
assert (Precise.stringAdd (z, w) === '-0.000001123');
|
286
|
+
assert (Precise.stringAdd (z, x) === '0.00000002');
|
287
|
+
assert (Precise.stringAdd (z, y) === '69696900000');
|
288
|
+
assert (Precise.stringAdd (w, z) === '-0.000001123');
|
289
|
+
assert (Precise.stringAdd (x, z) === '0.00000002');
|
290
|
+
assert (Precise.stringAdd (y, z) === '69696900000');
|
291
|
+
|
292
|
+
assert (Precise.stringMul (x, a) === '2');
|
293
|
+
assert (Precise.stringMul (a, x) === '2');
|
294
|
+
assert (Precise.stringMul (y, a) === '6969690000000000000');
|
295
|
+
assert (Precise.stringMul (a, y) === '6969690000000000000');
|
296
|
+
assert (Precise.stringDiv (y, a) === '696.969');
|
297
|
+
assert (Precise.stringDiv (y, a, -1) === '690');
|
298
|
+
assert (Precise.stringDiv (y, a, 0) === '696');
|
299
|
+
assert (Precise.stringDiv (y, a, 1) === '696.9');
|
300
|
+
assert (Precise.stringDiv (y, a, 2) === '696.96');
|
301
|
+
assert (Precise.stringDiv (a, y) === '0.001434784043479695');
|
302
|
+
|
303
|
+
assert (Precise.stringAbs ('0') === '0');
|
304
|
+
assert (Precise.stringAbs ('-0') === '0');
|
305
|
+
assert (Precise.stringAbs ('-500.1') === '500.1');
|
306
|
+
assert (Precise.stringAbs ('213') === '213');
|
307
|
+
|
308
|
+
assert (Precise.stringNeg ('0') === '0');
|
309
|
+
assert (Precise.stringNeg ('-0') === '0');
|
310
|
+
assert (Precise.stringNeg ('-500.1') === '500.1');
|
311
|
+
assert (Precise.stringNeg ('213') === '-213');
|
312
|
+
|
313
|
+
assert (Precise.stringMod ('57.123', '10') === '7.123');
|
314
|
+
assert (Precise.stringMod ('18', '6') === '0');
|
315
|
+
assert (Precise.stringMod ('10.1', '0.5') === '0.1');
|
316
|
+
assert (Precise.stringMod ('10000000', '5555') === '1000');
|
317
|
+
assert (Precise.stringMod ('5550', '120') === '30');
|
318
|
+
|
319
|
+
assert (Precise.stringEquals ('1.0000', '1'));
|
320
|
+
assert (Precise.stringEquals ('-0.0', '0'));
|
321
|
+
assert (Precise.stringEquals ('-0.0', '0.0'));
|
322
|
+
assert (Precise.stringEquals ('5.534000', '5.5340'));
|
323
|
+
|
324
|
+
assert (Precise.stringMin ('1.0000', '2') === '1');
|
325
|
+
assert (Precise.stringMin ('2', '1.2345') === '1.2345');
|
326
|
+
assert (Precise.stringMin ('3.1415', '-2') === '-2');
|
327
|
+
assert (Precise.stringMin ('-3.1415', '-2') === '-3.1415');
|
328
|
+
assert (Precise.stringMin ('0.000', '-0.0') === '0');
|
329
|
+
|
330
|
+
assert (Precise.stringMax ('1.0000', '2') === '2');
|
331
|
+
assert (Precise.stringMax ('2', '1.2345') === '2');
|
332
|
+
assert (Precise.stringMax ('3.1415', '-2') === '3.1415');
|
333
|
+
assert (Precise.stringMax ('-3.1415', '-2') === '-2');
|
334
|
+
assert (Precise.stringMax ('0.000', '-0.0') === '0');
|
335
|
+
|
336
|
+
assert (!Precise.stringGt ('1.0000', '2'));
|
337
|
+
assert (Precise.stringGt ('2', '1.2345'));
|
338
|
+
assert (Precise.stringGt ('3.1415', '-2'));
|
339
|
+
assert (!Precise.stringGt ('-3.1415', '-2'));
|
340
|
+
assert (!Precise.stringGt ('3.1415', '3.1415'));
|
341
|
+
assert (Precise.stringGt ('3.14150000000000000000001', '3.1415'));
|
342
|
+
|
343
|
+
assert (!Precise.stringGe ('1.0000', '2'));
|
344
|
+
assert (Precise.stringGe ('2', '1.2345'));
|
345
|
+
assert (Precise.stringGe ('3.1415', '-2'));
|
346
|
+
assert (!Precise.stringGe ('-3.1415', '-2'));
|
347
|
+
assert (Precise.stringGe ('3.1415', '3.1415'));
|
348
|
+
assert (Precise.stringGe ('3.14150000000000000000001', '3.1415'));
|
349
|
+
|
350
|
+
assert (Precise.stringLt ('1.0000', '2'));
|
351
|
+
assert (!Precise.stringLt ('2', '1.2345'));
|
352
|
+
assert (!Precise.stringLt ('3.1415', '-2'));
|
353
|
+
assert (Precise.stringLt ('-3.1415', '-2'));
|
354
|
+
assert (!Precise.stringLt ('3.1415', '3.1415'));
|
355
|
+
assert (Precise.stringLt ('3.1415', '3.14150000000000000000001'));
|
356
|
+
|
357
|
+
assert (Precise.stringLe ('1.0000', '2'));
|
358
|
+
assert (!Precise.stringLe ('2', '1.2345'));
|
359
|
+
assert (!Precise.stringLe ('3.1415', '-2'));
|
360
|
+
assert (Precise.stringLe ('-3.1415', '-2'));
|
361
|
+
assert (Precise.stringLe ('3.1415', '3.1415'));
|
362
|
+
assert (Precise.stringLe ('3.1415', '3.14150000000000000000001'));
|
@@ -0,0 +1,56 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
// ----------------------------------------------------------------------------
|
4
|
+
|
5
|
+
const { 'strictEqual': equal } = require ('assert')
|
6
|
+
const { setTimeout_safe, timeout, now, isWindows } = require ('../../../../ccxt')
|
7
|
+
, approxEqual = (a, b) => equal (true, Math.abs (a - b) <= 20)
|
8
|
+
, rejectsWith = (msg, x) =>
|
9
|
+
x.then (() => { throw new Error ('not rejected!') })
|
10
|
+
.catch ((e) => { equal (e.message, msg) })
|
11
|
+
|
12
|
+
// these tests break Travis 80% of the time
|
13
|
+
// TODO: make a more robust test that is not failing on certain machines under certain conditions
|
14
|
+
|
15
|
+
// ----------------------------------------------------------------------------
|
16
|
+
|
17
|
+
// it ('setTimeout_safe is working', (done) => {
|
18
|
+
// if (isWindows) {
|
19
|
+
// // temporarily skip this test with appveyor
|
20
|
+
// // todo: refix timer functions for windows properly
|
21
|
+
// done ()
|
22
|
+
// } else {
|
23
|
+
// const start = now ()
|
24
|
+
// const calls = []
|
25
|
+
// const brokenSetTimeout = (done, ms) => {
|
26
|
+
// calls.push ({ when: now () - start, ms_asked: ms })
|
27
|
+
// return setTimeout (done, 100) // simulates a defect setTimeout implementation that sleeps wrong time (100ms always in this test)
|
28
|
+
// }
|
29
|
+
// // ask to sleep 250ms
|
30
|
+
// setTimeout_safe (() => {
|
31
|
+
// approxEqual (calls[0].ms_asked, 250)
|
32
|
+
// approxEqual (calls[1].ms_asked, 150)
|
33
|
+
// approxEqual (calls[2].ms_asked, 50)
|
34
|
+
// done ()
|
35
|
+
// }, 250, brokenSetTimeout)
|
36
|
+
// }
|
37
|
+
// })
|
38
|
+
|
39
|
+
// ----------------------------------------------------------------------------
|
40
|
+
|
41
|
+
// it ('setTimeout_safe canceling is working', (done) => {
|
42
|
+
// const brokenSetTimeout = (done, ms) => setTimeout (done, 100) // simulates a defect setTimeout implementation that sleeps wrong time (100ms always in this test)
|
43
|
+
// const clear = setTimeout_safe (() => { throw new Error ('shouldnt happen!') }, 250, brokenSetTimeout)
|
44
|
+
// setTimeout (() => { clear () }, 200)
|
45
|
+
// setTimeout (() => { done () }, 400)
|
46
|
+
// })
|
47
|
+
|
48
|
+
// ----------------------------------------------------------------------------
|
49
|
+
|
50
|
+
// it ('timeout() is working', async () => {
|
51
|
+
// equal ('foo', await timeout (200, new Promise (resolve => setTimeout (() => resolve ('foo'), 100))))
|
52
|
+
// await rejectsWith ('foo', timeout (100, Promise.reject (new Error ('foo'))))
|
53
|
+
// await rejectsWith ('timed out', timeout (100, new Promise ((resolve, reject) => setTimeout (() => reject (new Error ('foo')), 200))))
|
54
|
+
// })
|
55
|
+
|
56
|
+
// ----------------------------------------------------------------------------
|
@@ -0,0 +1,53 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
const { safeFloat, safeInteger, safeValue } = require ('../../../../ccxt')
|
4
|
+
const { strictEqual: equal } = require ('assert')
|
5
|
+
|
6
|
+
function testSafeFloatSafeInteger() {
|
7
|
+
|
8
|
+
const $default = {}
|
9
|
+
|
10
|
+
const fns = { safeFloat, safeInteger }
|
11
|
+
|
12
|
+
for (const fn of ['safeFloat', 'safeInteger']) {
|
13
|
+
|
14
|
+
equal (fns[fn] ({ 'x': false }, 'x', $default), $default)
|
15
|
+
equal (fns[fn] ({ 'x': true }, 'x', $default), $default)
|
16
|
+
equal (fns[fn] ({ 'x': [] }, 'x', $default), $default)
|
17
|
+
equal (fns[fn] ({ 'x': [0] }, 'x', $default), $default)
|
18
|
+
equal (fns[fn] ({ 'x': [1] }, 'x', $default), $default)
|
19
|
+
equal (fns[fn] ({ 'x': {} }, 'x', $default), $default)
|
20
|
+
equal (fns[fn] ({ 'x': Number.NaN }, 'x'), undefined)
|
21
|
+
equal (fns[fn] ({ 'x': Number.POSITIVE_INFINITY }, 'x'), undefined)
|
22
|
+
equal (fns[fn] ({ 'x': null }, 'x', undefined), undefined)
|
23
|
+
equal (fns[fn] ({ 'x': null }, 'x', $default), $default)
|
24
|
+
equal (fns[fn] ({ 'x': '1.0' }, 'x'), 1.0)
|
25
|
+
equal (fns[fn] ({ 'x': '-1.0' }, 'x'), -1.0)
|
26
|
+
equal (fns[fn] ({ 'x': 1.0 }, 'x'), 1.0)
|
27
|
+
equal (fns[fn] ({ 'x': 0 }, 'x'), 0)
|
28
|
+
equal (fns[fn] ({ 'x': undefined }, 'x', $default), $default)
|
29
|
+
equal (fns[fn] ({ 'x': "" }, 'x'), undefined)
|
30
|
+
equal (fns[fn] ({ 'x': "" }, 'x', 0), 0)
|
31
|
+
equal (fns[fn] ({}, 'x'), undefined)
|
32
|
+
equal (fns[fn] ({}, 'x', 0), 0)
|
33
|
+
}
|
34
|
+
|
35
|
+
equal (safeFloat ({ 'x': 1.59999999 }, 'x'), 1.59999999)
|
36
|
+
equal (safeInteger ({ 'x': 1.59999999 }, 'x'), 1)
|
37
|
+
}
|
38
|
+
|
39
|
+
function testSafeValue() {
|
40
|
+
|
41
|
+
equal (safeValue ({}, 'foo'), undefined)
|
42
|
+
equal (safeValue ({}, 'foo', 'bar'), 'bar')
|
43
|
+
equal (safeValue ({ 'foo': 'bar' }, 'foo'), 'bar')
|
44
|
+
equal (safeValue ({ 'foo': '' }, 'foo'), '')
|
45
|
+
equal (safeValue ({ 'foo': 0 }, 'foo'), 0)
|
46
|
+
}
|
47
|
+
|
48
|
+
function testType () {
|
49
|
+
testSafeFloatSafeInteger ()
|
50
|
+
testSafeValue ()
|
51
|
+
}
|
52
|
+
|
53
|
+
testType ()
|