ccxt 4.2.73 → 4.2.75
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/CHANGELOG.md +206 -10
- package/README.md +10 -9
- package/build.sh +1 -1
- package/dist/ccxt.browser.js +1042 -297
- package/dist/ccxt.browser.min.js +3 -3
- package/dist/cjs/ccxt.js +4 -1
- package/dist/cjs/src/abstract/tradeogre.js +9 -0
- package/dist/cjs/src/ascendex.js +3 -2
- package/dist/cjs/src/base/Exchange.js +1 -1
- package/dist/cjs/src/bitget.js +62 -50
- package/dist/cjs/src/bitmart.js +1 -0
- package/dist/cjs/src/bybit.js +90 -30
- package/dist/cjs/src/coinbaseinternational.js +1 -1
- package/dist/cjs/src/coinex.js +4 -3
- package/dist/cjs/src/gate.js +1 -0
- package/dist/cjs/src/htx.js +16 -9
- package/dist/cjs/src/hyperliquid.js +2 -1
- package/dist/cjs/src/kraken.js +3 -3
- package/dist/cjs/src/kucoin.js +1 -1
- package/dist/cjs/src/pro/krakenfutures.js +8 -7
- package/dist/cjs/src/tradeogre.js +632 -0
- 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 +5 -2
- package/js/ccxt.js +4 -2
- package/js/src/abstract/tradeogre.d.ts +19 -0
- package/js/src/abstract/tradeogre.js +11 -0
- package/js/src/ascendex.d.ts +2 -7
- package/js/src/ascendex.js +3 -2
- package/js/src/base/Exchange.d.ts +7 -7
- package/js/src/base/Exchange.js +1 -1
- package/js/src/base/types.d.ts +7 -1
- package/js/src/binance.d.ts +1 -1
- package/js/src/bitget.js +62 -50
- package/js/src/bitmart.d.ts +1 -1
- package/js/src/bitmart.js +2 -1
- package/js/src/bybit.d.ts +3 -1
- package/js/src/bybit.js +90 -30
- package/js/src/coinbase.d.ts +4 -4
- package/js/src/coinbaseinternational.d.ts +1 -1
- package/js/src/coinbaseinternational.js +1 -1
- package/js/src/coinbasepro.d.ts +2 -2
- package/js/src/coinex.js +4 -3
- package/js/src/coinlist.d.ts +2 -2
- package/js/src/cryptocom.d.ts +2 -2
- package/js/src/currencycom.d.ts +2 -2
- package/js/src/deribit.d.ts +2 -2
- package/js/src/gate.d.ts +1 -1
- package/js/src/gate.js +1 -0
- package/js/src/htx.d.ts +2 -2
- package/js/src/htx.js +16 -9
- package/js/src/huobijp.d.ts +2 -2
- package/js/src/hyperliquid.js +2 -1
- package/js/src/kraken.d.ts +1 -1
- package/js/src/kraken.js +3 -3
- package/js/src/kucoin.d.ts +3 -3
- package/js/src/kucoin.js +1 -1
- package/js/src/luno.d.ts +2 -2
- package/js/src/mexc.d.ts +3 -3
- package/js/src/ndax.d.ts +2 -2
- package/js/src/novadax.d.ts +2 -2
- package/js/src/okx.d.ts +2 -2
- package/js/src/pro/bitfinex2.d.ts +1 -1
- package/js/src/pro/krakenfutures.js +8 -7
- package/js/src/tradeogre.d.ts +32 -0
- package/js/src/tradeogre.js +633 -0
- package/js/src/woo.d.ts +2 -2
- package/package.json +4 -1
- package/skip-tests.json +219 -424
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
import ccxt from '../../js/ccxt.js';
|
|
3
|
+
import log from 'ololog';
|
|
4
|
+
import asTable from 'as-table';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const table = asTable.configure ({ delimiter: ' | ' }), id = 'bitstamp', exchange = new ccxt[id] ({ enableRateLimit: true }), symbol = 'BTC/USD';(async function main () {
|
|
8
|
+
|
|
9
|
+
// Markets data
|
|
10
|
+
const markets = await exchange.fetchMarkets ()
|
|
11
|
+
console.log('Total number of markets: ', Object.keys(markets).length);
|
|
12
|
+
|
|
13
|
+
// Currencies
|
|
14
|
+
const currencies = await exchange.fetchCurrencies ()
|
|
15
|
+
console.log('Currencies: ', JSON.stringify(currencies));
|
|
16
|
+
|
|
17
|
+
// Order book data
|
|
18
|
+
const orderbook = await exchange.fetchOrderBook (symbol)
|
|
19
|
+
console.log ('Order book ', symbol, orderbook.asks[0], orderbook.bids[0])
|
|
20
|
+
|
|
21
|
+
// Ticker
|
|
22
|
+
const ticker = await exchange.fetchTicker (symbol)
|
|
23
|
+
console.log ('Ticker ', symbol, " bid ", ticker.bid, " ask ", ticker.ask)
|
|
24
|
+
|
|
25
|
+
// Trades
|
|
26
|
+
const response = await exchange.fetchTrades (symbol, null, 10)
|
|
27
|
+
log (table (response))
|
|
28
|
+
|
|
29
|
+
// OHLC data
|
|
30
|
+
const candles = await exchange.fetchOHLCV (symbol, '1m', undefined, 10);
|
|
31
|
+
const first = candles[0]
|
|
32
|
+
const last = candles[candles.length - 1]
|
|
33
|
+
console.log (
|
|
34
|
+
'Fetched', candles.length, symbol, 'candles',
|
|
35
|
+
'from', exchange.iso8601 (first[0]),
|
|
36
|
+
'to', exchange.iso8601 (last[0])
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
}) ()
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import ccxt from '../../js/ccxt.js';
|
|
4
|
+
import asTable from 'as-table';
|
|
5
|
+
import ansicolor from 'ansicolor';
|
|
6
|
+
import ololog from 'ololog'
|
|
7
|
+
|
|
8
|
+
const log = ololog.configure ({ locate: false })
|
|
9
|
+
|
|
10
|
+
ansicolor.nice
|
|
11
|
+
|
|
12
|
+
let sleep = (ms) => new Promise (resolve => setTimeout (resolve, ms))
|
|
13
|
+
|
|
14
|
+
;(async () => {
|
|
15
|
+
|
|
16
|
+
// instantiate the exchange
|
|
17
|
+
let exchange = new ccxt.bittrex ({
|
|
18
|
+
"apiKey": "471b47a06c384e81b24072e9a8739064",
|
|
19
|
+
"secret": "694025686e9445589787e8ca212b4cff",
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
|
|
25
|
+
// fetch account balance from the exchange
|
|
26
|
+
let balance = await exchange.fetchBalance ()
|
|
27
|
+
|
|
28
|
+
// output the result
|
|
29
|
+
log (exchange.name.green, 'balance', balance)
|
|
30
|
+
|
|
31
|
+
} catch (e) {
|
|
32
|
+
|
|
33
|
+
if (e instanceof ccxt.DDoSProtection || e.message.includes ('ECONNRESET')) {
|
|
34
|
+
log.bright.yellow ('[DDoS Protection] ' + e.message)
|
|
35
|
+
} else if (e instanceof ccxt.RequestTimeout) {
|
|
36
|
+
log.bright.yellow ('[Request Timeout] ' + e.message)
|
|
37
|
+
} else if (e instanceof ccxt.AuthenticationError) {
|
|
38
|
+
log.bright.yellow ('[Authentication Error] ' + e.message)
|
|
39
|
+
} else if (e instanceof ccxt.ExchangeNotAvailable) {
|
|
40
|
+
log.bright.yellow ('[Exchange Not Available Error] ' + e.message)
|
|
41
|
+
} else if (e instanceof ccxt.ExchangeError) {
|
|
42
|
+
log.bright.yellow ('[Exchange Error] ' + e.message)
|
|
43
|
+
} else if (e instanceof ccxt.NetworkError) {
|
|
44
|
+
log.bright.yellow ('[Network Error] ' + e.message)
|
|
45
|
+
} else {
|
|
46
|
+
throw e;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}) ()
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import ccxt from '../../js/ccxt.js';
|
|
2
|
+
import ololog from 'ololog';
|
|
3
|
+
import asTable from 'as-table';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const { noLocate } = ololog;
|
|
7
|
+
const log = noLocate;
|
|
8
|
+
|
|
9
|
+
const exchange = new ccxt.bittrex ({
|
|
10
|
+
'enableRateLimit': true,
|
|
11
|
+
'apiKey': 'YOUR_API_KEY',
|
|
12
|
+
'secret': 'YOUR_API_SECRET',
|
|
13
|
+
});(async () => {
|
|
14
|
+
|
|
15
|
+
await exchange.loadMarkets ()
|
|
16
|
+
|
|
17
|
+
const symbol = 'ETH/BTC'
|
|
18
|
+
, market = exchange.markets[symbol]
|
|
19
|
+
, startingDate = '2017-01-01T00:00:00'
|
|
20
|
+
, now = exchange.milliseconds ()
|
|
21
|
+
|
|
22
|
+
log.bright.green ('\nFetching history for:', symbol, '\n')
|
|
23
|
+
|
|
24
|
+
let allOrders = []
|
|
25
|
+
let since = exchange.parse8601 (startingDate)
|
|
26
|
+
|
|
27
|
+
while (since < now) {
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
|
|
31
|
+
log.bright.blue ('Fetching history for', symbol, 'since', exchange.iso8601 (since))
|
|
32
|
+
const orders = await exchange.fetchClosedOrders (symbol, since)
|
|
33
|
+
log.green.dim ('Fetched', orders.length, 'orders')
|
|
34
|
+
|
|
35
|
+
allOrders = allOrders.concat (orders)
|
|
36
|
+
|
|
37
|
+
if (orders.length) {
|
|
38
|
+
|
|
39
|
+
const lastOrder = orders[orders.length - 1]
|
|
40
|
+
since = lastOrder['timestamp'] + 1
|
|
41
|
+
|
|
42
|
+
} else {
|
|
43
|
+
|
|
44
|
+
break // no more orders left for this symbol, move to next one
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
} catch (e) {
|
|
48
|
+
|
|
49
|
+
log.red.unlimited (e)
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// omit the following keys for a compact table output
|
|
55
|
+
// otherwise it won't fit into the screen width
|
|
56
|
+
const omittedKeys = [
|
|
57
|
+
'info',
|
|
58
|
+
'timestamp',
|
|
59
|
+
'lastTradeTimestamp',
|
|
60
|
+
'fee',
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
log.yellow (asTable (allOrders.map (order => exchange.omit (order, omittedKeys))))
|
|
64
|
+
log.green ('Fetched', allOrders.length, symbol, 'orders in total')
|
|
65
|
+
|
|
66
|
+
// do whatever you want to do with them, calculate profit loss, etc...
|
|
67
|
+
|
|
68
|
+
}) ()
|
|
69
|
+
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const ccxt = require('../../ccxt.js')
|
|
4
|
+
const asTable = require('as-table')
|
|
5
|
+
const log = require('ololog').configure({ locate: false })
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const exchange = new ccxt.blockchaincom({
|
|
9
|
+
'secret': 'YOUR_API_SECRET',
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
// blockchaincom specific internal beneficiary id
|
|
13
|
+
const address = 'BENEFICIARY_ID';
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
(async () => {
|
|
17
|
+
|
|
18
|
+
const markets = await exchange.loadMarkets ()
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const code = 'USDT'
|
|
22
|
+
const amount = 5
|
|
23
|
+
|
|
24
|
+
// fetch withdrawal beneficiary ids
|
|
25
|
+
const whiteList = await exchange.privateGetWhitelistCurrency({'currency': code})
|
|
26
|
+
log('Withdrawl Whitelist', whiteList)
|
|
27
|
+
//
|
|
28
|
+
// [
|
|
29
|
+
// {
|
|
30
|
+
// "whitelistId":"adcd73fb-9ba6-41o7-8c0d-7013482cb88f", // unique id for each beneficiary, to be passed in as address into withdraw ()
|
|
31
|
+
// "name":"John Doe",
|
|
32
|
+
// "currency":"USDT"
|
|
33
|
+
// }
|
|
34
|
+
// ]
|
|
35
|
+
//
|
|
36
|
+
|
|
37
|
+
// withdrawal
|
|
38
|
+
let withdrawal = await exchange.withdraw(code, amount, address, undefined);
|
|
39
|
+
log('Withdrawal', withdrawal)
|
|
40
|
+
|
|
41
|
+
} catch (e) {
|
|
42
|
+
if (e instanceof ccxt.DDoSProtection || e.message.includes('ECONNRESET')) {
|
|
43
|
+
log('[DDoS Protection] ' + e.message)
|
|
44
|
+
} else if (e instanceof ccxt.RequestTimeout) {
|
|
45
|
+
log('[Request Timeout] ' + e.message)
|
|
46
|
+
} else if (e instanceof ccxt.AuthenticationError) {
|
|
47
|
+
log('[Authentication Error] ' + e.message)
|
|
48
|
+
} else if (e instanceof ccxt.ExchangeNotAvailable) {
|
|
49
|
+
log('[Exchange Not Available Error] ' + e.message)
|
|
50
|
+
} else if (e instanceof ccxt.ExchangeError) {
|
|
51
|
+
log('[Exchange Error] ' + e.message)
|
|
52
|
+
} else if (e instanceof ccxt.NetworkError) {
|
|
53
|
+
log('[Network Error] ' + e.message)
|
|
54
|
+
} else {
|
|
55
|
+
throw e;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
})()
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import ccxt from '../../js/ccxt.js';
|
|
2
|
+
// AUTO-TRANSPILE //
|
|
3
|
+
// Bulding OHLCV array from trades (executions) data is a bit tricky. For example, if you want to build 100 ohlcv bars of 1-minute timeframe, then you have to fetch the 100 minutes of trading data. So, higher timeframe bars require more trading data (i.e. building 100 bars of 1-day timeframe OHLCV would require massive amount of trading data, which might not be desirable for user, because of data-usage rate limits)
|
|
4
|
+
async function example_with_fetch_trades() {
|
|
5
|
+
const exch = new ccxt.binance({});
|
|
6
|
+
const timeframe = '1m';
|
|
7
|
+
const symbol = 'OGN/USDT';
|
|
8
|
+
const since = exch.milliseconds() - 1000 * 60 * 30; // last 30 mins
|
|
9
|
+
const limit = 1000;
|
|
10
|
+
const trades = await exch.fetchTrades(symbol, since, limit);
|
|
11
|
+
const generatedBars = exch.buildOHLCVC(trades, timeframe, since, limit);
|
|
12
|
+
// you can ignore 6th index ("count" field) from ohlcv entries, which is not part of OHLCV standard structure and is just added internally by `buildOHLCVC` method
|
|
13
|
+
console.log('[REST] Constructed', generatedBars.length, 'bars from trades: ', generatedBars);
|
|
14
|
+
}
|
|
15
|
+
async function example_with_watch_trades() {
|
|
16
|
+
const exch = new ccxt.pro.binance({});
|
|
17
|
+
const timeframe = '1m';
|
|
18
|
+
const symbol = 'DOGE/USDT';
|
|
19
|
+
const limit = 1000;
|
|
20
|
+
const since = exch.milliseconds() - 10 * 60 * 1000 * 1000; // last 10 hrs
|
|
21
|
+
let collectedTrades = [];
|
|
22
|
+
const collectedBars = [];
|
|
23
|
+
while (true) {
|
|
24
|
+
const wsTrades = await exch.watchTrades(symbol, since, limit, {});
|
|
25
|
+
collectedTrades = collectedTrades.concat(wsTrades);
|
|
26
|
+
const generatedBars = exch.buildOHLCVC(collectedTrades, timeframe, since, limit);
|
|
27
|
+
// Note: first bar would be partially constructed bar and its 'open' & 'high' & 'low' prices (except 'close' price) would probably have different values compared to real bar on chart, because the first obtained trade timestamp might be somewhere in the middle of timeframe period, so the pre-period would be missing because we would not have trades data. To fix that, you can get older data with `fetchTrades` to fill up bars till start bar.
|
|
28
|
+
for (let i = 0; i < generatedBars.length; i++) {
|
|
29
|
+
const bar = generatedBars[i];
|
|
30
|
+
const barTimestamp = bar[0];
|
|
31
|
+
const collectedBarsLength = collectedBars.length;
|
|
32
|
+
const lastCollectedBarTimestamp = collectedBarsLength > 0 ? collectedBars[collectedBarsLength - 1][0] : 0;
|
|
33
|
+
if (barTimestamp === lastCollectedBarTimestamp) {
|
|
34
|
+
// if timestamps are same, just updarte the last bar
|
|
35
|
+
collectedBars[collectedBarsLength - 1] = bar;
|
|
36
|
+
}
|
|
37
|
+
else if (barTimestamp > lastCollectedBarTimestamp) {
|
|
38
|
+
collectedBars.push(bar);
|
|
39
|
+
// remove the trades from saved array, which were till last collected bar's open timestamp
|
|
40
|
+
collectedTrades = exch.filterBySinceLimit(collectedTrades, barTimestamp);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Note: first bar would carry incomplete values, please read comment in "buildOHLCVCFromWatchTrades" method definition for further explanation
|
|
44
|
+
console.log('[WS] Constructed', collectedBars.length, 'bars from', symbol, 'trades: ', collectedBars);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
await example_with_fetch_trades();
|
|
48
|
+
await example_with_watch_trades();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import ccxt from '../../js/ccxt.js';
|
|
4
|
+
import log from 'ololog';
|
|
5
|
+
import { nice as ansi } from 'ansicolor';
|
|
6
|
+
import asTable from 'as-table';
|
|
7
|
+
|
|
8
|
+
const exchange = new ccxt.coinbasepro ()
|
|
9
|
+
const repeat = 100
|
|
10
|
+
|
|
11
|
+
async function test (symbol) {
|
|
12
|
+
|
|
13
|
+
for (let i = 0; i < repeat; i++) {
|
|
14
|
+
let ticker = await exchange.fetchTicker (symbol)
|
|
15
|
+
log (exchange.id.green, exchange.iso8601 (exchange.milliseconds ()), ticker['datetime'], symbol.green, ticker['last'])
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const concurrent = [
|
|
20
|
+
test ('BTC/USD'),
|
|
21
|
+
test ('ETH/BTC'),
|
|
22
|
+
test ('ETH/USD')
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
Promise.all (concurrent)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const ccxt = require ('../../ccxt');
|
|
4
|
+
|
|
5
|
+
console.log ('CCXT Version:', ccxt.version)
|
|
6
|
+
|
|
7
|
+
const exchange = new ccxt.bybit({
|
|
8
|
+
'apiKey': 'YOUR_API_KEY',
|
|
9
|
+
'secret': 'YOUR_API_KEY',
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
// exchange.set_sandbox_mode(true) // enable sandbox mode
|
|
13
|
+
|
|
14
|
+
// Example 1 :: Swap : open position and set trailing stop and close it
|
|
15
|
+
async function example1 () {
|
|
16
|
+
exchange['options']['defaultType'] = 'swap'; // very important set swap as default type
|
|
17
|
+
await exchange.loadMarkets ();
|
|
18
|
+
|
|
19
|
+
const symbol = 'LTC/USDT:USDT';
|
|
20
|
+
const market = exchange.market(symbol);
|
|
21
|
+
|
|
22
|
+
// fetch swap balance
|
|
23
|
+
const balance = await exchange.fetchBalance ();
|
|
24
|
+
console.log (balance)
|
|
25
|
+
|
|
26
|
+
// create order and open position
|
|
27
|
+
const type = 'market';
|
|
28
|
+
const side = 'buy';
|
|
29
|
+
const amount = 0.1
|
|
30
|
+
const price = undefined;
|
|
31
|
+
const createOrder = await exchange.createOrder (symbol, type, side, amount, price);
|
|
32
|
+
console.log ('Created order id:', createOrder['id'])
|
|
33
|
+
|
|
34
|
+
// set trailing stop
|
|
35
|
+
const rawSide = 'Buy'; // or 'Sell'
|
|
36
|
+
const trailing_stop = 30; // YOUR TRAILING STOP HERE
|
|
37
|
+
const trailingParams = {
|
|
38
|
+
'symbol': market['id'],
|
|
39
|
+
'side': rawSide,
|
|
40
|
+
'trailing_stop': trailing_stop
|
|
41
|
+
}
|
|
42
|
+
const trailing_response = await exchange.privatePostPrivateLinearPositionTradingStop (trailingParams);
|
|
43
|
+
console.log(trailing_response)
|
|
44
|
+
|
|
45
|
+
// check opened position
|
|
46
|
+
const symbols = [ symbol ];
|
|
47
|
+
const positions = await exchange.fetchPositions (symbols);
|
|
48
|
+
console.log (positions)
|
|
49
|
+
|
|
50
|
+
// Close position by issuing a order in the opposite direction
|
|
51
|
+
const params = {
|
|
52
|
+
'reduce_only': true
|
|
53
|
+
}
|
|
54
|
+
const closePositionOrder = await exchange.createOrder (symbol, type, side, amount, price, params);
|
|
55
|
+
console.log (closePositionOrder);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function main () {
|
|
59
|
+
await example1 ();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
main ();
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const ccxt = require ('../../dist/ccxt.bundle.cjs');
|
|
4
|
+
|
|
5
|
+
console.log ('CCXT Version:', ccxt.version)
|
|
6
|
+
|
|
7
|
+
const exchange = new ccxt.bybit ({
|
|
8
|
+
'apiKey': 'YOUR_API_KEY',
|
|
9
|
+
'secret': 'YOUR_SECRET_KEY',
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
// Example 1: Spot : fetch balance, create order, cancel it and check canceled orders
|
|
13
|
+
async function example1 () {
|
|
14
|
+
exchange['options']['defaultType'] = 'spot'; // very important set spot as default type
|
|
15
|
+
|
|
16
|
+
await exchange.loadMarkets ();
|
|
17
|
+
|
|
18
|
+
// fetch spot balance
|
|
19
|
+
const balance = await exchange.fetchBalance ();
|
|
20
|
+
console.log (balance)
|
|
21
|
+
|
|
22
|
+
// create order
|
|
23
|
+
const symbol = 'LTC/USDT';
|
|
24
|
+
const createOrder = await exchange.createOrder (symbol, 'limit', 'buy', 50, 0.1);
|
|
25
|
+
console.log ('Created order id:', createOrder['id'])
|
|
26
|
+
|
|
27
|
+
// cancel order
|
|
28
|
+
const cancelOrder = await exchange.cancelOrder (createOrder['id'], symbol);
|
|
29
|
+
|
|
30
|
+
// Check canceled orders (bybit does not have a single endpoint to check orders
|
|
31
|
+
// we have to choose whether to check open or closed orders and call fetchOpenOrders
|
|
32
|
+
// or fetchClosedOrders respectively
|
|
33
|
+
const canceledOrders = await exchange.fetchClosedOrders (symbol);
|
|
34
|
+
console.log (canceledOrders);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// -----------------------------------------------------------------------------------------
|
|
38
|
+
|
|
39
|
+
// Example 2 :: Swap : fetch balance, open a position and close it
|
|
40
|
+
async function example2 () {
|
|
41
|
+
exchange['options']['defaultType'] = 'swap'; // very important set swap as default type
|
|
42
|
+
await exchange.loadMarkets ();
|
|
43
|
+
|
|
44
|
+
// fetch swap balance
|
|
45
|
+
const balance = await exchange.fetchBalance ();
|
|
46
|
+
console.log (balance)
|
|
47
|
+
|
|
48
|
+
// create order and open position
|
|
49
|
+
const symbol = 'LTC/USDT:USDT';
|
|
50
|
+
const createOrder = await exchange.createOrder (symbol, 'market', 'buy', 0.1);
|
|
51
|
+
console.log ('Created order id:', createOrder['id'])
|
|
52
|
+
|
|
53
|
+
// check opened position
|
|
54
|
+
const symbols = [ symbol ];
|
|
55
|
+
const positions = await exchange.fetchPositions (symbols);
|
|
56
|
+
console.log (positions)
|
|
57
|
+
|
|
58
|
+
// Close position by issuing a order in the opposite direction
|
|
59
|
+
const params = {
|
|
60
|
+
'reduce_only': true
|
|
61
|
+
}
|
|
62
|
+
const closePositionOrder = await exchange.createOrder (symbol, 'market', 'sell', 0.1, undefined, params);
|
|
63
|
+
console.log (closePositionOrder);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// -----------------------------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
// Example 3 :: USDC Swap : fetch balance, open a position and close it
|
|
69
|
+
async function example3 () {
|
|
70
|
+
exchange['options']['defaultType'] = 'swap'; // very important set swap as default type
|
|
71
|
+
await exchange.loadMarkets ();
|
|
72
|
+
|
|
73
|
+
// fetch USDC swap balance
|
|
74
|
+
// when no symbol is available we can show our intent
|
|
75
|
+
// of using USDC endpoints by either using defaultSettle in options or
|
|
76
|
+
// settle in params
|
|
77
|
+
// Using Options: exchange['options']['defaultSettle'] = 'USDC';
|
|
78
|
+
// Using params:
|
|
79
|
+
const balanceParams = {
|
|
80
|
+
'settle': 'USDC'
|
|
81
|
+
}
|
|
82
|
+
const balance = await exchange.fetchBalance (balanceParams);
|
|
83
|
+
console.log (balance)
|
|
84
|
+
|
|
85
|
+
// create order and open position
|
|
86
|
+
// taking into consideration that USDC markets do not support
|
|
87
|
+
// market orders
|
|
88
|
+
const symbol = 'BTC/USD:USDC';
|
|
89
|
+
const amount = 0.1;
|
|
90
|
+
const price = 29940 // adjust this accordingly
|
|
91
|
+
const createOrder = await exchange.createOrder (symbol, 'limit', 'buy', amount, price);
|
|
92
|
+
console.log ('Created order id:', createOrder['id'])
|
|
93
|
+
|
|
94
|
+
// check if the order was filled and the position opened
|
|
95
|
+
const symbols = [ symbol ];
|
|
96
|
+
const positions = await exchange.fetchPositions (symbols);
|
|
97
|
+
console.log (positions)
|
|
98
|
+
|
|
99
|
+
// close position (assuming it was already opened) by issuing an order in the opposite direction
|
|
100
|
+
const params = {
|
|
101
|
+
'reduce_only': true
|
|
102
|
+
}
|
|
103
|
+
const closePositionOrder = await exchange.createOrder (symbol, 'limit', 'sell', amount, price, params);
|
|
104
|
+
console.log (closePositionOrder);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// -----------------------------------------------------------------------------------------
|
|
108
|
+
|
|
109
|
+
// Example 4 :: Future : fetch balance, create stop-order and check open stop-orders
|
|
110
|
+
async function example4 () {
|
|
111
|
+
exchange['options']['defaultType'] = 'future'; // very important set future as default type
|
|
112
|
+
await exchange.loadMarkets ();
|
|
113
|
+
|
|
114
|
+
// fetch future balance
|
|
115
|
+
const balance = await exchange.fetchBalance ();
|
|
116
|
+
console.log (balance)
|
|
117
|
+
|
|
118
|
+
// create stop-order
|
|
119
|
+
const symbol = 'ETH/USD:ETH-220930';
|
|
120
|
+
const amount = 10; // in USD for inverse futures
|
|
121
|
+
const price = 1200;
|
|
122
|
+
const side = 'buy';
|
|
123
|
+
const type = 'limit';
|
|
124
|
+
const stopOrderParams = {
|
|
125
|
+
'position_idx': 0, // 0 One-Way Mode, 1 Buy-side, 2 Sell-side, default = 0
|
|
126
|
+
'stopPrice': 1000, // mandatory for stop orders
|
|
127
|
+
'basePrice': 1100 // mandatory for stop orders
|
|
128
|
+
}
|
|
129
|
+
const stopOrder = await exchange.createOrder (symbol, type, side, amount, price, stopOrderParams);
|
|
130
|
+
console.log ('Created order id:', stopOrder['id'])
|
|
131
|
+
|
|
132
|
+
// check opened stop-order
|
|
133
|
+
const openOrderParams = {
|
|
134
|
+
'stop': true
|
|
135
|
+
}
|
|
136
|
+
const openOrders = await exchange.fetchOpenOrders (symbol, undefined, undefined, openOrderParams);
|
|
137
|
+
console.log (openOrders)
|
|
138
|
+
|
|
139
|
+
// Cancell open stop-order
|
|
140
|
+
const cancelOrder = await exchange.cancelOrder (stopOrder['id'], symbol, openOrderParams);
|
|
141
|
+
console.log (cancelOrder);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// -----------------------------------------------------------------------------------------
|
|
145
|
+
|
|
146
|
+
async function main () {
|
|
147
|
+
await example1 ();
|
|
148
|
+
await example2 ();
|
|
149
|
+
await example3 ();
|
|
150
|
+
await example4 ();
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
main ();
|