ccxt 4.2.99 → 4.3.1
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/README.md +3 -3
- package/dist/cjs/ccxt.js +1 -1
- package/dist/cjs/src/ascendex.js +1 -1
- package/dist/cjs/src/binance.js +56 -0
- package/dist/cjs/src/bingx.js +2 -2
- package/dist/cjs/src/bitget.js +64 -2
- package/dist/cjs/src/bybit.js +1 -1
- package/dist/cjs/src/coinex.js +55 -60
- package/dist/cjs/src/kraken.js +8 -3
- package/dist/cjs/src/kucoin.js +19 -17
- package/dist/cjs/src/okx.js +76 -5
- package/dist/cjs/src/pro/kraken.js +2 -2
- package/dist/cjs/src/woo.js +40 -0
- package/js/ccxt.d.ts +1 -1
- package/js/ccxt.js +1 -1
- package/js/src/ascendex.js +2 -2
- package/js/src/binance.d.ts +3 -1
- package/js/src/binance.js +56 -0
- package/js/src/bingx.js +3 -3
- package/js/src/bitget.d.ts +1 -0
- package/js/src/bitget.js +64 -2
- package/js/src/bybit.js +1 -1
- package/js/src/coinex.js +55 -60
- package/js/src/kraken.js +8 -3
- package/js/src/kucoin.js +19 -17
- package/js/src/okx.d.ts +1 -0
- package/js/src/okx.js +76 -5
- package/js/src/pro/kraken.js +2 -2
- package/js/src/woo.d.ts +1 -0
- package/js/src/woo.js +40 -0
- package/package.json +2 -1
- package/.dockerignore +0 -6
- package/.eslintignore +0 -1
- package/.git-templates/hooks/pre-push +0 -55
- package/.gitattributes +0 -7
- package/CHANGELOG.md +0 -6003
- package/CODEOWNERS +0 -1
- package/CONTRIBUTING.md +0 -1099
- package/build.sh +0 -217
- package/change.sh +0 -18
- package/cleanup.sh +0 -18
- package/composer-install.sh +0 -20
- package/dist/ccxt.browser.js +0 -327256
- package/dist/ccxt.browser.min.js +0 -30
- package/dist/ccxt.browser.min.js.LICENSE.txt +0 -12
- package/doc/FAQ.rst +0 -1
- package/doc/Makefile +0 -20
- package/doc/_static/css/dark.css +0 -101
- package/doc/_static/css/index.css +0 -128
- package/doc/_static/favicon.ico +0 -0
- package/doc/_static/javascript/binance-portal.min.js +0 -2369
- package/doc/_static/javascript/index.js +0 -195
- package/doc/_static/javascript/jquery-ui.min.js +0 -6
- package/doc/ccxt.pro.install.rst +0 -1
- package/doc/ccxt.pro.manual.rst +0 -1665
- package/doc/exchange-markets-by-country.rst +0 -1423
- package/doc/exchange-markets.rst +0 -1441
- package/doc/index.rst +0 -35
- package/doc/install.rst +0 -1
- package/doc/make.bat +0 -36
- package/doc/manual.rst +0 -7471
- package/doc/readme.rst +0 -2191
- package/doc/requirements.txt +0 -6
- package/examples/ccxt.pro/html/watchTicker.html +0 -51
- package/examples/ccxt.pro/js/binance-fetch-balance-snapshot-watch-balance-updates.js +0 -55
- package/examples/ccxt.pro/js/binance-https-proxy.js +0 -48
- package/examples/ccxt.pro/js/binance-watch-ohlcv-many-symbols-continuously.js +0 -38
- package/examples/ccxt.pro/js/binance-watch-ohlcv-many-symbols.js +0 -64
- package/examples/ccxt.pro/js/binance-watch-ticker-many-symbols.js +0 -62
- package/examples/ccxt.pro/js/build-ohlcv-many-symbols.js +0 -68
- package/examples/ccxt.pro/js/calculate-ohlcvs-from-trades-warmup.js +0 -82
- package/examples/ccxt.pro/js/calculate-ohlcvs-from-trades.js +0 -59
- package/examples/ccxt.pro/js/exchange-capabitities.js +0 -72
- package/examples/ccxt.pro/js/exchange-close.js +0 -46
- package/examples/ccxt.pro/js/gateio-swap-watch-many-orderbooks.js +0 -30
- package/examples/ccxt.pro/js/gateio-watch-balance.js +0 -23
- package/examples/ccxt.pro/js/gateio-watch-order-book.js +0 -71
- package/examples/ccxt.pro/js/graceful-shutdown.js +0 -43
- package/examples/ccxt.pro/js/many-exchanges-many-streams.js +0 -37
- package/examples/ccxt.pro/js/okex-create-futures-order.js +0 -48
- package/examples/ccxt.pro/js/okex-watch-balance-and-create-order.js +0 -54
- package/examples/ccxt.pro/js/okx-watch-tickers.js +0 -31
- package/examples/ccxt.pro/js/one-exchange-many-different-streams.js +0 -46
- package/examples/ccxt.pro/js/one-exchange-many-streams-2.js +0 -26
- package/examples/ccxt.pro/js/one-exchange-many-streams.js +0 -28
- package/examples/ccxt.pro/js/socks-binance-watch-orderbook.js +0 -30
- package/examples/ccxt.pro/js/watch-fetch-many-exchanges-many-ordersbooks.js +0 -40
- package/examples/ccxt.pro/js/watch-many-exchanges-many-ordersbooks.js +0 -38
- package/examples/ccxt.pro/js/watch-many-exchanges-many-symbols.js +0 -40
- package/examples/ccxt.pro/js/watch-many-orderbooks.js +0 -27
- package/examples/ccxt.pro/js/watch-new-trades-only.js +0 -43
- package/examples/ccxt.pro/js/watch-new-trades.js +0 -42
- package/examples/ccxt.pro/js/watch-trades-many-symbols.js +0 -29
- package/examples/ccxt.pro/js/watch-vs-fetch.js +0 -29
- package/examples/cs/Examples.sln +0 -22
- package/examples/cs/c#.csproj +0 -19
- package/examples/html/basic-cors-proxy.html +0 -46
- package/examples/html/basic-inheritance.html +0 -47
- package/examples/html/basic-poller.html +0 -52
- package/examples/html/basic-rate-limiting.html +0 -49
- package/examples/html/basic.html +0 -43
- package/examples/html/binance-cors-proxy.html +0 -28
- package/examples/html/bitmex-browser-cors-proxy.js +0 -7
- package/examples/html/bitmex-cors.html +0 -46
- package/examples/html/tradingview-charts.html +0 -61
- package/examples/html/webworker/index.html +0 -97
- package/examples/html/webworker/worker.js +0 -43
- package/examples/js/advanced-error-handling.js +0 -39
- package/examples/js/aggregate-orderbook.js +0 -54
- package/examples/js/arbitrage-pairs.js +0 -130
- package/examples/js/basic-chart.js +0 -29
- package/examples/js/basic-orderbook-polling.js +0 -13
- package/examples/js/bcc-vs-bch.js +0 -115
- package/examples/js/benchmark.js +0 -104
- package/examples/js/binance-fetch-all-deposits.js +0 -45
- package/examples/js/binance-fetch-ohlcv-many-symbols-async-await.js +0 -34
- package/examples/js/binance-fetch-ohlcv-many-symbols-promise-then-callbacks.js +0 -33
- package/examples/js/binance-fetchTicker-delivery-vs-future.js +0 -31
- package/examples/js/binance-futures-transfer-from-sub-account-to-master.js +0 -41
- package/examples/js/binance-margin-stop-order.js +0 -39
- package/examples/js/binance-server-time.js +0 -34
- package/examples/js/binance-universal-transfer.js +0 -16
- package/examples/js/bitfinex-fetch-trades.js +0 -35
- package/examples/js/bitfinex2-fetch-trades.js +0 -35
- package/examples/js/bitmex-browser-cors-proxy.js +0 -7
- package/examples/js/bitpanda-fetchMyTrades-reduce.js +0 -36
- package/examples/js/bitrue-fetch-balance.js +0 -28
- package/examples/js/bitstamp-private-api.js +0 -115
- package/examples/js/bitstamp-public-api.js +0 -39
- package/examples/js/bittrex-balance.js +0 -50
- package/examples/js/bittrex-fetch-closed-orders-history.js +0 -69
- package/examples/js/blockchaincom-withdrawal.js +0 -59
- package/examples/js/build-ohlcv-bars.js +0 -48
- package/examples/js/builtin-rate-limiting-rest-poller.js +0 -25
- package/examples/js/bybit-trailing.js +0 -62
- package/examples/js/bybit-updated.cjs +0 -154
- package/examples/js/coinbase-fetch-all-balances.js +0 -36
- package/examples/js/coinex-fetch-all-deposit-addresses-using-fetchDepositAddress.js +0 -47
- package/examples/js/coinex-futures.js +0 -75
- package/examples/js/coinone-fetch-tickers.js +0 -54
- package/examples/js/coinone-markets.js +0 -16
- package/examples/js/compare-two-exchanges-capabilities.js +0 -36
- package/examples/js/cors-proxy.js +0 -5
- package/examples/js/create-order-handle-errors.js +0 -55
- package/examples/js/create-order-position-with-takeprofit-stoploss.js +0 -71
- package/examples/js/create-order-with-retry.js +0 -65
- package/examples/js/create-order-ws-example.js +0 -25
- package/examples/js/create-orders-example.js +0 -17
- package/examples/js/create-trailing-amount-order.js +0 -36
- package/examples/js/create-trailing-percent-order.js +0 -36
- package/examples/js/credentials.json +0 -5
- package/examples/js/custom-proxy-agent-for-js.js +0 -10
- package/examples/js/custom-proxy-url.js +0 -23
- package/examples/js/delta-maintenance-margin-rate-max-leverage.js +0 -60
- package/examples/js/env-variables.js +0 -26
- package/examples/js/error-handling.js +0 -89
- package/examples/js/exchange-capabilities.js +0 -135
- package/examples/js/exchanges-by-volume.js +0 -60
- package/examples/js/exchanges.js +0 -40
- package/examples/js/fetch-all-balances.js +0 -219
- package/examples/js/fetch-all-tickers-to-files-2.js +0 -53
- package/examples/js/fetch-all-tickers-to-files.js +0 -77
- package/examples/js/fetch-balance.js +0 -28
- package/examples/js/fetch-create-deposit-address.js +0 -101
- package/examples/js/fetch-from-many-exchanges-simultaneously.js +0 -21
- package/examples/js/fetch-funding-rate-history.js +0 -25
- package/examples/js/fetch-futures/prettier.config.js +0 -5
- package/examples/js/fetch-futures/src/index.js +0 -25
- package/examples/js/fetch-ohlcv-from-to-mark-index-premium.js +0 -72
- package/examples/js/fetch-ohlcv-many-exchanges-continuosly.js +0 -39
- package/examples/js/fetch-ohlcv.js +0 -16
- package/examples/js/fetch-okex-futures.js +0 -22
- package/examples/js/fetch-orders.js +0 -27
- package/examples/js/fetch-ticker-from-multiple-exchanges.js +0 -35
- package/examples/js/fetch-ticker-where-available.js +0 -75
- package/examples/js/fetch-tickers/build/index.js +0 -19
- package/examples/js/fetch-tickers/prettier.config.js +0 -5
- package/examples/js/fetch-tickers/src/index.js +0 -17
- package/examples/js/gateio-create-batch-order.js +0 -43
- package/examples/js/gateio-futures.js +0 -49
- package/examples/js/gateio-open-close-contract.js +0 -49
- package/examples/js/gateio-swaps.js +0 -74
- package/examples/js/gdax-fetch-trades-pagination.js +0 -29
- package/examples/js/hitbtc2-withdraw.js +0 -61
- package/examples/js/how-to-import-one-exchange-esm.js +0 -10
- package/examples/js/huobi-futures.js +0 -71
- package/examples/js/huobi-open-close-contract.js +0 -63
- package/examples/js/huobi-swaps.js +0 -70
- package/examples/js/huobipro-market-buy-sell-fetch-trading-limits.js +0 -98
- package/examples/js/hybridCJSExample.cjs +0 -19
- package/examples/js/hybridESMExample.js +0 -19
- package/examples/js/idex-fetch-balance.js +0 -13
- package/examples/js/instantiate-all-at-once.js +0 -46
- package/examples/js/instantiate-all-from-json.js +0 -31
- package/examples/js/kraken-create-and-close-position.js +0 -54
- package/examples/js/kraken-fetch-order-trades.js +0 -33
- package/examples/js/kraken-margin-trading.js +0 -89
- package/examples/js/kucoin-rate-limit.js +0 -38
- package/examples/js/latoken-example.js +0 -108
- package/examples/js/live-orderbook.js +0 -106
- package/examples/js/live-ticker.js +0 -80
- package/examples/js/live-tickers.js +0 -74
- package/examples/js/load-all-contracts.js +0 -41
- package/examples/js/load-all-symbols-at-once.js +0 -69
- package/examples/js/load-all-tickers-at-once.js +0 -91
- package/examples/js/load-markets-to-files.js +0 -57
- package/examples/js/looping-over-all-symbols-of-specific-exchanges.js +0 -61
- package/examples/js/looping-over-specific-symbols-of-all-exchanges.js +0 -91
- package/examples/js/margin-loan-borrow-buy-sell-repay.js +0 -70
- package/examples/js/market-status-and-currency-status.js +0 -29
- package/examples/js/ohlcv-console-chart.js +0 -29
- package/examples/js/okex-fetch-closed-orders-archive.js +0 -31
- package/examples/js/okex-transfer.js +0 -51
- package/examples/js/okx-poll-fetch-my-trades.js +0 -37
- package/examples/js/okx-poll-rate-limit.js +0 -48
- package/examples/js/order-book-extra-level-depth-param.js +0 -20
- package/examples/js/phemex-create-order-position-with-takeprofit-stoploss.js +0 -49
- package/examples/js/poll-ohlcv.js +0 -43
- package/examples/js/poloniex-fetch-order-books.js +0 -35
- package/examples/js/poloniex-limits-amount-min.js +0 -62
- package/examples/js/proxy-round-robin.js +0 -98
- package/examples/js/proxy-usage.js +0 -32
- package/examples/js/sample-local-proxy-server-with-cors.js +0 -12
- package/examples/js/search-all-exchanges.js +0 -159
- package/examples/js/shared-load-markets.js +0 -80
- package/examples/js/sort-swap-markets-by-hourly-price-change.js +0 -55
- package/examples/js/symbols.js +0 -110
- package/examples/js/theocean.js +0 -41
- package/examples/js/tickers.js +0 -106
- package/examples/js/validate-paginated-data.js +0 -61
- package/examples/js/watch-OHLCV-For-Symbols.js +0 -15
- package/examples/js/watch-OHLCV.js +0 -12
- package/examples/js/watch-OrderBook-For-Symbols.js +0 -11
- package/examples/js/watch-Trades-For-Symbols.js +0 -11
- package/examples/js/watch-tickers.js +0 -11
- package/examples/js/watchOHLCVForSymbols.js +0 -15
- package/examples/js/watchOrderBookForSymbols.js +0 -11
- package/examples/js/watchPositions-many-exchanges-continuosly.d.ts +0 -2
- package/examples/js/watchPositions-many-exchanges-continuosly.d.ts.map +0 -1
- package/examples/js/watchPositions-many-exchanges-continuosly.js +0 -49
- package/examples/js/watchPositions.d.ts +0 -2
- package/examples/js/watchPositions.d.ts.map +0 -1
- package/examples/js/watchPositions.js +0 -13
- package/examples/js/watchPositionsForSymbols.d.ts +0 -2
- package/examples/js/watchPositionsForSymbols.d.ts.map +0 -1
- package/examples/js/watchPositionsForSymbols.js +0 -14
- package/examples/js/watchTradesForSymbols.js +0 -11
- package/examples/js/withdraw-from-one-exchange-to-another.js +0 -50
- package/examples/php/README.md +0 -7
- package/examples/py/README.md +0 -15
- package/examples/py/playing_with_ccxt_example.ipynb +0 -222
- package/examples/ts/.eslintrc +0 -111
- package/examples/ts/benchmark.ts +0 -134
- package/examples/ts/build-ohlcv-bars.ts +0 -53
- package/examples/ts/cli.ts +0 -397
- package/examples/ts/compare-two-exchanges-capabilities.ts +0 -36
- package/examples/ts/create-order-position-with-takeprofit-stoploss.ts +0 -89
- package/examples/ts/create-order-ws-example.ts +0 -33
- package/examples/ts/create-orders-example.ts +0 -21
- package/examples/ts/create-trailing-amount-order.ts +0 -37
- package/examples/ts/create-trailing-percent-order.ts +0 -37
- package/examples/ts/custom-proxy-agent-for-js.ts +0 -14
- package/examples/ts/fetch-futures/package-lock.json +0 -116
- package/examples/ts/fetch-futures/package.json +0 -34
- package/examples/ts/fetch-futures/prettier.config.js +0 -4
- package/examples/ts/fetch-futures/src/index.ts +0 -28
- package/examples/ts/fetch-futures/tsconfig.json +0 -28
- package/examples/ts/fetch-ohlcv-many-exchanges-continuosly.ts +0 -44
- package/examples/ts/fetch-ohlcv.ts +0 -17
- package/examples/ts/fetch-tickers/package-lock.json +0 -116
- package/examples/ts/fetch-tickers/package.json +0 -34
- package/examples/ts/fetch-tickers/prettier.config.js +0 -4
- package/examples/ts/fetch-tickers/src/index.ts +0 -21
- package/examples/ts/fetch-tickers/tsconfig.json +0 -28
- package/examples/ts/how-to-import-one-exchange-esm.ts +0 -11
- package/examples/ts/kraken-create-and-close-position.ts +0 -69
- package/examples/ts/margin-loan-borrow-buy-sell-repay.ts +0 -72
- package/examples/ts/nextjs-page-router/.eslintrc.json +0 -3
- package/examples/ts/nextjs-page-router/README.md +0 -43
- package/examples/ts/nextjs-page-router/next.config.js +0 -6
- package/examples/ts/nextjs-page-router/package-lock.json +0 -7425
- package/examples/ts/nextjs-page-router/package.json +0 -28
- package/examples/ts/nextjs-page-router/postcss.config.js +0 -6
- package/examples/ts/nextjs-page-router/public/favicon.ico +0 -0
- package/examples/ts/nextjs-page-router/src/pages/_app.tsx +0 -6
- package/examples/ts/nextjs-page-router/src/pages/_document.tsx +0 -13
- package/examples/ts/nextjs-page-router/src/pages/balance.tsx +0 -46
- package/examples/ts/nextjs-page-router/src/pages/index.tsx +0 -8
- package/examples/ts/nextjs-page-router/src/pages/tickers.tsx +0 -61
- package/examples/ts/nextjs-page-router/src/styles/globals.css +0 -27
- package/examples/ts/nextjs-page-router/tailwind.config.ts +0 -20
- package/examples/ts/nextjs-page-router/tsconfig.json +0 -22
- package/examples/ts/phemex-create-order-position-with-takeprofit-stoploss.ts +0 -62
- package/examples/ts/proxy-usage.ts +0 -41
- package/examples/ts/sample-local-proxy-server-with-cors.ts +0 -15
- package/examples/ts/watch-OHLCV-For-Symbols.ts +0 -17
- package/examples/ts/watch-OHLCV.ts +0 -14
- package/examples/ts/watch-OrderBook-For-Symbols.ts +0 -13
- package/examples/ts/watch-Trades-For-Symbols.ts +0 -13
- package/examples/ts/watch-tickers.ts +0 -13
- package/examples/ts/watchPositions-many-exchanges-continuosly.ts +0 -53
- package/examples/ts/watchPositions.ts +0 -15
- package/examples/ts/watchPositionsForSymbols.ts +0 -16
- package/examples/tsconfig.json +0 -27
- package/examples2md.js +0 -79
- package/gource.sh +0 -3
- package/index.html +0 -7
- package/jsdoc2md.js +0 -122
- package/multilang.sh +0 -164
- package/pro-tests.json +0 -57
- package/pyproject.toml +0 -8
- package/rollup.config.js +0 -60
- package/skip-tests.json +0 -1653
- package/test-commonjs.cjs +0 -65
- package/tests-manager.sh +0 -96
- package/tsconfig.json +0 -111
- package/webpack.config.js +0 -46
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import { PAD_WITH_ZERO } from '../../js/src/base/functions/number.js';
|
|
2
|
-
|
|
3
|
-
//-----------------------------------------------------------------------------
|
|
4
|
-
|
|
5
|
-
import ccxt from '../../js/ccxt.js';
|
|
6
|
-
|
|
7
|
-
import fs from 'fs';
|
|
8
|
-
import path from 'path';
|
|
9
|
-
import ansicolor from 'ansicolor';
|
|
10
|
-
import asTable from 'as-table';
|
|
11
|
-
import ololog from 'ololog';
|
|
12
|
-
|
|
13
|
-
ansicolor.nice
|
|
14
|
-
//-----------------------------------------------------------------------------
|
|
15
|
-
|
|
16
|
-
const table = asTable.configure ({
|
|
17
|
-
delimiter: '|'.lightGray.dim,
|
|
18
|
-
right: true,
|
|
19
|
-
title: x => String (x).lightGray,
|
|
20
|
-
print: x => {
|
|
21
|
-
if (typeof x === 'object') {
|
|
22
|
-
const j = JSON.stringify (x).trim ()
|
|
23
|
-
if (j.length < 100) return j
|
|
24
|
-
}
|
|
25
|
-
return String (x)
|
|
26
|
-
}
|
|
27
|
-
}),
|
|
28
|
-
{ ROUND, DECIMAL_PLACES, decimalToPrecision, omit, unique, flatten, extend } = ccxt,
|
|
29
|
-
log = ololog.handleNodeErrors ().noLocate.unlimited;
|
|
30
|
-
|
|
31
|
-
//-----------------------------------------------------------------------------
|
|
32
|
-
|
|
33
|
-
// set up keys and settings, if any
|
|
34
|
-
const keysGlobal = path.resolve ('keys.json')
|
|
35
|
-
const keysLocal = path.resolve ('keys.local.json')
|
|
36
|
-
|
|
37
|
-
const keysGlobalExists = fs.existsSync (keysGlobal)
|
|
38
|
-
const keysLocalExists = fs.existsSync (keysLocal)
|
|
39
|
-
|
|
40
|
-
if (!(keysGlobalExists || keysLocalExists)) {
|
|
41
|
-
const lines = [
|
|
42
|
-
'This script requires a keys.json or a keys.local.json file containing the API keys in JSON format',
|
|
43
|
-
'{',
|
|
44
|
-
' "binance": {',
|
|
45
|
-
' "apiKey": "YOUR_API_KEY",',
|
|
46
|
-
' "secret": "YOUR_SECRET"',
|
|
47
|
-
' }',
|
|
48
|
-
' "bitfinex": {',
|
|
49
|
-
' "apiKey": "YOUR_API_KEY",',
|
|
50
|
-
' "secret": "YOUR_SECRET"',
|
|
51
|
-
' }',
|
|
52
|
-
'}'
|
|
53
|
-
]
|
|
54
|
-
const errorMessage = lines.join ("\n")
|
|
55
|
-
log.red.bright (errorMessage)
|
|
56
|
-
process.exit ()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
let globalKeysFile = keysGlobalExists ? keysGlobal : false
|
|
60
|
-
let localKeysFile = keysLocalExists ? keysLocal : globalKeysFile
|
|
61
|
-
const dynamicLocalKeysFile = JSON.parse (fs.readFileSync (localKeysFile));
|
|
62
|
-
let settings = localKeysFile ? (dynamicLocalKeysFile || {}) : {}
|
|
63
|
-
|
|
64
|
-
//-----------------------------------------------------------------------------
|
|
65
|
-
|
|
66
|
-
const timeout = 30000
|
|
67
|
-
|
|
68
|
-
const coins = [
|
|
69
|
-
'BTC',
|
|
70
|
-
'ETH',
|
|
71
|
-
'BNB',
|
|
72
|
-
'EUR',
|
|
73
|
-
'LTC',
|
|
74
|
-
'USD',
|
|
75
|
-
'USDC',
|
|
76
|
-
'USDT',
|
|
77
|
-
'BUSD',
|
|
78
|
-
'XRP',
|
|
79
|
-
'DOGE',
|
|
80
|
-
'YFI',
|
|
81
|
-
'LINK',
|
|
82
|
-
'XLM',
|
|
83
|
-
'ADA',
|
|
84
|
-
'SOL',
|
|
85
|
-
]
|
|
86
|
-
|
|
87
|
-
function initializeAllExchanges () {
|
|
88
|
-
let numErrors = 0
|
|
89
|
-
const ignore = [
|
|
90
|
-
'bcex',
|
|
91
|
-
'bitsane',
|
|
92
|
-
'chbtc',
|
|
93
|
-
'coinbasepro',
|
|
94
|
-
'jubi',
|
|
95
|
-
'hitbtc',
|
|
96
|
-
'bitstamp1',
|
|
97
|
-
'bitfinex2',
|
|
98
|
-
'upbit',
|
|
99
|
-
'huobipro',
|
|
100
|
-
]
|
|
101
|
-
const result = []
|
|
102
|
-
ccxt.exchanges.filter (exchangeId => (!ignore.includes (exchangeId))).forEach (exchangeId => {
|
|
103
|
-
try {
|
|
104
|
-
const verbose = false
|
|
105
|
-
const exchange = new ccxt[exchangeId] ({
|
|
106
|
-
timeout,
|
|
107
|
-
verbose,
|
|
108
|
-
... (settings[exchangeId] || {})
|
|
109
|
-
})
|
|
110
|
-
exchange.checkRequiredCredentials ()
|
|
111
|
-
result.push (exchange)
|
|
112
|
-
} catch (e) {
|
|
113
|
-
numErrors++
|
|
114
|
-
log.red (exchangeId, 'initialization failed', e.constructor.name, e.message.slice (0, 100));
|
|
115
|
-
}
|
|
116
|
-
})
|
|
117
|
-
log ('Initialized', ccxt.exchanges.length - numErrors, 'of', ccxt.exchanges.length, 'exchanges,',
|
|
118
|
-
numErrors, 'error' + (((numErrors < 1) || (numErrors > 1)) ? 's' : '') + ',',
|
|
119
|
-
ignore.length, 'skipped')
|
|
120
|
-
return result
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
(async () => {
|
|
124
|
-
|
|
125
|
-
const exchanges = initializeAllExchanges ()
|
|
126
|
-
console.log (exchanges.map (exchange => exchange.id))
|
|
127
|
-
let results = []
|
|
128
|
-
const priceOracle = new ccxt.gate ()
|
|
129
|
-
const tickers = await priceOracle.fetchTickers ()
|
|
130
|
-
await Promise.all (exchanges.map ((exchange) => (async function () {
|
|
131
|
-
|
|
132
|
-
try {
|
|
133
|
-
|
|
134
|
-
if (exchange.has['signIn']) {
|
|
135
|
-
await exchange.signIn ()
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const balance = await exchange.fetchTotalBalance ()
|
|
139
|
-
if (!balance) {
|
|
140
|
-
throw new Error (exchange.id + ' erroneous balance')
|
|
141
|
-
}
|
|
142
|
-
const keys = Object.keys (balance).sort ()
|
|
143
|
-
const nonzeroBalance = {}
|
|
144
|
-
for (let i = 0; i < keys.length; i++) {
|
|
145
|
-
const key = keys[i]
|
|
146
|
-
if (coins.includes (key)) {
|
|
147
|
-
const value = balance[key]
|
|
148
|
-
const valueToPrecision = decimalToPrecision (value, ROUND, 8, DECIMAL_PLACES)
|
|
149
|
-
if (valueToPrecision !== '0') {
|
|
150
|
-
nonzeroBalance[key] = valueToPrecision
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
const numNonzeroKeys = Object.keys (nonzeroBalance).length
|
|
155
|
-
if (numNonzeroKeys < 1) {
|
|
156
|
-
log.yellow (exchange.id + ' empty balance')
|
|
157
|
-
} else {
|
|
158
|
-
log.green (exchange.id, numNonzeroKeys, 'currencies')
|
|
159
|
-
results.push ({ exchange: exchange.id, ... nonzeroBalance })
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
} catch (e) {
|
|
163
|
-
log.red (exchange.id, e.constructor.name, e.message.split ("\n")[0].slice (0, 100))
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
}) ()))
|
|
167
|
-
|
|
168
|
-
results = ccxt.sortBy (results, 'exchange')
|
|
169
|
-
|
|
170
|
-
const currencies = unique (flatten (results.map (result => Object.keys (omit (result, 'exchange')))))
|
|
171
|
-
currencies.sort ()
|
|
172
|
-
|
|
173
|
-
const total = {}
|
|
174
|
-
for (let i = 0; i < currencies.length; i++) {
|
|
175
|
-
const currency = currencies[i]
|
|
176
|
-
let sum = 0
|
|
177
|
-
results.forEach (result => {
|
|
178
|
-
if (currency in result) {
|
|
179
|
-
sum += parseFloat (result[currency])
|
|
180
|
-
}
|
|
181
|
-
})
|
|
182
|
-
total[currency] = decimalToPrecision (sum, ROUND, 8, DECIMAL_PLACES)
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
results.push (extend ({ 'exchange': 'total' }, total))
|
|
186
|
-
|
|
187
|
-
results = results.map (result => {
|
|
188
|
-
let value = 0;
|
|
189
|
-
const convertTo = 'USD'
|
|
190
|
-
currencies.forEach (currency => {
|
|
191
|
-
if (currency === convertTo) {
|
|
192
|
-
if (currency in result) {
|
|
193
|
-
value += parseFloat (result[currency])
|
|
194
|
-
}
|
|
195
|
-
} else {
|
|
196
|
-
const symbol = currency + '/' + convertTo
|
|
197
|
-
if (symbol in tickers) {
|
|
198
|
-
if (currency in result) {
|
|
199
|
-
const ticker = tickers[symbol]
|
|
200
|
-
value += parseFloat (result[currency]) * ticker['last']
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
})
|
|
205
|
-
return extend ({
|
|
206
|
-
'exchange': result.exchange,
|
|
207
|
-
'$': decimalToPrecision (value, ROUND, 2, DECIMAL_PLACES, PAD_WITH_ZERO),
|
|
208
|
-
}, result);
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
const tableResults = table (results)
|
|
212
|
-
|
|
213
|
-
log (tableResults)
|
|
214
|
-
|
|
215
|
-
log.green ('Currencies:', currencies)
|
|
216
|
-
|
|
217
|
-
console.log (new Date ())
|
|
218
|
-
|
|
219
|
-
}) ()
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import ccxt from '../../js/ccxt.js';
|
|
2
|
-
import { writeFileSync } from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
const enableRateLimit = true, exchanges = {}, tickers = {};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
ccxt.exchanges.forEach (id => {
|
|
9
|
-
try {
|
|
10
|
-
const exchange = new ccxt[id] ()
|
|
11
|
-
if (exchange.has['fetchTickers']) {
|
|
12
|
-
exchanges[id] = exchange
|
|
13
|
-
}
|
|
14
|
-
} catch (e) {
|
|
15
|
-
console.log ('Failed to initialize', id, e.constructor.name, e.message)
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
async function main () {
|
|
20
|
-
|
|
21
|
-
console.log ('Started')
|
|
22
|
-
const start = Date.now ()
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
const promises = Object.values (exchanges).map (exchange => (
|
|
26
|
-
(async () => {
|
|
27
|
-
console.log (exchange.id)
|
|
28
|
-
try {
|
|
29
|
-
const response = await exchange.fetchTickers ()
|
|
30
|
-
tickers[exchange.id] = response
|
|
31
|
-
} catch (e) {
|
|
32
|
-
console.log ('Failed to fetchTickers() from', exchange.id)
|
|
33
|
-
}
|
|
34
|
-
}) ()
|
|
35
|
-
))
|
|
36
|
-
await Promise.all (promises)
|
|
37
|
-
} catch (e) {
|
|
38
|
-
console.log ('Failed awaiting all exchanges to complete')
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
Object.entries (tickers).forEach (([ id, response ]) => {
|
|
42
|
-
const folder = 'C:/myproject/tickers'
|
|
43
|
-
const filename = `${id}-tickers.json`
|
|
44
|
-
console.log (path.join (folder, filename))
|
|
45
|
-
writeFileSync (path.join (folder, filename), JSON.stringify (response))
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
const end = Date.now ()
|
|
49
|
-
console.log (`Fetched tickers in ${(end - start) / 1000} seconds`)
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
main ()
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import ccxt from '../../js/ccxt.js';
|
|
4
|
-
import ololog from 'ololog';
|
|
5
|
-
|
|
6
|
-
const { noLocate } = ololog;
|
|
7
|
-
const log = noLocate;
|
|
8
|
-
|
|
9
|
-
import fs from 'fs';
|
|
10
|
-
|
|
11
|
-
// the numWorkers constant defines the number of concurrent workers
|
|
12
|
-
// those aren't really threads in terms of the async environment
|
|
13
|
-
// set this to the number of cores in your CPU * 2
|
|
14
|
-
// or play with this number to find a setting that works best for you
|
|
15
|
-
|
|
16
|
-
const numWorkers = 8;(async () => {
|
|
17
|
-
|
|
18
|
-
// make an array of all exchanges
|
|
19
|
-
const exchanges = ccxt.exchanges
|
|
20
|
-
|
|
21
|
-
// filter coinmarketcap and theocean
|
|
22
|
-
// coinmarketcap isn't really an exchange
|
|
23
|
-
// theocean requires web3 dependencies to be installed
|
|
24
|
-
|
|
25
|
-
.filter (id => ![ 'coinmarketcap', 'theocean' ].includes (id))
|
|
26
|
-
|
|
27
|
-
// instantiate each exchange and save it to the exchanges list
|
|
28
|
-
|
|
29
|
-
.map (id => new ccxt[id] ())
|
|
30
|
-
|
|
31
|
-
// the worker function for each "async thread"
|
|
32
|
-
const worker = async function () {
|
|
33
|
-
|
|
34
|
-
// while the array of all exchanges is not empty
|
|
35
|
-
while (exchanges.length > 0) {
|
|
36
|
-
|
|
37
|
-
// pop one exchange from the array
|
|
38
|
-
const exchange = exchanges.pop ()
|
|
39
|
-
|
|
40
|
-
// check if it has the necessary method implemented
|
|
41
|
-
if (exchange.has['fetchTickers']) {
|
|
42
|
-
|
|
43
|
-
// try to do "the work" and handle errors if any
|
|
44
|
-
try {
|
|
45
|
-
|
|
46
|
-
// fetch the response for all tickers from the exchange
|
|
47
|
-
const tickers = await exchange.fetchTickers ()
|
|
48
|
-
|
|
49
|
-
// make a filename from exchange id
|
|
50
|
-
const filename = exchange.id + '.json'
|
|
51
|
-
|
|
52
|
-
// save the response to a file
|
|
53
|
-
fs.writeFileSync (filename, JSON.stringify ({ tickers }));
|
|
54
|
-
|
|
55
|
-
// print out a message on success
|
|
56
|
-
log.green (exchange.id, 'tickers saved to', filename)
|
|
57
|
-
|
|
58
|
-
} catch (e) {
|
|
59
|
-
|
|
60
|
-
// in case of error - print it out and ignore it further
|
|
61
|
-
log.red (e.constructor.name, e.message)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
} else {
|
|
65
|
-
|
|
66
|
-
log.red (exchange.id, "has['fetchTickers'] = false");
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// create numWorkers "threads" (they aren't really threads)
|
|
72
|
-
const workers = [ ... Array (numWorkers) ].map (_ => worker ())
|
|
73
|
-
|
|
74
|
-
// wait for all of them to execute or fail
|
|
75
|
-
await Promise.all (workers)
|
|
76
|
-
|
|
77
|
-
}) ()
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const ccxt = require ('../../ccxt.js');
|
|
4
|
-
|
|
5
|
-
// instantiate the exchange
|
|
6
|
-
let exchange = new ccxt.coinbasepro ({
|
|
7
|
-
'apiKey': 'XXXXXXXXXXXXXX',
|
|
8
|
-
'secret': 'YYYYYYYYYYYYYY',
|
|
9
|
-
'password': 'ZZZZZZ', // if exchange requires password
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
async function checkMyBalance() {
|
|
14
|
-
try {
|
|
15
|
-
// fetch account balance from the exchange
|
|
16
|
-
let myBalance = await exchange.fetchBalance ();
|
|
17
|
-
|
|
18
|
-
// output the result
|
|
19
|
-
console.log (exchange.id, 'fetched balance', myBalance);
|
|
20
|
-
|
|
21
|
-
} catch (e) {
|
|
22
|
-
// fpr advanced error-handling, see the "advanced-error-handling.js" example file
|
|
23
|
-
console.log ('[' + e.constructor.name + '] ' + e.message);
|
|
24
|
-
throw e;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
checkMyBalance();
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
// ----------------------------------------------------------------------------
|
|
2
|
-
// setup
|
|
3
|
-
|
|
4
|
-
import ccxt from '../../js/ccxt.js';
|
|
5
|
-
|
|
6
|
-
// ----------------------------------------------------------------------------
|
|
7
|
-
// setup
|
|
8
|
-
|
|
9
|
-
const // change me
|
|
10
|
-
defaultCurrencyCode = 'BTC',
|
|
11
|
-
// change me
|
|
12
|
-
// currency code specified in commandline args ↓
|
|
13
|
-
// you can call this script like node examples/js/fetch-create-deposit-address ETH
|
|
14
|
-
exchangeId = 'poloniex',
|
|
15
|
-
currencyCode = process.argv[3] || defaultCurrencyCode,
|
|
16
|
-
exchange = new ccxt[exchangeId] ({
|
|
17
|
-
|
|
18
|
-
'apiKey': 'YOUR_API_KEY',
|
|
19
|
-
'secret': 'YOUR_SECRET',
|
|
20
|
-
|
|
21
|
-
'enableRateLimit': true, // ←- required! https://github.com/ccxt/ccxt/wiki/Manual#rate-limit
|
|
22
|
-
|
|
23
|
-
// 'verbose': true, // ←- uncomment this for verbose output
|
|
24
|
-
|
|
25
|
-
// additional credentials might be required in exchange-specific cases:
|
|
26
|
-
// uid or password for Coinbase Pro, etc...
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// ----------------------------------------------------------------------------
|
|
30
|
-
|
|
31
|
-
if (!exchange.has['fetchDepositAddress']) {
|
|
32
|
-
|
|
33
|
-
console.log ('The exchange does not support fetchDepositAddress() yet')
|
|
34
|
-
process.exit ()
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// ----------------------------------------------------------------------------
|
|
38
|
-
|
|
39
|
-
;(async () => {
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
|
|
43
|
-
console.log ('Trying to fetch deposit address for ' + currencyCode + ' from ' + exchangeId + '...')
|
|
44
|
-
|
|
45
|
-
let fetchResult = await exchange.fetchDepositAddress (currencyCode)
|
|
46
|
-
|
|
47
|
-
console.log ('Successfully fetched deposit address for ' + currencyCode)
|
|
48
|
-
console.log (fetchResult)
|
|
49
|
-
|
|
50
|
-
} catch (e) {
|
|
51
|
-
|
|
52
|
-
// never skip proper error handling, whatever it is you're building
|
|
53
|
-
// actually, with crypto error handling should be the largest part of your code
|
|
54
|
-
|
|
55
|
-
if (e instanceof ccxt.InvalidAddress) {
|
|
56
|
-
|
|
57
|
-
console.log ('The address for ' + currencyCode + ' does not exist yet')
|
|
58
|
-
|
|
59
|
-
if (exchange.has['createDepositAddress']) {
|
|
60
|
-
|
|
61
|
-
console.log ('Attempting to create a deposit address for ' + currencyCode + '...')
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
|
|
65
|
-
const createResult = await exchange.createDepositAddress (currencyCode)
|
|
66
|
-
|
|
67
|
-
// console.log (createResult) // for debugging
|
|
68
|
-
|
|
69
|
-
console.log ('Successfully created a deposit address for ' + currencyCode + ', fetching the deposit address now...')
|
|
70
|
-
|
|
71
|
-
try {
|
|
72
|
-
|
|
73
|
-
let fetchResult = await exchange.fetchDepositAddress (currencyCode)
|
|
74
|
-
|
|
75
|
-
console.log ('Successfully fetched deposit address for ' + currencyCode)
|
|
76
|
-
console.log (fetchResult);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
} catch (e) {
|
|
80
|
-
|
|
81
|
-
console.log ('Failed to fetch deposit address for ' + currencyCode, e.constructor.name, e.message)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
} catch (e) {
|
|
85
|
-
|
|
86
|
-
console.log ('Failed to create deposit address for ' + currencyCode, e.constructor.name, e.message)
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
} else {
|
|
91
|
-
|
|
92
|
-
console.log ('The exchange does not support createDepositAddress()')
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
} else {
|
|
96
|
-
|
|
97
|
-
console.log ('There was an error while fetching deposit address for ' + currencyCode, e.constructor.name, e.message)
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
}) ()
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import ccxt from '../../js/ccxt.js';
|
|
4
|
-
import log from 'ololog';
|
|
5
|
-
|
|
6
|
-
const symbol = 'ETH/BTC'
|
|
7
|
-
const exchanges = [ 'coinbasepro', 'hitbtc2', 'poloniex' ]
|
|
8
|
-
|
|
9
|
-
;(async () => {
|
|
10
|
-
|
|
11
|
-
const result = await Promise.all (exchanges.map (async id => {
|
|
12
|
-
|
|
13
|
-
const exchange = new ccxt[id] ()
|
|
14
|
-
const ticker = await exchange.fetchTicker (symbol)
|
|
15
|
-
return exchange.extend ({ 'exchange': id }, ticker)
|
|
16
|
-
|
|
17
|
-
}))
|
|
18
|
-
|
|
19
|
-
log (result);
|
|
20
|
-
|
|
21
|
-
}) ()
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import ccxt from '../../js/ccxt.js';
|
|
2
|
-
import asTable from 'as-table';
|
|
3
|
-
|
|
4
|
-
const table = asTable.configure ({ delimiter: ' | ' });
|
|
5
|
-
|
|
6
|
-
console.log ('CCXT Version:', ccxt.version)
|
|
7
|
-
|
|
8
|
-
async function main () {
|
|
9
|
-
|
|
10
|
-
const exchange = new ccxt.binanceusdm()
|
|
11
|
-
, symbol = 'ETH/USDT'
|
|
12
|
-
, since = undefined
|
|
13
|
-
, limit = undefined
|
|
14
|
-
, params = {}
|
|
15
|
-
|
|
16
|
-
// ------------------------------------------------------------------------
|
|
17
|
-
// fetch the history of the funding rate for a symbol
|
|
18
|
-
|
|
19
|
-
const response = await exchange.fetchFundingRateHistory (symbol, since, limit, params)
|
|
20
|
-
|
|
21
|
-
console.log (table (response))
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
main ()
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// Example code in typescript
|
|
2
|
-
// Based on /examples/js/fetch-okex-futures.js
|
|
3
|
-
import * as ccxt from 'ccxt';
|
|
4
|
-
const log = require('ololog');
|
|
5
|
-
const fetchFutures = async () => {
|
|
6
|
-
const exchange = new ccxt.bitmex();
|
|
7
|
-
exchange.markets = await exchange.loadMarkets(true);
|
|
8
|
-
for (let symbol in exchange.markets) {
|
|
9
|
-
log('----------------------------------------------------');
|
|
10
|
-
log(`symbol = ${symbol}`);
|
|
11
|
-
try {
|
|
12
|
-
const market = exchange.markets[symbol];
|
|
13
|
-
if (market['future']) {
|
|
14
|
-
const ticker = await exchange.fetchTicker(symbol);
|
|
15
|
-
log('----------------------------------------------------');
|
|
16
|
-
log(symbol, ticker);
|
|
17
|
-
await ccxt.sleep(exchange.rateLimit); // Missing type information.
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
log('error =', error);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
fetchFutures();
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const ccxt = require ('../../ccxt')
|
|
4
|
-
|
|
5
|
-
const exchange = new ccxt.binance ();
|
|
6
|
-
|
|
7
|
-
const symbols = [ 'BTC/USDT', 'ETH/USDT', 'ADA/USDT'];
|
|
8
|
-
// start from i.e. 01 february 2022
|
|
9
|
-
// you can use milliseconds integer or also parse uniform datetime string, i.e. exchange.parse8601 ('2020-02-01T00:00:00Z')
|
|
10
|
-
const fromTimestamp = 1643659200000;
|
|
11
|
-
const tillTimestamp = exchange.milliseconds ();
|
|
12
|
-
const timeframe = '1h';
|
|
13
|
-
const itemsLimit = 1000;
|
|
14
|
-
const fetchMethod = 'fetchOHLCV'; // if using swap exchanges, you can also use fetchMarkOHLCV, fetchIndexOHLCV, fetchPremiumIndexOHLCV
|
|
15
|
-
|
|
16
|
-
async function myDataFetch (symbol) {
|
|
17
|
-
|
|
18
|
-
await exchange.loadMarkets ();
|
|
19
|
-
|
|
20
|
-
// get the duration of one timeframe period in milliseconds
|
|
21
|
-
const duration = exchange.parseTimeframe (timeframe) * 1000;
|
|
22
|
-
console.log ('Fetching', symbol, timeframe, 'candles', 'from', exchange.iso8601 (fromTimestamp), 'to', exchange.iso8601 (tillTimestamp), '...');
|
|
23
|
-
|
|
24
|
-
let result = [];
|
|
25
|
-
let since = fromTimestamp;
|
|
26
|
-
do {
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
|
|
30
|
-
const candles = await exchange[fetchMethod] (symbol, timeframe, since, itemsLimit);
|
|
31
|
-
|
|
32
|
-
const message = '[' + symbol + '] Fetched ' + candles.length + ' ' + timeframe + ' candles since ' + exchange.iso8601 (since);
|
|
33
|
-
|
|
34
|
-
if (candles.length) {
|
|
35
|
-
|
|
36
|
-
const first = candles[0];
|
|
37
|
-
const last = candles[candles.length - 1];
|
|
38
|
-
console.log ( message, ' | first', exchange.iso8601 (first[0]), ' | last', exchange.iso8601 (last[0]) );
|
|
39
|
-
|
|
40
|
-
// store your candles to a database or to a file here
|
|
41
|
-
// ...
|
|
42
|
-
result = result.concat (candles);
|
|
43
|
-
since = last[0] + duration // next start from last candle timestamp + duration
|
|
44
|
-
|
|
45
|
-
} else {
|
|
46
|
-
console.log ( message, ' | moving into next period');
|
|
47
|
-
since = since + duration * itemsLimit; // next start from the current period's end
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
} catch (e) {
|
|
51
|
-
|
|
52
|
-
console.log (symbol, e.constructor.name, e.message, ' Taking small pause...');
|
|
53
|
-
await exchange.sleep (2000);
|
|
54
|
-
// retry on next iteration
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
} while (since + duration <= tillTimestamp)
|
|
58
|
-
|
|
59
|
-
console.log (symbol + ' completed !');
|
|
60
|
-
return result;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
async function checkAllSymbols() {
|
|
66
|
-
// download in parallel
|
|
67
|
-
await Promise.all (symbols.map (symbol => myDataFetch (symbol)));
|
|
68
|
-
// you can also do one by one (but that is not much optimal)
|
|
69
|
-
//for (const symbol of symbols) {
|
|
70
|
-
// const data = await myDataFetch (symbol);
|
|
71
|
-
}
|
|
72
|
-
checkAllSymbols();
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import ccxt from '../../js/ccxt.js';
|
|
2
|
-
// AUTO-TRANSPILE //
|
|
3
|
-
// fetch and handle constinuosly
|
|
4
|
-
async function fetchOHLCVContinuously(exchange, symbol) {
|
|
5
|
-
while (true) {
|
|
6
|
-
try {
|
|
7
|
-
const ohlcv = await exchange.fetchOHLCV(symbol);
|
|
8
|
-
const ohlcvLength = ohlcv.length;
|
|
9
|
-
console.log('Fetched ', exchange.id, ' - ', symbol, ' candles. last candle: ', ohlcv[ohlcvLength - 1]);
|
|
10
|
-
}
|
|
11
|
-
catch (e) {
|
|
12
|
-
console.log(e);
|
|
13
|
-
break;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
// start exchanges and fetch OHLCV loop
|
|
18
|
-
async function startExchange(exchangeName, symbols) {
|
|
19
|
-
const ex = new ccxt[exchangeName]({});
|
|
20
|
-
const promises = [];
|
|
21
|
-
for (let i = 0; i < symbols.length; i++) {
|
|
22
|
-
const symbol = symbols[i];
|
|
23
|
-
promises.push(fetchOHLCVContinuously(ex, symbol));
|
|
24
|
-
}
|
|
25
|
-
await Promise.all(promises);
|
|
26
|
-
await ex.close();
|
|
27
|
-
}
|
|
28
|
-
// main function
|
|
29
|
-
async function example() {
|
|
30
|
-
const exchanges = ['binance', 'okx', 'kraken'];
|
|
31
|
-
const symbols = ['BTC/USDT', 'ETH/USDT'];
|
|
32
|
-
const promises = [];
|
|
33
|
-
for (let i = 0; i < exchanges.length; i++) {
|
|
34
|
-
const exchangeName = exchanges[i];
|
|
35
|
-
promises.push(startExchange(exchangeName, symbols));
|
|
36
|
-
}
|
|
37
|
-
await Promise.all(promises);
|
|
38
|
-
}
|
|
39
|
-
await example();
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import ccxt from '../../js/ccxt.js';
|
|
2
|
-
// AUTO-TRANSPILE //
|
|
3
|
-
async function example() {
|
|
4
|
-
const myex = new ccxt.okx({});
|
|
5
|
-
const fromTimestamp = myex.milliseconds() - 86400 * 1000; // last 24 hrs
|
|
6
|
-
const ohlcv = await myex.fetchOHLCV('BTC/USDT', '1m', fromTimestamp, 3, { 'whatever': 123 });
|
|
7
|
-
const length = ohlcv.length;
|
|
8
|
-
if (length > 0) {
|
|
9
|
-
const lastPrice = ohlcv[length - 1][4];
|
|
10
|
-
console.log('Fetched ', length, ' candles for ', myex.id, ': last close ', lastPrice);
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
console.log('No candles have been fetched');
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
await example();
|