ccxt 4.2.72 → 4.2.74
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 +124 -122
- package/build.sh +2 -2
- package/dist/ccxt.browser.js +3277 -460
- package/dist/ccxt.browser.min.js +4 -4
- package/dist/cjs/ccxt.js +6 -1
- package/dist/cjs/src/abstract/coinbaseinternational.js +9 -0
- package/dist/cjs/src/base/Exchange.js +31 -7
- package/dist/cjs/src/bitget.js +62 -50
- package/dist/cjs/src/btcturk.js +3 -3
- package/dist/cjs/src/bybit.js +90 -30
- package/dist/cjs/src/coinbaseinternational.js +2019 -0
- package/dist/cjs/src/gate.js +1 -1
- package/dist/cjs/src/htx.js +16 -9
- package/dist/cjs/src/hyperliquid.js +9 -2
- package/dist/cjs/src/mexc.js +1 -1
- package/dist/cjs/src/okx.js +1 -1
- package/dist/cjs/src/pro/coinbaseinternational.js +645 -0
- package/dist/cjs/src/pro/krakenfutures.js +8 -7
- package/examples/README.md +308 -0
- package/examples/ccxt.pro/html/watchTicker.html +51 -0
- package/examples/ccxt.pro/js/binance-fetch-balance-snapshot-watch-balance-updates.js +55 -0
- package/examples/ccxt.pro/js/binance-https-proxy.js +48 -0
- package/examples/ccxt.pro/js/binance-watch-ohlcv-many-symbols-continuously.js +38 -0
- package/examples/ccxt.pro/js/binance-watch-ohlcv-many-symbols.js +64 -0
- package/examples/ccxt.pro/js/binance-watch-ticker-many-symbols.js +62 -0
- package/examples/ccxt.pro/js/build-ohlcv-many-symbols.js +68 -0
- package/examples/ccxt.pro/js/calculate-ohlcvs-from-trades-warmup.js +82 -0
- package/examples/ccxt.pro/js/calculate-ohlcvs-from-trades.js +59 -0
- package/examples/ccxt.pro/js/exchange-capabitities.js +72 -0
- package/examples/ccxt.pro/js/exchange-close.js +46 -0
- package/examples/ccxt.pro/js/gateio-swap-watch-many-orderbooks.js +30 -0
- package/examples/ccxt.pro/js/gateio-watch-balance.js +23 -0
- package/examples/ccxt.pro/js/gateio-watch-order-book.js +71 -0
- package/examples/ccxt.pro/js/graceful-shutdown.js +43 -0
- package/examples/ccxt.pro/js/many-exchanges-many-streams.js +37 -0
- package/examples/ccxt.pro/js/okex-create-futures-order.js +48 -0
- package/examples/ccxt.pro/js/okex-watch-balance-and-create-order.js +54 -0
- package/examples/ccxt.pro/js/okx-watch-tickers.js +31 -0
- package/examples/ccxt.pro/js/one-exchange-many-different-streams.js +46 -0
- package/examples/ccxt.pro/js/one-exchange-many-streams-2.js +26 -0
- package/examples/ccxt.pro/js/one-exchange-many-streams.js +28 -0
- package/examples/ccxt.pro/js/socks-binance-watch-orderbook.js +30 -0
- package/examples/ccxt.pro/js/watch-fetch-many-exchanges-many-ordersbooks.js +40 -0
- package/examples/ccxt.pro/js/watch-many-exchanges-many-ordersbooks.js +38 -0
- package/examples/ccxt.pro/js/watch-many-exchanges-many-symbols.js +40 -0
- package/examples/ccxt.pro/js/watch-many-orderbooks.js +27 -0
- package/examples/ccxt.pro/js/watch-new-trades-only.js +43 -0
- package/examples/ccxt.pro/js/watch-new-trades.js +42 -0
- package/examples/ccxt.pro/js/watch-trades-many-symbols.js +29 -0
- package/examples/ccxt.pro/js/watch-vs-fetch.js +29 -0
- package/examples/cs/Examples.sln +22 -0
- package/examples/cs/c#.csproj +19 -0
- package/examples/html/basic-cors-proxy.html +46 -0
- package/examples/html/basic-inheritance.html +47 -0
- package/examples/html/basic-poller.html +52 -0
- package/examples/html/basic-rate-limiting.html +49 -0
- package/examples/html/basic.html +43 -0
- package/examples/html/binance-cors-proxy.html +28 -0
- package/examples/html/bitmex-browser-cors-proxy.js +7 -0
- package/examples/html/bitmex-cors.html +46 -0
- package/examples/html/tradingview-charts.html +61 -0
- package/examples/html/webworker/index.html +97 -0
- package/examples/html/webworker/worker.js +43 -0
- package/examples/js/README.md +15 -0
- package/examples/js/advanced-error-handling.js +39 -0
- package/examples/js/aggregate-orderbook.js +54 -0
- package/examples/js/arbitrage-pairs.js +130 -0
- package/examples/js/basic-chart.js +29 -0
- package/examples/js/basic-orderbook-polling.js +13 -0
- package/examples/js/bcc-vs-bch.js +115 -0
- package/examples/js/binance-fetch-all-deposits.js +45 -0
- package/examples/js/binance-fetch-ohlcv-many-symbols-async-await.js +34 -0
- package/examples/js/binance-fetch-ohlcv-many-symbols-promise-then-callbacks.js +33 -0
- package/examples/js/binance-fetchTicker-delivery-vs-future.js +31 -0
- package/examples/js/binance-futures-transfer-from-sub-account-to-master.js +41 -0
- package/examples/js/binance-margin-stop-order.js +39 -0
- package/examples/js/binance-server-time.js +34 -0
- package/examples/js/binance-universal-transfer.js +16 -0
- package/examples/js/bitfinex-fetch-trades.js +35 -0
- package/examples/js/bitfinex2-fetch-trades.js +35 -0
- package/examples/js/bitmex-browser-cors-proxy.js +7 -0
- package/examples/js/bitpanda-fetchMyTrades-reduce.js +36 -0
- package/examples/js/bitrue-fetch-balance.js +28 -0
- package/examples/js/bitstamp-private-api.js +115 -0
- package/examples/js/bitstamp-public-api.js +39 -0
- package/examples/js/bittrex-balance.js +50 -0
- package/examples/js/bittrex-fetch-closed-orders-history.js +69 -0
- package/examples/js/blockchaincom-withdrawal.js +59 -0
- package/examples/js/build-ohlcv-bars.js +48 -0
- package/examples/js/builtin-rate-limiting-rest-poller.js +25 -0
- package/examples/js/bybit-trailing.js +62 -0
- package/examples/js/bybit-updated.cjs +154 -0
- package/examples/js/cli.js +405 -0
- package/examples/js/coinbase-fetch-all-balances.js +36 -0
- package/examples/js/coinex-fetch-all-deposit-addresses-using-fetchDepositAddress.js +47 -0
- package/examples/js/coinex-futures.js +75 -0
- package/examples/js/coinone-fetch-tickers.js +54 -0
- package/examples/js/coinone-markets.js +16 -0
- package/examples/js/compare-two-exchanges-capabilities.js +36 -0
- package/examples/js/cors-proxy.js +5 -0
- package/examples/js/create-order-handle-errors.js +55 -0
- package/examples/js/create-order-position-with-takeprofit-stoploss.js +71 -0
- package/examples/js/create-order-with-retry.js +65 -0
- package/examples/js/create-order-ws-example.js +25 -0
- package/examples/js/create-orders-example.js +17 -0
- package/examples/js/create-trailing-amount-order.js +36 -0
- package/examples/js/create-trailing-percent-order.js +36 -0
- package/examples/js/credentials.json +5 -0
- package/examples/js/custom-proxy-agent-for-js.js +10 -0
- package/examples/js/custom-proxy-url.js +23 -0
- package/examples/js/delta-maintenance-margin-rate-max-leverage.js +60 -0
- package/examples/js/env-variables.js +26 -0
- package/examples/js/error-handling.js +89 -0
- package/examples/js/exchange-capabilities.js +135 -0
- package/examples/js/exchanges-by-volume.js +60 -0
- package/examples/js/exchanges.js +40 -0
- package/examples/js/fetch-all-balances.js +219 -0
- package/examples/js/fetch-all-tickers-to-files-2.js +53 -0
- package/examples/js/fetch-all-tickers-to-files.js +77 -0
- package/examples/js/fetch-balance.js +28 -0
- package/examples/js/fetch-create-deposit-address.js +101 -0
- package/examples/js/fetch-from-many-exchanges-simultaneously.js +21 -0
- package/examples/js/fetch-funding-rate-history.js +25 -0
- package/examples/js/fetch-futures/prettier.config.js +5 -0
- package/examples/js/fetch-futures/src/index.js +25 -0
- package/examples/js/fetch-ohlcv-from-to-mark-index-premium.js +72 -0
- package/examples/js/fetch-ohlcv-many-exchanges-continuosly.js +39 -0
- package/examples/js/fetch-ohlcv.js +16 -0
- package/examples/js/fetch-okex-futures.js +22 -0
- package/examples/js/fetch-orders.js +27 -0
- package/examples/js/fetch-ticker-from-multiple-exchanges.js +35 -0
- package/examples/js/fetch-ticker-where-available.js +75 -0
- package/examples/js/fetch-tickers/build/index.js +19 -0
- package/examples/js/fetch-tickers/prettier.config.js +5 -0
- package/examples/js/fetch-tickers/src/index.js +17 -0
- package/examples/js/gateio-create-batch-order.js +43 -0
- package/examples/js/gateio-futures.js +49 -0
- package/examples/js/gateio-open-close-contract.js +49 -0
- package/examples/js/gateio-swaps.js +74 -0
- package/examples/js/gdax-fetch-trades-pagination.js +29 -0
- package/examples/js/hitbtc2-withdraw.js +61 -0
- package/examples/js/how-to-import-one-exchange-esm.js +10 -0
- package/examples/js/huobi-futures.js +71 -0
- package/examples/js/huobi-open-close-contract.js +63 -0
- package/examples/js/huobi-swaps.js +70 -0
- package/examples/js/huobipro-market-buy-sell-fetch-trading-limits.js +98 -0
- package/examples/js/hybridCJSExample.cjs +19 -0
- package/examples/js/hybridESMExample.js +19 -0
- package/examples/js/idex-fetch-balance.js +13 -0
- package/examples/js/instantiate-all-at-once.js +46 -0
- package/examples/js/instantiate-all-from-json.js +31 -0
- package/examples/js/kraken-create-and-close-position.js +54 -0
- package/examples/js/kraken-fetch-order-trades.js +33 -0
- package/examples/js/kraken-margin-trading.js +89 -0
- package/examples/js/kucoin-rate-limit.js +38 -0
- package/examples/js/latoken-example.js +108 -0
- package/examples/js/live-orderbook.js +106 -0
- package/examples/js/live-ticker.js +80 -0
- package/examples/js/live-tickers.js +74 -0
- package/examples/js/load-all-contracts.js +41 -0
- package/examples/js/load-all-symbols-at-once.js +69 -0
- package/examples/js/load-all-tickers-at-once.js +91 -0
- package/examples/js/load-markets-to-files.js +57 -0
- package/examples/js/looping-over-all-symbols-of-specific-exchanges.js +61 -0
- package/examples/js/looping-over-specific-symbols-of-all-exchanges.js +91 -0
- package/examples/js/margin-loan-borrow-buy-sell-repay.js +70 -0
- package/examples/js/market-status-and-currency-status.js +29 -0
- package/examples/js/ohlcv-console-chart.js +29 -0
- package/examples/js/okex-fetch-closed-orders-archive.js +31 -0
- package/examples/js/okex-transfer.js +51 -0
- package/examples/js/okx-poll-fetch-my-trades.js +37 -0
- package/examples/js/okx-poll-rate-limit.js +48 -0
- package/examples/js/order-book-extra-level-depth-param.js +20 -0
- package/examples/js/phemex-create-order-position-with-takeprofit-stoploss.js +49 -0
- package/examples/js/poll-ohlcv.js +43 -0
- package/examples/js/poloniex-fetch-order-books.js +35 -0
- package/examples/js/poloniex-limits-amount-min.js +62 -0
- package/examples/js/proxy-round-robin.js +98 -0
- package/examples/js/proxy-usage.js +32 -0
- package/examples/js/sample-local-proxy-server-with-cors.js +12 -0
- package/examples/js/search-all-exchanges.js +159 -0
- package/examples/js/shared-load-markets.js +80 -0
- package/examples/js/sort-swap-markets-by-hourly-price-change.js +55 -0
- package/examples/js/symbols.js +110 -0
- package/examples/js/theocean.js +41 -0
- package/examples/js/tickers.js +106 -0
- package/examples/js/validate-paginated-data.js +61 -0
- package/examples/js/watch-OHLCV-For-Symbols.js +15 -0
- package/examples/js/watch-OHLCV.js +12 -0
- package/examples/js/watch-OrderBook-For-Symbols.js +11 -0
- package/examples/js/watch-Trades-For-Symbols.js +11 -0
- package/examples/js/watch-tickers.js +11 -0
- package/examples/js/watchOHLCVForSymbols.js +15 -0
- package/examples/js/watchOrderBookForSymbols.js +11 -0
- package/examples/js/watchPositions-many-exchanges-continuosly.d.ts +2 -0
- package/examples/js/watchPositions-many-exchanges-continuosly.d.ts.map +1 -0
- package/examples/js/watchPositions-many-exchanges-continuosly.js +49 -0
- package/examples/js/watchPositions.d.ts +2 -0
- package/examples/js/watchPositions.d.ts.map +1 -0
- package/examples/js/watchPositions.js +13 -0
- package/examples/js/watchPositionsForSymbols.d.ts +2 -0
- package/examples/js/watchPositionsForSymbols.d.ts.map +1 -0
- package/examples/js/watchPositionsForSymbols.js +14 -0
- package/examples/js/watchTradesForSymbols.js +11 -0
- package/examples/js/withdraw-from-one-exchange-to-another.js +50 -0
- package/examples/php/README.md +7 -0
- package/examples/py/README.md +15 -0
- package/examples/py/playing_with_ccxt_example.ipynb +222 -0
- package/examples/ts/.eslintrc +111 -0
- package/examples/ts/build-ohlcv-bars.ts +53 -0
- package/examples/ts/cli.ts +397 -0
- package/examples/ts/compare-two-exchanges-capabilities.ts +36 -0
- package/examples/ts/create-order-position-with-takeprofit-stoploss.ts +89 -0
- package/examples/ts/create-order-ws-example.ts +33 -0
- package/examples/ts/create-orders-example.ts +21 -0
- package/examples/ts/create-trailing-amount-order.ts +37 -0
- package/examples/ts/create-trailing-percent-order.ts +37 -0
- package/examples/ts/custom-proxy-agent-for-js.ts +14 -0
- package/examples/ts/fetch-futures/package-lock.json +116 -0
- package/examples/ts/fetch-futures/package.json +34 -0
- package/examples/ts/fetch-futures/prettier.config.js +4 -0
- package/examples/ts/fetch-futures/src/index.ts +28 -0
- package/examples/ts/fetch-futures/tsconfig.json +28 -0
- package/examples/ts/fetch-ohlcv-many-exchanges-continuosly.ts +44 -0
- package/examples/ts/fetch-ohlcv.ts +17 -0
- package/examples/ts/fetch-tickers/package-lock.json +116 -0
- package/examples/ts/fetch-tickers/package.json +34 -0
- package/examples/ts/fetch-tickers/prettier.config.js +4 -0
- package/examples/ts/fetch-tickers/src/index.ts +21 -0
- package/examples/ts/fetch-tickers/tsconfig.json +28 -0
- package/examples/ts/how-to-import-one-exchange-esm.ts +11 -0
- package/examples/ts/kraken-create-and-close-position.ts +69 -0
- package/examples/ts/margin-loan-borrow-buy-sell-repay.ts +72 -0
- package/examples/ts/nextjs-page-router/.eslintrc.json +3 -0
- package/examples/ts/nextjs-page-router/README.md +43 -0
- package/examples/ts/nextjs-page-router/next.config.js +6 -0
- package/examples/ts/nextjs-page-router/package-lock.json +7425 -0
- package/examples/ts/nextjs-page-router/package.json +28 -0
- package/examples/ts/nextjs-page-router/postcss.config.js +6 -0
- package/examples/ts/nextjs-page-router/public/favicon.ico +0 -0
- package/examples/ts/nextjs-page-router/src/pages/_app.tsx +6 -0
- package/examples/ts/nextjs-page-router/src/pages/_document.tsx +13 -0
- package/examples/ts/nextjs-page-router/src/pages/balance.tsx +46 -0
- package/examples/ts/nextjs-page-router/src/pages/index.tsx +8 -0
- package/examples/ts/nextjs-page-router/src/pages/tickers.tsx +61 -0
- package/examples/ts/nextjs-page-router/src/styles/globals.css +27 -0
- package/examples/ts/nextjs-page-router/tailwind.config.ts +20 -0
- package/examples/ts/nextjs-page-router/tsconfig.json +22 -0
- package/examples/ts/phemex-create-order-position-with-takeprofit-stoploss.ts +62 -0
- package/examples/ts/proxy-usage.ts +41 -0
- package/examples/ts/sample-local-proxy-server-with-cors.ts +15 -0
- package/examples/ts/watch-OHLCV-For-Symbols.ts +17 -0
- package/examples/ts/watch-OHLCV.ts +14 -0
- package/examples/ts/watch-OrderBook-For-Symbols.ts +13 -0
- package/examples/ts/watch-Trades-For-Symbols.ts +13 -0
- package/examples/ts/watch-tickers.ts +13 -0
- package/examples/ts/watchPositions-many-exchanges-continuosly.ts +53 -0
- package/examples/ts/watchPositions.ts +15 -0
- package/examples/ts/watchPositionsForSymbols.ts +16 -0
- package/examples/tsconfig.json +27 -0
- package/js/ccxt.d.ts +8 -2
- package/js/ccxt.js +6 -2
- package/js/src/abstract/coinbaseinternational.d.ts +42 -0
- package/js/src/abstract/coinbaseinternational.js +11 -0
- package/js/src/ace.d.ts +2 -2
- package/js/src/alpaca.d.ts +2 -2
- package/js/src/ascendex.d.ts +3 -3
- package/js/src/base/Exchange.d.ts +27 -24
- package/js/src/base/Exchange.js +31 -7
- package/js/src/bigone.d.ts +2 -2
- package/js/src/binance.d.ts +7 -7
- package/js/src/bingx.d.ts +4 -4
- package/js/src/bit2c.d.ts +2 -2
- package/js/src/bitbank.d.ts +2 -2
- package/js/src/bitbns.d.ts +2 -2
- package/js/src/bitfinex.d.ts +3 -3
- package/js/src/bitfinex2.d.ts +4 -4
- package/js/src/bitflyer.d.ts +2 -2
- package/js/src/bitget.d.ts +4 -4
- package/js/src/bitget.js +62 -50
- package/js/src/bithumb.d.ts +2 -2
- package/js/src/bitmart.d.ts +4 -4
- package/js/src/bitmex.d.ts +3 -3
- package/js/src/bitopro.d.ts +2 -2
- package/js/src/bitrue.d.ts +2 -2
- package/js/src/bitso.d.ts +2 -2
- package/js/src/bitstamp.d.ts +2 -2
- package/js/src/bitteam.d.ts +2 -2
- package/js/src/bitvavo.d.ts +4 -4
- package/js/src/bl3p.d.ts +2 -2
- package/js/src/blockchaincom.d.ts +2 -2
- package/js/src/blofin.d.ts +4 -4
- package/js/src/btcalpha.d.ts +2 -2
- package/js/src/btcbox.d.ts +2 -2
- package/js/src/btcmarkets.d.ts +2 -2
- package/js/src/btcturk.d.ts +2 -2
- package/js/src/btcturk.js +3 -3
- package/js/src/bybit.d.ts +8 -6
- package/js/src/bybit.js +90 -30
- package/js/src/cex.d.ts +3 -3
- package/js/src/coinbase.d.ts +3 -3
- package/js/src/coinbaseinternational.d.ts +146 -0
- package/js/src/coinbaseinternational.js +2020 -0
- package/js/src/coinbasepro.d.ts +2 -2
- package/js/src/coincheck.d.ts +2 -2
- package/js/src/coinex.d.ts +4 -4
- package/js/src/coinlist.d.ts +3 -3
- package/js/src/coinmate.d.ts +2 -2
- package/js/src/coinmetro.d.ts +2 -2
- package/js/src/coinone.d.ts +2 -2
- package/js/src/coinsph.d.ts +2 -2
- package/js/src/coinspot.d.ts +2 -2
- package/js/src/cryptocom.d.ts +4 -4
- package/js/src/currencycom.d.ts +2 -2
- package/js/src/delta.d.ts +3 -3
- package/js/src/deribit.d.ts +3 -3
- package/js/src/digifinex.d.ts +3 -3
- package/js/src/exmo.d.ts +3 -3
- package/js/src/gate.d.ts +4 -4
- package/js/src/gate.js +1 -1
- package/js/src/gemini.d.ts +2 -2
- package/js/src/hitbtc.d.ts +4 -4
- package/js/src/hollaex.d.ts +2 -2
- package/js/src/htx.d.ts +5 -5
- package/js/src/htx.js +16 -9
- package/js/src/huobijp.d.ts +2 -2
- package/js/src/hyperliquid.d.ts +4 -3
- package/js/src/hyperliquid.js +10 -3
- package/js/src/idex.d.ts +2 -2
- package/js/src/independentreserve.d.ts +2 -2
- package/js/src/indodax.d.ts +2 -2
- package/js/src/kraken.d.ts +3 -3
- package/js/src/krakenfutures.d.ts +4 -4
- package/js/src/kucoin.d.ts +4 -4
- package/js/src/kucoinfutures.d.ts +3 -3
- package/js/src/kuna.d.ts +2 -2
- package/js/src/latoken.d.ts +2 -2
- package/js/src/lbank.d.ts +2 -2
- package/js/src/luno.d.ts +2 -2
- package/js/src/lykke.d.ts +2 -2
- package/js/src/mercado.d.ts +2 -2
- package/js/src/mexc.d.ts +2 -2
- package/js/src/mexc.js +1 -1
- package/js/src/ndax.d.ts +3 -3
- package/js/src/novadax.d.ts +2 -2
- package/js/src/oceanex.d.ts +2 -2
- package/js/src/okcoin.d.ts +3 -3
- package/js/src/okx.d.ts +4 -4
- package/js/src/okx.js +1 -1
- package/js/src/onetrading.d.ts +2 -2
- package/js/src/p2b.d.ts +2 -2
- package/js/src/paymium.d.ts +2 -2
- package/js/src/phemex.d.ts +3 -3
- package/js/src/poloniex.d.ts +3 -3
- package/js/src/poloniexfutures.d.ts +2 -2
- package/js/src/pro/binance.d.ts +3 -3
- package/js/src/pro/bitvavo.d.ts +3 -3
- package/js/src/pro/cex.d.ts +3 -3
- package/js/src/pro/coinbaseinternational.d.ts +28 -0
- package/js/src/pro/coinbaseinternational.js +646 -0
- package/js/src/pro/cryptocom.d.ts +2 -2
- package/js/src/pro/hitbtc.d.ts +2 -2
- package/js/src/pro/kraken.d.ts +3 -3
- package/js/src/pro/krakenfutures.js +8 -7
- package/js/src/pro/okx.d.ts +3 -3
- package/js/src/pro/poloniex.d.ts +2 -2
- package/js/src/probit.d.ts +2 -2
- package/js/src/timex.d.ts +3 -3
- package/js/src/tokocrypto.d.ts +2 -2
- package/js/src/upbit.d.ts +2 -2
- package/js/src/wavesexchange.d.ts +2 -2
- package/js/src/wazirx.d.ts +2 -2
- package/js/src/whitebit.d.ts +2 -2
- package/js/src/woo.d.ts +5 -5
- package/js/src/yobit.d.ts +2 -2
- package/js/src/zaif.d.ts +2 -2
- package/js/src/zonda.d.ts +2 -2
- package/package.json +4 -1
- package/skip-tests.json +227 -424
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import ccxt from '../../js/ccxt.js';
|
|
4
|
+
import asTable from 'as-table';
|
|
5
|
+
import ololog from 'ololog';
|
|
6
|
+
import ansicolor from 'ansicolor';
|
|
7
|
+
|
|
8
|
+
const log = ololog.configure ({ locate: false })
|
|
9
|
+
|
|
10
|
+
ansicolor.nice
|
|
11
|
+
|
|
12
|
+
//-----------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
// this script loads markets from all exchanges
|
|
15
|
+
// if it cannot connect to an exchange, it falls back to an alternative route via proxy
|
|
16
|
+
// it will retry to load a exchange until it either reaches the exchange or runs out of proxies
|
|
17
|
+
|
|
18
|
+
//-----------------------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
process.on ('uncaughtException', e => { log.bright.red.error (e); process.exit (1) })
|
|
21
|
+
process.on ('unhandledRejection', e => { log.bright.red.error (e); process.exit (1) })
|
|
22
|
+
|
|
23
|
+
//-----------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
let loadExchange = async exchange => {
|
|
26
|
+
await exchange.loadMarkets ()
|
|
27
|
+
log (exchange.id.green, 'loaded',
|
|
28
|
+
exchange.symbols.length.toString ().bright.green, 'symbols',
|
|
29
|
+
(exchange.proxy ? exchange.proxy : '_').blue)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//-----------------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
let tryAllProxies = async function (exchange, proxies) {
|
|
35
|
+
|
|
36
|
+
let currentProxy = 0
|
|
37
|
+
let maxRetries = proxies.length
|
|
38
|
+
|
|
39
|
+
// a special case for ccex
|
|
40
|
+
if (exchange.id == 'ccex')
|
|
41
|
+
currentProxy = 1
|
|
42
|
+
|
|
43
|
+
for (let numRetries = 0; numRetries < maxRetries; numRetries++) {
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
|
|
47
|
+
exchange.proxy = proxies[currentProxy]
|
|
48
|
+
await loadExchange (exchange)
|
|
49
|
+
break
|
|
50
|
+
|
|
51
|
+
} catch (e) {
|
|
52
|
+
|
|
53
|
+
currentProxy = ++currentProxy % proxies.length
|
|
54
|
+
if (e instanceof ccxt.DDoSProtection) {
|
|
55
|
+
log.bright.yellow (exchange.id, '[DDoS Protection] ' + e.message)
|
|
56
|
+
} else if (e instanceof ccxt.RequestTimeout) {
|
|
57
|
+
log.bright.yellow (exchange.id, '[Request Timeout] ' + e.message)
|
|
58
|
+
} else if (e instanceof ccxt.AuthenticationError) {
|
|
59
|
+
log.bright.yellow (exchange.id, '[Authentication Error] ' + e.message)
|
|
60
|
+
} else if (e instanceof ccxt.ExchangeNotAvailable) {
|
|
61
|
+
log.bright.yellow (exchange.id, '[Exchange Not Available] ' + e.message)
|
|
62
|
+
} else if (e instanceof ccxt.ExchangeError) {
|
|
63
|
+
log.bright.yellow (exchange.id, '[Exchange Error] ' + e.message)
|
|
64
|
+
} else if (e instanceof ccxt.NetworkError) {
|
|
65
|
+
log.bright.yellow (exchange.id, '[Network Error] ' + e.message)
|
|
66
|
+
} else {
|
|
67
|
+
throw e;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//-----------------------------------------------------------------------------
|
|
75
|
+
|
|
76
|
+
let proxies = [
|
|
77
|
+
'',
|
|
78
|
+
'https://cors-anywhere.herokuapp.com/',
|
|
79
|
+
'https://crossorigin.me/',
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
let exchanges = []
|
|
83
|
+
|
|
84
|
+
async function main () {
|
|
85
|
+
// instantiate all exchanges
|
|
86
|
+
await Promise.all (ccxt.exchanges.map (async id => {
|
|
87
|
+
let exchange = new (ccxt)[id] ()
|
|
88
|
+
exchanges.push (exchange)
|
|
89
|
+
await tryAllProxies (exchange, proxies)
|
|
90
|
+
}))
|
|
91
|
+
|
|
92
|
+
let succeeded = exchanges.filter (exchange => exchange.markets ? true : false).length.toString ().bright.green
|
|
93
|
+
let failed = exchanges.filter (exchange => exchange.markets ? false : true).length
|
|
94
|
+
let total = ccxt.exchanges.length.toString ().bright.white
|
|
95
|
+
console.log (succeeded, 'of', total, 'exchanges loaded', ('(' + failed + ' errors)').red)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
main ()
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import ccxt from '../../js/ccxt.js';
|
|
2
|
+
// AUTO-TRANSPILE //
|
|
3
|
+
// ABOUT CCXT PROXIES, READ MORE AT: https://docs.ccxt.com/#/README?id=proxy
|
|
4
|
+
async function example_proxyUrl() {
|
|
5
|
+
const myEx = new ccxt.kucoin();
|
|
6
|
+
myEx.proxyUrl = 'http://5.75.153.75:8090/proxy_url.php?caller=https://ccxt.com&url=';
|
|
7
|
+
console.log(await myEx.fetch('https://api.ipify.org/'));
|
|
8
|
+
}
|
|
9
|
+
async function example_httpProxy() {
|
|
10
|
+
const myEx = new ccxt.kucoin();
|
|
11
|
+
myEx.httpProxy = 'http://5.75.153.75:8002'; // "httpProxy" or "httpsProxy" (depending on your proxy protocol)
|
|
12
|
+
console.log(await myEx.fetch('https://api.ipify.org/'));
|
|
13
|
+
}
|
|
14
|
+
async function example_socksProxy() {
|
|
15
|
+
const myEx = new ccxt.kucoin();
|
|
16
|
+
myEx.socksProxy = 'socks5://127.0.0.1:1080'; // from protocols: socks, socks5, socks5h
|
|
17
|
+
console.log(await myEx.fetch('https://api.ipify.org/'));
|
|
18
|
+
}
|
|
19
|
+
async function example_webSockets() {
|
|
20
|
+
const myEx = new ccxt.pro.kucoin();
|
|
21
|
+
myEx.httpProxy = 'http://5.75.153.75:8002'; // even though you are using WebSockets, you might also need to set up proxy for the exchange's REST requests
|
|
22
|
+
myEx.wsProxy = 'http://5.75.153.75:8002'; // "wsProxy" or "wssProxy" or "wsSocksProxy" (depending on your proxy protocol)
|
|
23
|
+
await myEx.loadMarkets();
|
|
24
|
+
while (true) {
|
|
25
|
+
const ticker = await myEx.watchTicker('BTC/USDT');
|
|
26
|
+
console.log(ticker);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
await example_proxyUrl();
|
|
30
|
+
// await example_httpProxy ();
|
|
31
|
+
// await example_socksProxy ();
|
|
32
|
+
// await example_webSockets ();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// JavaScript sample Proxy with CORS support
|
|
3
|
+
// Save this in a file like cors.js and run with:
|
|
4
|
+
// node cors [port]
|
|
5
|
+
// It will listen for your requests on the port you pass in command line (or port 8080 by default)
|
|
6
|
+
import cors from 'cors-anywhere'; // npm install cors-anywhere
|
|
7
|
+
const port = (process.argv.length > 2) ? parseInt(process.argv[2]) : 8080; // if not provided from cli, default to 8080
|
|
8
|
+
cors.createServer({
|
|
9
|
+
// you can set origin, if needed by exchange
|
|
10
|
+
// setHeaders: { 'origin': 'https://www.bitmex.com' }
|
|
11
|
+
}).listen(port, 'localhost');
|
|
12
|
+
console.log('Running CORS Anywhere on localhost:' + port);
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import asTable from 'as-table';
|
|
2
|
+
import ololog from 'ololog';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import ansicolor from 'ansicolor';
|
|
6
|
+
import ccxt from '../../js/ccxt.js';
|
|
7
|
+
|
|
8
|
+
const { noLocate } = ololog;
|
|
9
|
+
const log = noLocate;
|
|
10
|
+
|
|
11
|
+
ansicolor.nice
|
|
12
|
+
/* ------------------------------------------------------------------------ */
|
|
13
|
+
|
|
14
|
+
const [processPath, , argument = null] = process.argv.filter (x => !x.startsWith ('--'))
|
|
15
|
+
, verbose = process.argv.includes ('--verbose')
|
|
16
|
+
, strict = process.argv.includes ('--strict')
|
|
17
|
+
, compact = process.argv.includes ('--compact')
|
|
18
|
+
, debug = process.argv.includes ('--debug')
|
|
19
|
+
, marketsOnly = process.argv.includes ('--markets')
|
|
20
|
+
, currenciesOnly = process.argv.includes ('--currencies')
|
|
21
|
+
|
|
22
|
+
/* ------------------------------------------------------------------------ */
|
|
23
|
+
|
|
24
|
+
const warn = log.bright.yellow.error // .error → stderr
|
|
25
|
+
|
|
26
|
+
/* ------------------------------------------------------------------------ */
|
|
27
|
+
|
|
28
|
+
process.on ('uncaughtException', e => { log.bright.red.error (e); process.exit (1) })
|
|
29
|
+
process.on ('unhandledRejection', e => { log.bright.red.error (e); process.exit (1) })
|
|
30
|
+
|
|
31
|
+
/* ------------------------------------------------------------------------ */
|
|
32
|
+
|
|
33
|
+
let printUsage = function () {
|
|
34
|
+
log (' Non-strict search: node', process.argv[1], 'symbol'.green)
|
|
35
|
+
log (' Non-strict search: node', process.argv[1], 'currency'.green)
|
|
36
|
+
log (' Strict search: node', process.argv[1], '--strict', 'argument'.green)
|
|
37
|
+
log (' Search markets only: node', process.argv[1], '--markets', 'argument'.green)
|
|
38
|
+
log ('Search currencies only: node', process.argv[1], '--currencies', 'argument'.green)
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (process.argv.length < 3) {
|
|
43
|
+
printUsage ()
|
|
44
|
+
process.exit ()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* ------------------------------------------------------------------------ */
|
|
48
|
+
|
|
49
|
+
const keysGlobal = path.resolve ('keys.json')
|
|
50
|
+
const keysLocal = path.resolve ('keys.local.json')
|
|
51
|
+
let globalKeysFile = fs.existsSync (keysGlobal) ? keysGlobal : false
|
|
52
|
+
let localKeysFile = fs.existsSync (keysLocal) ? keysLocal : globalKeysFile
|
|
53
|
+
|
|
54
|
+
const keys = JSON.parse (fs.readFileSync (localKeysFile))
|
|
55
|
+
|
|
56
|
+
/* ------------------------------------------------------------------------ */
|
|
57
|
+
|
|
58
|
+
log ('Looking up for:', argument.bright, strict ? '(strict search)' : '(non-strict search)')
|
|
59
|
+
|
|
60
|
+
const checkAgainst = strict ?
|
|
61
|
+
(a, b) => (a || '').toUpperCase ().includes ((b || '').toUpperCase ()) :
|
|
62
|
+
(a, b) => (a || '').toLowerCase ().includes ((b || '').toLowerCase ())
|
|
63
|
+
|
|
64
|
+
;(async function test () {
|
|
65
|
+
|
|
66
|
+
let exchanges = await Promise.all (ccxt.exchanges.map (async id => {
|
|
67
|
+
|
|
68
|
+
// instantiate the exchange
|
|
69
|
+
let exchange = new ccxt[id] (ccxt.extend (localKeysFile ? (keys[id] || {}) : {}, {
|
|
70
|
+
// agent, // set up keys and settings, if any
|
|
71
|
+
}))
|
|
72
|
+
|
|
73
|
+
if (exchange.has.fetchMarkets) {
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
|
|
77
|
+
// load markets
|
|
78
|
+
await exchange.loadMarkets ()
|
|
79
|
+
return exchange
|
|
80
|
+
|
|
81
|
+
} catch (e) {
|
|
82
|
+
|
|
83
|
+
if (debug) {
|
|
84
|
+
log.red (exchange.id, e.constructor.name)
|
|
85
|
+
}
|
|
86
|
+
return undefined
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}))
|
|
90
|
+
|
|
91
|
+
// filter out exchanges that failed to load
|
|
92
|
+
exchanges = exchanges.filter (exchange => exchange)
|
|
93
|
+
|
|
94
|
+
if (!currenciesOnly) {
|
|
95
|
+
|
|
96
|
+
log ("---------------------------------------------------------------")
|
|
97
|
+
|
|
98
|
+
log ("Markets And Symbols:")
|
|
99
|
+
|
|
100
|
+
let markets = ccxt.flatten (exchanges
|
|
101
|
+
.map (exchange =>
|
|
102
|
+
Object.values (exchange.markets).map (market =>
|
|
103
|
+
exchange.extend (market, {
|
|
104
|
+
exchange: exchange.id[(market.active !== false) ? 'green' : 'yellow'],
|
|
105
|
+
}))))
|
|
106
|
+
.filter (market => {
|
|
107
|
+
try {
|
|
108
|
+
return (
|
|
109
|
+
checkAgainst (market['base'], argument) ||
|
|
110
|
+
checkAgainst (market['quote'], argument) ||
|
|
111
|
+
(market['baseId'] ? checkAgainst (market['baseId'].toString (), argument) : false) ||
|
|
112
|
+
(market['quoteId'] ? checkAgainst (market['quoteId'].toString (), argument) : false) ||
|
|
113
|
+
checkAgainst (market['symbol'], argument) ||
|
|
114
|
+
checkAgainst (market['id'].toString (), argument) ||
|
|
115
|
+
checkAgainst (market['type'], argument)
|
|
116
|
+
)
|
|
117
|
+
} catch (e) {
|
|
118
|
+
if (debug) {
|
|
119
|
+
log.red (e.constructor.name, e.message)
|
|
120
|
+
}
|
|
121
|
+
return false
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
log (asTable (markets.map (market => {
|
|
126
|
+
market = ccxt.omit (market, [ 'info', 'limits', 'precision', 'tiers' ])
|
|
127
|
+
return (!compact) ? market : {
|
|
128
|
+
'symbol': market['symbol'],
|
|
129
|
+
'exchange': market['exchange'],
|
|
130
|
+
};
|
|
131
|
+
})))
|
|
132
|
+
|
|
133
|
+
log (markets.length.toString ().yellow, 'markets')
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (!marketsOnly) {
|
|
137
|
+
|
|
138
|
+
log ("---------------------------------------------------------------")
|
|
139
|
+
|
|
140
|
+
log ("Currencies:")
|
|
141
|
+
|
|
142
|
+
let currencies = ccxt.flatten (exchanges
|
|
143
|
+
.map (exchange =>
|
|
144
|
+
Object.values (exchange.currencies).map (currency =>
|
|
145
|
+
exchange.extend (currency, {
|
|
146
|
+
exchange: exchange.id[(currency.active !== false) ? 'green' : 'yellow'],
|
|
147
|
+
}))))
|
|
148
|
+
.filter (currency =>
|
|
149
|
+
checkAgainst (currency['code'], argument) ||
|
|
150
|
+
checkAgainst (currency['id'], argument))
|
|
151
|
+
|
|
152
|
+
log (asTable (currencies.map (currency => ccxt.omit (currency, [ 'info', 'limits', 'precision' ]))))
|
|
153
|
+
|
|
154
|
+
log (currencies.length.toString ().yellow, 'currencies')
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
process.exit ()
|
|
158
|
+
|
|
159
|
+
}) ()
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import ccxt from '../../js/ccxt.js';
|
|
2
|
+
|
|
3
|
+
// ----------------------------------------------------------------------------
|
|
4
|
+
// an example of how to load markets for each exchange just once
|
|
5
|
+
// in order to save memory and time for initializing multiple exchange instances
|
|
6
|
+
// see https://github.com/ccxt/ccxt/issues/7312 for details
|
|
7
|
+
// ----------------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
const globalIds = [ 'binance', 'poloniex', 'bittrex', 'bitstamp' ]
|
|
10
|
+
const globalExchanges = {}
|
|
11
|
+
|
|
12
|
+
async function loadExchange (id) {
|
|
13
|
+
try {
|
|
14
|
+
const exchange = new ccxt[id] ()
|
|
15
|
+
await exchange.loadMarkets ()
|
|
16
|
+
globalExchanges[id] = exchange
|
|
17
|
+
} catch (e) {
|
|
18
|
+
// throw e // uncomment to break the entire program on any error
|
|
19
|
+
// console.log (e) // print the exception and ignore this exchange
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function main () {
|
|
24
|
+
|
|
25
|
+
// initialize unique global exchange instances first
|
|
26
|
+
await Promise.all (globalIds.map (async (id) => loadExchange (id)))
|
|
27
|
+
console.log ('Loaded global exchanges:', Object.keys (globalExchanges))
|
|
28
|
+
|
|
29
|
+
// load user exchanges and keys from a database or configure these via JSON
|
|
30
|
+
const users = {
|
|
31
|
+
'user1': {
|
|
32
|
+
'binance': { 'apiKey': 'USER1_BINANCE_API_KEY', 'secret': 'USER1_BINANCE_SECRET' },
|
|
33
|
+
'poloniex': { 'apiKey': 'USER1_POLONIEX_API_KEY', 'secret': 'USER1_POLONIEX_SECRET' }
|
|
34
|
+
},
|
|
35
|
+
'user2': {
|
|
36
|
+
'poloniex': { 'apiKey': 'USER2_POLONIEX_API_KEY', 'secret': 'USER2_POLONIEX_SECRET' },
|
|
37
|
+
'bittrex': { 'apiKey': 'USER2_BITTREX_API_KEY', 'secret': 'USER2_BITTREX_SECRET' }
|
|
38
|
+
},
|
|
39
|
+
'user3': {
|
|
40
|
+
'bittrex': { 'apiKey': 'USER3_BITTREX_API_KEY', 'secret': 'USER3_BITTREX_SECRET' },
|
|
41
|
+
'bitstamp': { 'apiKey': 'USER3_BITSTAMP_API_KEY', 'secret': 'USER3_BITSTAMP_SECRET' }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// initialize local exchanges per user
|
|
46
|
+
const localExchanges = {}
|
|
47
|
+
for (const userId in users) {
|
|
48
|
+
const userExchanges = {}
|
|
49
|
+
for (const exchangeId in users[userId]) {
|
|
50
|
+
if (exchangeId in globalExchanges) {
|
|
51
|
+
const globalExchange = globalExchanges[exchangeId]
|
|
52
|
+
const exchange = new ccxt[exchangeId] ({
|
|
53
|
+
// 'verbose': true, // uncomment for debug output
|
|
54
|
+
... users[userId][exchangeId],
|
|
55
|
+
});
|
|
56
|
+
[
|
|
57
|
+
'ids',
|
|
58
|
+
'markets',
|
|
59
|
+
'markets_by_id',
|
|
60
|
+
'currencies',
|
|
61
|
+
'currencies_by_id',
|
|
62
|
+
'baseCurrencies',
|
|
63
|
+
'quoteCurrencies',
|
|
64
|
+
'symbols',
|
|
65
|
+
].forEach ((propertyName) => {
|
|
66
|
+
exchange[propertyName] = globalExchange[propertyName]
|
|
67
|
+
})
|
|
68
|
+
userExchanges[exchangeId] = exchange
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
localExchanges[userId] = userExchanges
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// print the loaded exchanges per user
|
|
75
|
+
for (const userId in localExchanges) {
|
|
76
|
+
console.log ('Loaded', userId, Object.keys (localExchanges[userId]))
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
main ()
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const ccxt = require ('../../ccxt.js');
|
|
4
|
+
|
|
5
|
+
const exchange = new ccxt.binanceusdm ();
|
|
6
|
+
const timeframe = '1h';
|
|
7
|
+
const type = 'swap';
|
|
8
|
+
|
|
9
|
+
async function fetchOHLCV (symbol) {
|
|
10
|
+
/**
|
|
11
|
+
* @description Wrapper around exchange.fetchOHLCV method
|
|
12
|
+
* @param {string} symbol CCXT unified symbol
|
|
13
|
+
* @returns {[float|str]} 1d array with a single ohlcv record with the market symbol appended
|
|
14
|
+
*/
|
|
15
|
+
try {
|
|
16
|
+
const ohlcv = await exchange.fetchOHLCV (symbol, timeframe, undefined, 1);
|
|
17
|
+
ohlcv[0].push (symbol);
|
|
18
|
+
return ohlcv[0];
|
|
19
|
+
} catch (err) {
|
|
20
|
+
console.log (symbol + ' failed fetchOHLCV with error ' + err)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getPriceChangePercent (ohlcv) {
|
|
25
|
+
/**
|
|
26
|
+
* @description Gets the price change of a market as a percentage
|
|
27
|
+
* @param {[float]} ohlcv A single ohlcv record with the market symbol appended
|
|
28
|
+
* @returns {[float, str]} The price change as a percent with the symbol for the market
|
|
29
|
+
*/
|
|
30
|
+
const open = ohlcv[1];
|
|
31
|
+
const close = ohlcv[4];
|
|
32
|
+
const symbol = ohlcv[6];
|
|
33
|
+
const priceIncrease = close - open;
|
|
34
|
+
const increaseAsRatio = priceIncrease / open;
|
|
35
|
+
const increaseAsPercent = increaseAsRatio * 100;
|
|
36
|
+
return [increaseAsPercent, symbol]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function sort (a, b) {
|
|
40
|
+
return a[0] - b[0];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function main () {
|
|
44
|
+
/**
|
|
45
|
+
* @description Gets the price change as a percent of every market matching type over the last timeframe matching timeframe and prints a sorted list. The most immediate candle is ignored because it is incomplete
|
|
46
|
+
*/
|
|
47
|
+
await exchange.loadMarkets ();
|
|
48
|
+
const allSwapSymbols = exchange.symbols.filter (symbol => exchange.market (symbol)[type] );
|
|
49
|
+
const ohlcvs = await Promise.all (allSwapSymbols.map (symbol => fetchOHLCV (symbol)));
|
|
50
|
+
const priceChanges = ohlcvs.map (ohlcv => getPriceChangePercent (ohlcv));
|
|
51
|
+
const sorted = priceChanges.sort (sort);
|
|
52
|
+
console.dir(sorted, {'maxArrayLength': null})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
main ()
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import ccxt from '../../js/ccxt.js';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import ololog from 'ololog';
|
|
6
|
+
import ansicolor from 'ansicolor';
|
|
7
|
+
import asTable from 'as-table';
|
|
8
|
+
|
|
9
|
+
const { noLocate } = ololog;
|
|
10
|
+
const log = noLocate;
|
|
11
|
+
|
|
12
|
+
ansicolor.nice
|
|
13
|
+
const table = asTable.configure ({ delimiter: ' | ' }), verbose = process.argv.includes ('--verbose'), debug = process.argv.includes ('--debug');
|
|
14
|
+
|
|
15
|
+
//-----------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
let printSupportedExchanges = function () {
|
|
18
|
+
log ('Supported exchanges:', ccxt.exchanges.join (', ').green)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let printUsage = function () {
|
|
22
|
+
log ('Usage: node', process.argv[1], 'id'.green)
|
|
23
|
+
printSupportedExchanges ()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let printSymbols = async (id) => {
|
|
27
|
+
|
|
28
|
+
// check if the exchange is supported by ccxt
|
|
29
|
+
let exchangeFound = ccxt.exchanges.indexOf (id) > -1
|
|
30
|
+
if (exchangeFound) {
|
|
31
|
+
|
|
32
|
+
log ('Instantiating', id.green, 'exchange')
|
|
33
|
+
|
|
34
|
+
// set up keys and settings, if any
|
|
35
|
+
const keysGlobal = 'keys.json'
|
|
36
|
+
const keysLocal = 'keys.local.json'
|
|
37
|
+
|
|
38
|
+
let keysFile = fs.existsSync (keysLocal) ? keysLocal : (fs.existsSync (keysGlobal) ? keysGlobal : false)
|
|
39
|
+
let settings = keysFile ? (require ('../../' + keysFile)[id] || {}) : {}
|
|
40
|
+
|
|
41
|
+
// instantiate the exchange by id
|
|
42
|
+
let exchange = new ccxt[id] (ccxt.extend ({
|
|
43
|
+
verbose,
|
|
44
|
+
// 'proxy': 'https://cors-anywhere.herokuapp.com/',
|
|
45
|
+
// 'proxy': 'https://crossorigin.me/',
|
|
46
|
+
}, settings))
|
|
47
|
+
|
|
48
|
+
// Object.assign (exchange, settings)
|
|
49
|
+
|
|
50
|
+
// load all markets from the exchange
|
|
51
|
+
let markets = await exchange.loadMarkets ()
|
|
52
|
+
|
|
53
|
+
// debug log
|
|
54
|
+
if (debug)
|
|
55
|
+
Object.values (markets).forEach (market => log (market))
|
|
56
|
+
|
|
57
|
+
log ("\nSymbols:\n")
|
|
58
|
+
|
|
59
|
+
// make a table of all markets
|
|
60
|
+
|
|
61
|
+
const marketsList =
|
|
62
|
+
ccxt.sortBy (Object.values (markets), 'symbol')
|
|
63
|
+
.map (market =>
|
|
64
|
+
ccxt.omit (market, [ 'info', 'limits', 'precision', 'fees' ]))
|
|
65
|
+
|
|
66
|
+
let table = table (marketsList)
|
|
67
|
+
log (table)
|
|
68
|
+
|
|
69
|
+
log ("\n---------------------------------------------------------------")
|
|
70
|
+
|
|
71
|
+
log ("\nCurrencies:\n")
|
|
72
|
+
|
|
73
|
+
// make a table of all currencies
|
|
74
|
+
|
|
75
|
+
const currenciesList =
|
|
76
|
+
ccxt.sortBy (Object.values (exchange.currencies), 'code')
|
|
77
|
+
.map (currency =>
|
|
78
|
+
ccxt.omit (currency, [ 'info', 'limits' ]))
|
|
79
|
+
|
|
80
|
+
const currenciesTable = table (currenciesList)
|
|
81
|
+
log (currenciesTable)
|
|
82
|
+
|
|
83
|
+
log ("\n---------------------------------------------------------------")
|
|
84
|
+
|
|
85
|
+
// output a summary
|
|
86
|
+
log (id.green, 'has', exchange.symbols.length.toString ().yellow, 'symbols and',
|
|
87
|
+
Object.keys (exchange.currencies).length.toString ().yellow, "currencies\n")
|
|
88
|
+
|
|
89
|
+
} else {
|
|
90
|
+
|
|
91
|
+
log ('Exchange ' + id.red + ' not found')
|
|
92
|
+
printSupportedExchanges ()
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
;(async function main () {
|
|
97
|
+
|
|
98
|
+
if (process.argv.length > 2) {
|
|
99
|
+
|
|
100
|
+
let id = process.argv[2]
|
|
101
|
+
await printSymbols (id)
|
|
102
|
+
|
|
103
|
+
} else {
|
|
104
|
+
|
|
105
|
+
printUsage ()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
process.exit ()
|
|
109
|
+
|
|
110
|
+
}) ()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import ccxt from '../../js/ccxt.js';
|
|
4
|
+
(async function main () {
|
|
5
|
+
const walletAddress = process.env['WALLET_ADDRESS']
|
|
6
|
+
const privateKey = process.env['PRIVATE_KEY']
|
|
7
|
+
const apiKey = process.env['API_KEY']
|
|
8
|
+
const secret = process.env['SECRET']
|
|
9
|
+
|
|
10
|
+
const ocean = new ccxt.theocean({
|
|
11
|
+
walletAddress,
|
|
12
|
+
privateKey,
|
|
13
|
+
apiKey,
|
|
14
|
+
secret
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// get balance
|
|
18
|
+
const balance = await ocean.fetchBalanceByCode('REP');
|
|
19
|
+
console.log('REP balance: ', balance);
|
|
20
|
+
|
|
21
|
+
// get order book
|
|
22
|
+
const orderBook = await ocean.fetchOrderBook('REP/ZRX');
|
|
23
|
+
console.log('REP/ZRX orderbook: ', orderBook);
|
|
24
|
+
|
|
25
|
+
// placing order
|
|
26
|
+
const placeResult = await ocean.createOrder('REP/ZRX', 'limit', 'sell', '0.5', '30');
|
|
27
|
+
const id = placeResult['id'];
|
|
28
|
+
console.log('result of placing order: ', placeResult);
|
|
29
|
+
|
|
30
|
+
// cancel order
|
|
31
|
+
if (placeResult['remaining'] > 0) {
|
|
32
|
+
const cancelResult = await ocean.cancelOrder(id);
|
|
33
|
+
console.log('cancel result: ', cancelResult);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// cancel all open user orders
|
|
37
|
+
const cancelAllOrderssResult = await ocean.cancelAllOrders();
|
|
38
|
+
console.log('cancel all orders result: ', cancelAllOrderssResult);
|
|
39
|
+
|
|
40
|
+
process.exit ();
|
|
41
|
+
}) ()
|