ccxt 4.2.11 → 4.2.13
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 +5 -5
- package/build.sh +2 -2
- package/dist/ccxt.browser.js +1347 -490
- package/dist/ccxt.browser.min.js +3 -3
- package/dist/cjs/_virtual/agent.js +7 -0
- package/dist/cjs/_virtual/parse-proxy-response.js +7 -0
- package/dist/cjs/_virtual/promisify.js +7 -0
- package/dist/cjs/ccxt.js +1 -1
- package/dist/cjs/js/ccxt.js +474 -0
- package/dist/cjs/js/src/abstract/ace.js +9 -0
- package/dist/cjs/js/src/abstract/alpaca.js +9 -0
- package/dist/cjs/js/src/abstract/ascendex.js +9 -0
- package/dist/cjs/js/src/abstract/bigone.js +9 -0
- package/dist/cjs/js/src/abstract/binance.js +9 -0
- package/dist/cjs/js/src/abstract/bingx.js +9 -0
- package/dist/cjs/js/src/abstract/bit2c.js +9 -0
- package/dist/cjs/js/src/abstract/bitbank.js +9 -0
- package/dist/cjs/js/src/abstract/bitbns.js +9 -0
- package/dist/cjs/js/src/abstract/bitfinex.js +9 -0
- package/dist/cjs/js/src/abstract/bitfinex2.js +9 -0
- package/dist/cjs/js/src/abstract/bitflyer.js +9 -0
- package/dist/cjs/js/src/abstract/bitforex.js +9 -0
- package/dist/cjs/js/src/abstract/bitget.js +9 -0
- package/dist/cjs/js/src/abstract/bithumb.js +9 -0
- package/dist/cjs/js/src/abstract/bitmart.js +9 -0
- package/dist/cjs/js/src/abstract/bitmex.js +9 -0
- package/dist/cjs/js/src/abstract/bitopro.js +9 -0
- package/dist/cjs/js/src/abstract/bitpanda.js +9 -0
- package/dist/cjs/js/src/abstract/bitrue.js +9 -0
- package/dist/cjs/js/src/abstract/bitso.js +9 -0
- package/dist/cjs/js/src/abstract/bitstamp.js +9 -0
- package/dist/cjs/js/src/abstract/bitteam.js +9 -0
- package/dist/cjs/js/src/abstract/bitvavo.js +9 -0
- package/dist/cjs/js/src/abstract/bl3p.js +9 -0
- package/dist/cjs/js/src/abstract/blockchaincom.js +9 -0
- package/dist/cjs/js/src/abstract/btcalpha.js +9 -0
- package/dist/cjs/js/src/abstract/btcbox.js +9 -0
- package/dist/cjs/js/src/abstract/btcmarkets.js +9 -0
- package/dist/cjs/js/src/abstract/btcturk.js +9 -0
- package/dist/cjs/js/src/abstract/bybit.js +9 -0
- package/dist/cjs/js/src/abstract/cex.js +9 -0
- package/dist/cjs/js/src/abstract/coinbase.js +9 -0
- package/dist/cjs/js/src/abstract/coinbasepro.js +9 -0
- package/dist/cjs/js/src/abstract/coincheck.js +9 -0
- package/dist/cjs/js/src/abstract/coinex.js +9 -0
- package/dist/cjs/js/src/abstract/coinlist.js +9 -0
- package/dist/cjs/js/src/abstract/coinmate.js +9 -0
- package/dist/cjs/js/src/abstract/coinone.js +9 -0
- package/dist/cjs/js/src/abstract/coinsph.js +9 -0
- package/dist/cjs/js/src/abstract/coinspot.js +9 -0
- package/dist/cjs/js/src/abstract/cryptocom.js +9 -0
- package/dist/cjs/js/src/abstract/currencycom.js +9 -0
- package/dist/cjs/js/src/abstract/delta.js +9 -0
- package/dist/cjs/js/src/abstract/deribit.js +9 -0
- package/dist/cjs/js/src/abstract/digifinex.js +9 -0
- package/dist/cjs/js/src/abstract/exmo.js +9 -0
- package/dist/cjs/js/src/abstract/gate.js +9 -0
- package/dist/cjs/js/src/abstract/gemini.js +9 -0
- package/dist/cjs/js/src/abstract/hitbtc.js +9 -0
- package/dist/cjs/js/src/abstract/hollaex.js +9 -0
- package/dist/cjs/js/src/abstract/htx.js +9 -0
- package/dist/cjs/js/src/abstract/huobijp.js +9 -0
- package/dist/cjs/js/src/abstract/idex.js +9 -0
- package/dist/cjs/js/src/abstract/independentreserve.js +9 -0
- package/dist/cjs/js/src/abstract/indodax.js +9 -0
- package/dist/cjs/js/src/abstract/kraken.js +9 -0
- package/dist/cjs/js/src/abstract/krakenfutures.js +9 -0
- package/dist/cjs/js/src/abstract/kucoin.js +9 -0
- package/dist/cjs/js/src/abstract/kucoinfutures.js +9 -0
- package/dist/cjs/js/src/abstract/kuna.js +9 -0
- package/dist/cjs/js/src/abstract/latoken.js +9 -0
- package/dist/cjs/js/src/abstract/lbank.js +9 -0
- package/dist/cjs/js/src/abstract/luno.js +9 -0
- package/dist/cjs/js/src/abstract/lykke.js +9 -0
- package/dist/cjs/js/src/abstract/mercado.js +9 -0
- package/dist/cjs/js/src/abstract/mexc.js +9 -0
- package/dist/cjs/js/src/abstract/ndax.js +9 -0
- package/dist/cjs/js/src/abstract/novadax.js +9 -0
- package/dist/cjs/js/src/abstract/oceanex.js +9 -0
- package/dist/cjs/js/src/abstract/okcoin.js +9 -0
- package/dist/cjs/js/src/abstract/okx.js +9 -0
- package/dist/cjs/js/src/abstract/p2b.js +9 -0
- package/dist/cjs/js/src/abstract/paymium.js +9 -0
- package/dist/cjs/js/src/abstract/phemex.js +9 -0
- package/dist/cjs/js/src/abstract/poloniex.js +9 -0
- package/dist/cjs/js/src/abstract/poloniexfutures.js +9 -0
- package/dist/cjs/js/src/abstract/probit.js +9 -0
- package/dist/cjs/js/src/abstract/timex.js +9 -0
- package/dist/cjs/js/src/abstract/tokocrypto.js +9 -0
- package/dist/cjs/js/src/abstract/upbit.js +9 -0
- package/dist/cjs/js/src/abstract/wavesexchange.js +9 -0
- package/dist/cjs/js/src/abstract/wazirx.js +9 -0
- package/dist/cjs/js/src/abstract/whitebit.js +9 -0
- package/dist/cjs/js/src/abstract/woo.js +9 -0
- package/dist/cjs/js/src/abstract/yobit.js +9 -0
- package/dist/cjs/js/src/abstract/zaif.js +9 -0
- package/dist/cjs/js/src/abstract/zonda.js +9 -0
- package/dist/cjs/js/src/ace.js +1058 -0
- package/dist/cjs/js/src/alpaca.js +1125 -0
- package/dist/cjs/js/src/ascendex.js +3360 -0
- package/dist/cjs/js/src/base/Exchange.js +5110 -0
- package/dist/cjs/js/src/base/Precise.js +263 -0
- package/dist/cjs/js/src/base/errors.js +299 -0
- package/dist/cjs/js/src/base/functions/crypto.js +78 -0
- package/dist/cjs/js/src/base/functions/encode.js +44 -0
- package/dist/cjs/js/src/base/functions/generic.js +193 -0
- package/dist/cjs/js/src/base/functions/misc.js +96 -0
- package/dist/cjs/js/src/base/functions/number.js +297 -0
- package/dist/cjs/js/src/base/functions/platform.js +28 -0
- package/dist/cjs/js/src/base/functions/rsa.js +34 -0
- package/dist/cjs/js/src/base/functions/string.js +48 -0
- package/dist/cjs/js/src/base/functions/throttle.js +66 -0
- package/dist/cjs/js/src/base/functions/time.js +187 -0
- package/dist/cjs/js/src/base/functions/totp.js +24 -0
- package/dist/cjs/js/src/base/functions/type.js +162 -0
- package/dist/cjs/js/src/base/functions.js +157 -0
- package/dist/cjs/js/src/base/ws/Cache.js +254 -0
- package/dist/cjs/js/src/base/ws/Client.js +299 -0
- package/dist/cjs/js/src/base/ws/Future.js +34 -0
- package/dist/cjs/js/src/base/ws/OrderBook.js +107 -0
- package/dist/cjs/js/src/base/ws/OrderBookSide.js +281 -0
- package/dist/cjs/js/src/base/ws/WsClient.js +69 -0
- package/dist/cjs/js/src/bequant.js +33 -0
- package/dist/cjs/js/src/bigone.js +2209 -0
- package/dist/cjs/js/src/binance.js +9736 -0
- package/dist/cjs/js/src/binancecoinm.js +45 -0
- package/dist/cjs/js/src/binanceus.js +84 -0
- package/dist/cjs/js/src/binanceusdm.js +58 -0
- package/dist/cjs/js/src/bingx.js +3807 -0
- package/dist/cjs/js/src/bit2c.js +916 -0
- package/dist/cjs/js/src/bitbank.js +1000 -0
- package/dist/cjs/js/src/bitbay.js +17 -0
- package/dist/cjs/js/src/bitbns.js +1220 -0
- package/dist/cjs/js/src/bitcoincom.js +17 -0
- package/dist/cjs/js/src/bitfinex.js +1670 -0
- package/dist/cjs/js/src/bitfinex2.js +2990 -0
- package/dist/cjs/js/src/bitflyer.js +1045 -0
- package/dist/cjs/js/src/bitforex.js +852 -0
- package/dist/cjs/js/src/bitget.js +8291 -0
- package/dist/cjs/js/src/bithumb.js +1090 -0
- package/dist/cjs/js/src/bitmart.js +4454 -0
- package/dist/cjs/js/src/bitmex.js +2884 -0
- package/dist/cjs/js/src/bitopro.js +1724 -0
- package/dist/cjs/js/src/bitpanda.js +2002 -0
- package/dist/cjs/js/src/bitrue.js +3253 -0
- package/dist/cjs/js/src/bitso.js +1753 -0
- package/dist/cjs/js/src/bitstamp.js +2188 -0
- package/dist/cjs/js/src/bitteam.js +2309 -0
- package/dist/cjs/js/src/bitvavo.js +1968 -0
- package/dist/cjs/js/src/bl3p.js +447 -0
- package/dist/cjs/js/src/blockchaincom.js +1160 -0
- package/dist/cjs/js/src/btcalpha.js +929 -0
- package/dist/cjs/js/src/btcbox.js +565 -0
- package/dist/cjs/js/src/btcmarkets.js +1237 -0
- package/dist/cjs/js/src/btcturk.js +929 -0
- package/dist/cjs/js/src/bybit.js +7646 -0
- package/dist/cjs/js/src/cex.js +1693 -0
- package/dist/cjs/js/src/coinbase.js +3424 -0
- package/dist/cjs/js/src/coinbasepro.js +1866 -0
- package/dist/cjs/js/src/coincheck.js +843 -0
- package/dist/cjs/js/src/coinex.js +5414 -0
- package/dist/cjs/js/src/coinlist.js +2329 -0
- package/dist/cjs/js/src/coinmate.js +989 -0
- package/dist/cjs/js/src/coinone.js +1185 -0
- package/dist/cjs/js/src/coinsph.js +1933 -0
- package/dist/cjs/js/src/coinspot.js +548 -0
- package/dist/cjs/js/src/cryptocom.js +3007 -0
- package/dist/cjs/js/src/currencycom.js +2015 -0
- package/dist/cjs/js/src/delta.js +3256 -0
- package/dist/cjs/js/src/deribit.js +3306 -0
- package/dist/cjs/js/src/digifinex.js +4307 -0
- package/dist/cjs/js/src/exmo.js +2645 -0
- package/dist/cjs/js/src/fmfwio.js +34 -0
- package/dist/cjs/js/src/gate.js +7072 -0
- package/dist/cjs/js/src/gateio.js +16 -0
- package/dist/cjs/js/src/gemini.js +1801 -0
- package/dist/cjs/js/src/hitbtc.js +3660 -0
- package/dist/cjs/js/src/hitbtc3.js +19 -0
- package/dist/cjs/js/src/hollaex.js +1882 -0
- package/dist/cjs/js/src/htx.js +9049 -0
- package/dist/cjs/js/src/huobi.js +16 -0
- package/dist/cjs/js/src/huobijp.js +1918 -0
- package/dist/cjs/js/src/idex.js +1770 -0
- package/dist/cjs/js/src/independentreserve.js +761 -0
- package/dist/cjs/js/src/indodax.js +1069 -0
- package/dist/cjs/js/src/kraken.js +2857 -0
- package/dist/cjs/js/src/krakenfutures.js +2407 -0
- package/dist/cjs/js/src/kucoin.js +4489 -0
- package/dist/cjs/js/src/kucoinfutures.js +2475 -0
- package/dist/cjs/js/src/kuna.js +1949 -0
- package/dist/cjs/js/src/latoken.js +1729 -0
- package/dist/cjs/js/src/lbank.js +2851 -0
- package/dist/cjs/js/src/luno.js +1044 -0
- package/dist/cjs/js/src/lykke.js +1303 -0
- package/dist/cjs/js/src/mercado.js +897 -0
- package/dist/cjs/js/src/mexc.js +5407 -0
- package/dist/cjs/js/src/ndax.js +2450 -0
- package/dist/cjs/js/src/novadax.js +1556 -0
- package/dist/cjs/js/src/oceanex.js +964 -0
- package/dist/cjs/js/src/okcoin.js +3115 -0
- package/dist/cjs/js/src/okx.js +7330 -0
- package/dist/cjs/js/src/p2b.js +1243 -0
- package/dist/cjs/js/src/paymium.js +597 -0
- package/dist/cjs/js/src/phemex.js +4722 -0
- package/dist/cjs/js/src/poloniex.js +2356 -0
- package/dist/cjs/js/src/poloniexfutures.js +1794 -0
- package/dist/cjs/js/src/pro/alpaca.js +714 -0
- package/dist/cjs/js/src/pro/ascendex.js +957 -0
- package/dist/cjs/js/src/pro/bequant.js +33 -0
- package/dist/cjs/js/src/pro/binance.js +2796 -0
- package/dist/cjs/js/src/pro/binancecoinm.js +23 -0
- package/dist/cjs/js/src/pro/binanceus.js +51 -0
- package/dist/cjs/js/src/pro/binanceusdm.js +32 -0
- package/dist/cjs/js/src/pro/bingx.js +944 -0
- package/dist/cjs/js/src/pro/bitcoincom.js +29 -0
- package/dist/cjs/js/src/pro/bitfinex.js +672 -0
- package/dist/cjs/js/src/pro/bitfinex2.js +1159 -0
- package/dist/cjs/js/src/pro/bitget.js +1733 -0
- package/dist/cjs/js/src/pro/bitmart.js +1486 -0
- package/dist/cjs/js/src/pro/bitmex.js +1576 -0
- package/dist/cjs/js/src/pro/bitopro.js +327 -0
- package/dist/cjs/js/src/pro/bitpanda.js +1341 -0
- package/dist/cjs/js/src/pro/bitrue.js +462 -0
- package/dist/cjs/js/src/pro/bitstamp.js +547 -0
- package/dist/cjs/js/src/pro/bitvavo.js +704 -0
- package/dist/cjs/js/src/pro/blockchaincom.js +794 -0
- package/dist/cjs/js/src/pro/bybit.js +1843 -0
- package/dist/cjs/js/src/pro/cex.js +1510 -0
- package/dist/cjs/js/src/pro/coinbase.js +561 -0
- package/dist/cjs/js/src/pro/coinbasepro.js +968 -0
- package/dist/cjs/js/src/pro/coinex.js +1095 -0
- package/dist/cjs/js/src/pro/cryptocom.js +1020 -0
- package/dist/cjs/js/src/pro/currencycom.js +563 -0
- package/dist/cjs/js/src/pro/deribit.js +825 -0
- package/dist/cjs/js/src/pro/exmo.js +658 -0
- package/dist/cjs/js/src/pro/gate.js +1316 -0
- package/dist/cjs/js/src/pro/gateio.js +16 -0
- package/dist/cjs/js/src/pro/gemini.js +649 -0
- package/dist/cjs/js/src/pro/hitbtc.js +1293 -0
- package/dist/cjs/js/src/pro/hollaex.js +597 -0
- package/dist/cjs/js/src/pro/htx.js +2383 -0
- package/dist/cjs/js/src/pro/huobi.js +16 -0
- package/dist/cjs/js/src/pro/huobijp.js +606 -0
- package/dist/cjs/js/src/pro/idex.js +714 -0
- package/dist/cjs/js/src/pro/independentreserve.js +280 -0
- package/dist/cjs/js/src/pro/kraken.js +1364 -0
- package/dist/cjs/js/src/pro/krakenfutures.js +1500 -0
- package/dist/cjs/js/src/pro/kucoin.js +1052 -0
- package/dist/cjs/js/src/pro/kucoinfutures.js +981 -0
- package/dist/cjs/js/src/pro/luno.js +322 -0
- package/dist/cjs/js/src/pro/mexc.js +1170 -0
- package/dist/cjs/js/src/pro/ndax.js +545 -0
- package/dist/cjs/js/src/pro/okcoin.js +760 -0
- package/dist/cjs/js/src/pro/okx.js +1608 -0
- package/dist/cjs/js/src/pro/phemex.js +1511 -0
- package/dist/cjs/js/src/pro/poloniex.js +1253 -0
- package/dist/cjs/js/src/pro/poloniexfutures.js +1014 -0
- package/dist/cjs/js/src/pro/probit.js +586 -0
- package/dist/cjs/js/src/pro/upbit.js +234 -0
- package/dist/cjs/js/src/pro/wazirx.js +776 -0
- package/dist/cjs/js/src/pro/whitebit.js +927 -0
- package/dist/cjs/js/src/pro/woo.js +769 -0
- package/dist/cjs/js/src/probit.js +1867 -0
- package/dist/cjs/js/src/static_dependencies/fflake/browser.js +401 -0
- package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncrypt.js +195 -0
- package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncryptRSAKey.js +308 -0
- package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/asn1.js +554 -0
- package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/base64.js +94 -0
- package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/hex.js +70 -0
- package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/int10.js +91 -0
- package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/base64.js +16 -0
- package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.js +1760 -0
- package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/prng4.js +52 -0
- package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rng.js +81 -0
- package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rsa.js +376 -0
- package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/util.js +70 -0
- package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.js +1580 -0
- package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/yahoo.js +74 -0
- package/dist/cjs/js/src/static_dependencies/noble-curves/_shortw_utils.js +24 -0
- package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/curve.js +158 -0
- package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/edwards.js +429 -0
- package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/hash-to-curve.js +176 -0
- package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/modular.js +324 -0
- package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/montgomery.js +163 -0
- package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/utils.js +245 -0
- package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/weierstrass.js +1018 -0
- package/dist/cjs/js/src/static_dependencies/noble-curves/ed25519.js +383 -0
- package/dist/cjs/js/src/static_dependencies/noble-curves/secp256k1.js +258 -0
- package/dist/cjs/js/src/static_dependencies/noble-hashes/_assert.js +53 -0
- package/dist/cjs/js/src/static_dependencies/noble-hashes/_sha2.js +120 -0
- package/dist/cjs/js/src/static_dependencies/noble-hashes/_u64.js +69 -0
- package/dist/cjs/js/src/static_dependencies/noble-hashes/crypto.js +7 -0
- package/dist/cjs/js/src/static_dependencies/noble-hashes/hmac.js +83 -0
- package/dist/cjs/js/src/static_dependencies/noble-hashes/md5.js +240 -0
- package/dist/cjs/js/src/static_dependencies/noble-hashes/sha1.js +91 -0
- package/dist/cjs/js/src/static_dependencies/noble-hashes/sha256.js +130 -0
- package/dist/cjs/js/src/static_dependencies/noble-hashes/sha3.js +214 -0
- package/dist/cjs/js/src/static_dependencies/noble-hashes/sha512.js +239 -0
- package/dist/cjs/js/src/static_dependencies/noble-hashes/utils.js +93 -0
- package/dist/cjs/js/src/static_dependencies/node-fetch/body.js +354 -0
- package/dist/cjs/js/src/static_dependencies/node-fetch/errors/abort-error.js +16 -0
- package/dist/cjs/js/src/static_dependencies/node-fetch/errors/base.js +20 -0
- package/dist/cjs/js/src/static_dependencies/node-fetch/errors/fetch-error.js +30 -0
- package/dist/cjs/js/src/static_dependencies/node-fetch/headers.js +239 -0
- package/dist/cjs/js/src/static_dependencies/node-fetch/index.js +372 -0
- package/dist/cjs/js/src/static_dependencies/node-fetch/request.js +273 -0
- package/dist/cjs/js/src/static_dependencies/node-fetch/response.js +139 -0
- package/dist/cjs/js/src/static_dependencies/node-fetch/utils/get-search.js +14 -0
- package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is-redirect.js +16 -0
- package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is.js +81 -0
- package/dist/cjs/js/src/static_dependencies/node-fetch/utils/referrer.js +292 -0
- package/dist/cjs/js/src/static_dependencies/proxies/agent-base/index.js +103 -0
- package/dist/cjs/js/src/static_dependencies/proxies/http-proxy-agent/index.js +140 -0
- package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/index.js +175 -0
- package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/parse-proxy-response.js +95 -0
- package/dist/cjs/js/src/static_dependencies/qs/index.cjs.js +7 -0
- package/dist/cjs/js/src/static_dependencies/scure-base/index.js +383 -0
- package/dist/cjs/js/src/timex.js +1562 -0
- package/dist/cjs/js/src/tokocrypto.js +2542 -0
- package/dist/cjs/js/src/upbit.js +1844 -0
- package/dist/cjs/js/src/wavesexchange.js +2607 -0
- package/dist/cjs/js/src/wazirx.js +953 -0
- package/dist/cjs/js/src/whitebit.js +2309 -0
- package/dist/cjs/js/src/woo.js +2765 -0
- package/dist/cjs/js/src/yobit.js +1314 -0
- package/dist/cjs/js/src/zaif.js +736 -0
- package/dist/cjs/js/src/zonda.js +1883 -0
- package/js/ccxt.d.ts +1 -1
- package/js/ccxt.js +1 -1
- package/js/src/abstract/bigone.d.ts +18 -0
- package/js/src/abstract/binance.d.ts +2 -0
- package/js/src/abstract/binancecoinm.d.ts +2 -0
- package/js/src/abstract/binanceus.d.ts +2 -0
- package/js/src/abstract/binanceusdm.d.ts +2 -0
- package/js/src/abstract/bingx.d.ts +2 -0
- package/js/src/abstract/bybit.d.ts +1 -0
- package/js/src/abstract/gate.d.ts +11 -0
- package/js/src/abstract/gateio.d.ts +11 -0
- package/js/src/abstract/okx.d.ts +1 -0
- package/js/src/alpaca.js +18 -18
- package/js/src/base/Exchange.d.ts +5 -1
- package/js/src/base/Exchange.js +101 -12
- package/js/src/bigone.d.ts +3 -2
- package/js/src/bigone.js +429 -167
- package/js/src/binance.js +48 -34
- package/js/src/bingx.js +115 -38
- package/js/src/bitfinex.d.ts +2 -2
- package/js/src/bitfinex.js +2 -3
- package/js/src/bitget.js +33 -13
- package/js/src/bitmart.d.ts +2 -2
- package/js/src/bitmart.js +5 -5
- package/js/src/bitmex.js +1 -0
- package/js/src/bybit.js +2 -0
- package/js/src/coinbase.d.ts +26 -3
- package/js/src/coinbase.js +176 -26
- package/js/src/coinlist.js +3 -4
- package/js/src/coinone.js +1 -1
- package/js/src/coinsph.js +2 -3
- package/js/src/deribit.js +1 -0
- package/js/src/gate.d.ts +4 -4
- package/js/src/gate.js +96 -59
- package/js/src/gemini.js +1 -1
- package/js/src/hitbtc.d.ts +4 -4
- package/js/src/hitbtc.js +2 -3
- package/js/src/htx.d.ts +1 -0
- package/js/src/htx.js +29 -7
- package/js/src/huobijp.js +2 -3
- package/js/src/independentreserve.js +7 -5
- package/js/src/kraken.js +3 -6
- package/js/src/lbank.js +59 -33
- package/js/src/mexc.js +2 -1
- package/js/src/oceanex.js +1 -1
- package/js/src/okx.js +14 -3
- package/js/src/phemex.js +9 -2
- package/js/src/pro/binance.d.ts +2 -23
- package/js/src/pro/binance.js +58 -22
- package/js/src/pro/coinbase.d.ts +2 -2
- package/js/src/pro/coinbase.js +4 -1
- package/js/src/pro/coinbasepro.d.ts +2 -2
- package/js/src/pro/hitbtc.d.ts +2 -2
- package/js/src/pro/kraken.js +1 -1
- package/js/src/pro/okx.d.ts +1 -0
- package/js/src/pro/okx.js +52 -2
- package/js/src/pro/poloniex.d.ts +2 -2
- package/js/src/probit.js +4 -2
- package/js/src/upbit.d.ts +3 -101
- package/js/src/upbit.js +12 -12
- package/js/src/wavesexchange.js +1 -1
- package/js/src/woo.d.ts +2 -0
- package/js/src/woo.js +52 -0
- package/package.json +1 -1
- package/skip-tests.json +5 -0
|
@@ -0,0 +1,1608 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var okx$1 = require('../okx.js');
|
|
4
|
+
var errors = require('../base/errors.js');
|
|
5
|
+
var Cache = require('../base/ws/Cache.js');
|
|
6
|
+
var sha256 = require('../static_dependencies/noble-hashes/sha256.js');
|
|
7
|
+
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
class okx extends okx$1 {
|
|
11
|
+
describe() {
|
|
12
|
+
return this.deepExtend(super.describe(), {
|
|
13
|
+
'has': {
|
|
14
|
+
'ws': true,
|
|
15
|
+
'watchTicker': true,
|
|
16
|
+
'watchTickers': true,
|
|
17
|
+
'watchOrderBook': true,
|
|
18
|
+
'watchTrades': true,
|
|
19
|
+
'watchTradesForSymbols': true,
|
|
20
|
+
'watchOrderBookForSymbols': true,
|
|
21
|
+
'watchBalance': true,
|
|
22
|
+
'watchOHLCV': true,
|
|
23
|
+
'watchOHLCVForSymbols': true,
|
|
24
|
+
'watchOrders': true,
|
|
25
|
+
'watchMyTrades': true,
|
|
26
|
+
'watchPositions': true,
|
|
27
|
+
'createOrderWs': true,
|
|
28
|
+
'editOrderWs': true,
|
|
29
|
+
'cancelOrderWs': true,
|
|
30
|
+
'cancelOrdersWs': true,
|
|
31
|
+
'cancelAllOrdersWs': true,
|
|
32
|
+
},
|
|
33
|
+
'urls': {
|
|
34
|
+
'api': {
|
|
35
|
+
'ws': 'wss://ws.okx.com:8443/ws/v5',
|
|
36
|
+
},
|
|
37
|
+
'test': {
|
|
38
|
+
'ws': 'wss://wspap.okx.com:8443/ws/v5',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
'options': {
|
|
42
|
+
'watchOrderBook': {
|
|
43
|
+
//
|
|
44
|
+
// bbo-tbt
|
|
45
|
+
// 1. Newly added channel that sends tick-by-tick Level 1 data
|
|
46
|
+
// 2. All API users can subscribe
|
|
47
|
+
// 3. Public depth channel, verification not required
|
|
48
|
+
//
|
|
49
|
+
// books-l2-tbt
|
|
50
|
+
// 1. Only users who're VIP5 and above can subscribe
|
|
51
|
+
// 2. Identity verification required before subscription
|
|
52
|
+
//
|
|
53
|
+
// books50-l2-tbt
|
|
54
|
+
// 1. Only users who're VIP4 and above can subscribe
|
|
55
|
+
// 2. Identity verification required before subscription
|
|
56
|
+
//
|
|
57
|
+
// books
|
|
58
|
+
// 1. All API users can subscribe
|
|
59
|
+
// 2. Public depth channel, verification not required
|
|
60
|
+
//
|
|
61
|
+
// books5
|
|
62
|
+
// 1. All API users can subscribe
|
|
63
|
+
// 2. Public depth channel, verification not required
|
|
64
|
+
// 3. Data feeds will be delivered every 100ms (vs. every 200ms now)
|
|
65
|
+
//
|
|
66
|
+
'depth': 'books',
|
|
67
|
+
},
|
|
68
|
+
'watchBalance': 'spot',
|
|
69
|
+
'watchTicker': {
|
|
70
|
+
'channel': 'tickers', // tickers, sprd-tickers, index-tickers, block-tickers
|
|
71
|
+
},
|
|
72
|
+
'watchTickers': {
|
|
73
|
+
'channel': 'tickers', // tickers, sprd-tickers, index-tickers, block-tickers
|
|
74
|
+
},
|
|
75
|
+
'watchOrders': {
|
|
76
|
+
'type': 'ANY', // SPOT, MARGIN, SWAP, FUTURES, OPTION, ANY
|
|
77
|
+
},
|
|
78
|
+
'watchMyTrades': {
|
|
79
|
+
'type': 'ANY', // SPOT, MARGIN, SWAP, FUTURES, OPTION, ANY
|
|
80
|
+
},
|
|
81
|
+
'createOrderWs': {
|
|
82
|
+
'op': 'batch-orders', // order, batch-orders
|
|
83
|
+
},
|
|
84
|
+
'editOrderWs': {
|
|
85
|
+
'op': 'amend-order', // amend-order, batch-amend-orders
|
|
86
|
+
},
|
|
87
|
+
'ws': {
|
|
88
|
+
// 'inflate': true,
|
|
89
|
+
},
|
|
90
|
+
'checksum': true,
|
|
91
|
+
},
|
|
92
|
+
'streaming': {
|
|
93
|
+
// okex does not support built-in ws protocol-level ping-pong
|
|
94
|
+
// instead it requires a custom text-based ping-pong
|
|
95
|
+
'ping': this.ping,
|
|
96
|
+
'keepAlive': 20000,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
getUrl(channel, access = 'public') {
|
|
101
|
+
// for context: https://www.okx.com/help-center/changes-to-v5-api-websocket-subscription-parameter-and-url
|
|
102
|
+
const isSandbox = this.options['sandboxMode'];
|
|
103
|
+
const sandboxSuffix = isSandbox ? '?brokerId=9999' : '';
|
|
104
|
+
const isBusiness = (access === 'business');
|
|
105
|
+
const isPublic = (access === 'public');
|
|
106
|
+
const url = this.urls['api']['ws'];
|
|
107
|
+
if (isBusiness || (channel.indexOf('candle') > -1) || (channel === 'orders-algo')) {
|
|
108
|
+
return url + '/business' + sandboxSuffix;
|
|
109
|
+
}
|
|
110
|
+
else if (isPublic) {
|
|
111
|
+
return url + '/public' + sandboxSuffix;
|
|
112
|
+
}
|
|
113
|
+
return url + '/private' + sandboxSuffix;
|
|
114
|
+
}
|
|
115
|
+
async subscribeMultiple(access, channel, symbols = undefined, params = {}) {
|
|
116
|
+
await this.loadMarkets();
|
|
117
|
+
if (symbols === undefined) {
|
|
118
|
+
symbols = this.symbols;
|
|
119
|
+
}
|
|
120
|
+
symbols = this.marketSymbols(symbols);
|
|
121
|
+
const url = this.getUrl(channel, access);
|
|
122
|
+
let messageHash = channel;
|
|
123
|
+
const args = [];
|
|
124
|
+
messageHash += '::' + symbols.join(',');
|
|
125
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
126
|
+
const marketId = this.marketId(symbols[i]);
|
|
127
|
+
const arg = {
|
|
128
|
+
'channel': channel,
|
|
129
|
+
'instId': marketId,
|
|
130
|
+
};
|
|
131
|
+
args.push(this.extend(arg, params));
|
|
132
|
+
}
|
|
133
|
+
const request = {
|
|
134
|
+
'op': 'subscribe',
|
|
135
|
+
'args': args,
|
|
136
|
+
};
|
|
137
|
+
return await this.watch(url, messageHash, request, messageHash);
|
|
138
|
+
}
|
|
139
|
+
async subscribe(access, messageHash, channel, symbol, params = {}) {
|
|
140
|
+
await this.loadMarkets();
|
|
141
|
+
const url = this.getUrl(channel, access);
|
|
142
|
+
const firstArgument = {
|
|
143
|
+
'channel': channel,
|
|
144
|
+
};
|
|
145
|
+
if (symbol !== undefined) {
|
|
146
|
+
const market = this.market(symbol);
|
|
147
|
+
messageHash += ':' + market['id'];
|
|
148
|
+
firstArgument['instId'] = market['id'];
|
|
149
|
+
}
|
|
150
|
+
const request = {
|
|
151
|
+
'op': 'subscribe',
|
|
152
|
+
'args': [
|
|
153
|
+
this.deepExtend(firstArgument, params),
|
|
154
|
+
],
|
|
155
|
+
};
|
|
156
|
+
return await this.watch(url, messageHash, request, messageHash);
|
|
157
|
+
}
|
|
158
|
+
async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
|
|
159
|
+
/**
|
|
160
|
+
* @method
|
|
161
|
+
* @name okx#watchTrades
|
|
162
|
+
* @description get the list of most recent trades for a particular symbol
|
|
163
|
+
* @param {string} symbol unified symbol of the market to fetch trades for
|
|
164
|
+
* @param {int} [since] timestamp in ms of the earliest trade to fetch
|
|
165
|
+
* @param {int} [limit] the maximum amount of trades to fetch
|
|
166
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
167
|
+
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
|
|
168
|
+
*/
|
|
169
|
+
return await this.watchTradesForSymbols([symbol], since, limit, params);
|
|
170
|
+
}
|
|
171
|
+
async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
|
|
172
|
+
/**
|
|
173
|
+
* @method
|
|
174
|
+
* @name okx#watchTradesForSymbols
|
|
175
|
+
* @description get the list of most recent trades for a particular symbol
|
|
176
|
+
* @param {string} symbol unified symbol of the market to fetch trades for
|
|
177
|
+
* @param {int} [since] timestamp in ms of the earliest trade to fetch
|
|
178
|
+
* @param {int} [limit] the maximum amount of trades to fetch
|
|
179
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
180
|
+
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
|
|
181
|
+
*/
|
|
182
|
+
const symbolsLength = symbols.length;
|
|
183
|
+
if (symbolsLength === 0) {
|
|
184
|
+
throw new errors.ArgumentsRequired(this.id + ' watchTradesForSymbols() requires a non-empty array of symbols');
|
|
185
|
+
}
|
|
186
|
+
await this.loadMarkets();
|
|
187
|
+
symbols = this.marketSymbols(symbols);
|
|
188
|
+
const channel = 'trades';
|
|
189
|
+
const topics = [];
|
|
190
|
+
const messageHashes = [];
|
|
191
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
192
|
+
const symbol = symbols[i];
|
|
193
|
+
messageHashes.push(channel + ':' + symbol);
|
|
194
|
+
const marketId = this.marketId(symbol);
|
|
195
|
+
const topic = {
|
|
196
|
+
'channel': channel,
|
|
197
|
+
'instId': marketId,
|
|
198
|
+
};
|
|
199
|
+
topics.push(topic);
|
|
200
|
+
}
|
|
201
|
+
const request = {
|
|
202
|
+
'op': 'subscribe',
|
|
203
|
+
'args': topics,
|
|
204
|
+
};
|
|
205
|
+
const url = this.getUrl(channel, 'public');
|
|
206
|
+
const trades = await this.watchMultiple(url, messageHashes, request, messageHashes);
|
|
207
|
+
if (this.newUpdates) {
|
|
208
|
+
const first = this.safeValue(trades, 0);
|
|
209
|
+
const tradeSymbol = this.safeString(first, 'symbol');
|
|
210
|
+
limit = trades.getLimit(tradeSymbol, limit);
|
|
211
|
+
}
|
|
212
|
+
return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
|
|
213
|
+
}
|
|
214
|
+
handleTrades(client, message) {
|
|
215
|
+
//
|
|
216
|
+
// {
|
|
217
|
+
// "arg": { channel: "trades", instId: "BTC-USDT" },
|
|
218
|
+
// "data": [
|
|
219
|
+
// {
|
|
220
|
+
// "instId": "BTC-USDT",
|
|
221
|
+
// "tradeId": "216970876",
|
|
222
|
+
// "px": "31684.5",
|
|
223
|
+
// "sz": "0.00001186",
|
|
224
|
+
// "side": "buy",
|
|
225
|
+
// "ts": "1626531038288"
|
|
226
|
+
// }
|
|
227
|
+
// ]
|
|
228
|
+
// }
|
|
229
|
+
//
|
|
230
|
+
const arg = this.safeValue(message, 'arg', {});
|
|
231
|
+
const channel = this.safeString(arg, 'channel');
|
|
232
|
+
const marketId = this.safeString(arg, 'instId');
|
|
233
|
+
const symbol = this.safeSymbol(marketId);
|
|
234
|
+
const data = this.safeValue(message, 'data', []);
|
|
235
|
+
const tradesLimit = this.safeInteger(this.options, 'tradesLimit', 1000);
|
|
236
|
+
for (let i = 0; i < data.length; i++) {
|
|
237
|
+
const trade = this.parseTrade(data[i]);
|
|
238
|
+
const messageHash = channel + ':' + symbol;
|
|
239
|
+
let stored = this.safeValue(this.trades, symbol);
|
|
240
|
+
if (stored === undefined) {
|
|
241
|
+
stored = new Cache.ArrayCache(tradesLimit);
|
|
242
|
+
this.trades[symbol] = stored;
|
|
243
|
+
}
|
|
244
|
+
stored.append(trade);
|
|
245
|
+
client.resolve(stored, messageHash);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async watchTicker(symbol, params = {}) {
|
|
249
|
+
/**
|
|
250
|
+
* @method
|
|
251
|
+
* @name okx#watchTicker
|
|
252
|
+
* @see https://www.okx.com/docs-v5/en/#order-book-trading-market-data-ws-tickers-channel
|
|
253
|
+
* @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
|
|
254
|
+
* @param {string} symbol unified symbol of the market to fetch the ticker for
|
|
255
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
256
|
+
* @param {string} [params.channel] the channel to subscribe to, tickers by default. Can be tickers, sprd-tickers, index-tickers, block-tickers
|
|
257
|
+
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
|
|
258
|
+
*/
|
|
259
|
+
let channel = undefined;
|
|
260
|
+
[channel, params] = this.handleOptionAndParams(params, 'watchTicker', 'channel', 'tickers');
|
|
261
|
+
params['channel'] = channel;
|
|
262
|
+
const ticker = await this.watchTickers([symbol], params);
|
|
263
|
+
return this.safeValue(ticker, symbol);
|
|
264
|
+
}
|
|
265
|
+
async watchTickers(symbols = undefined, params = {}) {
|
|
266
|
+
/**
|
|
267
|
+
* @method
|
|
268
|
+
* @name okx#watchTickers
|
|
269
|
+
* @see https://www.okx.com/docs-v5/en/#order-book-trading-market-data-ws-tickers-channel
|
|
270
|
+
* @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
|
|
271
|
+
* @param {string[]} [symbols] unified symbol of the market to fetch the ticker for
|
|
272
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
273
|
+
* @param {string} [params.channel] the channel to subscribe to, tickers by default. Can be tickers, sprd-tickers, index-tickers, block-tickers
|
|
274
|
+
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
|
|
275
|
+
*/
|
|
276
|
+
if (this.isEmpty(symbols)) {
|
|
277
|
+
throw new errors.ArgumentsRequired(this.id + ' watchTickers requires a list of symbols');
|
|
278
|
+
}
|
|
279
|
+
let channel = undefined;
|
|
280
|
+
[channel, params] = this.handleOptionAndParams(params, 'watchTickers', 'channel', 'tickers');
|
|
281
|
+
const newTickers = await this.subscribeMultiple('public', channel, symbols, params);
|
|
282
|
+
if (this.newUpdates) {
|
|
283
|
+
return newTickers;
|
|
284
|
+
}
|
|
285
|
+
return this.filterByArray(this.tickers, 'symbol', symbols);
|
|
286
|
+
}
|
|
287
|
+
handleTicker(client, message) {
|
|
288
|
+
//
|
|
289
|
+
// {
|
|
290
|
+
// "arg": { channel: "tickers", instId: "BTC-USDT" },
|
|
291
|
+
// "data": [
|
|
292
|
+
// {
|
|
293
|
+
// "instType": "SPOT",
|
|
294
|
+
// "instId": "BTC-USDT",
|
|
295
|
+
// "last": "31500.1",
|
|
296
|
+
// "lastSz": "0.00001754",
|
|
297
|
+
// "askPx": "31500.1",
|
|
298
|
+
// "askSz": "0.00998144",
|
|
299
|
+
// "bidPx": "31500",
|
|
300
|
+
// "bidSz": "3.05652439",
|
|
301
|
+
// "open24h": "31697",
|
|
302
|
+
// "high24h": "32248",
|
|
303
|
+
// "low24h": "31165.6",
|
|
304
|
+
// "sodUtc0": "31385.5",
|
|
305
|
+
// "sodUtc8": "32134.9",
|
|
306
|
+
// "volCcy24h": "503403597.38138519",
|
|
307
|
+
// "vol24h": "15937.10781721",
|
|
308
|
+
// "ts": "1626526618762"
|
|
309
|
+
// }
|
|
310
|
+
// ]
|
|
311
|
+
// }
|
|
312
|
+
//
|
|
313
|
+
const arg = this.safeValue(message, 'arg', {});
|
|
314
|
+
const channel = this.safeString(arg, 'channel');
|
|
315
|
+
const data = this.safeValue(message, 'data', []);
|
|
316
|
+
const newTickers = [];
|
|
317
|
+
for (let i = 0; i < data.length; i++) {
|
|
318
|
+
const ticker = this.parseTicker(data[i]);
|
|
319
|
+
const symbol = ticker['symbol'];
|
|
320
|
+
this.tickers[symbol] = ticker;
|
|
321
|
+
newTickers.push(ticker);
|
|
322
|
+
}
|
|
323
|
+
const messageHashes = this.findMessageHashes(client, channel + '::');
|
|
324
|
+
for (let i = 0; i < messageHashes.length; i++) {
|
|
325
|
+
const messageHash = messageHashes[i];
|
|
326
|
+
const parts = messageHash.split('::');
|
|
327
|
+
const symbolsString = parts[1];
|
|
328
|
+
const symbols = symbolsString.split(',');
|
|
329
|
+
const tickers = this.filterByArray(newTickers, 'symbol', symbols);
|
|
330
|
+
const tickersSymbols = Object.keys(tickers);
|
|
331
|
+
const numTickers = tickersSymbols.length;
|
|
332
|
+
if (numTickers > 0) {
|
|
333
|
+
client.resolve(tickers, messageHash);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return message;
|
|
337
|
+
}
|
|
338
|
+
async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
|
|
339
|
+
/**
|
|
340
|
+
* @method
|
|
341
|
+
* @name okx#watchOHLCV
|
|
342
|
+
* @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
|
|
343
|
+
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
|
|
344
|
+
* @param {string} timeframe the length of time each candle represents
|
|
345
|
+
* @param {int} [since] timestamp in ms of the earliest candle to fetch
|
|
346
|
+
* @param {int} [limit] the maximum amount of candles to fetch
|
|
347
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
348
|
+
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
|
|
349
|
+
*/
|
|
350
|
+
await this.loadMarkets();
|
|
351
|
+
symbol = this.symbol(symbol);
|
|
352
|
+
const interval = this.safeString(this.timeframes, timeframe, timeframe);
|
|
353
|
+
const name = 'candle' + interval;
|
|
354
|
+
const ohlcv = await this.subscribe('public', name, name, symbol, params);
|
|
355
|
+
if (this.newUpdates) {
|
|
356
|
+
limit = ohlcv.getLimit(symbol, limit);
|
|
357
|
+
}
|
|
358
|
+
return this.filterBySinceLimit(ohlcv, since, limit, 0, true);
|
|
359
|
+
}
|
|
360
|
+
async watchOHLCVForSymbols(symbolsAndTimeframes, since = undefined, limit = undefined, params = {}) {
|
|
361
|
+
/**
|
|
362
|
+
* @method
|
|
363
|
+
* @name okx#watchOHLCVForSymbols
|
|
364
|
+
* @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
|
|
365
|
+
* @param {string[][]} symbolsAndTimeframes array of arrays containing unified symbols and timeframes to fetch OHLCV data for, example [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]
|
|
366
|
+
* @param {int} [since] timestamp in ms of the earliest candle to fetch
|
|
367
|
+
* @param {int} [limit] the maximum amount of candles to fetch
|
|
368
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
369
|
+
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
|
|
370
|
+
*/
|
|
371
|
+
const symbolsLength = symbolsAndTimeframes.length;
|
|
372
|
+
if (symbolsLength === 0 || !Array.isArray(symbolsAndTimeframes[0])) {
|
|
373
|
+
throw new errors.ArgumentsRequired(this.id + " watchOHLCVForSymbols() requires a an array of symbols and timeframes, like [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]");
|
|
374
|
+
}
|
|
375
|
+
await this.loadMarkets();
|
|
376
|
+
const topics = [];
|
|
377
|
+
const messageHashes = [];
|
|
378
|
+
for (let i = 0; i < symbolsAndTimeframes.length; i++) {
|
|
379
|
+
const symbolAndTimeframe = symbolsAndTimeframes[i];
|
|
380
|
+
const sym = symbolAndTimeframe[0];
|
|
381
|
+
const tf = symbolAndTimeframe[1];
|
|
382
|
+
const marketId = this.marketId(sym);
|
|
383
|
+
const interval = this.safeString(this.timeframes, tf, tf);
|
|
384
|
+
const channel = 'candle' + interval;
|
|
385
|
+
const topic = {
|
|
386
|
+
'channel': channel,
|
|
387
|
+
'instId': marketId,
|
|
388
|
+
};
|
|
389
|
+
topics.push(topic);
|
|
390
|
+
messageHashes.push('multi:' + channel + ':' + sym);
|
|
391
|
+
}
|
|
392
|
+
const request = {
|
|
393
|
+
'op': 'subscribe',
|
|
394
|
+
'args': topics,
|
|
395
|
+
};
|
|
396
|
+
const url = this.getUrl('candle', 'public');
|
|
397
|
+
const [symbol, timeframe, candles] = await this.watchMultiple(url, messageHashes, request, messageHashes);
|
|
398
|
+
if (this.newUpdates) {
|
|
399
|
+
limit = candles.getLimit(symbol, limit);
|
|
400
|
+
}
|
|
401
|
+
const filtered = this.filterBySinceLimit(candles, since, limit, 0, true);
|
|
402
|
+
return this.createOHLCVObject(symbol, timeframe, filtered);
|
|
403
|
+
}
|
|
404
|
+
handleOHLCV(client, message) {
|
|
405
|
+
//
|
|
406
|
+
// {
|
|
407
|
+
// "arg": { channel: "candle1m", instId: "BTC-USDT" },
|
|
408
|
+
// "data": [
|
|
409
|
+
// [
|
|
410
|
+
// "1626690720000",
|
|
411
|
+
// "31334",
|
|
412
|
+
// "31334",
|
|
413
|
+
// "31334",
|
|
414
|
+
// "31334",
|
|
415
|
+
// "0.0077",
|
|
416
|
+
// "241.2718"
|
|
417
|
+
// ]
|
|
418
|
+
// ]
|
|
419
|
+
// }
|
|
420
|
+
//
|
|
421
|
+
const arg = this.safeValue(message, 'arg', {});
|
|
422
|
+
const channel = this.safeString(arg, 'channel');
|
|
423
|
+
const data = this.safeValue(message, 'data', []);
|
|
424
|
+
const marketId = this.safeString(arg, 'instId');
|
|
425
|
+
const market = this.safeMarket(marketId);
|
|
426
|
+
const symbol = market['symbol'];
|
|
427
|
+
const interval = channel.replace('candle', '');
|
|
428
|
+
// use a reverse lookup in a static map instead
|
|
429
|
+
const timeframe = this.findTimeframe(interval);
|
|
430
|
+
for (let i = 0; i < data.length; i++) {
|
|
431
|
+
const parsed = this.parseOHLCV(data[i], market);
|
|
432
|
+
this.ohlcvs[symbol] = this.safeValue(this.ohlcvs, symbol, {});
|
|
433
|
+
let stored = this.safeValue(this.ohlcvs[symbol], timeframe);
|
|
434
|
+
if (stored === undefined) {
|
|
435
|
+
const limit = this.safeInteger(this.options, 'OHLCVLimit', 1000);
|
|
436
|
+
stored = new Cache.ArrayCacheByTimestamp(limit);
|
|
437
|
+
this.ohlcvs[symbol][timeframe] = stored;
|
|
438
|
+
}
|
|
439
|
+
stored.append(parsed);
|
|
440
|
+
const messageHash = channel + ':' + market['id'];
|
|
441
|
+
client.resolve(stored, messageHash);
|
|
442
|
+
// for multiOHLCV we need special object, as opposed to other "multi"
|
|
443
|
+
// methods, because OHLCV response item does not contain symbol
|
|
444
|
+
// or timeframe, thus otherwise it would be unrecognizable
|
|
445
|
+
const messageHashForMulti = 'multi:' + channel + ':' + symbol;
|
|
446
|
+
client.resolve([symbol, timeframe, stored], messageHashForMulti);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
async watchOrderBook(symbol, limit = undefined, params = {}) {
|
|
450
|
+
/**
|
|
451
|
+
* @method
|
|
452
|
+
* @name okx#watchOrderBook
|
|
453
|
+
* @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
|
|
454
|
+
* @param {string} symbol unified symbol of the market to fetch the order book for
|
|
455
|
+
* @param {int} [limit] the maximum amount of order book entries to return
|
|
456
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
457
|
+
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
|
|
458
|
+
*/
|
|
459
|
+
//
|
|
460
|
+
// bbo-tbt
|
|
461
|
+
// 1. Newly added channel that sends tick-by-tick Level 1 data
|
|
462
|
+
// 2. All API users can subscribe
|
|
463
|
+
// 3. Public depth channel, verification not required
|
|
464
|
+
//
|
|
465
|
+
// books-l2-tbt
|
|
466
|
+
// 1. Only users who're VIP5 and above can subscribe
|
|
467
|
+
// 2. Identity verification required before subscription
|
|
468
|
+
//
|
|
469
|
+
// books50-l2-tbt
|
|
470
|
+
// 1. Only users who're VIP4 and above can subscribe
|
|
471
|
+
// 2. Identity verification required before subscription
|
|
472
|
+
//
|
|
473
|
+
// books
|
|
474
|
+
// 1. All API users can subscribe
|
|
475
|
+
// 2. Public depth channel, verification not required
|
|
476
|
+
//
|
|
477
|
+
// books5
|
|
478
|
+
// 1. All API users can subscribe
|
|
479
|
+
// 2. Public depth channel, verification not required
|
|
480
|
+
// 3. Data feeds will be delivered every 100ms (vs. every 200ms now)
|
|
481
|
+
//
|
|
482
|
+
return await this.watchOrderBookForSymbols([symbol], limit, params);
|
|
483
|
+
}
|
|
484
|
+
async watchOrderBookForSymbols(symbols, limit = undefined, params = {}) {
|
|
485
|
+
/**
|
|
486
|
+
* @method
|
|
487
|
+
* @name okx#watchOrderBookForSymbols
|
|
488
|
+
* @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
|
|
489
|
+
* @param {string[]} symbols unified array of symbols
|
|
490
|
+
* @param {int} [limit] the maximum amount of order book entries to return
|
|
491
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
492
|
+
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
|
|
493
|
+
*/
|
|
494
|
+
await this.loadMarkets();
|
|
495
|
+
symbols = this.marketSymbols(symbols);
|
|
496
|
+
const options = this.safeValue(this.options, 'watchOrderBook', {});
|
|
497
|
+
const depth = this.safeString(options, 'depth', 'books');
|
|
498
|
+
if ((depth === 'books-l2-tbt') || (depth === 'books50-l2-tbt')) {
|
|
499
|
+
await this.authenticate({ 'access': 'public' });
|
|
500
|
+
}
|
|
501
|
+
const topics = [];
|
|
502
|
+
const messageHashes = [];
|
|
503
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
504
|
+
const symbol = symbols[i];
|
|
505
|
+
messageHashes.push(depth + ':' + symbol);
|
|
506
|
+
const marketId = this.marketId(symbol);
|
|
507
|
+
const topic = {
|
|
508
|
+
'channel': depth,
|
|
509
|
+
'instId': marketId,
|
|
510
|
+
};
|
|
511
|
+
topics.push(topic);
|
|
512
|
+
}
|
|
513
|
+
const request = {
|
|
514
|
+
'op': 'subscribe',
|
|
515
|
+
'args': topics,
|
|
516
|
+
};
|
|
517
|
+
const url = this.getUrl(depth, 'public');
|
|
518
|
+
const orderbook = await this.watchMultiple(url, messageHashes, request, messageHashes);
|
|
519
|
+
return orderbook.limit();
|
|
520
|
+
}
|
|
521
|
+
handleDelta(bookside, delta) {
|
|
522
|
+
//
|
|
523
|
+
// [
|
|
524
|
+
// "31685", // price
|
|
525
|
+
// "0.78069158", // amount
|
|
526
|
+
// "0", // liquidated orders
|
|
527
|
+
// "17" // orders
|
|
528
|
+
// ]
|
|
529
|
+
//
|
|
530
|
+
const price = this.safeFloat(delta, 0);
|
|
531
|
+
const amount = this.safeFloat(delta, 1);
|
|
532
|
+
bookside.store(price, amount);
|
|
533
|
+
}
|
|
534
|
+
handleDeltas(bookside, deltas) {
|
|
535
|
+
for (let i = 0; i < deltas.length; i++) {
|
|
536
|
+
this.handleDelta(bookside, deltas[i]);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
handleOrderBookMessage(client, message, orderbook, messageHash) {
|
|
540
|
+
//
|
|
541
|
+
// {
|
|
542
|
+
// "asks": [
|
|
543
|
+
// [ '31738.3', '0.05973179', "0", "3" ],
|
|
544
|
+
// [ '31738.5', '0.11035404', "0", "2" ],
|
|
545
|
+
// [ '31739.6', '0.01', "0", "1" ],
|
|
546
|
+
// ],
|
|
547
|
+
// "bids": [
|
|
548
|
+
// [ '31738.2', '0.67557666', "0", "9" ],
|
|
549
|
+
// [ '31738', '0.02466947', "0", "2" ],
|
|
550
|
+
// [ '31736.3', '0.01705046', "0", "2" ],
|
|
551
|
+
// ],
|
|
552
|
+
// "instId": "BTC-USDT",
|
|
553
|
+
// "ts": "1626537446491"
|
|
554
|
+
// }
|
|
555
|
+
//
|
|
556
|
+
const asks = this.safeValue(message, 'asks', []);
|
|
557
|
+
const bids = this.safeValue(message, 'bids', []);
|
|
558
|
+
const storedAsks = orderbook['asks'];
|
|
559
|
+
const storedBids = orderbook['bids'];
|
|
560
|
+
this.handleDeltas(storedAsks, asks);
|
|
561
|
+
this.handleDeltas(storedBids, bids);
|
|
562
|
+
const checksum = this.safeValue(this.options, 'checksum', true);
|
|
563
|
+
if (checksum) {
|
|
564
|
+
const asksLength = storedAsks.length;
|
|
565
|
+
const bidsLength = storedBids.length;
|
|
566
|
+
const payloadArray = [];
|
|
567
|
+
for (let i = 0; i < 25; i++) {
|
|
568
|
+
if (i < bidsLength) {
|
|
569
|
+
payloadArray.push(this.numberToString(storedBids[i][0]));
|
|
570
|
+
payloadArray.push(this.numberToString(storedBids[i][1]));
|
|
571
|
+
}
|
|
572
|
+
if (i < asksLength) {
|
|
573
|
+
payloadArray.push(this.numberToString(storedAsks[i][0]));
|
|
574
|
+
payloadArray.push(this.numberToString(storedAsks[i][1]));
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
const payload = payloadArray.join(':');
|
|
578
|
+
const responseChecksum = this.safeInteger(message, 'checksum');
|
|
579
|
+
const localChecksum = this.crc32(payload, true);
|
|
580
|
+
if (responseChecksum !== localChecksum) {
|
|
581
|
+
const error = new errors.InvalidNonce(this.id + ' invalid checksum');
|
|
582
|
+
client.reject(error, messageHash);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
const timestamp = this.safeInteger(message, 'ts');
|
|
586
|
+
orderbook['timestamp'] = timestamp;
|
|
587
|
+
orderbook['datetime'] = this.iso8601(timestamp);
|
|
588
|
+
return orderbook;
|
|
589
|
+
}
|
|
590
|
+
handleOrderBook(client, message) {
|
|
591
|
+
//
|
|
592
|
+
// snapshot
|
|
593
|
+
//
|
|
594
|
+
// {
|
|
595
|
+
// "arg": { channel: 'books-l2-tbt', instId: "BTC-USDT" },
|
|
596
|
+
// "action": "snapshot",
|
|
597
|
+
// "data": [
|
|
598
|
+
// {
|
|
599
|
+
// "asks": [
|
|
600
|
+
// [ '31685', '0.78069158', "0", "17" ],
|
|
601
|
+
// [ '31685.1', '0.0001', "0", "1" ],
|
|
602
|
+
// [ '31685.6', '0.04543165', "0", "1" ],
|
|
603
|
+
// ],
|
|
604
|
+
// "bids": [
|
|
605
|
+
// [ '31684.9', '0.01', "0", "1" ],
|
|
606
|
+
// [ '31682.9', '0.0001', "0", "1" ],
|
|
607
|
+
// [ '31680.7', '0.01', "0", "1" ],
|
|
608
|
+
// ],
|
|
609
|
+
// "ts": "1626532416403",
|
|
610
|
+
// "checksum": -1023440116
|
|
611
|
+
// }
|
|
612
|
+
// ]
|
|
613
|
+
// }
|
|
614
|
+
//
|
|
615
|
+
// update
|
|
616
|
+
//
|
|
617
|
+
// {
|
|
618
|
+
// "arg": { channel: 'books-l2-tbt', instId: "BTC-USDT" },
|
|
619
|
+
// "action": "update",
|
|
620
|
+
// "data": [
|
|
621
|
+
// {
|
|
622
|
+
// "asks": [
|
|
623
|
+
// [ '31657.7', '0', "0", "0" ],
|
|
624
|
+
// [ '31659.7', '0.01', "0", "1" ],
|
|
625
|
+
// [ '31987.3', '0.01', "0", "1" ]
|
|
626
|
+
// ],
|
|
627
|
+
// "bids": [
|
|
628
|
+
// [ '31642.9', '0.50296385', "0", "4" ],
|
|
629
|
+
// [ '31639.9', '0', "0", "0" ],
|
|
630
|
+
// [ '31638.7', '0.01', "0", "1" ],
|
|
631
|
+
// ],
|
|
632
|
+
// "ts": "1626535709008",
|
|
633
|
+
// "checksum": 830931827
|
|
634
|
+
// }
|
|
635
|
+
// ]
|
|
636
|
+
// }
|
|
637
|
+
//
|
|
638
|
+
// books5
|
|
639
|
+
//
|
|
640
|
+
// {
|
|
641
|
+
// "arg": { channel: "books5", instId: "BTC-USDT" },
|
|
642
|
+
// "data": [
|
|
643
|
+
// {
|
|
644
|
+
// "asks": [
|
|
645
|
+
// [ '31738.3', '0.05973179', "0", "3" ],
|
|
646
|
+
// [ '31738.5', '0.11035404', "0", "2" ],
|
|
647
|
+
// [ '31739.6', '0.01', "0", "1" ],
|
|
648
|
+
// ],
|
|
649
|
+
// "bids": [
|
|
650
|
+
// [ '31738.2', '0.67557666', "0", "9" ],
|
|
651
|
+
// [ '31738', '0.02466947', "0", "2" ],
|
|
652
|
+
// [ '31736.3', '0.01705046', "0", "2" ],
|
|
653
|
+
// ],
|
|
654
|
+
// "instId": "BTC-USDT",
|
|
655
|
+
// "ts": "1626537446491"
|
|
656
|
+
// }
|
|
657
|
+
// ]
|
|
658
|
+
// }
|
|
659
|
+
//
|
|
660
|
+
// bbo-tbt
|
|
661
|
+
//
|
|
662
|
+
// {
|
|
663
|
+
// "arg":{
|
|
664
|
+
// "channel":"bbo-tbt",
|
|
665
|
+
// "instId":"BTC-USDT"
|
|
666
|
+
// },
|
|
667
|
+
// "data":[
|
|
668
|
+
// {
|
|
669
|
+
// "asks":[["36232.2","1.8826134","0","17"]],
|
|
670
|
+
// "bids":[["36232.1","0.00572212","0","2"]],
|
|
671
|
+
// "ts":"1651826598363"
|
|
672
|
+
// }
|
|
673
|
+
// ]
|
|
674
|
+
// }
|
|
675
|
+
//
|
|
676
|
+
const arg = this.safeValue(message, 'arg', {});
|
|
677
|
+
const channel = this.safeString(arg, 'channel');
|
|
678
|
+
const action = this.safeString(message, 'action');
|
|
679
|
+
const data = this.safeValue(message, 'data', []);
|
|
680
|
+
const marketId = this.safeString(arg, 'instId');
|
|
681
|
+
const market = this.safeMarket(marketId);
|
|
682
|
+
const symbol = market['symbol'];
|
|
683
|
+
const depths = {
|
|
684
|
+
'bbo-tbt': 1,
|
|
685
|
+
'books': 400,
|
|
686
|
+
'books5': 5,
|
|
687
|
+
'books-l2-tbt': 400,
|
|
688
|
+
'books50-l2-tbt': 50,
|
|
689
|
+
};
|
|
690
|
+
const limit = this.safeInteger(depths, channel);
|
|
691
|
+
const messageHash = channel + ':' + symbol;
|
|
692
|
+
if (action === 'snapshot') {
|
|
693
|
+
for (let i = 0; i < data.length; i++) {
|
|
694
|
+
const update = data[i];
|
|
695
|
+
const orderbook = this.orderBook({}, limit);
|
|
696
|
+
this.orderbooks[symbol] = orderbook;
|
|
697
|
+
orderbook['symbol'] = symbol;
|
|
698
|
+
this.handleOrderBookMessage(client, update, orderbook, messageHash);
|
|
699
|
+
client.resolve(orderbook, messageHash);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
else if (action === 'update') {
|
|
703
|
+
if (symbol in this.orderbooks) {
|
|
704
|
+
const orderbook = this.orderbooks[symbol];
|
|
705
|
+
for (let i = 0; i < data.length; i++) {
|
|
706
|
+
const update = data[i];
|
|
707
|
+
this.handleOrderBookMessage(client, update, orderbook, messageHash);
|
|
708
|
+
client.resolve(orderbook, messageHash);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
else if ((channel === 'books5') || (channel === 'bbo-tbt')) {
|
|
713
|
+
let orderbook = this.safeValue(this.orderbooks, symbol);
|
|
714
|
+
if (orderbook === undefined) {
|
|
715
|
+
orderbook = this.orderBook({}, limit);
|
|
716
|
+
}
|
|
717
|
+
this.orderbooks[symbol] = orderbook;
|
|
718
|
+
for (let i = 0; i < data.length; i++) {
|
|
719
|
+
const update = data[i];
|
|
720
|
+
const timestamp = this.safeInteger(update, 'ts');
|
|
721
|
+
const snapshot = this.parseOrderBook(update, symbol, timestamp, 'bids', 'asks', 0, 1);
|
|
722
|
+
orderbook.reset(snapshot);
|
|
723
|
+
client.resolve(orderbook, messageHash);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
return message;
|
|
727
|
+
}
|
|
728
|
+
async authenticate(params = {}) {
|
|
729
|
+
this.checkRequiredCredentials();
|
|
730
|
+
const access = this.safeString(params, 'access', 'private');
|
|
731
|
+
params = this.omit(params, ['access']);
|
|
732
|
+
const url = this.getUrl('users', access);
|
|
733
|
+
const messageHash = 'authenticated';
|
|
734
|
+
const client = this.client(url);
|
|
735
|
+
const future = client.future(messageHash);
|
|
736
|
+
const authenticated = this.safeValue(client.subscriptions, messageHash);
|
|
737
|
+
if (authenticated === undefined) {
|
|
738
|
+
const timestamp = this.seconds().toString();
|
|
739
|
+
const method = 'GET';
|
|
740
|
+
const path = '/users/self/verify';
|
|
741
|
+
const auth = timestamp + method + path;
|
|
742
|
+
const signature = this.hmac(this.encode(auth), this.encode(this.secret), sha256.sha256, 'base64');
|
|
743
|
+
const operation = 'login';
|
|
744
|
+
const request = {
|
|
745
|
+
'op': operation,
|
|
746
|
+
'args': [
|
|
747
|
+
{
|
|
748
|
+
'apiKey': this.apiKey,
|
|
749
|
+
'passphrase': this.password,
|
|
750
|
+
'timestamp': timestamp,
|
|
751
|
+
'sign': signature,
|
|
752
|
+
},
|
|
753
|
+
],
|
|
754
|
+
};
|
|
755
|
+
const message = this.extend(request, params);
|
|
756
|
+
this.watch(url, messageHash, message, messageHash);
|
|
757
|
+
}
|
|
758
|
+
return future;
|
|
759
|
+
}
|
|
760
|
+
async watchBalance(params = {}) {
|
|
761
|
+
/**
|
|
762
|
+
* @method
|
|
763
|
+
* @name okx#watchBalance
|
|
764
|
+
* @description watch balance and get the amount of funds available for trading or funds locked in orders
|
|
765
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
766
|
+
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
|
|
767
|
+
*/
|
|
768
|
+
await this.loadMarkets();
|
|
769
|
+
await this.authenticate();
|
|
770
|
+
return await this.subscribe('private', 'account', 'account', undefined, params);
|
|
771
|
+
}
|
|
772
|
+
handleBalance(client, message) {
|
|
773
|
+
//
|
|
774
|
+
// {
|
|
775
|
+
// "arg": { channel: "account" },
|
|
776
|
+
// "data": [
|
|
777
|
+
// {
|
|
778
|
+
// "adjEq": '',
|
|
779
|
+
// "details": [
|
|
780
|
+
// {
|
|
781
|
+
// "availBal": '',
|
|
782
|
+
// "availEq": "8.21009913",
|
|
783
|
+
// "cashBal": "8.21009913",
|
|
784
|
+
// "ccy": "USDT",
|
|
785
|
+
// "coinUsdPrice": "0.99994",
|
|
786
|
+
// "crossLiab": '',
|
|
787
|
+
// "disEq": "8.2096065240522",
|
|
788
|
+
// "eq": "8.21009913",
|
|
789
|
+
// "eqUsd": "8.2096065240522",
|
|
790
|
+
// "frozenBal": "0",
|
|
791
|
+
// "interest": '',
|
|
792
|
+
// "isoEq": "0",
|
|
793
|
+
// "isoLiab": '',
|
|
794
|
+
// "liab": '',
|
|
795
|
+
// "maxLoan": '',
|
|
796
|
+
// "mgnRatio": '',
|
|
797
|
+
// "notionalLever": "0",
|
|
798
|
+
// "ordFrozen": "0",
|
|
799
|
+
// "twap": "0",
|
|
800
|
+
// "uTime": "1621927314996",
|
|
801
|
+
// "upl": "0"
|
|
802
|
+
// },
|
|
803
|
+
// ],
|
|
804
|
+
// "imr": '',
|
|
805
|
+
// "isoEq": "0",
|
|
806
|
+
// "mgnRatio": '',
|
|
807
|
+
// "mmr": '',
|
|
808
|
+
// "notionalUsd": '',
|
|
809
|
+
// "ordFroz": '',
|
|
810
|
+
// "totalEq": "22.1930992296832",
|
|
811
|
+
// "uTime": "1626692120916"
|
|
812
|
+
// }
|
|
813
|
+
// ]
|
|
814
|
+
// }
|
|
815
|
+
//
|
|
816
|
+
const arg = this.safeValue(message, 'arg', {});
|
|
817
|
+
const channel = this.safeString(arg, 'channel');
|
|
818
|
+
const type = 'spot';
|
|
819
|
+
const balance = this.parseTradingBalance(message);
|
|
820
|
+
const oldBalance = this.safeValue(this.balance, type, {});
|
|
821
|
+
const newBalance = this.deepExtend(oldBalance, balance);
|
|
822
|
+
this.balance[type] = this.safeBalance(newBalance);
|
|
823
|
+
client.resolve(this.balance[type], channel);
|
|
824
|
+
}
|
|
825
|
+
orderToTrade(order, market = undefined) {
|
|
826
|
+
const info = this.safeValue(order, 'info', {});
|
|
827
|
+
const timestamp = this.safeInteger(info, 'fillTime');
|
|
828
|
+
const feeMarketId = this.safeString(info, 'fillFeeCcy');
|
|
829
|
+
const isTaker = this.safeString(info, 'execType', '') === 'T';
|
|
830
|
+
return this.safeTrade({
|
|
831
|
+
'info': info,
|
|
832
|
+
'timestamp': timestamp,
|
|
833
|
+
'datetime': this.iso8601(timestamp),
|
|
834
|
+
'symbol': this.safeString(order, 'symbol'),
|
|
835
|
+
'id': this.safeString(info, 'tradeId'),
|
|
836
|
+
'order': this.safeString(order, 'id'),
|
|
837
|
+
'type': this.safeString(order, 'type'),
|
|
838
|
+
'takerOrMaker': (isTaker) ? 'taker' : 'maker',
|
|
839
|
+
'side': this.safeString(order, 'side'),
|
|
840
|
+
'price': this.safeNumber(info, 'fillPx'),
|
|
841
|
+
'amount': this.safeNumber(info, 'fillSz'),
|
|
842
|
+
'cost': this.safeNumber(order, 'cost'),
|
|
843
|
+
'fee': {
|
|
844
|
+
'cost': this.safeNumber(info, 'fillFee'),
|
|
845
|
+
'currency': this.safeCurrencyCode(feeMarketId),
|
|
846
|
+
},
|
|
847
|
+
}, market);
|
|
848
|
+
}
|
|
849
|
+
async watchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
850
|
+
/**
|
|
851
|
+
* @method
|
|
852
|
+
* @name okx#watchMyTrades
|
|
853
|
+
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-order-channel
|
|
854
|
+
* @description watches information on multiple trades made by the user
|
|
855
|
+
* @param {string} [symbol] unified market symbol of the market trades were made in
|
|
856
|
+
* @param {int} [since] the earliest time in ms to fetch trades for
|
|
857
|
+
* @param {int} [limit] the maximum number of trade structures to retrieve
|
|
858
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
859
|
+
* @param {bool} [params.stop] true if fetching trigger or conditional trades
|
|
860
|
+
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure
|
|
861
|
+
*/
|
|
862
|
+
// By default, receive order updates from any instrument type
|
|
863
|
+
let type = undefined;
|
|
864
|
+
[type, params] = this.handleOptionAndParams(params, 'watchMyTrades', 'type', 'ANY');
|
|
865
|
+
const isStop = this.safeValue(params, 'stop', false);
|
|
866
|
+
params = this.omit(params, ['stop']);
|
|
867
|
+
await this.loadMarkets();
|
|
868
|
+
await this.authenticate({ 'access': isStop ? 'business' : 'private' });
|
|
869
|
+
const channel = isStop ? 'orders-algo' : 'orders';
|
|
870
|
+
let messageHash = channel + '::myTrades';
|
|
871
|
+
let market = undefined;
|
|
872
|
+
if (symbol !== undefined) {
|
|
873
|
+
market = this.market(symbol);
|
|
874
|
+
symbol = market['symbol'];
|
|
875
|
+
type = market['type'];
|
|
876
|
+
messageHash = messageHash + '::' + symbol;
|
|
877
|
+
}
|
|
878
|
+
if (type === 'future') {
|
|
879
|
+
type = 'futures';
|
|
880
|
+
}
|
|
881
|
+
const uppercaseType = type.toUpperCase();
|
|
882
|
+
const request = {
|
|
883
|
+
'instType': uppercaseType,
|
|
884
|
+
};
|
|
885
|
+
const orders = await this.subscribe('private', messageHash, channel, undefined, this.extend(request, params));
|
|
886
|
+
if (this.newUpdates) {
|
|
887
|
+
limit = orders.getLimit(symbol, limit);
|
|
888
|
+
}
|
|
889
|
+
return this.filterBySymbolSinceLimit(orders, symbol, since, limit, true);
|
|
890
|
+
}
|
|
891
|
+
async watchPositions(symbols = undefined, since = undefined, limit = undefined, params = {}) {
|
|
892
|
+
/**
|
|
893
|
+
* @method
|
|
894
|
+
* @name okx#watchPositions
|
|
895
|
+
* @see https://www.okx.com/docs-v5/en/#trading-account-websocket-positions-channel
|
|
896
|
+
* @description watch all open positions
|
|
897
|
+
* @param {string[]|undefined} symbols list of unified market symbols
|
|
898
|
+
* @param {object} params extra parameters specific to the exchange API endpoint
|
|
899
|
+
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
|
|
900
|
+
*/
|
|
901
|
+
if (this.isEmpty(symbols)) {
|
|
902
|
+
throw new errors.ArgumentsRequired(this.id + ' watchPositions requires a list of symbols');
|
|
903
|
+
}
|
|
904
|
+
await this.loadMarkets();
|
|
905
|
+
await this.authenticate(params);
|
|
906
|
+
symbols = this.marketSymbols(symbols);
|
|
907
|
+
const request = {
|
|
908
|
+
'instType': 'ANY',
|
|
909
|
+
};
|
|
910
|
+
const channel = 'positions';
|
|
911
|
+
const newPositions = await this.subscribeMultiple('private', channel, symbols, this.extend(request, params));
|
|
912
|
+
if (this.newUpdates) {
|
|
913
|
+
return newPositions;
|
|
914
|
+
}
|
|
915
|
+
return this.filterBySymbolsSinceLimit(this.positions, symbols, since, limit, true);
|
|
916
|
+
}
|
|
917
|
+
handlePositions(client, message) {
|
|
918
|
+
//
|
|
919
|
+
// {
|
|
920
|
+
// arg: {
|
|
921
|
+
// channel: 'positions',
|
|
922
|
+
// instType: 'ANY',
|
|
923
|
+
// instId: 'XRP-USDT-SWAP',
|
|
924
|
+
// uid: '464737184507959869'
|
|
925
|
+
// },
|
|
926
|
+
// data: [{
|
|
927
|
+
// adl: '1',
|
|
928
|
+
// availPos: '',
|
|
929
|
+
// avgPx: '0.52668',
|
|
930
|
+
// baseBal: '',
|
|
931
|
+
// baseBorrowed: '',
|
|
932
|
+
// baseInterest: '',
|
|
933
|
+
// bizRefId: '',
|
|
934
|
+
// bizRefType: '',
|
|
935
|
+
// cTime: '1693151444408',
|
|
936
|
+
// ccy: 'USDT',
|
|
937
|
+
// closeOrderAlgo: [],
|
|
938
|
+
// deltaBS: '',
|
|
939
|
+
// deltaPA: '',
|
|
940
|
+
// gammaBS: '',
|
|
941
|
+
// gammaPA: '',
|
|
942
|
+
// idxPx: '0.52683',
|
|
943
|
+
// imr: '17.564000000000004',
|
|
944
|
+
// instId: 'XRP-USDT-SWAP',
|
|
945
|
+
// instType: 'SWAP',
|
|
946
|
+
// interest: '',
|
|
947
|
+
// last: '0.52691',
|
|
948
|
+
// lever: '3',
|
|
949
|
+
// liab: '',
|
|
950
|
+
// liabCcy: '',
|
|
951
|
+
// liqPx: '0.3287514731020614',
|
|
952
|
+
// margin: '',
|
|
953
|
+
// markPx: '0.52692',
|
|
954
|
+
// mgnMode: 'cross',
|
|
955
|
+
// mgnRatio: '69.00363001456147',
|
|
956
|
+
// mmr: '0.26346',
|
|
957
|
+
// notionalUsd: '52.68620388000001',
|
|
958
|
+
// optVal: '',
|
|
959
|
+
// pTime: '1693151906023',
|
|
960
|
+
// pendingCloseOrdLiabVal: '',
|
|
961
|
+
// pos: '1',
|
|
962
|
+
// posCcy: '',
|
|
963
|
+
// posId: '616057041198907393',
|
|
964
|
+
// posSide: 'net',
|
|
965
|
+
// quoteBal: '',
|
|
966
|
+
// quoteBorrowed: '',
|
|
967
|
+
// quoteInterest: '',
|
|
968
|
+
// spotInUseAmt: '',
|
|
969
|
+
// spotInUseCcy: '',
|
|
970
|
+
// thetaBS: '',
|
|
971
|
+
// thetaPA: '',
|
|
972
|
+
// tradeId: '138745402',
|
|
973
|
+
// uTime: '1693151444408',
|
|
974
|
+
// upl: '0.0240000000000018',
|
|
975
|
+
// uplLastPx: '0.0229999999999952',
|
|
976
|
+
// uplRatio: '0.0013670539986328',
|
|
977
|
+
// uplRatioLastPx: '0.001310093415356',
|
|
978
|
+
// usdPx: '',
|
|
979
|
+
// vegaBS: '',
|
|
980
|
+
// vegaPA: ''
|
|
981
|
+
// }]
|
|
982
|
+
// }
|
|
983
|
+
//
|
|
984
|
+
const arg = this.safeValue(message, 'arg', {});
|
|
985
|
+
const channel = this.safeString(arg, 'channel', '');
|
|
986
|
+
const data = this.safeValue(message, 'data', []);
|
|
987
|
+
if (this.positions === undefined) {
|
|
988
|
+
this.positions = new Cache.ArrayCacheBySymbolBySide();
|
|
989
|
+
}
|
|
990
|
+
const cache = this.positions;
|
|
991
|
+
const newPositions = [];
|
|
992
|
+
for (let i = 0; i < data.length; i++) {
|
|
993
|
+
const rawPosition = data[i];
|
|
994
|
+
const position = this.parsePosition(rawPosition);
|
|
995
|
+
newPositions.push(position);
|
|
996
|
+
cache.append(position);
|
|
997
|
+
}
|
|
998
|
+
const messageHashes = this.findMessageHashes(client, channel + '::');
|
|
999
|
+
for (let i = 0; i < messageHashes.length; i++) {
|
|
1000
|
+
const messageHash = messageHashes[i];
|
|
1001
|
+
const parts = messageHash.split('::');
|
|
1002
|
+
const symbolsString = parts[1];
|
|
1003
|
+
const symbols = symbolsString.split(',');
|
|
1004
|
+
const positions = this.filterByArray(newPositions, 'symbol', symbols, false);
|
|
1005
|
+
if (!this.isEmpty(positions)) {
|
|
1006
|
+
client.resolve(positions, messageHash);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
async watchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1011
|
+
/**
|
|
1012
|
+
* @method
|
|
1013
|
+
* @name okx#watchOrders
|
|
1014
|
+
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-order-channel
|
|
1015
|
+
* @description watches information on multiple orders made by the user
|
|
1016
|
+
* @param {string} [symbol] unified market symbol of the market orders were made in
|
|
1017
|
+
* @param {int} [since] the earliest time in ms to fetch orders for
|
|
1018
|
+
* @param {int} [limit] the maximum number of order structures to retrieve
|
|
1019
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1020
|
+
* @param {bool} [params.stop] true if fetching trigger or conditional orders
|
|
1021
|
+
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1022
|
+
*/
|
|
1023
|
+
let type = undefined;
|
|
1024
|
+
// By default, receive order updates from any instrument type
|
|
1025
|
+
[type, params] = this.handleOptionAndParams(params, 'watchOrders', 'type', 'ANY');
|
|
1026
|
+
const isStop = this.safeValue2(params, 'stop', 'trigger', false);
|
|
1027
|
+
params = this.omit(params, ['stop', 'trigger']);
|
|
1028
|
+
await this.loadMarkets();
|
|
1029
|
+
await this.authenticate({ 'access': isStop ? 'business' : 'private' });
|
|
1030
|
+
let market = undefined;
|
|
1031
|
+
if (symbol !== undefined) {
|
|
1032
|
+
market = this.market(symbol);
|
|
1033
|
+
symbol = market['symbol'];
|
|
1034
|
+
type = market['type'];
|
|
1035
|
+
}
|
|
1036
|
+
if (type === 'future') {
|
|
1037
|
+
type = 'futures';
|
|
1038
|
+
}
|
|
1039
|
+
const uppercaseType = type.toUpperCase();
|
|
1040
|
+
const request = {
|
|
1041
|
+
'instType': uppercaseType,
|
|
1042
|
+
};
|
|
1043
|
+
const channel = isStop ? 'orders-algo' : 'orders';
|
|
1044
|
+
const orders = await this.subscribe('private', channel, channel, symbol, this.extend(request, params));
|
|
1045
|
+
if (this.newUpdates) {
|
|
1046
|
+
limit = orders.getLimit(symbol, limit);
|
|
1047
|
+
}
|
|
1048
|
+
return this.filterBySymbolSinceLimit(orders, symbol, since, limit, true);
|
|
1049
|
+
}
|
|
1050
|
+
handleOrders(client, message, subscription = undefined) {
|
|
1051
|
+
//
|
|
1052
|
+
// {
|
|
1053
|
+
// "arg":{
|
|
1054
|
+
// "channel":"orders",
|
|
1055
|
+
// "instType":"SPOT"
|
|
1056
|
+
// },
|
|
1057
|
+
// "data":[
|
|
1058
|
+
// {
|
|
1059
|
+
// "accFillSz":"0",
|
|
1060
|
+
// "amendResult":"",
|
|
1061
|
+
// "avgPx":"",
|
|
1062
|
+
// "cTime":"1634548275191",
|
|
1063
|
+
// "category":"normal",
|
|
1064
|
+
// "ccy":"",
|
|
1065
|
+
// "clOrdId":"e847386590ce4dBC330547db94a08ba0",
|
|
1066
|
+
// "code":"0",
|
|
1067
|
+
// "execType":"",
|
|
1068
|
+
// "fee":"0",
|
|
1069
|
+
// "feeCcy":"USDT",
|
|
1070
|
+
// "fillFee":"0",
|
|
1071
|
+
// "fillFeeCcy":"",
|
|
1072
|
+
// "fillNotionalUsd":"",
|
|
1073
|
+
// "fillPx":"",
|
|
1074
|
+
// "fillSz":"0",
|
|
1075
|
+
// "fillTime":"",
|
|
1076
|
+
// "instId":"ETH-USDT",
|
|
1077
|
+
// "instType":"SPOT",
|
|
1078
|
+
// "lever":"",
|
|
1079
|
+
// "msg":"",
|
|
1080
|
+
// "notionalUsd":"451.4516256",
|
|
1081
|
+
// "ordId":"370257534141235201",
|
|
1082
|
+
// "ordType":"limit",
|
|
1083
|
+
// "pnl":"0",
|
|
1084
|
+
// "posSide":"",
|
|
1085
|
+
// "px":"60000",
|
|
1086
|
+
// "rebate":"0",
|
|
1087
|
+
// "rebateCcy":"ETH",
|
|
1088
|
+
// "reqId":"",
|
|
1089
|
+
// "side":"sell",
|
|
1090
|
+
// "slOrdPx":"",
|
|
1091
|
+
// "slTriggerPx":"",
|
|
1092
|
+
// "state":"live",
|
|
1093
|
+
// "sz":"0.007526",
|
|
1094
|
+
// "tag":"",
|
|
1095
|
+
// "tdMode":"cash",
|
|
1096
|
+
// "tgtCcy":"",
|
|
1097
|
+
// "tpOrdPx":"",
|
|
1098
|
+
// "tpTriggerPx":"",
|
|
1099
|
+
// "tradeId":"",
|
|
1100
|
+
// "uTime":"1634548275191"
|
|
1101
|
+
// }
|
|
1102
|
+
// ]
|
|
1103
|
+
// }
|
|
1104
|
+
//
|
|
1105
|
+
this.handleMyTrades(client, message);
|
|
1106
|
+
const arg = this.safeValue(message, 'arg', {});
|
|
1107
|
+
const channel = this.safeString(arg, 'channel');
|
|
1108
|
+
const orders = this.safeValue(message, 'data', []);
|
|
1109
|
+
const ordersLength = orders.length;
|
|
1110
|
+
if (ordersLength > 0) {
|
|
1111
|
+
const limit = this.safeInteger(this.options, 'ordersLimit', 1000);
|
|
1112
|
+
if (this.orders === undefined) {
|
|
1113
|
+
this.orders = new Cache.ArrayCacheBySymbolById(limit);
|
|
1114
|
+
this.triggerOrders = new Cache.ArrayCacheBySymbolById(limit);
|
|
1115
|
+
}
|
|
1116
|
+
const stored = (channel === 'orders-algo') ? this.triggerOrders : this.orders;
|
|
1117
|
+
const marketIds = [];
|
|
1118
|
+
const parsed = this.parseOrders(orders);
|
|
1119
|
+
for (let i = 0; i < parsed.length; i++) {
|
|
1120
|
+
const order = parsed[i];
|
|
1121
|
+
stored.append(order);
|
|
1122
|
+
const symbol = order['symbol'];
|
|
1123
|
+
const market = this.market(symbol);
|
|
1124
|
+
marketIds.push(market['id']);
|
|
1125
|
+
}
|
|
1126
|
+
client.resolve(stored, channel);
|
|
1127
|
+
for (let i = 0; i < marketIds.length; i++) {
|
|
1128
|
+
const messageHash = channel + ':' + marketIds[i];
|
|
1129
|
+
client.resolve(stored, messageHash);
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
handleMyTrades(client, message) {
|
|
1134
|
+
//
|
|
1135
|
+
// {
|
|
1136
|
+
// "arg":{
|
|
1137
|
+
// "channel":"orders",
|
|
1138
|
+
// "instType":"SPOT"
|
|
1139
|
+
// },
|
|
1140
|
+
// "data":[
|
|
1141
|
+
// {
|
|
1142
|
+
// "accFillSz":"0",
|
|
1143
|
+
// "amendResult":"",
|
|
1144
|
+
// "avgPx":"",
|
|
1145
|
+
// "cTime":"1634548275191",
|
|
1146
|
+
// "category":"normal",
|
|
1147
|
+
// "ccy":"",
|
|
1148
|
+
// "clOrdId":"e847386590ce4dBC330547db94a08ba0",
|
|
1149
|
+
// "code":"0",
|
|
1150
|
+
// "execType":"",
|
|
1151
|
+
// "fee":"0",
|
|
1152
|
+
// "feeCcy":"USDT",
|
|
1153
|
+
// "fillFee":"0",
|
|
1154
|
+
// "fillFeeCcy":"",
|
|
1155
|
+
// "fillNotionalUsd":"",
|
|
1156
|
+
// "fillPx":"",
|
|
1157
|
+
// "fillSz":"0",
|
|
1158
|
+
// "fillTime":"",
|
|
1159
|
+
// "instId":"ETH-USDT",
|
|
1160
|
+
// "instType":"SPOT",
|
|
1161
|
+
// "lever":"",
|
|
1162
|
+
// "msg":"",
|
|
1163
|
+
// "notionalUsd":"451.4516256",
|
|
1164
|
+
// "ordId":"370257534141235201",
|
|
1165
|
+
// "ordType":"limit",
|
|
1166
|
+
// "pnl":"0",
|
|
1167
|
+
// "posSide":"",
|
|
1168
|
+
// "px":"60000",
|
|
1169
|
+
// "rebate":"0",
|
|
1170
|
+
// "rebateCcy":"ETH",
|
|
1171
|
+
// "reqId":"",
|
|
1172
|
+
// "side":"sell",
|
|
1173
|
+
// "slOrdPx":"",
|
|
1174
|
+
// "slTriggerPx":"",
|
|
1175
|
+
// "state":"live",
|
|
1176
|
+
// "sz":"0.007526",
|
|
1177
|
+
// "tag":"",
|
|
1178
|
+
// "tdMode":"cash",
|
|
1179
|
+
// "tgtCcy":"",
|
|
1180
|
+
// "tpOrdPx":"",
|
|
1181
|
+
// "tpTriggerPx":"",
|
|
1182
|
+
// "tradeId":"",
|
|
1183
|
+
// "uTime":"1634548275191"
|
|
1184
|
+
// }
|
|
1185
|
+
// ]
|
|
1186
|
+
// }
|
|
1187
|
+
//
|
|
1188
|
+
const arg = this.safeValue(message, 'arg', {});
|
|
1189
|
+
const channel = this.safeString(arg, 'channel');
|
|
1190
|
+
const rawOrders = this.safeValue(message, 'data', []);
|
|
1191
|
+
const filteredOrders = [];
|
|
1192
|
+
// filter orders with no last trade id
|
|
1193
|
+
for (let i = 0; i < rawOrders.length; i++) {
|
|
1194
|
+
const rawOrder = rawOrders[i];
|
|
1195
|
+
const tradeId = this.safeString(rawOrder, 'tradeId', '');
|
|
1196
|
+
if (tradeId.length > 0) {
|
|
1197
|
+
const order = this.parseOrder(rawOrder);
|
|
1198
|
+
filteredOrders.push(order);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
const tradesLength = filteredOrders.length;
|
|
1202
|
+
if (tradesLength === 0) {
|
|
1203
|
+
return;
|
|
1204
|
+
}
|
|
1205
|
+
if (this.myTrades === undefined) {
|
|
1206
|
+
const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
|
|
1207
|
+
this.myTrades = new Cache.ArrayCacheBySymbolById(limit);
|
|
1208
|
+
}
|
|
1209
|
+
const myTrades = this.myTrades;
|
|
1210
|
+
const symbols = {};
|
|
1211
|
+
for (let i = 0; i < filteredOrders.length; i++) {
|
|
1212
|
+
const rawTrade = filteredOrders[i];
|
|
1213
|
+
const trade = this.orderToTrade(rawTrade);
|
|
1214
|
+
myTrades.append(trade);
|
|
1215
|
+
const symbol = trade['symbol'];
|
|
1216
|
+
symbols[symbol] = true;
|
|
1217
|
+
}
|
|
1218
|
+
const messageHash = channel + '::myTrades';
|
|
1219
|
+
client.resolve(this.myTrades, messageHash);
|
|
1220
|
+
const tradeSymbols = Object.keys(symbols);
|
|
1221
|
+
for (let i = 0; i < tradeSymbols.length; i++) {
|
|
1222
|
+
const symbolMessageHash = messageHash + '::' + tradeSymbols[i];
|
|
1223
|
+
client.resolve(this.orders, symbolMessageHash);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
async createOrderWs(symbol, type, side, amount, price = undefined, params = {}) {
|
|
1227
|
+
/**
|
|
1228
|
+
* @method
|
|
1229
|
+
* @name okx#createOrderWs
|
|
1230
|
+
* @see https://www.okx.com/docs-v5/en/#websocket-api-trade-place-order
|
|
1231
|
+
* @description create a trade order
|
|
1232
|
+
* @param {string} symbol unified symbol of the market to create an order in
|
|
1233
|
+
* @param {string} type 'market' or 'limit'
|
|
1234
|
+
* @param {string} side 'buy' or 'sell'
|
|
1235
|
+
* @param {float} amount how much of currency you want to trade in units of base currency
|
|
1236
|
+
* @param {float|undefined} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
|
|
1237
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1238
|
+
* @param {boolean} params.test test order, default false
|
|
1239
|
+
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1240
|
+
*/
|
|
1241
|
+
await this.loadMarkets();
|
|
1242
|
+
await this.authenticate();
|
|
1243
|
+
const url = this.getUrl('private', 'private');
|
|
1244
|
+
const messageHash = this.nonce().toString();
|
|
1245
|
+
let op = undefined;
|
|
1246
|
+
[op, params] = this.handleOptionAndParams(params, 'createOrderWs', 'op', 'batch-orders');
|
|
1247
|
+
const args = this.createOrderRequest(symbol, type, side, amount, price, params);
|
|
1248
|
+
const ordType = this.safeString(args, 'ordType');
|
|
1249
|
+
if ((ordType === 'trigger') || (ordType === 'conditional') || (type === 'oco') || (type === 'move_order_stop') || (type === 'iceberg') || (type === 'twap')) {
|
|
1250
|
+
throw new errors.BadRequest(this.id + ' createOrderWs() does not support algo trading. this.options["createOrderWs"]["op"] must be either order or batch-order');
|
|
1251
|
+
}
|
|
1252
|
+
if ((op !== 'order') && (op !== 'batch-orders')) {
|
|
1253
|
+
throw new errors.BadRequest(this.id + ' createOrderWs() does not support algo trading. this.options["createOrderWs"]["op"] must be either order or privatePostTradeOrder or privatePostTradeOrderAlgo');
|
|
1254
|
+
}
|
|
1255
|
+
const request = {
|
|
1256
|
+
'id': messageHash,
|
|
1257
|
+
'op': op,
|
|
1258
|
+
'args': [args],
|
|
1259
|
+
};
|
|
1260
|
+
return await this.watch(url, messageHash, request, messageHash);
|
|
1261
|
+
}
|
|
1262
|
+
handlePlaceOrders(client, message) {
|
|
1263
|
+
//
|
|
1264
|
+
// batch-orders/order/cancel-order
|
|
1265
|
+
// {
|
|
1266
|
+
// "id": "1689281055",
|
|
1267
|
+
// "op": "batch-orders",
|
|
1268
|
+
// "code": "0",
|
|
1269
|
+
// "msg": '',
|
|
1270
|
+
// "data": [{
|
|
1271
|
+
// "tag": "e847386590ce4dBC",
|
|
1272
|
+
// "ordId": "599823446566084608",
|
|
1273
|
+
// "clOrdId": "e847386590ce4dBCb939511604f394b0",
|
|
1274
|
+
// "sCode": "0",
|
|
1275
|
+
// "sMsg": "Order successfully placed."
|
|
1276
|
+
// },
|
|
1277
|
+
// ...
|
|
1278
|
+
// ]
|
|
1279
|
+
// }
|
|
1280
|
+
//
|
|
1281
|
+
const messageHash = this.safeString(message, 'id');
|
|
1282
|
+
let args = this.safeValue(message, 'data', []);
|
|
1283
|
+
// filter out partial errors
|
|
1284
|
+
args = this.filterBy(args, 'sCode', '0');
|
|
1285
|
+
// if empty means request failed and handle error
|
|
1286
|
+
if (this.isEmpty(args)) {
|
|
1287
|
+
const method = this.safeString(message, 'op');
|
|
1288
|
+
const stringMsg = this.json(message);
|
|
1289
|
+
this.handleErrors(undefined, undefined, client.url, method, undefined, stringMsg, stringMsg, undefined, undefined);
|
|
1290
|
+
}
|
|
1291
|
+
const orders = this.parseOrders(args, undefined, undefined, undefined);
|
|
1292
|
+
client.resolve(orders, messageHash);
|
|
1293
|
+
}
|
|
1294
|
+
async editOrderWs(id, symbol, type, side, amount, price = undefined, params = {}) {
|
|
1295
|
+
/**
|
|
1296
|
+
* @method
|
|
1297
|
+
* @name okx#editOrderWs
|
|
1298
|
+
* @description edit a trade order
|
|
1299
|
+
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-amend-order
|
|
1300
|
+
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-amend-multiple-orders
|
|
1301
|
+
* @param {string} id order id
|
|
1302
|
+
* @param {string} symbol unified symbol of the market to create an order in
|
|
1303
|
+
* @param {string} type 'market' or 'limit'
|
|
1304
|
+
* @param {string} side 'buy' or 'sell'
|
|
1305
|
+
* @param {float} amount how much of the currency you want to trade in units of the base currency
|
|
1306
|
+
* @param {float|undefined} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
|
|
1307
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1308
|
+
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1309
|
+
*/
|
|
1310
|
+
await this.loadMarkets();
|
|
1311
|
+
await this.authenticate();
|
|
1312
|
+
const url = this.getUrl('private', 'private');
|
|
1313
|
+
const messageHash = this.nonce().toString();
|
|
1314
|
+
let op = undefined;
|
|
1315
|
+
[op, params] = this.handleOptionAndParams(params, 'editOrderWs', 'op', 'amend-order');
|
|
1316
|
+
const args = this.editOrderRequest(id, symbol, type, side, amount, price, params);
|
|
1317
|
+
const request = {
|
|
1318
|
+
'id': messageHash,
|
|
1319
|
+
'op': op,
|
|
1320
|
+
'args': [args],
|
|
1321
|
+
};
|
|
1322
|
+
return await this.watch(url, messageHash, this.extend(request, params), messageHash);
|
|
1323
|
+
}
|
|
1324
|
+
async cancelOrderWs(id, symbol = undefined, params = {}) {
|
|
1325
|
+
/**
|
|
1326
|
+
* @method
|
|
1327
|
+
* @name okx#cancelOrderWs
|
|
1328
|
+
* @see https://okx-docs.github.io/apidocs/websocket_api/en/#cancel-order-trade
|
|
1329
|
+
* @description cancel multiple orders
|
|
1330
|
+
* @param {string} id order id
|
|
1331
|
+
* @param {string} symbol unified market symbol, default is undefined
|
|
1332
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1333
|
+
* @param {string} [params.clOrdId] client order id
|
|
1334
|
+
* @returns {object} an list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1335
|
+
*/
|
|
1336
|
+
if (symbol === undefined) {
|
|
1337
|
+
throw new errors.BadRequest(this.id + ' cancelOrderWs() requires a symbol argument');
|
|
1338
|
+
}
|
|
1339
|
+
await this.loadMarkets();
|
|
1340
|
+
await this.authenticate();
|
|
1341
|
+
const url = this.getUrl('private', 'private');
|
|
1342
|
+
const messageHash = this.nonce().toString();
|
|
1343
|
+
const clientOrderId = this.safeString2(params, 'clOrdId', 'clientOrderId');
|
|
1344
|
+
params = this.omit(params, ['clientOrderId', 'clOrdId']);
|
|
1345
|
+
const arg = {
|
|
1346
|
+
'instId': this.marketId(symbol),
|
|
1347
|
+
};
|
|
1348
|
+
if (clientOrderId !== undefined) {
|
|
1349
|
+
arg['clOrdId'] = clientOrderId;
|
|
1350
|
+
}
|
|
1351
|
+
else {
|
|
1352
|
+
arg['ordId'] = id;
|
|
1353
|
+
}
|
|
1354
|
+
const request = {
|
|
1355
|
+
'id': messageHash,
|
|
1356
|
+
'op': 'cancel-order',
|
|
1357
|
+
'args': [this.extend(arg, params)],
|
|
1358
|
+
};
|
|
1359
|
+
return await this.watch(url, messageHash, request, messageHash);
|
|
1360
|
+
}
|
|
1361
|
+
async cancelOrdersWs(ids, symbol = undefined, params = {}) {
|
|
1362
|
+
/**
|
|
1363
|
+
* @method
|
|
1364
|
+
* @name okx#cancelOrdersWs
|
|
1365
|
+
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-mass-cancel-order
|
|
1366
|
+
* @description cancel multiple orders
|
|
1367
|
+
* @param {string[]} ids order ids
|
|
1368
|
+
* @param {string} symbol unified market symbol, default is undefined
|
|
1369
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1370
|
+
* @returns {object} an list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1371
|
+
*/
|
|
1372
|
+
const idsLength = ids.length;
|
|
1373
|
+
if (idsLength > 20) {
|
|
1374
|
+
throw new errors.BadRequest(this.id + ' cancelOrdersWs() accepts up to 20 ids at a time');
|
|
1375
|
+
}
|
|
1376
|
+
if (symbol === undefined) {
|
|
1377
|
+
throw new errors.BadRequest(this.id + ' cancelOrdersWs() requires a symbol argument');
|
|
1378
|
+
}
|
|
1379
|
+
await this.loadMarkets();
|
|
1380
|
+
await this.authenticate();
|
|
1381
|
+
const url = this.getUrl('private', 'private');
|
|
1382
|
+
const messageHash = this.nonce().toString();
|
|
1383
|
+
const args = [];
|
|
1384
|
+
for (let i = 0; i < idsLength; i++) {
|
|
1385
|
+
const arg = {
|
|
1386
|
+
'instId': this.marketId(symbol),
|
|
1387
|
+
'ordId': ids[i],
|
|
1388
|
+
};
|
|
1389
|
+
args.push(arg);
|
|
1390
|
+
}
|
|
1391
|
+
const request = {
|
|
1392
|
+
'id': messageHash,
|
|
1393
|
+
'op': 'batch-cancel-orders',
|
|
1394
|
+
'args': args,
|
|
1395
|
+
};
|
|
1396
|
+
return await this.watch(url, messageHash, this.deepExtend(request, params), messageHash);
|
|
1397
|
+
}
|
|
1398
|
+
async cancelAllOrdersWs(symbol = undefined, params = {}) {
|
|
1399
|
+
/**
|
|
1400
|
+
* @method
|
|
1401
|
+
* @name okx#cancelAllOrdersWs
|
|
1402
|
+
* @see https://docs.okx.com/websockets/#message-cancelAll
|
|
1403
|
+
* @description cancel all open orders of a type. Only applicable to Option in Portfolio Margin mode, and MMP privilege is required.
|
|
1404
|
+
* @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
|
|
1405
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1406
|
+
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1407
|
+
*/
|
|
1408
|
+
if (symbol === undefined) {
|
|
1409
|
+
throw new errors.BadRequest(this.id + ' cancelAllOrdersWs() requires a symbol argument');
|
|
1410
|
+
}
|
|
1411
|
+
await this.loadMarkets();
|
|
1412
|
+
await this.authenticate();
|
|
1413
|
+
const market = this.market(symbol);
|
|
1414
|
+
if (market['type'] !== 'option') {
|
|
1415
|
+
throw new errors.BadRequest(this.id + 'cancelAllOrdersWs is only applicable to Option in Portfolio Margin mode, and MMP privilege is required.');
|
|
1416
|
+
}
|
|
1417
|
+
const url = this.getUrl('private', 'private');
|
|
1418
|
+
const messageHash = this.nonce().toString();
|
|
1419
|
+
const request = {
|
|
1420
|
+
'id': messageHash,
|
|
1421
|
+
'op': 'mass-cancel',
|
|
1422
|
+
'args': [this.extend({
|
|
1423
|
+
'instType': 'OPTION',
|
|
1424
|
+
'instFamily': market['id'],
|
|
1425
|
+
}, params)],
|
|
1426
|
+
};
|
|
1427
|
+
return await this.watch(url, messageHash, request, messageHash);
|
|
1428
|
+
}
|
|
1429
|
+
handleCancelAllOrders(client, message) {
|
|
1430
|
+
//
|
|
1431
|
+
// {
|
|
1432
|
+
// "id": "1512",
|
|
1433
|
+
// "op": "mass-cancel",
|
|
1434
|
+
// "data": [
|
|
1435
|
+
// {
|
|
1436
|
+
// "result": true
|
|
1437
|
+
// }
|
|
1438
|
+
// ],
|
|
1439
|
+
// "code": "0",
|
|
1440
|
+
// "msg": ""
|
|
1441
|
+
// }
|
|
1442
|
+
//
|
|
1443
|
+
const messageHash = this.safeString(message, 'id');
|
|
1444
|
+
const data = this.safeValue(message, 'data', []);
|
|
1445
|
+
client.resolve(data, messageHash);
|
|
1446
|
+
}
|
|
1447
|
+
handleSubscriptionStatus(client, message) {
|
|
1448
|
+
//
|
|
1449
|
+
// { event: 'subscribe', arg: { channel: "tickers", instId: "BTC-USDT" } }
|
|
1450
|
+
//
|
|
1451
|
+
// const channel = this.safeString (message, "channel");
|
|
1452
|
+
// client.subscriptions[channel] = message;
|
|
1453
|
+
return message;
|
|
1454
|
+
}
|
|
1455
|
+
handleAuthenticate(client, message) {
|
|
1456
|
+
//
|
|
1457
|
+
// { event: "login", success: true }
|
|
1458
|
+
//
|
|
1459
|
+
const future = this.safeValue(client.futures, 'authenticated');
|
|
1460
|
+
future.resolve(true);
|
|
1461
|
+
}
|
|
1462
|
+
ping(client) {
|
|
1463
|
+
// okex does not support built-in ws protocol-level ping-pong
|
|
1464
|
+
// instead it requires custom text-based ping-pong
|
|
1465
|
+
return 'ping';
|
|
1466
|
+
}
|
|
1467
|
+
handlePong(client, message) {
|
|
1468
|
+
client.lastPong = this.milliseconds();
|
|
1469
|
+
return message;
|
|
1470
|
+
}
|
|
1471
|
+
handleErrorMessage(client, message) {
|
|
1472
|
+
//
|
|
1473
|
+
// { event: 'error', msg: "Illegal request: {"op":"subscribe","args":["spot/ticker:BTC-USDT"]}", code: "60012" }
|
|
1474
|
+
// { event: 'error", msg: "channel:ticker,instId:BTC-USDT doesn"t exist", code: "60018" }
|
|
1475
|
+
//
|
|
1476
|
+
const errorCode = this.safeInteger(message, 'code');
|
|
1477
|
+
try {
|
|
1478
|
+
if (errorCode) {
|
|
1479
|
+
const feedback = this.id + ' ' + this.json(message);
|
|
1480
|
+
this.throwExactlyMatchedException(this.exceptions['exact'], errorCode, feedback);
|
|
1481
|
+
const messageString = this.safeValue(message, 'msg');
|
|
1482
|
+
if (messageString !== undefined) {
|
|
1483
|
+
this.throwBroadlyMatchedException(this.exceptions['broad'], messageString, feedback);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
catch (e) {
|
|
1488
|
+
if (e instanceof errors.AuthenticationError) {
|
|
1489
|
+
const messageHash = 'authenticated';
|
|
1490
|
+
client.reject(e, messageHash);
|
|
1491
|
+
if (messageHash in client.subscriptions) {
|
|
1492
|
+
delete client.subscriptions[messageHash];
|
|
1493
|
+
}
|
|
1494
|
+
return false;
|
|
1495
|
+
}
|
|
1496
|
+
else {
|
|
1497
|
+
client.reject(e);
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
return message;
|
|
1501
|
+
}
|
|
1502
|
+
handleMessage(client, message) {
|
|
1503
|
+
if (!this.handleErrorMessage(client, message)) {
|
|
1504
|
+
return;
|
|
1505
|
+
}
|
|
1506
|
+
//
|
|
1507
|
+
// { event: 'subscribe', arg: { channel: "tickers", instId: "BTC-USDT" } }
|
|
1508
|
+
// { event: 'login", msg: '", code: "0" }
|
|
1509
|
+
//
|
|
1510
|
+
// {
|
|
1511
|
+
// "arg": { channel: "tickers", instId: "BTC-USDT" },
|
|
1512
|
+
// "data": [
|
|
1513
|
+
// {
|
|
1514
|
+
// "instType": "SPOT",
|
|
1515
|
+
// "instId": "BTC-USDT",
|
|
1516
|
+
// "last": "31500.1",
|
|
1517
|
+
// "lastSz": "0.00001754",
|
|
1518
|
+
// "askPx": "31500.1",
|
|
1519
|
+
// "askSz": "0.00998144",
|
|
1520
|
+
// "bidPx": "31500",
|
|
1521
|
+
// "bidSz": "3.05652439",
|
|
1522
|
+
// "open24h": "31697",
|
|
1523
|
+
// "high24h": "32248",
|
|
1524
|
+
// "low24h": "31165.6",
|
|
1525
|
+
// "sodUtc0": "31385.5",
|
|
1526
|
+
// "sodUtc8": "32134.9",
|
|
1527
|
+
// "volCcy24h": "503403597.38138519",
|
|
1528
|
+
// "vol24h": "15937.10781721",
|
|
1529
|
+
// "ts": "1626526618762"
|
|
1530
|
+
// }
|
|
1531
|
+
// ]
|
|
1532
|
+
// }
|
|
1533
|
+
//
|
|
1534
|
+
// { event: 'error', msg: "Illegal request: {"op":"subscribe","args":["spot/ticker:BTC-USDT"]}", code: "60012" }
|
|
1535
|
+
// { event: 'error", msg: "channel:ticker,instId:BTC-USDT doesn"t exist", code: "60018" }
|
|
1536
|
+
// { event: 'error', msg: "Invalid OK_ACCESS_KEY", code: "60005" }
|
|
1537
|
+
// {
|
|
1538
|
+
// "event": "error",
|
|
1539
|
+
// "msg": "Illegal request: {"op":"login","args":["de89b035-b233-44b2-9a13-0ccdd00bda0e","7KUcc8YzQhnxBE3K","1626691289","H57N99mBt5NvW8U19FITrPdOxycAERFMaapQWRqLaSE="]}",
|
|
1540
|
+
// "code": "60012"
|
|
1541
|
+
// }
|
|
1542
|
+
//
|
|
1543
|
+
//
|
|
1544
|
+
//
|
|
1545
|
+
if (message === 'pong') {
|
|
1546
|
+
return this.handlePong(client, message);
|
|
1547
|
+
}
|
|
1548
|
+
// const table = this.safeString (message, 'table');
|
|
1549
|
+
// if (table === undefined) {
|
|
1550
|
+
const event = this.safeString2(message, 'event', 'op');
|
|
1551
|
+
if (event !== undefined) {
|
|
1552
|
+
const methods = {
|
|
1553
|
+
// 'info': this.handleSystemStatus,
|
|
1554
|
+
// 'book': 'handleOrderBook',
|
|
1555
|
+
'login': this.handleAuthenticate,
|
|
1556
|
+
'subscribe': this.handleSubscriptionStatus,
|
|
1557
|
+
'order': this.handlePlaceOrders,
|
|
1558
|
+
'batch-orders': this.handlePlaceOrders,
|
|
1559
|
+
'amend-order': this.handlePlaceOrders,
|
|
1560
|
+
'batch-amend-orders': this.handlePlaceOrders,
|
|
1561
|
+
'cancel-order': this.handlePlaceOrders,
|
|
1562
|
+
'mass-cancel': this.handleCancelAllOrders,
|
|
1563
|
+
};
|
|
1564
|
+
const method = this.safeValue(methods, event);
|
|
1565
|
+
if (method === undefined) {
|
|
1566
|
+
return message;
|
|
1567
|
+
}
|
|
1568
|
+
else {
|
|
1569
|
+
return method.call(this, client, message);
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
else {
|
|
1573
|
+
const arg = this.safeValue(message, 'arg', {});
|
|
1574
|
+
const channel = this.safeString(arg, 'channel');
|
|
1575
|
+
const methods = {
|
|
1576
|
+
'bbo-tbt': this.handleOrderBook,
|
|
1577
|
+
'books': this.handleOrderBook,
|
|
1578
|
+
'books5': this.handleOrderBook,
|
|
1579
|
+
'books50-l2-tbt': this.handleOrderBook,
|
|
1580
|
+
'books-l2-tbt': this.handleOrderBook,
|
|
1581
|
+
'tickers': this.handleTicker,
|
|
1582
|
+
'positions': this.handlePositions,
|
|
1583
|
+
'index-tickers': this.handleTicker,
|
|
1584
|
+
'sprd-tickers': this.handleTicker,
|
|
1585
|
+
'block-tickers': this.handleTicker,
|
|
1586
|
+
'trades': this.handleTrades,
|
|
1587
|
+
'account': this.handleBalance,
|
|
1588
|
+
// 'margin_account': this.handleBalance,
|
|
1589
|
+
'orders': this.handleOrders,
|
|
1590
|
+
'orders-algo': this.handleOrders,
|
|
1591
|
+
};
|
|
1592
|
+
const method = this.safeValue(methods, channel);
|
|
1593
|
+
if (method === undefined) {
|
|
1594
|
+
if (channel.indexOf('candle') === 0) {
|
|
1595
|
+
this.handleOHLCV(client, message);
|
|
1596
|
+
}
|
|
1597
|
+
else {
|
|
1598
|
+
return message;
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
else {
|
|
1602
|
+
return method.call(this, client, message);
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
module.exports = okx;
|