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,3007 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var cryptocom$1 = require('./abstract/cryptocom.js');
|
|
4
|
+
var Precise = require('./base/Precise.js');
|
|
5
|
+
var errors = require('./base/errors.js');
|
|
6
|
+
var number = require('./base/functions/number.js');
|
|
7
|
+
var sha256 = require('./static_dependencies/noble-hashes/sha256.js');
|
|
8
|
+
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
/**
|
|
11
|
+
* @class cryptocom
|
|
12
|
+
* @augments Exchange
|
|
13
|
+
*/
|
|
14
|
+
class cryptocom extends cryptocom$1 {
|
|
15
|
+
describe() {
|
|
16
|
+
return this.deepExtend(super.describe(), {
|
|
17
|
+
'id': 'cryptocom',
|
|
18
|
+
'name': 'Crypto.com',
|
|
19
|
+
'countries': ['MT'],
|
|
20
|
+
'version': 'v2',
|
|
21
|
+
'rateLimit': 10,
|
|
22
|
+
'certified': true,
|
|
23
|
+
'pro': true,
|
|
24
|
+
'has': {
|
|
25
|
+
'CORS': false,
|
|
26
|
+
'spot': true,
|
|
27
|
+
'margin': true,
|
|
28
|
+
'swap': true,
|
|
29
|
+
'future': true,
|
|
30
|
+
'option': true,
|
|
31
|
+
'addMargin': false,
|
|
32
|
+
'cancelAllOrders': true,
|
|
33
|
+
'cancelOrder': true,
|
|
34
|
+
'cancelOrders': true,
|
|
35
|
+
'closeAllPositions': false,
|
|
36
|
+
'closePosition': true,
|
|
37
|
+
'createMarketBuyOrderWithCost': false,
|
|
38
|
+
'createMarketOrderWithCost': false,
|
|
39
|
+
'createMarketSellOrderWithCost': false,
|
|
40
|
+
'createOrder': true,
|
|
41
|
+
'createOrders': true,
|
|
42
|
+
'fetchAccounts': true,
|
|
43
|
+
'fetchBalance': true,
|
|
44
|
+
'fetchBidsAsks': false,
|
|
45
|
+
'fetchBorrowInterest': false,
|
|
46
|
+
'fetchBorrowRateHistories': false,
|
|
47
|
+
'fetchBorrowRateHistory': false,
|
|
48
|
+
'fetchClosedOrders': 'emulated',
|
|
49
|
+
'fetchCrossBorrowRate': false,
|
|
50
|
+
'fetchCrossBorrowRates': false,
|
|
51
|
+
'fetchCurrencies': false,
|
|
52
|
+
'fetchDepositAddress': true,
|
|
53
|
+
'fetchDepositAddressesByNetwork': true,
|
|
54
|
+
'fetchDeposits': true,
|
|
55
|
+
'fetchDepositsWithdrawals': false,
|
|
56
|
+
'fetchDepositWithdrawFee': 'emulated',
|
|
57
|
+
'fetchDepositWithdrawFees': true,
|
|
58
|
+
'fetchFundingHistory': false,
|
|
59
|
+
'fetchFundingRate': false,
|
|
60
|
+
'fetchFundingRateHistory': true,
|
|
61
|
+
'fetchFundingRates': false,
|
|
62
|
+
'fetchGreeks': false,
|
|
63
|
+
'fetchIndexOHLCV': false,
|
|
64
|
+
'fetchIsolatedBorrowRate': false,
|
|
65
|
+
'fetchIsolatedBorrowRates': false,
|
|
66
|
+
'fetchLedger': true,
|
|
67
|
+
'fetchLeverage': false,
|
|
68
|
+
'fetchLeverageTiers': false,
|
|
69
|
+
'fetchMarginMode': false,
|
|
70
|
+
'fetchMarketLeverageTiers': false,
|
|
71
|
+
'fetchMarkets': true,
|
|
72
|
+
'fetchMarkOHLCV': false,
|
|
73
|
+
'fetchMySettlementHistory': false,
|
|
74
|
+
'fetchMyTrades': true,
|
|
75
|
+
'fetchOHLCV': true,
|
|
76
|
+
'fetchOpenOrders': true,
|
|
77
|
+
'fetchOrder': true,
|
|
78
|
+
'fetchOrderBook': true,
|
|
79
|
+
'fetchOrders': true,
|
|
80
|
+
'fetchPosition': true,
|
|
81
|
+
'fetchPositionMode': false,
|
|
82
|
+
'fetchPositions': true,
|
|
83
|
+
'fetchPremiumIndexOHLCV': false,
|
|
84
|
+
'fetchSettlementHistory': true,
|
|
85
|
+
'fetchStatus': false,
|
|
86
|
+
'fetchTicker': true,
|
|
87
|
+
'fetchTickers': true,
|
|
88
|
+
'fetchTime': false,
|
|
89
|
+
'fetchTrades': true,
|
|
90
|
+
'fetchTradingFee': false,
|
|
91
|
+
'fetchTradingFees': false,
|
|
92
|
+
'fetchTransactionFees': false,
|
|
93
|
+
'fetchTransactions': false,
|
|
94
|
+
'fetchTransfers': false,
|
|
95
|
+
'fetchUnderlyingAssets': false,
|
|
96
|
+
'fetchVolatilityHistory': false,
|
|
97
|
+
'fetchWithdrawals': true,
|
|
98
|
+
'reduceMargin': false,
|
|
99
|
+
'repayCrossMargin': false,
|
|
100
|
+
'repayIsolatedMargin': false,
|
|
101
|
+
'setLeverage': false,
|
|
102
|
+
'setMarginMode': false,
|
|
103
|
+
'setPositionMode': false,
|
|
104
|
+
'transfer': false,
|
|
105
|
+
'withdraw': true,
|
|
106
|
+
},
|
|
107
|
+
'timeframes': {
|
|
108
|
+
'1m': '1m',
|
|
109
|
+
'5m': '5m',
|
|
110
|
+
'15m': '15m',
|
|
111
|
+
'30m': '30m',
|
|
112
|
+
'1h': '1h',
|
|
113
|
+
'4h': '4h',
|
|
114
|
+
'6h': '6h',
|
|
115
|
+
'12h': '12h',
|
|
116
|
+
'1d': '1D',
|
|
117
|
+
'1w': '7D',
|
|
118
|
+
'2w': '14D',
|
|
119
|
+
'1M': '1M',
|
|
120
|
+
},
|
|
121
|
+
'urls': {
|
|
122
|
+
'logo': 'https://user-images.githubusercontent.com/1294454/147792121-38ed5e36-c229-48d6-b49a-48d05fc19ed4.jpeg',
|
|
123
|
+
'test': {
|
|
124
|
+
'v1': 'https://uat-api.3ona.co/exchange/v1',
|
|
125
|
+
'v2': 'https://uat-api.3ona.co/v2',
|
|
126
|
+
'derivatives': 'https://uat-api.3ona.co/v2',
|
|
127
|
+
},
|
|
128
|
+
'api': {
|
|
129
|
+
'v1': 'https://api.crypto.com/exchange/v1',
|
|
130
|
+
'v2': 'https://api.crypto.com/v2',
|
|
131
|
+
'derivatives': 'https://deriv-api.crypto.com/v1',
|
|
132
|
+
},
|
|
133
|
+
'www': 'https://crypto.com/',
|
|
134
|
+
'referral': {
|
|
135
|
+
'url': 'https://crypto.com/exch/kdacthrnxt',
|
|
136
|
+
'discount': 0.15,
|
|
137
|
+
},
|
|
138
|
+
'doc': [
|
|
139
|
+
'https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html',
|
|
140
|
+
'https://exchange-docs.crypto.com/spot/index.html',
|
|
141
|
+
'https://exchange-docs.crypto.com/derivatives/index.html',
|
|
142
|
+
],
|
|
143
|
+
'fees': 'https://crypto.com/exchange/document/fees-limits',
|
|
144
|
+
},
|
|
145
|
+
'api': {
|
|
146
|
+
'v1': {
|
|
147
|
+
'public': {
|
|
148
|
+
'get': {
|
|
149
|
+
'public/auth': 10 / 3,
|
|
150
|
+
'public/get-instruments': 10 / 3,
|
|
151
|
+
'public/get-book': 1,
|
|
152
|
+
'public/get-candlestick': 1,
|
|
153
|
+
'public/get-trades': 1,
|
|
154
|
+
'public/get-tickers': 1,
|
|
155
|
+
'public/get-valuations': 1,
|
|
156
|
+
'public/get-expired-settlement-price': 10 / 3,
|
|
157
|
+
'public/get-insurance': 1,
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
'private': {
|
|
161
|
+
'post': {
|
|
162
|
+
'private/set-cancel-on-disconnect': 10 / 3,
|
|
163
|
+
'private/get-cancel-on-disconnect': 10 / 3,
|
|
164
|
+
'private/user-balance': 10 / 3,
|
|
165
|
+
'private/user-balance-history': 10 / 3,
|
|
166
|
+
'private/get-positions': 10 / 3,
|
|
167
|
+
'private/create-order': 2 / 3,
|
|
168
|
+
'private/create-order-list': 10 / 3,
|
|
169
|
+
'private/cancel-order': 2 / 3,
|
|
170
|
+
'private/cancel-order-list': 10 / 3,
|
|
171
|
+
'private/cancel-all-orders': 2 / 3,
|
|
172
|
+
'private/close-position': 10 / 3,
|
|
173
|
+
'private/get-order-history': 100,
|
|
174
|
+
'private/get-open-orders': 10 / 3,
|
|
175
|
+
'private/get-order-detail': 1 / 3,
|
|
176
|
+
'private/get-trades': 100,
|
|
177
|
+
'private/change-account-leverage': 10 / 3,
|
|
178
|
+
'private/get-transactions': 10 / 3,
|
|
179
|
+
'private/create-subaccount-transfer': 10 / 3,
|
|
180
|
+
'private/get-subaccount-balances': 10 / 3,
|
|
181
|
+
'private/get-order-list': 10 / 3,
|
|
182
|
+
'private/create-withdrawal': 10 / 3,
|
|
183
|
+
'private/get-currency-networks': 10 / 3,
|
|
184
|
+
'private/get-deposit-address': 10 / 3,
|
|
185
|
+
'private/get-accounts': 10 / 3,
|
|
186
|
+
'private/get-withdrawal-history': 10 / 3,
|
|
187
|
+
'private/get-deposit-history': 10 / 3,
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
'v2': {
|
|
192
|
+
'public': {
|
|
193
|
+
'get': {
|
|
194
|
+
'public/auth': 1,
|
|
195
|
+
'public/get-instruments': 1,
|
|
196
|
+
'public/get-book': 1,
|
|
197
|
+
'public/get-candlestick': 1,
|
|
198
|
+
'public/get-ticker': 1,
|
|
199
|
+
'public/get-trades': 1,
|
|
200
|
+
'public/margin/get-transfer-currencies': 1,
|
|
201
|
+
'public/margin/get-load-currenices': 1,
|
|
202
|
+
'public/respond-heartbeat': 1,
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
'private': {
|
|
206
|
+
'post': {
|
|
207
|
+
'private/set-cancel-on-disconnect': 10 / 3,
|
|
208
|
+
'private/get-cancel-on-disconnect': 10 / 3,
|
|
209
|
+
'private/create-withdrawal': 10 / 3,
|
|
210
|
+
'private/get-withdrawal-history': 10 / 3,
|
|
211
|
+
'private/get-currency-networks': 10 / 3,
|
|
212
|
+
'private/get-deposit-history': 10 / 3,
|
|
213
|
+
'private/get-deposit-address': 10 / 3,
|
|
214
|
+
'private/export/create-export-request': 10 / 3,
|
|
215
|
+
'private/export/get-export-requests': 10 / 3,
|
|
216
|
+
'private/export/download-export-output': 10 / 3,
|
|
217
|
+
'private/get-account-summary': 10 / 3,
|
|
218
|
+
'private/create-order': 2 / 3,
|
|
219
|
+
'private/cancel-order': 2 / 3,
|
|
220
|
+
'private/cancel-all-orders': 2 / 3,
|
|
221
|
+
'private/create-order-list': 10 / 3,
|
|
222
|
+
'private/get-order-history': 10 / 3,
|
|
223
|
+
'private/get-open-orders': 10 / 3,
|
|
224
|
+
'private/get-order-detail': 1 / 3,
|
|
225
|
+
'private/get-trades': 100,
|
|
226
|
+
'private/get-accounts': 10 / 3,
|
|
227
|
+
'private/get-subaccount-balances': 10 / 3,
|
|
228
|
+
'private/create-subaccount-transfer': 10 / 3,
|
|
229
|
+
'private/otc/get-otc-user': 10 / 3,
|
|
230
|
+
'private/otc/get-instruments': 10 / 3,
|
|
231
|
+
'private/otc/request-quote': 100,
|
|
232
|
+
'private/otc/accept-quote': 100,
|
|
233
|
+
'private/otc/get-quote-history': 10 / 3,
|
|
234
|
+
'private/otc/get-trade-history': 10 / 3,
|
|
235
|
+
'private/otc/create-order': 10 / 3,
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
'derivatives': {
|
|
240
|
+
'public': {
|
|
241
|
+
'get': {
|
|
242
|
+
'public/auth': 10 / 3,
|
|
243
|
+
'public/get-instruments': 10 / 3,
|
|
244
|
+
'public/get-book': 1,
|
|
245
|
+
'public/get-candlestick': 1,
|
|
246
|
+
'public/get-trades': 1,
|
|
247
|
+
'public/get-tickers': 1,
|
|
248
|
+
'public/get-valuations': 1,
|
|
249
|
+
'public/get-expired-settlement-price': 10 / 3,
|
|
250
|
+
'public/get-insurance': 1,
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
'private': {
|
|
254
|
+
'post': {
|
|
255
|
+
'private/set-cancel-on-disconnect': 10 / 3,
|
|
256
|
+
'private/get-cancel-on-disconnect': 10 / 3,
|
|
257
|
+
'private/user-balance': 10 / 3,
|
|
258
|
+
'private/user-balance-history': 10 / 3,
|
|
259
|
+
'private/get-positions': 10 / 3,
|
|
260
|
+
'private/create-order': 2 / 3,
|
|
261
|
+
'private/create-order-list': 10 / 3,
|
|
262
|
+
'private/cancel-order': 2 / 3,
|
|
263
|
+
'private/cancel-order-list': 10 / 3,
|
|
264
|
+
'private/cancel-all-orders': 2 / 3,
|
|
265
|
+
'private/close-position': 10 / 3,
|
|
266
|
+
'private/convert-collateral': 10 / 3,
|
|
267
|
+
'private/get-order-history': 100,
|
|
268
|
+
'private/get-open-orders': 10 / 3,
|
|
269
|
+
'private/get-order-detail': 1 / 3,
|
|
270
|
+
'private/get-trades': 100,
|
|
271
|
+
'private/change-account-leverage': 10 / 3,
|
|
272
|
+
'private/get-transactions': 10 / 3,
|
|
273
|
+
'private/create-subaccount-transfer': 10 / 3,
|
|
274
|
+
'private/get-subaccount-balances': 10 / 3,
|
|
275
|
+
'private/get-order-list': 10 / 3,
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
'fees': {
|
|
281
|
+
'trading': {
|
|
282
|
+
'maker': this.parseNumber('0.004'),
|
|
283
|
+
'taker': this.parseNumber('0.004'),
|
|
284
|
+
'tiers': {
|
|
285
|
+
'maker': [
|
|
286
|
+
[this.parseNumber('0'), this.parseNumber('0.004')],
|
|
287
|
+
[this.parseNumber('25000'), this.parseNumber('0.0035')],
|
|
288
|
+
[this.parseNumber('50000'), this.parseNumber('0.0015')],
|
|
289
|
+
[this.parseNumber('100000'), this.parseNumber('0.001')],
|
|
290
|
+
[this.parseNumber('250000'), this.parseNumber('0.0009')],
|
|
291
|
+
[this.parseNumber('1000000'), this.parseNumber('0.0008')],
|
|
292
|
+
[this.parseNumber('20000000'), this.parseNumber('0.0007')],
|
|
293
|
+
[this.parseNumber('100000000'), this.parseNumber('0.0006')],
|
|
294
|
+
[this.parseNumber('200000000'), this.parseNumber('0.0004')],
|
|
295
|
+
],
|
|
296
|
+
'taker': [
|
|
297
|
+
[this.parseNumber('0'), this.parseNumber('0.004')],
|
|
298
|
+
[this.parseNumber('25000'), this.parseNumber('0.0035')],
|
|
299
|
+
[this.parseNumber('50000'), this.parseNumber('0.0025')],
|
|
300
|
+
[this.parseNumber('100000'), this.parseNumber('0.0016')],
|
|
301
|
+
[this.parseNumber('250000'), this.parseNumber('0.00015')],
|
|
302
|
+
[this.parseNumber('1000000'), this.parseNumber('0.00014')],
|
|
303
|
+
[this.parseNumber('20000000'), this.parseNumber('0.00013')],
|
|
304
|
+
[this.parseNumber('100000000'), this.parseNumber('0.00012')],
|
|
305
|
+
[this.parseNumber('200000000'), this.parseNumber('0.0001')],
|
|
306
|
+
],
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
'options': {
|
|
311
|
+
'defaultType': 'spot',
|
|
312
|
+
'accountsById': {
|
|
313
|
+
'funding': 'SPOT',
|
|
314
|
+
'spot': 'SPOT',
|
|
315
|
+
'margin': 'MARGIN',
|
|
316
|
+
'derivatives': 'DERIVATIVES',
|
|
317
|
+
'swap': 'DERIVATIVES',
|
|
318
|
+
'future': 'DERIVATIVES',
|
|
319
|
+
},
|
|
320
|
+
'networks': {
|
|
321
|
+
'BEP20': 'BSC',
|
|
322
|
+
'ERC20': 'ETH',
|
|
323
|
+
'TRC20': 'TRON',
|
|
324
|
+
},
|
|
325
|
+
'broker': 'CCXT',
|
|
326
|
+
},
|
|
327
|
+
// https://exchange-docs.crypto.com/spot/index.html#response-and-reason-codes
|
|
328
|
+
'commonCurrencies': {
|
|
329
|
+
'USD_STABLE_COIN': 'USDC',
|
|
330
|
+
},
|
|
331
|
+
'precisionMode': number.TICK_SIZE,
|
|
332
|
+
'exceptions': {
|
|
333
|
+
'exact': {
|
|
334
|
+
'219': errors.InvalidOrder,
|
|
335
|
+
'314': errors.InvalidOrder,
|
|
336
|
+
'10001': errors.ExchangeError,
|
|
337
|
+
'10002': errors.PermissionDenied,
|
|
338
|
+
'10003': errors.PermissionDenied,
|
|
339
|
+
'10004': errors.BadRequest,
|
|
340
|
+
'10005': errors.PermissionDenied,
|
|
341
|
+
'10006': errors.DDoSProtection,
|
|
342
|
+
'10007': errors.InvalidNonce,
|
|
343
|
+
'10008': errors.BadRequest,
|
|
344
|
+
'10009': errors.BadRequest,
|
|
345
|
+
'20001': errors.BadRequest,
|
|
346
|
+
'20002': errors.InsufficientFunds,
|
|
347
|
+
'20005': errors.AccountNotEnabled,
|
|
348
|
+
'30003': errors.BadSymbol,
|
|
349
|
+
'30004': errors.BadRequest,
|
|
350
|
+
'30005': errors.BadRequest,
|
|
351
|
+
'30006': errors.InvalidOrder,
|
|
352
|
+
'30007': errors.InvalidOrder,
|
|
353
|
+
'30008': errors.InvalidOrder,
|
|
354
|
+
'30009': errors.InvalidOrder,
|
|
355
|
+
'30010': errors.BadRequest,
|
|
356
|
+
'30013': errors.InvalidOrder,
|
|
357
|
+
'30014': errors.InvalidOrder,
|
|
358
|
+
'30016': errors.InvalidOrder,
|
|
359
|
+
'30017': errors.InvalidOrder,
|
|
360
|
+
'30023': errors.InvalidOrder,
|
|
361
|
+
'30024': errors.InvalidOrder,
|
|
362
|
+
'30025': errors.InvalidOrder,
|
|
363
|
+
'40001': errors.BadRequest,
|
|
364
|
+
'40002': errors.BadRequest,
|
|
365
|
+
'40003': errors.BadRequest,
|
|
366
|
+
'40004': errors.BadRequest,
|
|
367
|
+
'40005': errors.BadRequest,
|
|
368
|
+
'40006': errors.BadRequest,
|
|
369
|
+
'40007': errors.BadRequest,
|
|
370
|
+
'40101': errors.AuthenticationError,
|
|
371
|
+
'50001': errors.BadRequest,
|
|
372
|
+
'9010001': errors.OnMaintenance, // {"code":9010001,"message":"SYSTEM_MAINTENANCE","details":"Crypto.com Exchange is currently under maintenance. Please refer to https://status.crypto.com for more details."}
|
|
373
|
+
},
|
|
374
|
+
'broad': {},
|
|
375
|
+
},
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
async fetchMarkets(params = {}) {
|
|
379
|
+
/**
|
|
380
|
+
* @method
|
|
381
|
+
* @name cryptocom#fetchMarkets
|
|
382
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-instruments
|
|
383
|
+
* @description retrieves data on all markets for cryptocom
|
|
384
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
385
|
+
* @returns {object[]} an array of objects representing market data
|
|
386
|
+
*/
|
|
387
|
+
const response = await this.v1PublicGetPublicGetInstruments(params);
|
|
388
|
+
//
|
|
389
|
+
// {
|
|
390
|
+
// "id": 1,
|
|
391
|
+
// "method": "public/get-instruments",
|
|
392
|
+
// "code": 0,
|
|
393
|
+
// "result": {
|
|
394
|
+
// "data": [
|
|
395
|
+
// {
|
|
396
|
+
// "symbol": "BTC_USDT",
|
|
397
|
+
// "inst_type": "CCY_PAIR",
|
|
398
|
+
// "display_name": "BTC/USDT",
|
|
399
|
+
// "base_ccy": "BTC",
|
|
400
|
+
// "quote_ccy": "USDT",
|
|
401
|
+
// "quote_decimals": 2,
|
|
402
|
+
// "quantity_decimals": 5,
|
|
403
|
+
// "price_tick_size": "0.01",
|
|
404
|
+
// "qty_tick_size": "0.00001",
|
|
405
|
+
// "max_leverage": "50",
|
|
406
|
+
// "tradable": true,
|
|
407
|
+
// "expiry_timestamp_ms": 0,
|
|
408
|
+
// "beta_product": false,
|
|
409
|
+
// "margin_buy_enabled": false,
|
|
410
|
+
// "margin_sell_enabled": true
|
|
411
|
+
// },
|
|
412
|
+
// {
|
|
413
|
+
// "symbol": "RUNEUSD-PERP",
|
|
414
|
+
// "inst_type": "PERPETUAL_SWAP",
|
|
415
|
+
// "display_name": "RUNEUSD Perpetual",
|
|
416
|
+
// "base_ccy": "RUNE",
|
|
417
|
+
// "quote_ccy": "USD",
|
|
418
|
+
// "quote_decimals": 3,
|
|
419
|
+
// "quantity_decimals": 1,
|
|
420
|
+
// "price_tick_size": "0.001",
|
|
421
|
+
// "qty_tick_size": "0.1",
|
|
422
|
+
// "max_leverage": "50",
|
|
423
|
+
// "tradable": true,
|
|
424
|
+
// "expiry_timestamp_ms": 0,
|
|
425
|
+
// "beta_product": false,
|
|
426
|
+
// "underlying_symbol": "RUNEUSD-INDEX",
|
|
427
|
+
// "contract_size": "1",
|
|
428
|
+
// "margin_buy_enabled": false,
|
|
429
|
+
// "margin_sell_enabled": false
|
|
430
|
+
// },
|
|
431
|
+
// {
|
|
432
|
+
// "symbol": "ETHUSD-230825",
|
|
433
|
+
// "inst_type": "FUTURE",
|
|
434
|
+
// "display_name": "ETHUSD Futures 20230825",
|
|
435
|
+
// "base_ccy": "ETH",
|
|
436
|
+
// "quote_ccy": "USD",
|
|
437
|
+
// "quote_decimals": 2,
|
|
438
|
+
// "quantity_decimals": 4,
|
|
439
|
+
// "price_tick_size": "0.01",
|
|
440
|
+
// "qty_tick_size": "0.0001",
|
|
441
|
+
// "max_leverage": "100",
|
|
442
|
+
// "tradable": true,
|
|
443
|
+
// "expiry_timestamp_ms": 1692950400000,
|
|
444
|
+
// "beta_product": false,
|
|
445
|
+
// "underlying_symbol": "ETHUSD-INDEX",
|
|
446
|
+
// "contract_size": "1",
|
|
447
|
+
// "margin_buy_enabled": false,
|
|
448
|
+
// "margin_sell_enabled": false
|
|
449
|
+
// },
|
|
450
|
+
// {
|
|
451
|
+
// "symbol": "BTCUSD-230630-CW30000",
|
|
452
|
+
// "inst_type": "WARRANT",
|
|
453
|
+
// "display_name": "BTCUSD-230630-CW30000",
|
|
454
|
+
// "base_ccy": "BTC",
|
|
455
|
+
// "quote_ccy": "USD",
|
|
456
|
+
// "quote_decimals": 3,
|
|
457
|
+
// "quantity_decimals": 0,
|
|
458
|
+
// "price_tick_size": "0.001",
|
|
459
|
+
// "qty_tick_size": "10",
|
|
460
|
+
// "max_leverage": "50",
|
|
461
|
+
// "tradable": true,
|
|
462
|
+
// "expiry_timestamp_ms": 1688112000000,
|
|
463
|
+
// "beta_product": false,
|
|
464
|
+
// "underlying_symbol": "BTCUSD-INDEX",
|
|
465
|
+
// "put_call": "CALL",
|
|
466
|
+
// "strike": "30000",
|
|
467
|
+
// "contract_size": "0.0001",
|
|
468
|
+
// "margin_buy_enabled": false,
|
|
469
|
+
// "margin_sell_enabled": false
|
|
470
|
+
// },
|
|
471
|
+
// ]
|
|
472
|
+
// }
|
|
473
|
+
// }
|
|
474
|
+
//
|
|
475
|
+
const resultResponse = this.safeValue(response, 'result', {});
|
|
476
|
+
const data = this.safeValue(resultResponse, 'data', []);
|
|
477
|
+
const result = [];
|
|
478
|
+
for (let i = 0; i < data.length; i++) {
|
|
479
|
+
const market = data[i];
|
|
480
|
+
const inst_type = this.safeString(market, 'inst_type');
|
|
481
|
+
const spot = inst_type === 'CCY_PAIR';
|
|
482
|
+
const swap = inst_type === 'PERPETUAL_SWAP';
|
|
483
|
+
const future = inst_type === 'FUTURE';
|
|
484
|
+
const option = inst_type === 'WARRANT';
|
|
485
|
+
const baseId = this.safeString(market, 'base_ccy');
|
|
486
|
+
const quoteId = this.safeString(market, 'quote_ccy');
|
|
487
|
+
const settleId = spot ? undefined : quoteId;
|
|
488
|
+
const base = this.safeCurrencyCode(baseId);
|
|
489
|
+
const quote = this.safeCurrencyCode(quoteId);
|
|
490
|
+
const settle = spot ? undefined : this.safeCurrencyCode(settleId);
|
|
491
|
+
const optionType = this.safeStringLower(market, 'put_call');
|
|
492
|
+
const strike = this.safeString(market, 'strike');
|
|
493
|
+
const marginBuyEnabled = this.safeValue(market, 'margin_buy_enabled');
|
|
494
|
+
const marginSellEnabled = this.safeValue(market, 'margin_sell_enabled');
|
|
495
|
+
const expiry = this.omitZero(this.safeInteger(market, 'expiry_timestamp_ms'));
|
|
496
|
+
let symbol = base + '/' + quote;
|
|
497
|
+
let type = undefined;
|
|
498
|
+
let contract = undefined;
|
|
499
|
+
if (inst_type === 'CCY_PAIR') {
|
|
500
|
+
type = 'spot';
|
|
501
|
+
contract = false;
|
|
502
|
+
}
|
|
503
|
+
else if (inst_type === 'PERPETUAL_SWAP') {
|
|
504
|
+
type = 'swap';
|
|
505
|
+
symbol = symbol + ':' + quote;
|
|
506
|
+
contract = true;
|
|
507
|
+
}
|
|
508
|
+
else if (inst_type === 'FUTURE') {
|
|
509
|
+
type = 'future';
|
|
510
|
+
symbol = symbol + ':' + quote + '-' + this.yymmdd(expiry);
|
|
511
|
+
contract = true;
|
|
512
|
+
}
|
|
513
|
+
else if (inst_type === 'WARRANT') {
|
|
514
|
+
type = 'option';
|
|
515
|
+
const symbolOptionType = (optionType === 'call') ? 'C' : 'P';
|
|
516
|
+
symbol = symbol + ':' + quote + '-' + this.yymmdd(expiry) + '-' + strike + '-' + symbolOptionType;
|
|
517
|
+
contract = true;
|
|
518
|
+
}
|
|
519
|
+
result.push({
|
|
520
|
+
'id': this.safeString(market, 'symbol'),
|
|
521
|
+
'symbol': symbol,
|
|
522
|
+
'base': base,
|
|
523
|
+
'quote': quote,
|
|
524
|
+
'settle': settle,
|
|
525
|
+
'baseId': baseId,
|
|
526
|
+
'quoteId': quoteId,
|
|
527
|
+
'settleId': settleId,
|
|
528
|
+
'type': type,
|
|
529
|
+
'spot': spot,
|
|
530
|
+
'margin': ((marginBuyEnabled) || (marginSellEnabled)),
|
|
531
|
+
'swap': swap,
|
|
532
|
+
'future': future,
|
|
533
|
+
'option': option,
|
|
534
|
+
'active': this.safeValue(market, 'tradable'),
|
|
535
|
+
'contract': contract,
|
|
536
|
+
'linear': (contract) ? true : undefined,
|
|
537
|
+
'inverse': (contract) ? false : undefined,
|
|
538
|
+
'contractSize': this.safeNumber(market, 'contract_size'),
|
|
539
|
+
'expiry': expiry,
|
|
540
|
+
'expiryDatetime': this.iso8601(expiry),
|
|
541
|
+
'strike': this.parseNumber(strike),
|
|
542
|
+
'optionType': optionType,
|
|
543
|
+
'precision': {
|
|
544
|
+
'price': this.parseNumber(this.safeString(market, 'price_tick_size')),
|
|
545
|
+
'amount': this.parseNumber(this.safeString(market, 'qty_tick_size')),
|
|
546
|
+
},
|
|
547
|
+
'limits': {
|
|
548
|
+
'leverage': {
|
|
549
|
+
'min': this.parseNumber('1'),
|
|
550
|
+
'max': this.safeNumber(market, 'max_leverage'),
|
|
551
|
+
},
|
|
552
|
+
'amount': {
|
|
553
|
+
'min': undefined,
|
|
554
|
+
'max': undefined,
|
|
555
|
+
},
|
|
556
|
+
'price': {
|
|
557
|
+
'min': undefined,
|
|
558
|
+
'max': undefined,
|
|
559
|
+
},
|
|
560
|
+
'cost': {
|
|
561
|
+
'min': undefined,
|
|
562
|
+
'max': undefined,
|
|
563
|
+
},
|
|
564
|
+
},
|
|
565
|
+
'created': undefined,
|
|
566
|
+
'info': market,
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
return result;
|
|
570
|
+
}
|
|
571
|
+
async fetchTickers(symbols = undefined, params = {}) {
|
|
572
|
+
/**
|
|
573
|
+
* @method
|
|
574
|
+
* @name cryptocom#fetchTickers
|
|
575
|
+
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
|
|
576
|
+
* @see https://exchange-docs.crypto.com/spot/index.html#public-get-ticker
|
|
577
|
+
* @see https://exchange-docs.crypto.com/derivatives/index.html#public-get-tickers
|
|
578
|
+
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
|
|
579
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
580
|
+
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
|
|
581
|
+
*/
|
|
582
|
+
await this.loadMarkets();
|
|
583
|
+
let market = undefined;
|
|
584
|
+
const request = {};
|
|
585
|
+
if (symbols !== undefined) {
|
|
586
|
+
let symbol = undefined;
|
|
587
|
+
if (Array.isArray(symbols)) {
|
|
588
|
+
const symbolsLength = symbols.length;
|
|
589
|
+
if (symbolsLength > 1) {
|
|
590
|
+
throw new errors.BadRequest(this.id + ' fetchTickers() symbols argument cannot contain more than 1 symbol');
|
|
591
|
+
}
|
|
592
|
+
symbol = symbols[0];
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
symbol = symbols;
|
|
596
|
+
}
|
|
597
|
+
market = this.market(symbol);
|
|
598
|
+
request['instrument_name'] = market['id'];
|
|
599
|
+
}
|
|
600
|
+
const response = await this.v1PublicGetPublicGetTickers(this.extend(request, params));
|
|
601
|
+
//
|
|
602
|
+
// {
|
|
603
|
+
// "id": -1,
|
|
604
|
+
// "method": "public/get-tickers",
|
|
605
|
+
// "code": 0,
|
|
606
|
+
// "result": {
|
|
607
|
+
// "data": [
|
|
608
|
+
// {
|
|
609
|
+
// "i": "AVAXUSD-PERP",
|
|
610
|
+
// "h": "13.209",
|
|
611
|
+
// "l": "12.148",
|
|
612
|
+
// "a": "13.209",
|
|
613
|
+
// "v": "1109.8",
|
|
614
|
+
// "vv": "14017.33",
|
|
615
|
+
// "c": "0.0732",
|
|
616
|
+
// "b": "13.210",
|
|
617
|
+
// "k": "13.230",
|
|
618
|
+
// "oi": "10888.9",
|
|
619
|
+
// "t": 1687402657575
|
|
620
|
+
// },
|
|
621
|
+
// ]
|
|
622
|
+
// }
|
|
623
|
+
// }
|
|
624
|
+
//
|
|
625
|
+
const result = this.safeValue(response, 'result', {});
|
|
626
|
+
const data = this.safeValue(result, 'data', []);
|
|
627
|
+
return this.parseTickers(data, symbols);
|
|
628
|
+
}
|
|
629
|
+
async fetchTicker(symbol, params = {}) {
|
|
630
|
+
/**
|
|
631
|
+
* @method
|
|
632
|
+
* @name cryptocom#fetchTicker
|
|
633
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-tickers
|
|
634
|
+
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
|
|
635
|
+
* @param {string} symbol unified symbol of the market to fetch the ticker for
|
|
636
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
637
|
+
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
|
|
638
|
+
*/
|
|
639
|
+
await this.loadMarkets();
|
|
640
|
+
symbol = this.symbol(symbol);
|
|
641
|
+
const tickers = await this.fetchTickers([symbol], params);
|
|
642
|
+
return this.safeValue(tickers, symbol);
|
|
643
|
+
}
|
|
644
|
+
async fetchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
645
|
+
/**
|
|
646
|
+
* @method
|
|
647
|
+
* @name cryptocom#fetchOrders
|
|
648
|
+
* @description fetches information on multiple orders made by the user
|
|
649
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-order-history
|
|
650
|
+
* @param {string} symbol unified market symbol of the market the orders were made in
|
|
651
|
+
* @param {int} [since] the earliest time in ms to fetch orders for, max date range is one day
|
|
652
|
+
* @param {int} [limit] the maximum number of order structures to retrieve, default 100 max 100
|
|
653
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
654
|
+
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
|
|
655
|
+
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
|
|
656
|
+
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
657
|
+
*/
|
|
658
|
+
await this.loadMarkets();
|
|
659
|
+
let paginate = false;
|
|
660
|
+
[paginate, params] = this.handleOptionAndParams(params, 'fetchOrders', 'paginate');
|
|
661
|
+
if (paginate) {
|
|
662
|
+
return await this.fetchPaginatedCallDynamic('fetchOrders', symbol, since, limit, params);
|
|
663
|
+
}
|
|
664
|
+
let market = undefined;
|
|
665
|
+
const request = {};
|
|
666
|
+
if (symbol !== undefined) {
|
|
667
|
+
market = this.market(symbol);
|
|
668
|
+
request['instrument_name'] = market['id'];
|
|
669
|
+
}
|
|
670
|
+
if (since !== undefined) {
|
|
671
|
+
request['start_time'] = since;
|
|
672
|
+
}
|
|
673
|
+
if (limit !== undefined) {
|
|
674
|
+
request['limit'] = limit;
|
|
675
|
+
}
|
|
676
|
+
const until = this.safeInteger2(params, 'until', 'till');
|
|
677
|
+
params = this.omit(params, ['until', 'till']);
|
|
678
|
+
if (until !== undefined) {
|
|
679
|
+
request['end_time'] = until;
|
|
680
|
+
}
|
|
681
|
+
const response = await this.v1PrivatePostPrivateGetOrderHistory(this.extend(request, params));
|
|
682
|
+
//
|
|
683
|
+
// {
|
|
684
|
+
// "id": 1686881486183,
|
|
685
|
+
// "method": "private/get-order-history",
|
|
686
|
+
// "code": 0,
|
|
687
|
+
// "result": {
|
|
688
|
+
// "data": [
|
|
689
|
+
// {
|
|
690
|
+
// "account_id": "ce075bef-1234-4321-bd6g-ff9007252e63",
|
|
691
|
+
// "order_id": "6142909895014042762",
|
|
692
|
+
// "client_oid": "4e918597-1234-4321-8201-a7577e1e1d91",
|
|
693
|
+
// "order_type": "MARKET",
|
|
694
|
+
// "time_in_force": "GOOD_TILL_CANCEL",
|
|
695
|
+
// "side": "SELL",
|
|
696
|
+
// "exec_inst": [ ],
|
|
697
|
+
// "quantity": "0.00024",
|
|
698
|
+
// "order_value": "5.7054672",
|
|
699
|
+
// "maker_fee_rate": "0",
|
|
700
|
+
// "taker_fee_rate": "0",
|
|
701
|
+
// "avg_price": "25023.97",
|
|
702
|
+
// "trigger_price": "0",
|
|
703
|
+
// "ref_price": "0",
|
|
704
|
+
// "ref_price_type": "NULL_VAL",
|
|
705
|
+
// "cumulative_quantity": "0.00024",
|
|
706
|
+
// "cumulative_value": "6.0057528",
|
|
707
|
+
// "cumulative_fee": "0.001501438200",
|
|
708
|
+
// "status": "FILLED",
|
|
709
|
+
// "update_user_id": "ce075bef-1234-4321-bd6g-ff9007252e63",
|
|
710
|
+
// "order_date": "2023-06-15",
|
|
711
|
+
// "instrument_name": "BTC_USD",
|
|
712
|
+
// "fee_instrument_name": "USD",
|
|
713
|
+
// "create_time": 1686805465891,
|
|
714
|
+
// "create_time_ns": "1686805465891812578",
|
|
715
|
+
// "update_time": 1686805465891
|
|
716
|
+
// }
|
|
717
|
+
// ]
|
|
718
|
+
// }
|
|
719
|
+
// }
|
|
720
|
+
//
|
|
721
|
+
const data = this.safeValue(response, 'result', {});
|
|
722
|
+
const orders = this.safeValue(data, 'data', []);
|
|
723
|
+
return this.parseOrders(orders, market, since, limit);
|
|
724
|
+
}
|
|
725
|
+
async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
|
|
726
|
+
/**
|
|
727
|
+
* @method
|
|
728
|
+
* @name cryptocom#fetchTrades
|
|
729
|
+
* @description get a list of the most recent trades for a particular symbol
|
|
730
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-trades
|
|
731
|
+
* @param {string} symbol unified symbol of the market to fetch trades for
|
|
732
|
+
* @param {int} [since] timestamp in ms of the earliest trade to fetch, maximum date range is one day
|
|
733
|
+
* @param {int} [limit] the maximum number of trades to fetch
|
|
734
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
735
|
+
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
|
|
736
|
+
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
|
|
737
|
+
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
|
|
738
|
+
*/
|
|
739
|
+
await this.loadMarkets();
|
|
740
|
+
let paginate = false;
|
|
741
|
+
[paginate, params] = this.handleOptionAndParams(params, 'fetchTrades', 'paginate');
|
|
742
|
+
if (paginate) {
|
|
743
|
+
return await this.fetchPaginatedCallDynamic('fetchTrades', symbol, since, limit, params);
|
|
744
|
+
}
|
|
745
|
+
const market = this.market(symbol);
|
|
746
|
+
const request = {
|
|
747
|
+
'instrument_name': market['id'],
|
|
748
|
+
};
|
|
749
|
+
if (since !== undefined) {
|
|
750
|
+
request['start_ts'] = since;
|
|
751
|
+
}
|
|
752
|
+
if (limit !== undefined) {
|
|
753
|
+
request['count'] = limit;
|
|
754
|
+
}
|
|
755
|
+
const until = this.safeInteger2(params, 'until', 'till');
|
|
756
|
+
params = this.omit(params, ['until', 'till']);
|
|
757
|
+
if (until !== undefined) {
|
|
758
|
+
request['end_ts'] = until;
|
|
759
|
+
}
|
|
760
|
+
const response = await this.v1PublicGetPublicGetTrades(this.extend(request, params));
|
|
761
|
+
//
|
|
762
|
+
// {
|
|
763
|
+
// "id": -1,
|
|
764
|
+
// "method": "public/get-trades",
|
|
765
|
+
// "code": 0,
|
|
766
|
+
// "result": {
|
|
767
|
+
// "data": [
|
|
768
|
+
// {
|
|
769
|
+
// "s": "sell",
|
|
770
|
+
// "p": "26386.00",
|
|
771
|
+
// "q": "0.00453",
|
|
772
|
+
// "t": 1686944282062,
|
|
773
|
+
// "tn" : 1704476468851524373,
|
|
774
|
+
// "d": "4611686018455979970",
|
|
775
|
+
// "i": "BTC_USD"
|
|
776
|
+
// },
|
|
777
|
+
// ]
|
|
778
|
+
// }
|
|
779
|
+
// }
|
|
780
|
+
//
|
|
781
|
+
const result = this.safeValue(response, 'result', {});
|
|
782
|
+
const trades = this.safeValue(result, 'data', []);
|
|
783
|
+
return this.parseTrades(trades, market, since, limit);
|
|
784
|
+
}
|
|
785
|
+
async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
|
|
786
|
+
/**
|
|
787
|
+
* @method
|
|
788
|
+
* @name cryptocom#fetchOHLCV
|
|
789
|
+
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
|
|
790
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-candlestick
|
|
791
|
+
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
|
|
792
|
+
* @param {string} timeframe the length of time each candle represents
|
|
793
|
+
* @param {int} [since] timestamp in ms of the earliest candle to fetch
|
|
794
|
+
* @param {int} [limit] the maximum amount of candles to fetch
|
|
795
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
796
|
+
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
|
|
797
|
+
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
|
|
798
|
+
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
|
|
799
|
+
*/
|
|
800
|
+
await this.loadMarkets();
|
|
801
|
+
let paginate = false;
|
|
802
|
+
[paginate, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'paginate', false);
|
|
803
|
+
if (paginate) {
|
|
804
|
+
return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 300);
|
|
805
|
+
}
|
|
806
|
+
const market = this.market(symbol);
|
|
807
|
+
const request = {
|
|
808
|
+
'instrument_name': market['id'],
|
|
809
|
+
'timeframe': this.safeString(this.timeframes, timeframe, timeframe),
|
|
810
|
+
};
|
|
811
|
+
if (since !== undefined) {
|
|
812
|
+
request['start_ts'] = since;
|
|
813
|
+
}
|
|
814
|
+
if (limit !== undefined) {
|
|
815
|
+
request['count'] = limit;
|
|
816
|
+
}
|
|
817
|
+
const until = this.safeInteger2(params, 'until', 'till');
|
|
818
|
+
params = this.omit(params, ['until', 'till']);
|
|
819
|
+
if (until !== undefined) {
|
|
820
|
+
request['end_ts'] = until;
|
|
821
|
+
}
|
|
822
|
+
const response = await this.v1PublicGetPublicGetCandlestick(this.extend(request, params));
|
|
823
|
+
//
|
|
824
|
+
// {
|
|
825
|
+
// "id": -1,
|
|
826
|
+
// "method": "public/get-candlestick",
|
|
827
|
+
// "code": 0,
|
|
828
|
+
// "result": {
|
|
829
|
+
// "interval": "1m",
|
|
830
|
+
// "data": [
|
|
831
|
+
// {
|
|
832
|
+
// "o": "26949.89",
|
|
833
|
+
// "h": "26957.64",
|
|
834
|
+
// "l": "26948.24",
|
|
835
|
+
// "c": "26950.00",
|
|
836
|
+
// "v": "0.0670",
|
|
837
|
+
// "t": 1687237080000
|
|
838
|
+
// },
|
|
839
|
+
// ],
|
|
840
|
+
// "instrument_name": "BTC_USD"
|
|
841
|
+
// }
|
|
842
|
+
// }
|
|
843
|
+
//
|
|
844
|
+
const result = this.safeValue(response, 'result', {});
|
|
845
|
+
const data = this.safeValue(result, 'data', []);
|
|
846
|
+
return this.parseOHLCVs(data, market, timeframe, since, limit);
|
|
847
|
+
}
|
|
848
|
+
async fetchOrderBook(symbol, limit = undefined, params = {}) {
|
|
849
|
+
/**
|
|
850
|
+
* @method
|
|
851
|
+
* @name cryptocom#fetchOrderBook
|
|
852
|
+
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
|
|
853
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-book
|
|
854
|
+
* @param {string} symbol unified symbol of the market to fetch the order book for
|
|
855
|
+
* @param {int} [limit] the number of order book entries to return, max 50
|
|
856
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
857
|
+
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
|
|
858
|
+
*/
|
|
859
|
+
await this.loadMarkets();
|
|
860
|
+
const market = this.market(symbol);
|
|
861
|
+
const request = {
|
|
862
|
+
'instrument_name': market['id'],
|
|
863
|
+
};
|
|
864
|
+
if (limit) {
|
|
865
|
+
request['depth'] = limit;
|
|
866
|
+
}
|
|
867
|
+
const response = await this.v1PublicGetPublicGetBook(this.extend(request, params));
|
|
868
|
+
//
|
|
869
|
+
// {
|
|
870
|
+
// "id": -1,
|
|
871
|
+
// "method": "public/get-book",
|
|
872
|
+
// "code": 0,
|
|
873
|
+
// "result": {
|
|
874
|
+
// "depth": 3,
|
|
875
|
+
// "data": [
|
|
876
|
+
// {
|
|
877
|
+
// "bids": [ [ "30025.00", "0.00004", "1" ], [ "30020.15", "0.02498", "1" ], [ "30020.00", "0.00004", "1" ] ],
|
|
878
|
+
// "asks": [ [ "30025.01", "0.04090", "1" ], [ "30025.70", "0.01000", "1" ], [ "30026.94", "0.02681", "1" ] ],
|
|
879
|
+
// "t": 1687491287380
|
|
880
|
+
// }
|
|
881
|
+
// ],
|
|
882
|
+
// "instrument_name": "BTC_USD"
|
|
883
|
+
// }
|
|
884
|
+
// }
|
|
885
|
+
//
|
|
886
|
+
const result = this.safeValue(response, 'result', {});
|
|
887
|
+
const data = this.safeValue(result, 'data', []);
|
|
888
|
+
const orderBook = this.safeValue(data, 0);
|
|
889
|
+
const timestamp = this.safeInteger(orderBook, 't');
|
|
890
|
+
return this.parseOrderBook(orderBook, symbol, timestamp);
|
|
891
|
+
}
|
|
892
|
+
parseBalance(response) {
|
|
893
|
+
const responseResult = this.safeValue(response, 'result', {});
|
|
894
|
+
const data = this.safeValue(responseResult, 'data', []);
|
|
895
|
+
const positionBalances = this.safeValue(data[0], 'position_balances', []);
|
|
896
|
+
const result = { 'info': response };
|
|
897
|
+
for (let i = 0; i < positionBalances.length; i++) {
|
|
898
|
+
const balance = positionBalances[i];
|
|
899
|
+
const currencyId = this.safeString(balance, 'instrument_name');
|
|
900
|
+
const code = this.safeCurrencyCode(currencyId);
|
|
901
|
+
const account = this.account();
|
|
902
|
+
account['total'] = this.safeString(balance, 'quantity');
|
|
903
|
+
account['used'] = this.safeString(balance, 'reserved_qty');
|
|
904
|
+
result[code] = account;
|
|
905
|
+
}
|
|
906
|
+
return this.safeBalance(result);
|
|
907
|
+
}
|
|
908
|
+
async fetchBalance(params = {}) {
|
|
909
|
+
/**
|
|
910
|
+
* @method
|
|
911
|
+
* @name cryptocom#fetchBalance
|
|
912
|
+
* @description query for balance and get the amount of funds available for trading or funds locked in orders
|
|
913
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-user-balance
|
|
914
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
915
|
+
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
|
|
916
|
+
*/
|
|
917
|
+
await this.loadMarkets();
|
|
918
|
+
const response = await this.v1PrivatePostPrivateUserBalance(params);
|
|
919
|
+
//
|
|
920
|
+
// {
|
|
921
|
+
// "id": 1687300499018,
|
|
922
|
+
// "method": "private/user-balance",
|
|
923
|
+
// "code": 0,
|
|
924
|
+
// "result": {
|
|
925
|
+
// "data": [
|
|
926
|
+
// {
|
|
927
|
+
// "total_available_balance": "5.84684368",
|
|
928
|
+
// "total_margin_balance": "5.84684368",
|
|
929
|
+
// "total_initial_margin": "0",
|
|
930
|
+
// "total_maintenance_margin": "0",
|
|
931
|
+
// "total_position_cost": "0",
|
|
932
|
+
// "total_cash_balance": "6.44412101",
|
|
933
|
+
// "total_collateral_value": "5.846843685",
|
|
934
|
+
// "total_session_unrealized_pnl": "0",
|
|
935
|
+
// "instrument_name": "USD",
|
|
936
|
+
// "total_session_realized_pnl": "0",
|
|
937
|
+
// "position_balances": [
|
|
938
|
+
// {
|
|
939
|
+
// "quantity": "0.0002119875",
|
|
940
|
+
// "reserved_qty": "0",
|
|
941
|
+
// "collateral_weight": "0.9",
|
|
942
|
+
// "collateral_amount": "5.37549592",
|
|
943
|
+
// "market_value": "5.97277325",
|
|
944
|
+
// "max_withdrawal_balance": "0.00021198",
|
|
945
|
+
// "instrument_name": "BTC",
|
|
946
|
+
// "hourly_interest_rate": "0"
|
|
947
|
+
// },
|
|
948
|
+
// ],
|
|
949
|
+
// "total_effective_leverage": "0",
|
|
950
|
+
// "position_limit": "3000000",
|
|
951
|
+
// "used_position_limit": "0",
|
|
952
|
+
// "total_borrow": "0",
|
|
953
|
+
// "margin_score": "0",
|
|
954
|
+
// "is_liquidating": false,
|
|
955
|
+
// "has_risk": false,
|
|
956
|
+
// "terminatable": true
|
|
957
|
+
// }
|
|
958
|
+
// ]
|
|
959
|
+
// }
|
|
960
|
+
// }
|
|
961
|
+
//
|
|
962
|
+
return this.parseBalance(response);
|
|
963
|
+
}
|
|
964
|
+
async fetchOrder(id, symbol = undefined, params = {}) {
|
|
965
|
+
/**
|
|
966
|
+
* @method
|
|
967
|
+
* @name cryptocom#fetchOrder
|
|
968
|
+
* @description fetches information on an order made by the user
|
|
969
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-order-detail
|
|
970
|
+
* @param {string} symbol unified symbol of the market the order was made in
|
|
971
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
972
|
+
* @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
973
|
+
*/
|
|
974
|
+
await this.loadMarkets();
|
|
975
|
+
let market = undefined;
|
|
976
|
+
if (symbol !== undefined) {
|
|
977
|
+
market = this.market(symbol);
|
|
978
|
+
}
|
|
979
|
+
const request = {
|
|
980
|
+
'order_id': id,
|
|
981
|
+
};
|
|
982
|
+
const response = await this.v1PrivatePostPrivateGetOrderDetail(this.extend(request, params));
|
|
983
|
+
//
|
|
984
|
+
// {
|
|
985
|
+
// "id": 1686872583882,
|
|
986
|
+
// "method": "private/get-order-detail",
|
|
987
|
+
// "code": 0,
|
|
988
|
+
// "result": {
|
|
989
|
+
// "account_id": "ae075bef-1234-4321-bd6g-bb9007252a63",
|
|
990
|
+
// "order_id": "6142909895025252686",
|
|
991
|
+
// "client_oid": "CCXT_c2d2152cc32d40a3ae7fbf",
|
|
992
|
+
// "order_type": "LIMIT",
|
|
993
|
+
// "time_in_force": "GOOD_TILL_CANCEL",
|
|
994
|
+
// "side": "BUY",
|
|
995
|
+
// "exec_inst": [ ],
|
|
996
|
+
// "quantity": "0.00020",
|
|
997
|
+
// "limit_price": "20000.00",
|
|
998
|
+
// "order_value": "4",
|
|
999
|
+
// "avg_price": "0",
|
|
1000
|
+
// "trigger_price": "0",
|
|
1001
|
+
// "ref_price": "0",
|
|
1002
|
+
// "cumulative_quantity": "0",
|
|
1003
|
+
// "cumulative_value": "0",
|
|
1004
|
+
// "cumulative_fee": "0",
|
|
1005
|
+
// "status": "ACTIVE",
|
|
1006
|
+
// "update_user_id": "ae075bef-1234-4321-bd6g-bb9007252a63",
|
|
1007
|
+
// "order_date": "2023-06-15",
|
|
1008
|
+
// "instrument_name": "BTC_USD",
|
|
1009
|
+
// "fee_instrument_name": "BTC",
|
|
1010
|
+
// "create_time": 1686870220684,
|
|
1011
|
+
// "create_time_ns": "1686870220684239675",
|
|
1012
|
+
// "update_time": 1686870220684
|
|
1013
|
+
// }
|
|
1014
|
+
// }
|
|
1015
|
+
//
|
|
1016
|
+
const order = this.safeValue(response, 'result', {});
|
|
1017
|
+
return this.parseOrder(order, market);
|
|
1018
|
+
}
|
|
1019
|
+
createOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
|
|
1020
|
+
const market = this.market(symbol);
|
|
1021
|
+
const uppercaseType = type.toUpperCase();
|
|
1022
|
+
const request = {
|
|
1023
|
+
'instrument_name': market['id'],
|
|
1024
|
+
'side': side.toUpperCase(),
|
|
1025
|
+
'quantity': this.amountToPrecision(symbol, amount),
|
|
1026
|
+
};
|
|
1027
|
+
if ((uppercaseType === 'LIMIT') || (uppercaseType === 'STOP_LIMIT') || (uppercaseType === 'TAKE_PROFIT_LIMIT')) {
|
|
1028
|
+
request['price'] = this.priceToPrecision(symbol, price);
|
|
1029
|
+
}
|
|
1030
|
+
const broker = this.safeString(this.options, 'broker', 'CCXT');
|
|
1031
|
+
request['broker_id'] = broker;
|
|
1032
|
+
let marketType = undefined;
|
|
1033
|
+
let marginMode = undefined;
|
|
1034
|
+
[marketType, params] = this.handleMarketTypeAndParams('createOrder', market, params);
|
|
1035
|
+
[marginMode, params] = this.customHandleMarginModeAndParams('createOrder', params);
|
|
1036
|
+
if ((marketType === 'margin') || (marginMode !== undefined)) {
|
|
1037
|
+
request['spot_margin'] = 'MARGIN';
|
|
1038
|
+
}
|
|
1039
|
+
else if (marketType === 'spot') {
|
|
1040
|
+
request['spot_margin'] = 'SPOT';
|
|
1041
|
+
}
|
|
1042
|
+
const timeInForce = this.safeStringUpper2(params, 'timeInForce', 'time_in_force');
|
|
1043
|
+
if (timeInForce !== undefined) {
|
|
1044
|
+
if (timeInForce === 'GTC') {
|
|
1045
|
+
request['time_in_force'] = 'GOOD_TILL_CANCEL';
|
|
1046
|
+
}
|
|
1047
|
+
else if (timeInForce === 'IOC') {
|
|
1048
|
+
request['time_in_force'] = 'IMMEDIATE_OR_CANCEL';
|
|
1049
|
+
}
|
|
1050
|
+
else if (timeInForce === 'FOK') {
|
|
1051
|
+
request['time_in_force'] = 'FILL_OR_KILL';
|
|
1052
|
+
}
|
|
1053
|
+
else {
|
|
1054
|
+
request['time_in_force'] = timeInForce;
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
const postOnly = this.safeValue(params, 'postOnly', false);
|
|
1058
|
+
if ((postOnly) || (timeInForce === 'PO')) {
|
|
1059
|
+
request['exec_inst'] = ['POST_ONLY'];
|
|
1060
|
+
request['time_in_force'] = 'GOOD_TILL_CANCEL';
|
|
1061
|
+
}
|
|
1062
|
+
const triggerPrice = this.safeStringN(params, ['stopPrice', 'triggerPrice', 'ref_price']);
|
|
1063
|
+
const stopLossPrice = this.safeNumber(params, 'stopLossPrice');
|
|
1064
|
+
const takeProfitPrice = this.safeNumber(params, 'takeProfitPrice');
|
|
1065
|
+
const isTrigger = (triggerPrice !== undefined);
|
|
1066
|
+
const isStopLossTrigger = (stopLossPrice !== undefined);
|
|
1067
|
+
const isTakeProfitTrigger = (takeProfitPrice !== undefined);
|
|
1068
|
+
if (isTrigger) {
|
|
1069
|
+
request['ref_price'] = this.priceToPrecision(symbol, triggerPrice);
|
|
1070
|
+
price = price.toString();
|
|
1071
|
+
if ((uppercaseType === 'LIMIT') || (uppercaseType === 'STOP_LIMIT') || (uppercaseType === 'TAKE_PROFIT_LIMIT')) {
|
|
1072
|
+
if (side === 'buy') {
|
|
1073
|
+
if (Precise["default"].stringLt(price, triggerPrice)) {
|
|
1074
|
+
request['type'] = 'TAKE_PROFIT_LIMIT';
|
|
1075
|
+
}
|
|
1076
|
+
else {
|
|
1077
|
+
request['type'] = 'STOP_LIMIT';
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
else {
|
|
1081
|
+
if (Precise["default"].stringLt(price, triggerPrice)) {
|
|
1082
|
+
request['type'] = 'STOP_LIMIT';
|
|
1083
|
+
}
|
|
1084
|
+
else {
|
|
1085
|
+
request['type'] = 'TAKE_PROFIT_LIMIT';
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
else {
|
|
1090
|
+
if (side === 'buy') {
|
|
1091
|
+
if (Precise["default"].stringLt(price, triggerPrice)) {
|
|
1092
|
+
request['type'] = 'TAKE_PROFIT';
|
|
1093
|
+
}
|
|
1094
|
+
else {
|
|
1095
|
+
request['type'] = 'STOP_LOSS';
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
else {
|
|
1099
|
+
if (Precise["default"].stringLt(price, triggerPrice)) {
|
|
1100
|
+
request['type'] = 'STOP_LOSS';
|
|
1101
|
+
}
|
|
1102
|
+
else {
|
|
1103
|
+
request['type'] = 'TAKE_PROFIT';
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
else if (isStopLossTrigger) {
|
|
1109
|
+
if ((uppercaseType === 'LIMIT') || (uppercaseType === 'STOP_LIMIT')) {
|
|
1110
|
+
request['type'] = 'STOP_LIMIT';
|
|
1111
|
+
}
|
|
1112
|
+
else {
|
|
1113
|
+
request['type'] = 'STOP_LOSS';
|
|
1114
|
+
}
|
|
1115
|
+
request['ref_price'] = this.priceToPrecision(symbol, stopLossPrice);
|
|
1116
|
+
}
|
|
1117
|
+
else if (isTakeProfitTrigger) {
|
|
1118
|
+
if ((uppercaseType === 'LIMIT') || (uppercaseType === 'TAKE_PROFIT_LIMIT')) {
|
|
1119
|
+
request['type'] = 'TAKE_PROFIT_LIMIT';
|
|
1120
|
+
}
|
|
1121
|
+
else {
|
|
1122
|
+
request['type'] = 'TAKE_PROFIT';
|
|
1123
|
+
}
|
|
1124
|
+
request['ref_price'] = this.priceToPrecision(symbol, takeProfitPrice);
|
|
1125
|
+
}
|
|
1126
|
+
else {
|
|
1127
|
+
request['type'] = uppercaseType;
|
|
1128
|
+
}
|
|
1129
|
+
params = this.omit(params, ['postOnly', 'clientOrderId', 'timeInForce', 'stopPrice', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice']);
|
|
1130
|
+
return this.extend(request, params);
|
|
1131
|
+
}
|
|
1132
|
+
async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
|
|
1133
|
+
/**
|
|
1134
|
+
* @method
|
|
1135
|
+
* @name cryptocom#createOrder
|
|
1136
|
+
* @description create a trade order
|
|
1137
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-create-order
|
|
1138
|
+
* @param {string} symbol unified symbol of the market to create an order in
|
|
1139
|
+
* @param {string} type 'market', 'limit', 'stop_loss', 'stop_limit', 'take_profit', 'take_profit_limit'
|
|
1140
|
+
* @param {string} side 'buy' or 'sell'
|
|
1141
|
+
* @param {float} amount how much you want to trade in units of base currency
|
|
1142
|
+
* @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
|
|
1143
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1144
|
+
* @param {string} [params.timeInForce] 'GTC', 'IOC', 'FOK' or 'PO'
|
|
1145
|
+
* @param {string} [params.ref_price_type] 'MARK_PRICE', 'INDEX_PRICE', 'LAST_PRICE' which trigger price type to use, default is MARK_PRICE
|
|
1146
|
+
* @param {float} [params.stopPrice] price to trigger a stop order
|
|
1147
|
+
* @param {float} [params.stopLossPrice] price to trigger a stop-loss trigger order
|
|
1148
|
+
* @param {float} [params.takeProfitPrice] price to trigger a take-profit trigger order
|
|
1149
|
+
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1150
|
+
*/
|
|
1151
|
+
await this.loadMarkets();
|
|
1152
|
+
const market = this.market(symbol);
|
|
1153
|
+
const request = this.createOrderRequest(symbol, type, side, amount, price, params);
|
|
1154
|
+
const response = await this.v1PrivatePostPrivateCreateOrder(request);
|
|
1155
|
+
//
|
|
1156
|
+
// {
|
|
1157
|
+
// "id": 1686804664362,
|
|
1158
|
+
// "method": "private/create-order",
|
|
1159
|
+
// "code" : 0,
|
|
1160
|
+
// "result": {
|
|
1161
|
+
// "order_id": "6540219377766741832",
|
|
1162
|
+
// "client_oid": "CCXT_d6ef7c3db6c1495aa8b757"
|
|
1163
|
+
// }
|
|
1164
|
+
// }
|
|
1165
|
+
//
|
|
1166
|
+
const result = this.safeValue(response, 'result', {});
|
|
1167
|
+
return this.parseOrder(result, market);
|
|
1168
|
+
}
|
|
1169
|
+
async createOrders(orders, params = {}) {
|
|
1170
|
+
/**
|
|
1171
|
+
* @method
|
|
1172
|
+
* @name cryptocom#createOrders
|
|
1173
|
+
* @description create a list of trade orders
|
|
1174
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-create-order-list-list
|
|
1175
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-create-order-list-oco
|
|
1176
|
+
* @param {Array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
|
|
1177
|
+
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1178
|
+
*/
|
|
1179
|
+
await this.loadMarkets();
|
|
1180
|
+
const ordersRequests = [];
|
|
1181
|
+
for (let i = 0; i < orders.length; i++) {
|
|
1182
|
+
const rawOrder = orders[i];
|
|
1183
|
+
const marketId = this.safeString(rawOrder, 'symbol');
|
|
1184
|
+
const type = this.safeString(rawOrder, 'type');
|
|
1185
|
+
const side = this.safeString(rawOrder, 'side');
|
|
1186
|
+
const amount = this.safeValue(rawOrder, 'amount');
|
|
1187
|
+
const price = this.safeValue(rawOrder, 'price');
|
|
1188
|
+
const orderParams = this.safeValue(rawOrder, 'params', {});
|
|
1189
|
+
const orderRequest = this.createAdvancedOrderRequest(marketId, type, side, amount, price, orderParams);
|
|
1190
|
+
ordersRequests.push(orderRequest);
|
|
1191
|
+
}
|
|
1192
|
+
const contigency = this.safeString(params, 'contingency_type', 'LIST');
|
|
1193
|
+
const request = {
|
|
1194
|
+
'contingency_type': contigency,
|
|
1195
|
+
'order_list': ordersRequests,
|
|
1196
|
+
};
|
|
1197
|
+
const response = await this.v1PrivatePostPrivateCreateOrderList(this.extend(request, params));
|
|
1198
|
+
//
|
|
1199
|
+
// {
|
|
1200
|
+
// "id": 12,
|
|
1201
|
+
// "method": "private/create-order-list",
|
|
1202
|
+
// "code": 10001,
|
|
1203
|
+
// "result": {
|
|
1204
|
+
// "result_list": [
|
|
1205
|
+
// {
|
|
1206
|
+
// "index": 0,
|
|
1207
|
+
// "code": 0,
|
|
1208
|
+
// "order_id": "2015106383706015873",
|
|
1209
|
+
// "client_oid": "my_order_0001"
|
|
1210
|
+
// },
|
|
1211
|
+
// {
|
|
1212
|
+
// "index": 1,
|
|
1213
|
+
// "code": 20007,
|
|
1214
|
+
// "message": "INVALID_REQUEST",
|
|
1215
|
+
// "client_oid": "my_order_0002"
|
|
1216
|
+
// }
|
|
1217
|
+
// ]
|
|
1218
|
+
// }
|
|
1219
|
+
// }
|
|
1220
|
+
//
|
|
1221
|
+
// {
|
|
1222
|
+
// "id" : 1698068111133,
|
|
1223
|
+
// "method" : "private/create-order-list",
|
|
1224
|
+
// "code" : 0,
|
|
1225
|
+
// "result" : [ {
|
|
1226
|
+
// "code" : 0,
|
|
1227
|
+
// "index" : 0,
|
|
1228
|
+
// "client_oid" : "1698068111133_0",
|
|
1229
|
+
// "order_id" : "6142909896519488206"
|
|
1230
|
+
// }, {
|
|
1231
|
+
// "code" : 306,
|
|
1232
|
+
// "index" : 1,
|
|
1233
|
+
// "client_oid" : "1698068111133_1",
|
|
1234
|
+
// "message" : "INSUFFICIENT_AVAILABLE_BALANCE",
|
|
1235
|
+
// "order_id" : "6142909896519488207"
|
|
1236
|
+
// } ]
|
|
1237
|
+
// }
|
|
1238
|
+
//
|
|
1239
|
+
const result = this.safeValue(response, 'result', []);
|
|
1240
|
+
const listId = this.safeString(result, 'list_id');
|
|
1241
|
+
if (listId !== undefined) {
|
|
1242
|
+
const ocoOrders = [{ 'order_id': listId }];
|
|
1243
|
+
return this.parseOrders(ocoOrders);
|
|
1244
|
+
}
|
|
1245
|
+
return this.parseOrders(result);
|
|
1246
|
+
}
|
|
1247
|
+
createAdvancedOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
|
|
1248
|
+
// differs slightly from createOrderRequest
|
|
1249
|
+
// since the advanced order endpoint requires a different set of parameters
|
|
1250
|
+
// namely here we don't support ref_price or spot_margin
|
|
1251
|
+
// and market-buy orders need to send notional instead of quantity
|
|
1252
|
+
const market = this.market(symbol);
|
|
1253
|
+
const uppercaseType = type.toUpperCase();
|
|
1254
|
+
const request = {
|
|
1255
|
+
'instrument_name': market['id'],
|
|
1256
|
+
'side': side.toUpperCase(),
|
|
1257
|
+
};
|
|
1258
|
+
if ((uppercaseType === 'LIMIT') || (uppercaseType === 'STOP_LIMIT') || (uppercaseType === 'TAKE_PROFIT_LIMIT')) {
|
|
1259
|
+
request['price'] = this.priceToPrecision(symbol, price);
|
|
1260
|
+
}
|
|
1261
|
+
const broker = this.safeString(this.options, 'broker', 'CCXT');
|
|
1262
|
+
request['broker_id'] = broker;
|
|
1263
|
+
const timeInForce = this.safeStringUpper2(params, 'timeInForce', 'time_in_force');
|
|
1264
|
+
if (timeInForce !== undefined) {
|
|
1265
|
+
if (timeInForce === 'GTC') {
|
|
1266
|
+
request['time_in_force'] = 'GOOD_TILL_CANCEL';
|
|
1267
|
+
}
|
|
1268
|
+
else if (timeInForce === 'IOC') {
|
|
1269
|
+
request['time_in_force'] = 'IMMEDIATE_OR_CANCEL';
|
|
1270
|
+
}
|
|
1271
|
+
else if (timeInForce === 'FOK') {
|
|
1272
|
+
request['time_in_force'] = 'FILL_OR_KILL';
|
|
1273
|
+
}
|
|
1274
|
+
else {
|
|
1275
|
+
request['time_in_force'] = timeInForce;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
const postOnly = this.safeValue(params, 'postOnly', false);
|
|
1279
|
+
if ((postOnly) || (timeInForce === 'PO')) {
|
|
1280
|
+
request['exec_inst'] = ['POST_ONLY'];
|
|
1281
|
+
request['time_in_force'] = 'GOOD_TILL_CANCEL';
|
|
1282
|
+
}
|
|
1283
|
+
const triggerPrice = this.safeStringN(params, ['stopPrice', 'triggerPrice', 'ref_price']);
|
|
1284
|
+
const stopLossPrice = this.safeNumber(params, 'stopLossPrice');
|
|
1285
|
+
const takeProfitPrice = this.safeNumber(params, 'takeProfitPrice');
|
|
1286
|
+
const isTrigger = (triggerPrice !== undefined);
|
|
1287
|
+
const isStopLossTrigger = (stopLossPrice !== undefined);
|
|
1288
|
+
const isTakeProfitTrigger = (takeProfitPrice !== undefined);
|
|
1289
|
+
if (isTrigger) {
|
|
1290
|
+
price = price.toString();
|
|
1291
|
+
if ((uppercaseType === 'LIMIT') || (uppercaseType === 'STOP_LIMIT') || (uppercaseType === 'TAKE_PROFIT_LIMIT')) {
|
|
1292
|
+
if (side === 'buy') {
|
|
1293
|
+
if (Precise["default"].stringLt(price, triggerPrice)) {
|
|
1294
|
+
request['type'] = 'TAKE_PROFIT_LIMIT';
|
|
1295
|
+
}
|
|
1296
|
+
else {
|
|
1297
|
+
request['type'] = 'STOP_LIMIT';
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
else {
|
|
1301
|
+
if (Precise["default"].stringLt(price, triggerPrice)) {
|
|
1302
|
+
request['type'] = 'STOP_LIMIT';
|
|
1303
|
+
}
|
|
1304
|
+
else {
|
|
1305
|
+
request['type'] = 'TAKE_PROFIT_LIMIT';
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
else {
|
|
1310
|
+
if (side === 'buy') {
|
|
1311
|
+
if (Precise["default"].stringLt(price, triggerPrice)) {
|
|
1312
|
+
request['type'] = 'TAKE_PROFIT';
|
|
1313
|
+
}
|
|
1314
|
+
else {
|
|
1315
|
+
request['type'] = 'STOP_LOSS';
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
else {
|
|
1319
|
+
if (Precise["default"].stringLt(price, triggerPrice)) {
|
|
1320
|
+
request['type'] = 'STOP_LOSS';
|
|
1321
|
+
}
|
|
1322
|
+
else {
|
|
1323
|
+
request['type'] = 'TAKE_PROFIT';
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
else if (isStopLossTrigger) {
|
|
1329
|
+
if ((uppercaseType === 'LIMIT') || (uppercaseType === 'STOP_LIMIT')) {
|
|
1330
|
+
request['type'] = 'STOP_LIMIT';
|
|
1331
|
+
}
|
|
1332
|
+
else {
|
|
1333
|
+
request['type'] = 'STOP_LOSS';
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
else if (isTakeProfitTrigger) {
|
|
1337
|
+
if ((uppercaseType === 'LIMIT') || (uppercaseType === 'TAKE_PROFIT_LIMIT')) {
|
|
1338
|
+
request['type'] = 'TAKE_PROFIT_LIMIT';
|
|
1339
|
+
}
|
|
1340
|
+
else {
|
|
1341
|
+
request['type'] = 'TAKE_PROFIT';
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
else {
|
|
1345
|
+
request['type'] = uppercaseType;
|
|
1346
|
+
}
|
|
1347
|
+
if ((side === 'buy') && ((uppercaseType === 'MARKET') || (uppercaseType === 'STOP_LOSS') || (uppercaseType === 'TAKE_PROFIT'))) {
|
|
1348
|
+
// use createmarketBuy logic here
|
|
1349
|
+
let quoteAmount = undefined;
|
|
1350
|
+
let createMarketBuyOrderRequiresPrice = true;
|
|
1351
|
+
[createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
|
|
1352
|
+
const cost = this.safeNumber2(params, 'cost', 'notional');
|
|
1353
|
+
params = this.omit(params, 'cost');
|
|
1354
|
+
if (cost !== undefined) {
|
|
1355
|
+
quoteAmount = this.costToPrecision(symbol, cost);
|
|
1356
|
+
}
|
|
1357
|
+
else if (createMarketBuyOrderRequiresPrice) {
|
|
1358
|
+
if (price === undefined) {
|
|
1359
|
+
throw new errors.InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend (quote quantity) in the amount argument');
|
|
1360
|
+
}
|
|
1361
|
+
else {
|
|
1362
|
+
const amountString = this.numberToString(amount);
|
|
1363
|
+
const priceString = this.numberToString(price);
|
|
1364
|
+
const costRequest = Precise["default"].stringMul(amountString, priceString);
|
|
1365
|
+
quoteAmount = this.costToPrecision(symbol, costRequest);
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
else {
|
|
1369
|
+
quoteAmount = this.costToPrecision(symbol, amount);
|
|
1370
|
+
}
|
|
1371
|
+
request['notional'] = quoteAmount;
|
|
1372
|
+
}
|
|
1373
|
+
else {
|
|
1374
|
+
request['quantity'] = this.amountToPrecision(symbol, amount);
|
|
1375
|
+
}
|
|
1376
|
+
params = this.omit(params, ['postOnly', 'clientOrderId', 'timeInForce', 'stopPrice', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice']);
|
|
1377
|
+
return this.extend(request, params);
|
|
1378
|
+
}
|
|
1379
|
+
async cancelAllOrders(symbol = undefined, params = {}) {
|
|
1380
|
+
/**
|
|
1381
|
+
* @method
|
|
1382
|
+
* @name cryptocom#cancelAllOrders
|
|
1383
|
+
* @description cancel all open orders
|
|
1384
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-all-orders
|
|
1385
|
+
* @param {string} symbol unified market symbol of the orders to cancel
|
|
1386
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1387
|
+
* @returns {object} Returns exchange raw message{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1388
|
+
*/
|
|
1389
|
+
await this.loadMarkets();
|
|
1390
|
+
let market = undefined;
|
|
1391
|
+
const request = {};
|
|
1392
|
+
if (symbol !== undefined) {
|
|
1393
|
+
market = this.market(symbol);
|
|
1394
|
+
request['instrument_name'] = market['id'];
|
|
1395
|
+
}
|
|
1396
|
+
return await this.v1PrivatePostPrivateCancelAllOrders(this.extend(request, params));
|
|
1397
|
+
}
|
|
1398
|
+
async cancelOrder(id, symbol = undefined, params = {}) {
|
|
1399
|
+
/**
|
|
1400
|
+
* @method
|
|
1401
|
+
* @name cryptocom#cancelOrder
|
|
1402
|
+
* @description cancels an open order
|
|
1403
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-order
|
|
1404
|
+
* @param {string} id the order id of the order to cancel
|
|
1405
|
+
* @param {string} [symbol] unified symbol of the market the order was made in
|
|
1406
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1407
|
+
* @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1408
|
+
*/
|
|
1409
|
+
await this.loadMarkets();
|
|
1410
|
+
let market = undefined;
|
|
1411
|
+
if (symbol !== undefined) {
|
|
1412
|
+
market = this.market(symbol);
|
|
1413
|
+
}
|
|
1414
|
+
const request = {
|
|
1415
|
+
'order_id': id,
|
|
1416
|
+
};
|
|
1417
|
+
const response = await this.v1PrivatePostPrivateCancelOrder(this.extend(request, params));
|
|
1418
|
+
//
|
|
1419
|
+
// {
|
|
1420
|
+
// "id": 1686882846638,
|
|
1421
|
+
// "method": "private/cancel-order",
|
|
1422
|
+
// "code": 0,
|
|
1423
|
+
// "message": "NO_ERROR",
|
|
1424
|
+
// "result": {
|
|
1425
|
+
// "client_oid": "CCXT_c2d2152cc32d40a3ae7fbf",
|
|
1426
|
+
// "order_id": "6142909895025252686"
|
|
1427
|
+
// }
|
|
1428
|
+
// }
|
|
1429
|
+
//
|
|
1430
|
+
const result = this.safeValue(response, 'result', {});
|
|
1431
|
+
return this.parseOrder(result, market);
|
|
1432
|
+
}
|
|
1433
|
+
async cancelOrders(ids, symbol = undefined, params = {}) {
|
|
1434
|
+
/**
|
|
1435
|
+
* @method
|
|
1436
|
+
* @name cryptocom#cancelOrders
|
|
1437
|
+
* @description cancel multiple orders
|
|
1438
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-order-list-list
|
|
1439
|
+
* @param {string[]} ids order ids
|
|
1440
|
+
* @param {string} symbol unified market symbol
|
|
1441
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1442
|
+
* @returns {object} an list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1443
|
+
*/
|
|
1444
|
+
if (symbol === undefined) {
|
|
1445
|
+
throw new errors.ArgumentsRequired(this.id + ' cancelOrders() requires a symbol argument');
|
|
1446
|
+
}
|
|
1447
|
+
await this.loadMarkets();
|
|
1448
|
+
const market = this.market(symbol);
|
|
1449
|
+
const orderRequests = [];
|
|
1450
|
+
for (let i = 0; i < ids.length; i++) {
|
|
1451
|
+
const id = ids[i];
|
|
1452
|
+
const order = {
|
|
1453
|
+
'instrument_name': market['id'],
|
|
1454
|
+
'order_id': id.toString(),
|
|
1455
|
+
};
|
|
1456
|
+
orderRequests.push(order);
|
|
1457
|
+
}
|
|
1458
|
+
const request = {
|
|
1459
|
+
'contingency_type': 'LIST',
|
|
1460
|
+
'order_list': orderRequests,
|
|
1461
|
+
};
|
|
1462
|
+
const response = await this.v1PrivatePostPrivateCancelOrderList(this.extend(request, params));
|
|
1463
|
+
const result = this.safeValue(response, 'result', []);
|
|
1464
|
+
return this.parseOrders(result, market, undefined, undefined, params);
|
|
1465
|
+
}
|
|
1466
|
+
async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1467
|
+
/**
|
|
1468
|
+
* @method
|
|
1469
|
+
* @name cryptocom#fetchOpenOrders
|
|
1470
|
+
* @description fetch all unfilled currently open orders
|
|
1471
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-open-orders
|
|
1472
|
+
* @param {string} symbol unified market symbol
|
|
1473
|
+
* @param {int} [since] the earliest time in ms to fetch open orders for
|
|
1474
|
+
* @param {int} [limit] the maximum number of open order structures to retrieve
|
|
1475
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1476
|
+
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1477
|
+
*/
|
|
1478
|
+
await this.loadMarkets();
|
|
1479
|
+
let market = undefined;
|
|
1480
|
+
const request = {};
|
|
1481
|
+
if (symbol !== undefined) {
|
|
1482
|
+
market = this.market(symbol);
|
|
1483
|
+
request['instrument_name'] = market['id'];
|
|
1484
|
+
}
|
|
1485
|
+
const response = await this.v1PrivatePostPrivateGetOpenOrders(this.extend(request, params));
|
|
1486
|
+
//
|
|
1487
|
+
// {
|
|
1488
|
+
// "id": 1686806134961,
|
|
1489
|
+
// "method": "private/get-open-orders",
|
|
1490
|
+
// "code": 0,
|
|
1491
|
+
// "result": {
|
|
1492
|
+
// "data": [
|
|
1493
|
+
// {
|
|
1494
|
+
// "account_id": "ce075bef-1234-4321-bd6g-ff9007252e63",
|
|
1495
|
+
// "order_id": "6530219477767564494",
|
|
1496
|
+
// "client_oid": "CCXT_7ce730f0388441df9bc218",
|
|
1497
|
+
// "order_type": "LIMIT",
|
|
1498
|
+
// "time_in_force": "GOOD_TILL_CANCEL",
|
|
1499
|
+
// "side": "BUY",
|
|
1500
|
+
// "exec_inst": [ ],
|
|
1501
|
+
// "quantity": "0.00020",
|
|
1502
|
+
// "limit_price": "20000.00",
|
|
1503
|
+
// "order_value": "4",
|
|
1504
|
+
// "avg_price": "0",
|
|
1505
|
+
// "trigger_price": "0",
|
|
1506
|
+
// "ref_price": "0",
|
|
1507
|
+
// "cumulative_quantity": "0",
|
|
1508
|
+
// "cumulative_value": "0",
|
|
1509
|
+
// "cumulative_fee": "0",
|
|
1510
|
+
// "status": "ACTIVE",
|
|
1511
|
+
// "update_user_id": "ce075bef-1234-4321-bd6g-gg9007252e63",
|
|
1512
|
+
// "order_date": "2023-06-15",
|
|
1513
|
+
// "instrument_name": "BTC_USD",
|
|
1514
|
+
// "fee_instrument_name": "BTC",
|
|
1515
|
+
// "create_time": 1686806053992,
|
|
1516
|
+
// "create_time_ns": "1686806053992921880",
|
|
1517
|
+
// "update_time": 1686806053993
|
|
1518
|
+
// }
|
|
1519
|
+
// ]
|
|
1520
|
+
// }
|
|
1521
|
+
// }
|
|
1522
|
+
//
|
|
1523
|
+
const data = this.safeValue(response, 'result', {});
|
|
1524
|
+
const orders = this.safeValue(data, 'data', []);
|
|
1525
|
+
return this.parseOrders(orders, market, since, limit);
|
|
1526
|
+
}
|
|
1527
|
+
async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1528
|
+
/**
|
|
1529
|
+
* @method
|
|
1530
|
+
* @name cryptocom#fetchMyTrades
|
|
1531
|
+
* @description fetch all trades made by the user
|
|
1532
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-trades
|
|
1533
|
+
* @param {string} symbol unified market symbol
|
|
1534
|
+
* @param {int} [since] the earliest time in ms to fetch trades for, maximum date range is one day
|
|
1535
|
+
* @param {int} [limit] the maximum number of trade structures to retrieve
|
|
1536
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1537
|
+
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
|
|
1538
|
+
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
|
|
1539
|
+
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
|
|
1540
|
+
*/
|
|
1541
|
+
await this.loadMarkets();
|
|
1542
|
+
let paginate = false;
|
|
1543
|
+
[paginate, params] = this.handleOptionAndParams(params, 'fetchMyTrades', 'paginate');
|
|
1544
|
+
if (paginate) {
|
|
1545
|
+
return await this.fetchPaginatedCallDynamic('fetchMyTrades', symbol, since, limit, params);
|
|
1546
|
+
}
|
|
1547
|
+
const request = {};
|
|
1548
|
+
let market = undefined;
|
|
1549
|
+
if (symbol !== undefined) {
|
|
1550
|
+
market = this.market(symbol);
|
|
1551
|
+
request['instrument_name'] = market['id'];
|
|
1552
|
+
}
|
|
1553
|
+
if (since !== undefined) {
|
|
1554
|
+
request['start_time'] = since;
|
|
1555
|
+
}
|
|
1556
|
+
if (limit !== undefined) {
|
|
1557
|
+
request['limit'] = limit;
|
|
1558
|
+
}
|
|
1559
|
+
const until = this.safeInteger2(params, 'until', 'till');
|
|
1560
|
+
params = this.omit(params, ['until', 'till']);
|
|
1561
|
+
if (until !== undefined) {
|
|
1562
|
+
request['end_time'] = until;
|
|
1563
|
+
}
|
|
1564
|
+
const response = await this.v1PrivatePostPrivateGetTrades(this.extend(request, params));
|
|
1565
|
+
//
|
|
1566
|
+
// {
|
|
1567
|
+
// "id": 1686942003520,
|
|
1568
|
+
// "method": "private/get-trades",
|
|
1569
|
+
// "code": 0,
|
|
1570
|
+
// "result": {
|
|
1571
|
+
// "data": [
|
|
1572
|
+
// {
|
|
1573
|
+
// "account_id": "ds075abc-1234-4321-bd6g-ff9007252r63",
|
|
1574
|
+
// "event_date": "2023-06-16",
|
|
1575
|
+
// "journal_type": "TRADING",
|
|
1576
|
+
// "side": "BUY",
|
|
1577
|
+
// "instrument_name": "BTC_USD",
|
|
1578
|
+
// "fees": "-0.0000000525",
|
|
1579
|
+
// "trade_id": "6142909898247428343",
|
|
1580
|
+
// "trade_match_id": "4611686018455978480",
|
|
1581
|
+
// "create_time": 1686941992887,
|
|
1582
|
+
// "traded_price": "26347.16",
|
|
1583
|
+
// "traded_quantity": "0.00021",
|
|
1584
|
+
// "fee_instrument_name": "BTC",
|
|
1585
|
+
// "client_oid": "d1c70a60-810e-4c92-b2a0-72b931cb31e0",
|
|
1586
|
+
// "taker_side": "TAKER",
|
|
1587
|
+
// "order_id": "6142909895036331486",
|
|
1588
|
+
// "create_time_ns": "1686941992887207066"
|
|
1589
|
+
// }
|
|
1590
|
+
// ]
|
|
1591
|
+
// }
|
|
1592
|
+
// }
|
|
1593
|
+
//
|
|
1594
|
+
const result = this.safeValue(response, 'result', {});
|
|
1595
|
+
const trades = this.safeValue(result, 'data', []);
|
|
1596
|
+
return this.parseTrades(trades, market, since, limit);
|
|
1597
|
+
}
|
|
1598
|
+
parseAddress(addressString) {
|
|
1599
|
+
let address = undefined;
|
|
1600
|
+
let tag = undefined;
|
|
1601
|
+
let rawTag = undefined;
|
|
1602
|
+
if (addressString.indexOf('?') > 0) {
|
|
1603
|
+
[address, rawTag] = addressString.split('?');
|
|
1604
|
+
const splitted = rawTag.split('=');
|
|
1605
|
+
tag = splitted[1];
|
|
1606
|
+
}
|
|
1607
|
+
else {
|
|
1608
|
+
address = addressString;
|
|
1609
|
+
}
|
|
1610
|
+
return [address, tag];
|
|
1611
|
+
}
|
|
1612
|
+
async withdraw(code, amount, address, tag = undefined, params = {}) {
|
|
1613
|
+
/**
|
|
1614
|
+
* @method
|
|
1615
|
+
* @name cryptocom#withdraw
|
|
1616
|
+
* @description make a withdrawal
|
|
1617
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-create-withdrawal
|
|
1618
|
+
* @param {string} code unified currency code
|
|
1619
|
+
* @param {float} amount the amount to withdraw
|
|
1620
|
+
* @param {string} address the address to withdraw to
|
|
1621
|
+
* @param {string} tag
|
|
1622
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1623
|
+
* @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
|
|
1624
|
+
*/
|
|
1625
|
+
[tag, params] = this.handleWithdrawTagAndParams(tag, params);
|
|
1626
|
+
await this.loadMarkets();
|
|
1627
|
+
const currency = this.currency(code);
|
|
1628
|
+
const request = {
|
|
1629
|
+
'currency': currency['id'],
|
|
1630
|
+
'amount': amount,
|
|
1631
|
+
'address': address,
|
|
1632
|
+
};
|
|
1633
|
+
if (tag !== undefined) {
|
|
1634
|
+
request['address_tag'] = tag;
|
|
1635
|
+
}
|
|
1636
|
+
let networkCode = undefined;
|
|
1637
|
+
[networkCode, params] = this.handleNetworkCodeAndParams(params);
|
|
1638
|
+
const networkId = this.networkCodeToId(networkCode);
|
|
1639
|
+
if (networkId !== undefined) {
|
|
1640
|
+
request['network_id'] = networkId;
|
|
1641
|
+
}
|
|
1642
|
+
const response = await this.v1PrivatePostPrivateCreateWithdrawal(this.extend(request, params));
|
|
1643
|
+
//
|
|
1644
|
+
// {
|
|
1645
|
+
// "id":-1,
|
|
1646
|
+
// "method":"private/create-withdrawal",
|
|
1647
|
+
// "code":0,
|
|
1648
|
+
// "result": {
|
|
1649
|
+
// "id": 2220,
|
|
1650
|
+
// "amount": 1,
|
|
1651
|
+
// "fee": 0.0004,
|
|
1652
|
+
// "symbol": "BTC",
|
|
1653
|
+
// "address": "2NBqqD5GRJ8wHy1PYyCXTe9ke5226FhavBf",
|
|
1654
|
+
// "client_wid": "my_withdrawal_002",
|
|
1655
|
+
// "create_time":1607063412000
|
|
1656
|
+
// }
|
|
1657
|
+
// }
|
|
1658
|
+
//
|
|
1659
|
+
const result = this.safeValue(response, 'result');
|
|
1660
|
+
return this.parseTransaction(result, currency);
|
|
1661
|
+
}
|
|
1662
|
+
async fetchDepositAddressesByNetwork(code, params = {}) {
|
|
1663
|
+
/**
|
|
1664
|
+
* @method
|
|
1665
|
+
* @name cryptocom#fetchDepositAddressesByNetwork
|
|
1666
|
+
* @description fetch a dictionary of addresses for a currency, indexed by network
|
|
1667
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-deposit-address
|
|
1668
|
+
* @param {string} code unified currency code of the currency for the deposit address
|
|
1669
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1670
|
+
* @returns {object} a dictionary of [address structures]{@link https://docs.ccxt.com/#/?id=address-structure} indexed by the network
|
|
1671
|
+
*/
|
|
1672
|
+
await this.loadMarkets();
|
|
1673
|
+
const currency = this.currency(code);
|
|
1674
|
+
const request = {
|
|
1675
|
+
'currency': currency['id'],
|
|
1676
|
+
};
|
|
1677
|
+
const response = await this.v1PrivatePostPrivateGetDepositAddress(this.extend(request, params));
|
|
1678
|
+
//
|
|
1679
|
+
// {
|
|
1680
|
+
// "id": 1234555011221,
|
|
1681
|
+
// "method": "private/get-deposit-address",
|
|
1682
|
+
// "code": 0,
|
|
1683
|
+
// "result": {
|
|
1684
|
+
// "deposit_address_list": [
|
|
1685
|
+
// {
|
|
1686
|
+
// "currency": "BTC",
|
|
1687
|
+
// "create_time": 1686730755000,
|
|
1688
|
+
// "id": "3737377",
|
|
1689
|
+
// "address": "3N9afggxTSmJ3H4jaMQuWyEiLBzZdAbK6d",
|
|
1690
|
+
// "status":"1",
|
|
1691
|
+
// "network": "BTC"
|
|
1692
|
+
// },
|
|
1693
|
+
// ]
|
|
1694
|
+
// }
|
|
1695
|
+
// }
|
|
1696
|
+
//
|
|
1697
|
+
const data = this.safeValue(response, 'result', {});
|
|
1698
|
+
const addresses = this.safeValue(data, 'deposit_address_list', []);
|
|
1699
|
+
const addressesLength = addresses.length;
|
|
1700
|
+
if (addressesLength === 0) {
|
|
1701
|
+
throw new errors.ExchangeError(this.id + ' fetchDepositAddressesByNetwork() generating address...');
|
|
1702
|
+
}
|
|
1703
|
+
const result = {};
|
|
1704
|
+
for (let i = 0; i < addressesLength; i++) {
|
|
1705
|
+
const value = this.safeValue(addresses, i);
|
|
1706
|
+
const addressString = this.safeString(value, 'address');
|
|
1707
|
+
const currencyId = this.safeString(value, 'currency');
|
|
1708
|
+
const responseCode = this.safeCurrencyCode(currencyId);
|
|
1709
|
+
const [address, tag] = this.parseAddress(addressString);
|
|
1710
|
+
this.checkAddress(address);
|
|
1711
|
+
const networkId = this.safeString(value, 'network');
|
|
1712
|
+
const network = this.networkIdToCode(networkId, responseCode);
|
|
1713
|
+
result[network] = {
|
|
1714
|
+
'info': value,
|
|
1715
|
+
'currency': responseCode,
|
|
1716
|
+
'address': address,
|
|
1717
|
+
'tag': tag,
|
|
1718
|
+
'network': network,
|
|
1719
|
+
};
|
|
1720
|
+
}
|
|
1721
|
+
return result;
|
|
1722
|
+
}
|
|
1723
|
+
async fetchDepositAddress(code, params = {}) {
|
|
1724
|
+
/**
|
|
1725
|
+
* @method
|
|
1726
|
+
* @name cryptocom#fetchDepositAddress
|
|
1727
|
+
* @description fetch the deposit address for a currency associated with this account
|
|
1728
|
+
* @param {string} code unified currency code
|
|
1729
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1730
|
+
* @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
|
|
1731
|
+
*/
|
|
1732
|
+
const network = this.safeStringUpper(params, 'network');
|
|
1733
|
+
params = this.omit(params, ['network']);
|
|
1734
|
+
const depositAddresses = await this.fetchDepositAddressesByNetwork(code, params);
|
|
1735
|
+
if (network in depositAddresses) {
|
|
1736
|
+
return depositAddresses[network];
|
|
1737
|
+
}
|
|
1738
|
+
else {
|
|
1739
|
+
const keys = Object.keys(depositAddresses);
|
|
1740
|
+
return depositAddresses[keys[0]];
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
safeNetwork(networkId) {
|
|
1744
|
+
const networksById = {
|
|
1745
|
+
'BTC': 'BTC',
|
|
1746
|
+
'ETH': 'ETH',
|
|
1747
|
+
'SOL': 'SOL',
|
|
1748
|
+
'BNB': 'BNB',
|
|
1749
|
+
'CRONOS': 'CRONOS',
|
|
1750
|
+
'MATIC': 'MATIC',
|
|
1751
|
+
'OP': 'OP',
|
|
1752
|
+
};
|
|
1753
|
+
return this.safeString(networksById, networkId, networkId);
|
|
1754
|
+
}
|
|
1755
|
+
async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1756
|
+
/**
|
|
1757
|
+
* @method
|
|
1758
|
+
* @name cryptocom#fetchDeposits
|
|
1759
|
+
* @description fetch all deposits made to an account
|
|
1760
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-deposit-history
|
|
1761
|
+
* @param {string} code unified currency code
|
|
1762
|
+
* @param {int} [since] the earliest time in ms to fetch deposits for
|
|
1763
|
+
* @param {int} [limit] the maximum number of deposits structures to retrieve
|
|
1764
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1765
|
+
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
|
|
1766
|
+
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
|
|
1767
|
+
*/
|
|
1768
|
+
await this.loadMarkets();
|
|
1769
|
+
let currency = undefined;
|
|
1770
|
+
const request = {};
|
|
1771
|
+
if (code !== undefined) {
|
|
1772
|
+
currency = this.currency(code);
|
|
1773
|
+
request['currency'] = currency['id'];
|
|
1774
|
+
}
|
|
1775
|
+
if (since !== undefined) {
|
|
1776
|
+
// 90 days date range
|
|
1777
|
+
request['start_ts'] = since;
|
|
1778
|
+
}
|
|
1779
|
+
if (limit !== undefined) {
|
|
1780
|
+
request['page_size'] = limit;
|
|
1781
|
+
}
|
|
1782
|
+
const until = this.safeInteger2(params, 'until', 'till');
|
|
1783
|
+
params = this.omit(params, ['until', 'till']);
|
|
1784
|
+
if (until !== undefined) {
|
|
1785
|
+
request['end_ts'] = until;
|
|
1786
|
+
}
|
|
1787
|
+
const response = await this.v1PrivatePostPrivateGetDepositHistory(this.extend(request, params));
|
|
1788
|
+
//
|
|
1789
|
+
// {
|
|
1790
|
+
// "id": 1688701375714,
|
|
1791
|
+
// "method": "private/get-deposit-history",
|
|
1792
|
+
// "code": 0,
|
|
1793
|
+
// "result": {
|
|
1794
|
+
// "deposit_list": [
|
|
1795
|
+
// {
|
|
1796
|
+
// "currency": "BTC",
|
|
1797
|
+
// "fee": 0,
|
|
1798
|
+
// "create_time": 1688023659000,
|
|
1799
|
+
// "id": "6201135",
|
|
1800
|
+
// "update_time": 1688178509000,
|
|
1801
|
+
// "amount": 0.00114571,
|
|
1802
|
+
// "address": "1234fggxTSmJ3H4jaMQuWyEiLBzZdAbK6d",
|
|
1803
|
+
// "status": "1",
|
|
1804
|
+
// "txid": "f0ae4202b76eb999c301eccdde44dc639bee42d1fdd5974105286ca3393f6065/2"
|
|
1805
|
+
// },
|
|
1806
|
+
// ]
|
|
1807
|
+
// }
|
|
1808
|
+
// }
|
|
1809
|
+
//
|
|
1810
|
+
const data = this.safeValue(response, 'result', {});
|
|
1811
|
+
const depositList = this.safeValue(data, 'deposit_list', []);
|
|
1812
|
+
return this.parseTransactions(depositList, currency, since, limit);
|
|
1813
|
+
}
|
|
1814
|
+
async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1815
|
+
/**
|
|
1816
|
+
* @method
|
|
1817
|
+
* @name cryptocom#fetchWithdrawals
|
|
1818
|
+
* @description fetch all withdrawals made from an account
|
|
1819
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-withdrawal-history
|
|
1820
|
+
* @param {string} code unified currency code
|
|
1821
|
+
* @param {int} [since] the earliest time in ms to fetch withdrawals for
|
|
1822
|
+
* @param {int} [limit] the maximum number of withdrawals structures to retrieve
|
|
1823
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1824
|
+
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
|
|
1825
|
+
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
|
|
1826
|
+
*/
|
|
1827
|
+
await this.loadMarkets();
|
|
1828
|
+
let currency = undefined;
|
|
1829
|
+
const request = {};
|
|
1830
|
+
if (code !== undefined) {
|
|
1831
|
+
currency = this.currency(code);
|
|
1832
|
+
request['currency'] = currency['id'];
|
|
1833
|
+
}
|
|
1834
|
+
if (since !== undefined) {
|
|
1835
|
+
// 90 days date range
|
|
1836
|
+
request['start_ts'] = since;
|
|
1837
|
+
}
|
|
1838
|
+
if (limit !== undefined) {
|
|
1839
|
+
request['page_size'] = limit;
|
|
1840
|
+
}
|
|
1841
|
+
const until = this.safeInteger2(params, 'until', 'till');
|
|
1842
|
+
params = this.omit(params, ['until', 'till']);
|
|
1843
|
+
if (until !== undefined) {
|
|
1844
|
+
request['end_ts'] = until;
|
|
1845
|
+
}
|
|
1846
|
+
const response = await this.v1PrivatePostPrivateGetWithdrawalHistory(this.extend(request, params));
|
|
1847
|
+
//
|
|
1848
|
+
// {
|
|
1849
|
+
// "id": 1688613879534,
|
|
1850
|
+
// "method": "private/get-withdrawal-history",
|
|
1851
|
+
// "code": 0,
|
|
1852
|
+
// "result": {
|
|
1853
|
+
// "withdrawal_list": [
|
|
1854
|
+
// {
|
|
1855
|
+
// "currency": "BTC",
|
|
1856
|
+
// "client_wid": "",
|
|
1857
|
+
// "fee": 0.0005,
|
|
1858
|
+
// "create_time": 1688613850000,
|
|
1859
|
+
// "id": "5275977",
|
|
1860
|
+
// "update_time": 1688613850000,
|
|
1861
|
+
// "amount": 0.0005,
|
|
1862
|
+
// "address": "1234NMEWbiF8ZkwUMxmfzMxi2A1MQ44bMn",
|
|
1863
|
+
// "status": "1",
|
|
1864
|
+
// "txid": "",
|
|
1865
|
+
// "network_id": "BTC"
|
|
1866
|
+
// }
|
|
1867
|
+
// ]
|
|
1868
|
+
// }
|
|
1869
|
+
// }
|
|
1870
|
+
//
|
|
1871
|
+
const data = this.safeValue(response, 'result', {});
|
|
1872
|
+
const withdrawalList = this.safeValue(data, 'withdrawal_list', []);
|
|
1873
|
+
return this.parseTransactions(withdrawalList, currency, since, limit);
|
|
1874
|
+
}
|
|
1875
|
+
parseTicker(ticker, market = undefined) {
|
|
1876
|
+
//
|
|
1877
|
+
// fetchTicker
|
|
1878
|
+
//
|
|
1879
|
+
// {
|
|
1880
|
+
// "i": "BTC_USD",
|
|
1881
|
+
// "h": "30821.45",
|
|
1882
|
+
// "l": "28685.11",
|
|
1883
|
+
// "a": "30446.00",
|
|
1884
|
+
// "v": "1767.8734",
|
|
1885
|
+
// "vv": "52436726.42",
|
|
1886
|
+
// "c": "0.0583",
|
|
1887
|
+
// "b": "30442.00",
|
|
1888
|
+
// "k": "30447.66",
|
|
1889
|
+
// "t": 1687403045415
|
|
1890
|
+
// }
|
|
1891
|
+
//
|
|
1892
|
+
// fetchTickers
|
|
1893
|
+
//
|
|
1894
|
+
// {
|
|
1895
|
+
// "i": "AVAXUSD-PERP",
|
|
1896
|
+
// "h": "13.209",
|
|
1897
|
+
// "l": "12.148",
|
|
1898
|
+
// "a": "13.209",
|
|
1899
|
+
// "v": "1109.8",
|
|
1900
|
+
// "vv": "14017.33",
|
|
1901
|
+
// "c": "0.0732",
|
|
1902
|
+
// "b": "13.210",
|
|
1903
|
+
// "k": "13.230",
|
|
1904
|
+
// "oi": "10888.9",
|
|
1905
|
+
// "t": 1687402657575
|
|
1906
|
+
// }
|
|
1907
|
+
//
|
|
1908
|
+
const timestamp = this.safeInteger(ticker, 't');
|
|
1909
|
+
const marketId = this.safeString(ticker, 'i');
|
|
1910
|
+
market = this.safeMarket(marketId, market, '_');
|
|
1911
|
+
const quote = this.safeString(market, 'quote');
|
|
1912
|
+
const last = this.safeString(ticker, 'a');
|
|
1913
|
+
return this.safeTicker({
|
|
1914
|
+
'symbol': market['symbol'],
|
|
1915
|
+
'timestamp': timestamp,
|
|
1916
|
+
'datetime': this.iso8601(timestamp),
|
|
1917
|
+
'high': this.safeNumber(ticker, 'h'),
|
|
1918
|
+
'low': this.safeNumber(ticker, 'l'),
|
|
1919
|
+
'bid': this.safeNumber(ticker, 'b'),
|
|
1920
|
+
'bidVolume': undefined,
|
|
1921
|
+
'ask': this.safeNumber(ticker, 'k'),
|
|
1922
|
+
'askVolume': undefined,
|
|
1923
|
+
'vwap': undefined,
|
|
1924
|
+
'open': undefined,
|
|
1925
|
+
'close': last,
|
|
1926
|
+
'last': last,
|
|
1927
|
+
'previousClose': undefined,
|
|
1928
|
+
'change': undefined,
|
|
1929
|
+
'percentage': this.safeString(ticker, 'c'),
|
|
1930
|
+
'average': undefined,
|
|
1931
|
+
'baseVolume': this.safeString(ticker, 'v'),
|
|
1932
|
+
'quoteVolume': (quote === 'USD') ? this.safeString(ticker, 'vv') : undefined,
|
|
1933
|
+
'info': ticker,
|
|
1934
|
+
}, market);
|
|
1935
|
+
}
|
|
1936
|
+
parseTrade(trade, market = undefined) {
|
|
1937
|
+
//
|
|
1938
|
+
// fetchTrades
|
|
1939
|
+
//
|
|
1940
|
+
// {
|
|
1941
|
+
// "s": "sell",
|
|
1942
|
+
// "p": "26386.00",
|
|
1943
|
+
// "q": "0.00453",
|
|
1944
|
+
// "tn": 1686944282062,
|
|
1945
|
+
// "tn": 1704476468851524373,
|
|
1946
|
+
// "d": "4611686018455979970",
|
|
1947
|
+
// "i": "BTC_USD"
|
|
1948
|
+
// }
|
|
1949
|
+
//
|
|
1950
|
+
// fetchMyTrades
|
|
1951
|
+
//
|
|
1952
|
+
// {
|
|
1953
|
+
// "account_id": "ds075abc-1234-4321-bd6g-ff9007252r63",
|
|
1954
|
+
// "event_date": "2023-06-16",
|
|
1955
|
+
// "journal_type": "TRADING",
|
|
1956
|
+
// "side": "BUY",
|
|
1957
|
+
// "instrument_name": "BTC_USD",
|
|
1958
|
+
// "fees": "-0.0000000525",
|
|
1959
|
+
// "trade_id": "6142909898247428343",
|
|
1960
|
+
// "trade_match_id": "4611686018455978480",
|
|
1961
|
+
// "create_time": 1686941992887,
|
|
1962
|
+
// "traded_price": "26347.16",
|
|
1963
|
+
// "traded_quantity": "0.00021",
|
|
1964
|
+
// "fee_instrument_name": "BTC",
|
|
1965
|
+
// "client_oid": "d1c70a60-1234-4c92-b2a0-72b931cb31e0",
|
|
1966
|
+
// "taker_side": "TAKER",
|
|
1967
|
+
// "order_id": "6142909895036331486",
|
|
1968
|
+
// "create_time_ns": "1686941992887207066"
|
|
1969
|
+
// }
|
|
1970
|
+
//
|
|
1971
|
+
const timestamp = this.safeInteger2(trade, 't', 'create_time');
|
|
1972
|
+
const marketId = this.safeString2(trade, 'i', 'instrument_name');
|
|
1973
|
+
market = this.safeMarket(marketId, market, '_');
|
|
1974
|
+
const feeCurrency = this.safeString(trade, 'fee_instrument_name');
|
|
1975
|
+
const feeCostString = this.safeString(trade, 'fees');
|
|
1976
|
+
return this.safeTrade({
|
|
1977
|
+
'info': trade,
|
|
1978
|
+
'id': this.safeString2(trade, 'd', 'trade_id'),
|
|
1979
|
+
'timestamp': timestamp,
|
|
1980
|
+
'datetime': this.iso8601(timestamp),
|
|
1981
|
+
'symbol': market['symbol'],
|
|
1982
|
+
'order': this.safeString(trade, 'order_id'),
|
|
1983
|
+
'side': this.safeStringLower2(trade, 's', 'side'),
|
|
1984
|
+
'takerOrMaker': this.safeStringLower(trade, 'taker_side'),
|
|
1985
|
+
'price': this.safeNumber2(trade, 'p', 'traded_price'),
|
|
1986
|
+
'amount': this.safeNumber2(trade, 'q', 'traded_quantity'),
|
|
1987
|
+
'cost': undefined,
|
|
1988
|
+
'type': undefined,
|
|
1989
|
+
'fee': {
|
|
1990
|
+
'currency': this.safeCurrencyCode(feeCurrency),
|
|
1991
|
+
'cost': this.parseNumber(Precise["default"].stringNeg(feeCostString)),
|
|
1992
|
+
},
|
|
1993
|
+
}, market);
|
|
1994
|
+
}
|
|
1995
|
+
parseOHLCV(ohlcv, market = undefined) {
|
|
1996
|
+
//
|
|
1997
|
+
// {
|
|
1998
|
+
// "o": "26949.89",
|
|
1999
|
+
// "h": "26957.64",
|
|
2000
|
+
// "l": "26948.24",
|
|
2001
|
+
// "c": "26950.00",
|
|
2002
|
+
// "v": "0.0670",
|
|
2003
|
+
// "t": 1687237080000
|
|
2004
|
+
// }
|
|
2005
|
+
//
|
|
2006
|
+
return [
|
|
2007
|
+
this.safeInteger(ohlcv, 't'),
|
|
2008
|
+
this.safeNumber(ohlcv, 'o'),
|
|
2009
|
+
this.safeNumber(ohlcv, 'h'),
|
|
2010
|
+
this.safeNumber(ohlcv, 'l'),
|
|
2011
|
+
this.safeNumber(ohlcv, 'c'),
|
|
2012
|
+
this.safeNumber(ohlcv, 'v'),
|
|
2013
|
+
];
|
|
2014
|
+
}
|
|
2015
|
+
parseOrderStatus(status) {
|
|
2016
|
+
const statuses = {
|
|
2017
|
+
'ACTIVE': 'open',
|
|
2018
|
+
'CANCELED': 'canceled',
|
|
2019
|
+
'FILLED': 'closed',
|
|
2020
|
+
'REJECTED': 'rejected',
|
|
2021
|
+
'EXPIRED': 'expired',
|
|
2022
|
+
};
|
|
2023
|
+
return this.safeString(statuses, status, status);
|
|
2024
|
+
}
|
|
2025
|
+
parseTimeInForce(timeInForce) {
|
|
2026
|
+
const timeInForces = {
|
|
2027
|
+
'GOOD_TILL_CANCEL': 'GTC',
|
|
2028
|
+
'IMMEDIATE_OR_CANCEL': 'IOC',
|
|
2029
|
+
'FILL_OR_KILL': 'FOK',
|
|
2030
|
+
};
|
|
2031
|
+
return this.safeString(timeInForces, timeInForce, timeInForce);
|
|
2032
|
+
}
|
|
2033
|
+
parseOrder(order, market = undefined) {
|
|
2034
|
+
//
|
|
2035
|
+
// createOrder, cancelOrder
|
|
2036
|
+
//
|
|
2037
|
+
// {
|
|
2038
|
+
// "order_id": "6540219377766741832",
|
|
2039
|
+
// "client_oid": "CCXT_d6ef7c3db6c1495aa8b757"
|
|
2040
|
+
// }
|
|
2041
|
+
//
|
|
2042
|
+
// fetchOpenOrders, fetchOrder, fetchOrders
|
|
2043
|
+
//
|
|
2044
|
+
// {
|
|
2045
|
+
// "account_id": "ce075bef-1234-4321-bd6g-ff9007252e63",
|
|
2046
|
+
// "order_id": "6530219477767564494",
|
|
2047
|
+
// "client_oid": "CCXT_7ce730f0388441df9bc218",
|
|
2048
|
+
// "order_type": "LIMIT",
|
|
2049
|
+
// "time_in_force": "GOOD_TILL_CANCEL",
|
|
2050
|
+
// "side": "BUY",
|
|
2051
|
+
// "exec_inst": [ ],
|
|
2052
|
+
// "quantity": "0.00020",
|
|
2053
|
+
// "limit_price": "20000.00",
|
|
2054
|
+
// "order_value": "4",
|
|
2055
|
+
// "avg_price": "0",
|
|
2056
|
+
// "trigger_price": "0",
|
|
2057
|
+
// "ref_price": "0",
|
|
2058
|
+
// "cumulative_quantity": "0",
|
|
2059
|
+
// "cumulative_value": "0",
|
|
2060
|
+
// "cumulative_fee": "0",
|
|
2061
|
+
// "status": "ACTIVE",
|
|
2062
|
+
// "update_user_id": "ce075bef-1234-4321-bd6g-gg9007252e63",
|
|
2063
|
+
// "order_date": "2023-06-15",
|
|
2064
|
+
// "instrument_name": "BTC_USD",
|
|
2065
|
+
// "fee_instrument_name": "BTC",
|
|
2066
|
+
// "create_time": 1686806053992,
|
|
2067
|
+
// "create_time_ns": "1686806053992921880",
|
|
2068
|
+
// "update_time": 1686806053993
|
|
2069
|
+
// }
|
|
2070
|
+
//
|
|
2071
|
+
// createOrders
|
|
2072
|
+
// {
|
|
2073
|
+
// "code" : 306,
|
|
2074
|
+
// "index" : 1,
|
|
2075
|
+
// "client_oid" : "1698068111133_1",
|
|
2076
|
+
// "message" : "INSUFFICIENT_AVAILABLE_BALANCE",
|
|
2077
|
+
// "order_id" : "6142909896519488207"
|
|
2078
|
+
// }
|
|
2079
|
+
//
|
|
2080
|
+
const code = this.safeInteger(order, 'code');
|
|
2081
|
+
if ((code !== undefined) && (code !== 0)) {
|
|
2082
|
+
return this.safeOrder({
|
|
2083
|
+
'id': this.safeString(order, 'order_id'),
|
|
2084
|
+
'clientOrderId': this.safeString(order, 'client_oid'),
|
|
2085
|
+
'info': order,
|
|
2086
|
+
'status': 'rejected',
|
|
2087
|
+
});
|
|
2088
|
+
}
|
|
2089
|
+
const created = this.safeInteger(order, 'create_time');
|
|
2090
|
+
const marketId = this.safeString(order, 'instrument_name');
|
|
2091
|
+
const symbol = this.safeSymbol(marketId, market);
|
|
2092
|
+
const execInst = this.safeValue(order, 'exec_inst');
|
|
2093
|
+
let postOnly = undefined;
|
|
2094
|
+
if (execInst !== undefined) {
|
|
2095
|
+
postOnly = false;
|
|
2096
|
+
for (let i = 0; i < execInst.length; i++) {
|
|
2097
|
+
const inst = execInst[i];
|
|
2098
|
+
if (inst === 'POST_ONLY') {
|
|
2099
|
+
postOnly = true;
|
|
2100
|
+
break;
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
const feeCurrency = this.safeString(order, 'fee_instrument_name');
|
|
2105
|
+
return this.safeOrder({
|
|
2106
|
+
'info': order,
|
|
2107
|
+
'id': this.safeString(order, 'order_id'),
|
|
2108
|
+
'clientOrderId': this.safeString(order, 'client_oid'),
|
|
2109
|
+
'timestamp': created,
|
|
2110
|
+
'datetime': this.iso8601(created),
|
|
2111
|
+
'lastTradeTimestamp': this.safeInteger(order, 'update_time'),
|
|
2112
|
+
'status': this.parseOrderStatus(this.safeString(order, 'status')),
|
|
2113
|
+
'symbol': symbol,
|
|
2114
|
+
'type': this.safeStringLower(order, 'order_type'),
|
|
2115
|
+
'timeInForce': this.parseTimeInForce(this.safeString(order, 'time_in_force')),
|
|
2116
|
+
'postOnly': postOnly,
|
|
2117
|
+
'side': this.safeStringLower(order, 'side'),
|
|
2118
|
+
'price': this.safeNumber(order, 'limit_price'),
|
|
2119
|
+
'amount': this.safeNumber(order, 'quantity'),
|
|
2120
|
+
'filled': this.safeNumber(order, 'cumulative_quantity'),
|
|
2121
|
+
'remaining': undefined,
|
|
2122
|
+
'average': this.safeNumber(order, 'avg_price'),
|
|
2123
|
+
'cost': this.safeNumber(order, 'cumulative_value'),
|
|
2124
|
+
'fee': {
|
|
2125
|
+
'currency': this.safeCurrencyCode(feeCurrency),
|
|
2126
|
+
'cost': this.safeNumber(order, 'cumulative_fee'),
|
|
2127
|
+
},
|
|
2128
|
+
'trades': [],
|
|
2129
|
+
}, market);
|
|
2130
|
+
}
|
|
2131
|
+
parseDepositStatus(status) {
|
|
2132
|
+
const statuses = {
|
|
2133
|
+
'0': 'pending',
|
|
2134
|
+
'1': 'ok',
|
|
2135
|
+
'2': 'failed',
|
|
2136
|
+
'3': 'pending',
|
|
2137
|
+
};
|
|
2138
|
+
return this.safeString(statuses, status, status);
|
|
2139
|
+
}
|
|
2140
|
+
parseWithdrawalStatus(status) {
|
|
2141
|
+
const statuses = {
|
|
2142
|
+
'0': 'pending',
|
|
2143
|
+
'1': 'pending',
|
|
2144
|
+
'2': 'failed',
|
|
2145
|
+
'3': 'pending',
|
|
2146
|
+
'4': 'failed',
|
|
2147
|
+
'5': 'ok',
|
|
2148
|
+
'6': 'canceled',
|
|
2149
|
+
};
|
|
2150
|
+
return this.safeString(statuses, status, status);
|
|
2151
|
+
}
|
|
2152
|
+
parseTransaction(transaction, currency = undefined) {
|
|
2153
|
+
//
|
|
2154
|
+
// fetchDeposits
|
|
2155
|
+
//
|
|
2156
|
+
// {
|
|
2157
|
+
// "currency": "BTC",
|
|
2158
|
+
// "fee": 0,
|
|
2159
|
+
// "create_time": 1688023659000,
|
|
2160
|
+
// "id": "6201135",
|
|
2161
|
+
// "update_time": 1688178509000,
|
|
2162
|
+
// "amount": 0.00114571,
|
|
2163
|
+
// "address": "1234fggxTSmJ3H4jaMQuWyEiLBzZdAbK6d",
|
|
2164
|
+
// "status": "1",
|
|
2165
|
+
// "txid": "f0ae4202b76eb999c301eccdde44dc639bee42d1fdd5974105286ca3393f6065/2"
|
|
2166
|
+
// }
|
|
2167
|
+
//
|
|
2168
|
+
// fetchWithdrawals
|
|
2169
|
+
//
|
|
2170
|
+
// {
|
|
2171
|
+
// "currency": "BTC",
|
|
2172
|
+
// "client_wid": "",
|
|
2173
|
+
// "fee": 0.0005,
|
|
2174
|
+
// "create_time": 1688613850000,
|
|
2175
|
+
// "id": "5775977",
|
|
2176
|
+
// "update_time": 1688613850000,
|
|
2177
|
+
// "amount": 0.0005,
|
|
2178
|
+
// "address": "1234NMEWbiF8ZkwUMxmfzMxi2A1MQ44bMn",
|
|
2179
|
+
// "status": "1",
|
|
2180
|
+
// "txid": "",
|
|
2181
|
+
// "network_id": "BTC"
|
|
2182
|
+
// }
|
|
2183
|
+
//
|
|
2184
|
+
// withdraw
|
|
2185
|
+
//
|
|
2186
|
+
// {
|
|
2187
|
+
// "id": 2220,
|
|
2188
|
+
// "amount": 1,
|
|
2189
|
+
// "fee": 0.0004,
|
|
2190
|
+
// "symbol": "BTC",
|
|
2191
|
+
// "address": "2NBqqD5GRJ8wHy1PYyCXTe9ke5226FhavBf",
|
|
2192
|
+
// "client_wid": "my_withdrawal_002",
|
|
2193
|
+
// "create_time":1607063412000
|
|
2194
|
+
// }
|
|
2195
|
+
//
|
|
2196
|
+
let type = undefined;
|
|
2197
|
+
const rawStatus = this.safeString(transaction, 'status');
|
|
2198
|
+
let status = undefined;
|
|
2199
|
+
if ('client_wid' in transaction) {
|
|
2200
|
+
type = 'withdrawal';
|
|
2201
|
+
status = this.parseWithdrawalStatus(rawStatus);
|
|
2202
|
+
}
|
|
2203
|
+
else {
|
|
2204
|
+
type = 'deposit';
|
|
2205
|
+
status = this.parseDepositStatus(rawStatus);
|
|
2206
|
+
}
|
|
2207
|
+
const addressString = this.safeString(transaction, 'address');
|
|
2208
|
+
const [address, tag] = this.parseAddress(addressString);
|
|
2209
|
+
const currencyId = this.safeString(transaction, 'currency');
|
|
2210
|
+
const code = this.safeCurrencyCode(currencyId, currency);
|
|
2211
|
+
const timestamp = this.safeInteger(transaction, 'create_time');
|
|
2212
|
+
const feeCost = this.safeNumber(transaction, 'fee');
|
|
2213
|
+
let fee = undefined;
|
|
2214
|
+
if (feeCost !== undefined) {
|
|
2215
|
+
fee = { 'currency': code, 'cost': feeCost };
|
|
2216
|
+
}
|
|
2217
|
+
return {
|
|
2218
|
+
'info': transaction,
|
|
2219
|
+
'id': this.safeString(transaction, 'id'),
|
|
2220
|
+
'txid': this.safeString(transaction, 'txid'),
|
|
2221
|
+
'timestamp': timestamp,
|
|
2222
|
+
'datetime': this.iso8601(timestamp),
|
|
2223
|
+
'network': undefined,
|
|
2224
|
+
'address': address,
|
|
2225
|
+
'addressTo': address,
|
|
2226
|
+
'addressFrom': undefined,
|
|
2227
|
+
'tag': tag,
|
|
2228
|
+
'tagTo': tag,
|
|
2229
|
+
'tagFrom': undefined,
|
|
2230
|
+
'type': type,
|
|
2231
|
+
'amount': this.safeNumber(transaction, 'amount'),
|
|
2232
|
+
'currency': code,
|
|
2233
|
+
'status': status,
|
|
2234
|
+
'updated': this.safeInteger(transaction, 'update_time'),
|
|
2235
|
+
'internal': undefined,
|
|
2236
|
+
'comment': this.safeString(transaction, 'client_wid'),
|
|
2237
|
+
'fee': fee,
|
|
2238
|
+
};
|
|
2239
|
+
}
|
|
2240
|
+
customHandleMarginModeAndParams(methodName, params = {}) {
|
|
2241
|
+
/**
|
|
2242
|
+
* @ignore
|
|
2243
|
+
* @method
|
|
2244
|
+
* @description marginMode specified by params["marginMode"], this.options["marginMode"], this.options["defaultMarginMode"], params["margin"] = true or this.options["defaultType"] = 'margin'
|
|
2245
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2246
|
+
* @returns {Array} the marginMode in lowercase
|
|
2247
|
+
*/
|
|
2248
|
+
const defaultType = this.safeString(this.options, 'defaultType');
|
|
2249
|
+
const isMargin = this.safeValue(params, 'margin', false);
|
|
2250
|
+
params = this.omit(params, 'margin');
|
|
2251
|
+
let marginMode = undefined;
|
|
2252
|
+
[marginMode, params] = this.handleMarginModeAndParams(methodName, params);
|
|
2253
|
+
if (marginMode !== undefined) {
|
|
2254
|
+
if (marginMode !== 'cross') {
|
|
2255
|
+
throw new errors.NotSupported(this.id + ' only cross margin is supported');
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
else {
|
|
2259
|
+
if ((defaultType === 'margin') || (isMargin === true)) {
|
|
2260
|
+
marginMode = 'cross';
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
return [marginMode, params];
|
|
2264
|
+
}
|
|
2265
|
+
parseDepositWithdrawFee(fee, currency = undefined) {
|
|
2266
|
+
//
|
|
2267
|
+
// {
|
|
2268
|
+
// "full_name": "Alchemix",
|
|
2269
|
+
// "default_network": "ETH",
|
|
2270
|
+
// "network_list": [
|
|
2271
|
+
// {
|
|
2272
|
+
// "network_id": "ETH",
|
|
2273
|
+
// "withdrawal_fee": "0.25000000",
|
|
2274
|
+
// "withdraw_enabled": true,
|
|
2275
|
+
// "min_withdrawal_amount": "0.5",
|
|
2276
|
+
// "deposit_enabled": true,
|
|
2277
|
+
// "confirmation_required": "0"
|
|
2278
|
+
// }
|
|
2279
|
+
// ]
|
|
2280
|
+
// }
|
|
2281
|
+
//
|
|
2282
|
+
const networkList = this.safeValue(fee, 'network_list');
|
|
2283
|
+
const networkListLength = networkList.length;
|
|
2284
|
+
const result = {
|
|
2285
|
+
'info': fee,
|
|
2286
|
+
'withdraw': {
|
|
2287
|
+
'fee': undefined,
|
|
2288
|
+
'percentage': undefined,
|
|
2289
|
+
},
|
|
2290
|
+
'deposit': {
|
|
2291
|
+
'fee': undefined,
|
|
2292
|
+
'percentage': undefined,
|
|
2293
|
+
},
|
|
2294
|
+
'networks': {},
|
|
2295
|
+
};
|
|
2296
|
+
if (networkList !== undefined) {
|
|
2297
|
+
for (let i = 0; i < networkListLength; i++) {
|
|
2298
|
+
const networkInfo = networkList[i];
|
|
2299
|
+
const networkId = this.safeString(networkInfo, 'network_id');
|
|
2300
|
+
const currencyCode = this.safeString(currency, 'code');
|
|
2301
|
+
const networkCode = this.networkIdToCode(networkId, currencyCode);
|
|
2302
|
+
result['networks'][networkCode] = {
|
|
2303
|
+
'deposit': { 'fee': undefined, 'percentage': undefined },
|
|
2304
|
+
'withdraw': { 'fee': this.safeNumber(networkInfo, 'withdrawal_fee'), 'percentage': false },
|
|
2305
|
+
};
|
|
2306
|
+
if (networkListLength === 1) {
|
|
2307
|
+
result['withdraw']['fee'] = this.safeNumber(networkInfo, 'withdrawal_fee');
|
|
2308
|
+
result['withdraw']['percentage'] = false;
|
|
2309
|
+
}
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2312
|
+
return result;
|
|
2313
|
+
}
|
|
2314
|
+
async fetchDepositWithdrawFees(codes = undefined, params = {}) {
|
|
2315
|
+
/**
|
|
2316
|
+
* @method
|
|
2317
|
+
* @name cryptocom#fetchDepositWithdrawFees
|
|
2318
|
+
* @description fetch deposit and withdraw fees
|
|
2319
|
+
* @see https://exchange-docs.crypto.com/spot/index.html#private-get-currency-networks
|
|
2320
|
+
* @param {string[]|undefined} codes list of unified currency codes
|
|
2321
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2322
|
+
* @returns {object} a list of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure}
|
|
2323
|
+
*/
|
|
2324
|
+
await this.loadMarkets();
|
|
2325
|
+
const response = await this.v2PrivatePostPrivateGetCurrencyNetworks(params);
|
|
2326
|
+
const data = this.safeValue(response, 'result');
|
|
2327
|
+
const currencyMap = this.safeValue(data, 'currency_map');
|
|
2328
|
+
return this.parseDepositWithdrawFees(currencyMap, codes, 'full_name');
|
|
2329
|
+
}
|
|
2330
|
+
async fetchLedger(code = undefined, since = undefined, limit = undefined, params = {}) {
|
|
2331
|
+
/**
|
|
2332
|
+
* @method
|
|
2333
|
+
* @name cryptocom#fetchLedger
|
|
2334
|
+
* @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
|
|
2335
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-transactions
|
|
2336
|
+
* @param {string} code unified currency code
|
|
2337
|
+
* @param {int} [since] timestamp in ms of the earliest ledger entry
|
|
2338
|
+
* @param {int} [limit] max number of ledger entries to return
|
|
2339
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2340
|
+
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
|
|
2341
|
+
* @returns {object} a [ledger structure]{@link https://docs.ccxt.com/#/?id=ledger-structure}
|
|
2342
|
+
*/
|
|
2343
|
+
await this.loadMarkets();
|
|
2344
|
+
const request = {};
|
|
2345
|
+
let currency = undefined;
|
|
2346
|
+
if (code !== undefined) {
|
|
2347
|
+
currency = this.currency(code);
|
|
2348
|
+
}
|
|
2349
|
+
if (since !== undefined) {
|
|
2350
|
+
request['start_time'] = since;
|
|
2351
|
+
}
|
|
2352
|
+
if (limit !== undefined) {
|
|
2353
|
+
request['limit'] = limit;
|
|
2354
|
+
}
|
|
2355
|
+
const until = this.safeInteger2(params, 'until', 'till');
|
|
2356
|
+
params = this.omit(params, ['until', 'till']);
|
|
2357
|
+
if (until !== undefined) {
|
|
2358
|
+
request['end_time'] = until;
|
|
2359
|
+
}
|
|
2360
|
+
const response = await this.v1PrivatePostPrivateGetTransactions(this.extend(request, params));
|
|
2361
|
+
//
|
|
2362
|
+
// {
|
|
2363
|
+
// "id": 1686813195698,
|
|
2364
|
+
// "method": "private/get-transactions",
|
|
2365
|
+
// "code": 0,
|
|
2366
|
+
// "result": {
|
|
2367
|
+
// "data": [
|
|
2368
|
+
// {
|
|
2369
|
+
// "account_id": "ce075cef-1234-4321-bd6e-gf9007351e64",
|
|
2370
|
+
// "event_date": "2023-06-15",
|
|
2371
|
+
// "journal_type": "TRADING",
|
|
2372
|
+
// "journal_id": "6530219460124075091",
|
|
2373
|
+
// "transaction_qty": "6.0091224",
|
|
2374
|
+
// "transaction_cost": "6.0091224",
|
|
2375
|
+
// "realized_pnl": "0",
|
|
2376
|
+
// "order_id": "6530219477766741833",
|
|
2377
|
+
// "trade_id": "6530219495775954765",
|
|
2378
|
+
// "trade_match_id": "4611686018455865176",
|
|
2379
|
+
// "event_timestamp_ms": 1686804665013,
|
|
2380
|
+
// "event_timestamp_ns": "1686804665013642422",
|
|
2381
|
+
// "client_oid": "CCXT_d6ea7c5db6c1495aa8b758",
|
|
2382
|
+
// "taker_side": "",
|
|
2383
|
+
// "side": "BUY",
|
|
2384
|
+
// "instrument_name": "USD"
|
|
2385
|
+
// },
|
|
2386
|
+
// ]
|
|
2387
|
+
// }
|
|
2388
|
+
// }
|
|
2389
|
+
//
|
|
2390
|
+
const result = this.safeValue(response, 'result', {});
|
|
2391
|
+
const ledger = this.safeValue(result, 'data', []);
|
|
2392
|
+
return this.parseLedger(ledger, currency, since, limit);
|
|
2393
|
+
}
|
|
2394
|
+
parseLedgerEntry(item, currency = undefined) {
|
|
2395
|
+
//
|
|
2396
|
+
// {
|
|
2397
|
+
// "account_id": "ce075cef-1234-4321-bd6e-gf9007351e64",
|
|
2398
|
+
// "event_date": "2023-06-15",
|
|
2399
|
+
// "journal_type": "TRADING",
|
|
2400
|
+
// "journal_id": "6530219460124075091",
|
|
2401
|
+
// "transaction_qty": "6.0091224",
|
|
2402
|
+
// "transaction_cost": "6.0091224",
|
|
2403
|
+
// "realized_pnl": "0",
|
|
2404
|
+
// "order_id": "6530219477766741833",
|
|
2405
|
+
// "trade_id": "6530219495775954765",
|
|
2406
|
+
// "trade_match_id": "4611686018455865176",
|
|
2407
|
+
// "event_timestamp_ms": 1686804665013,
|
|
2408
|
+
// "event_timestamp_ns": "1686804665013642422",
|
|
2409
|
+
// "client_oid": "CCXT_d6ea7c5db6c1495aa8b758",
|
|
2410
|
+
// "taker_side": "",
|
|
2411
|
+
// "side": "BUY",
|
|
2412
|
+
// "instrument_name": "USD"
|
|
2413
|
+
// }
|
|
2414
|
+
//
|
|
2415
|
+
const timestamp = this.safeInteger(item, 'event_timestamp_ms');
|
|
2416
|
+
const currencyId = this.safeString(item, 'instrument_name');
|
|
2417
|
+
let amount = this.safeString(item, 'transaction_qty');
|
|
2418
|
+
let direction = undefined;
|
|
2419
|
+
if (Precise["default"].stringLt(amount, '0')) {
|
|
2420
|
+
direction = 'out';
|
|
2421
|
+
amount = Precise["default"].stringAbs(amount);
|
|
2422
|
+
}
|
|
2423
|
+
else {
|
|
2424
|
+
direction = 'in';
|
|
2425
|
+
}
|
|
2426
|
+
return {
|
|
2427
|
+
'id': this.safeString(item, 'order_id'),
|
|
2428
|
+
'direction': direction,
|
|
2429
|
+
'account': this.safeString(item, 'account_id'),
|
|
2430
|
+
'referenceId': this.safeString(item, 'trade_id'),
|
|
2431
|
+
'referenceAccount': this.safeString(item, 'trade_match_id'),
|
|
2432
|
+
'type': this.parseLedgerEntryType(this.safeString(item, 'journal_type')),
|
|
2433
|
+
'currency': this.safeCurrencyCode(currencyId, currency),
|
|
2434
|
+
'amount': this.parseNumber(amount),
|
|
2435
|
+
'timestamp': timestamp,
|
|
2436
|
+
'datetime': this.iso8601(timestamp),
|
|
2437
|
+
'before': undefined,
|
|
2438
|
+
'after': undefined,
|
|
2439
|
+
'status': undefined,
|
|
2440
|
+
'fee': {
|
|
2441
|
+
'currency': undefined,
|
|
2442
|
+
'cost': undefined,
|
|
2443
|
+
},
|
|
2444
|
+
'info': item,
|
|
2445
|
+
};
|
|
2446
|
+
}
|
|
2447
|
+
parseLedgerEntryType(type) {
|
|
2448
|
+
const ledgerType = {
|
|
2449
|
+
'TRADING': 'trade',
|
|
2450
|
+
'TRADE_FEE': 'fee',
|
|
2451
|
+
'WITHDRAW_FEE': 'fee',
|
|
2452
|
+
'WITHDRAW': 'withdrawal',
|
|
2453
|
+
'DEPOSIT': 'deposit',
|
|
2454
|
+
'ROLLBACK_WITHDRAW': 'rollback',
|
|
2455
|
+
'ROLLBACK_DEPOSIT': 'rollback',
|
|
2456
|
+
'FUNDING': 'fee',
|
|
2457
|
+
'REALIZED_PNL': 'trade',
|
|
2458
|
+
'INSURANCE_FUND': 'insurance',
|
|
2459
|
+
'SOCIALIZED_LOSS': 'trade',
|
|
2460
|
+
'LIQUIDATION_FEE': 'fee',
|
|
2461
|
+
'SESSION_RESET': 'reset',
|
|
2462
|
+
'ADJUSTMENT': 'adjustment',
|
|
2463
|
+
'SESSION_SETTLE': 'settlement',
|
|
2464
|
+
'UNCOVERED_LOSS': 'trade',
|
|
2465
|
+
'ADMIN_ADJUSTMENT': 'adjustment',
|
|
2466
|
+
'DELIST': 'delist',
|
|
2467
|
+
'SETTLEMENT_FEE': 'fee',
|
|
2468
|
+
'AUTO_CONVERSION': 'conversion',
|
|
2469
|
+
'MANUAL_CONVERSION': 'conversion',
|
|
2470
|
+
};
|
|
2471
|
+
return this.safeString(ledgerType, type, type);
|
|
2472
|
+
}
|
|
2473
|
+
async fetchAccounts(params = {}) {
|
|
2474
|
+
/**
|
|
2475
|
+
* @method
|
|
2476
|
+
* @name cryptocom#fetchAccounts
|
|
2477
|
+
* @description fetch all the accounts associated with a profile
|
|
2478
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-accounts
|
|
2479
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2480
|
+
* @returns {object} a dictionary of [account structures]{@link https://docs.ccxt.com/#/?id=account-structure} indexed by the account type
|
|
2481
|
+
*/
|
|
2482
|
+
await this.loadMarkets();
|
|
2483
|
+
const response = await this.v1PrivatePostPrivateGetAccounts(params);
|
|
2484
|
+
//
|
|
2485
|
+
// {
|
|
2486
|
+
// "id": 1234567894321,
|
|
2487
|
+
// "method": "private/get-accounts",
|
|
2488
|
+
// "code": 0,
|
|
2489
|
+
// "result": {
|
|
2490
|
+
// "master_account": {
|
|
2491
|
+
// "uuid": "a1234abc-1234-4321-q5r7-b1ab0a0b12b",
|
|
2492
|
+
// "user_uuid": "a1234abc-1234-4321-q5r7-b1ab0a0b12b",
|
|
2493
|
+
// "enabled": true,
|
|
2494
|
+
// "tradable": true,
|
|
2495
|
+
// "name": "YOUR_NAME",
|
|
2496
|
+
// "country_code": "CAN",
|
|
2497
|
+
// "phone_country_code": "CAN",
|
|
2498
|
+
// "incorp_country_code": "",
|
|
2499
|
+
// "margin_access": "DEFAULT",
|
|
2500
|
+
// "derivatives_access": "DEFAULT",
|
|
2501
|
+
// "create_time": 1656445188000,
|
|
2502
|
+
// "update_time": 1660794567262,
|
|
2503
|
+
// "two_fa_enabled": true,
|
|
2504
|
+
// "kyc_level": "ADVANCED",
|
|
2505
|
+
// "suspended": false,
|
|
2506
|
+
// "terminated": false,
|
|
2507
|
+
// "spot_enabled": false,
|
|
2508
|
+
// "margin_enabled": false,
|
|
2509
|
+
// "derivatives_enabled": false
|
|
2510
|
+
// },
|
|
2511
|
+
// "sub_account_list": []
|
|
2512
|
+
// }
|
|
2513
|
+
// }
|
|
2514
|
+
//
|
|
2515
|
+
const result = this.safeValue(response, 'result', {});
|
|
2516
|
+
const masterAccount = this.safeValue(result, 'master_account', {});
|
|
2517
|
+
const accounts = this.safeValue(result, 'sub_account_list', []);
|
|
2518
|
+
accounts.push(masterAccount);
|
|
2519
|
+
return this.parseAccounts(accounts, params);
|
|
2520
|
+
}
|
|
2521
|
+
parseAccount(account) {
|
|
2522
|
+
//
|
|
2523
|
+
// {
|
|
2524
|
+
// "uuid": "a1234abc-1234-4321-q5r7-b1ab0a0b12b",
|
|
2525
|
+
// "user_uuid": "a1234abc-1234-4321-q5r7-b1ab0a0b12b",
|
|
2526
|
+
// "master_account_uuid": "a1234abc-1234-4321-q5r7-b1ab0a0b12b",
|
|
2527
|
+
// "label": "FORMER_MASTER_MARGIN",
|
|
2528
|
+
// "enabled": true,
|
|
2529
|
+
// "tradable": true,
|
|
2530
|
+
// "name": "YOUR_NAME",
|
|
2531
|
+
// "country_code": "YOUR_COUNTRY_CODE",
|
|
2532
|
+
// "incorp_country_code": "",
|
|
2533
|
+
// "margin_access": "DEFAULT",
|
|
2534
|
+
// "derivatives_access": "DEFAULT",
|
|
2535
|
+
// "create_time": 1656481992000,
|
|
2536
|
+
// "update_time": 1667272884594,
|
|
2537
|
+
// "two_fa_enabled": false,
|
|
2538
|
+
// "kyc_level": "ADVANCED",
|
|
2539
|
+
// "suspended": false,
|
|
2540
|
+
// "terminated": false,
|
|
2541
|
+
// "spot_enabled": false,
|
|
2542
|
+
// "margin_enabled": false,
|
|
2543
|
+
// "derivatives_enabled": false,
|
|
2544
|
+
// "system_label": "FORMER_MASTER_MARGIN"
|
|
2545
|
+
// }
|
|
2546
|
+
//
|
|
2547
|
+
return {
|
|
2548
|
+
'id': this.safeString(account, 'uuid'),
|
|
2549
|
+
'type': this.safeString(account, 'label'),
|
|
2550
|
+
'code': undefined,
|
|
2551
|
+
'info': account,
|
|
2552
|
+
};
|
|
2553
|
+
}
|
|
2554
|
+
async fetchSettlementHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
2555
|
+
/**
|
|
2556
|
+
* @method
|
|
2557
|
+
* @name cryptocom#fetchSettlementHistory
|
|
2558
|
+
* @description fetches historical settlement records
|
|
2559
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-expired-settlement-price
|
|
2560
|
+
* @param {string} symbol unified market symbol of the settlement history
|
|
2561
|
+
* @param {int} [since] timestamp in ms
|
|
2562
|
+
* @param {int} [limit] number of records
|
|
2563
|
+
* @param {object} [params] exchange specific params
|
|
2564
|
+
* @param {int} [params.type] 'future', 'option'
|
|
2565
|
+
* @returns {object[]} a list of [settlement history objects]{@link https://docs.ccxt.com/#/?id=settlement-history-structure}
|
|
2566
|
+
*/
|
|
2567
|
+
await this.loadMarkets();
|
|
2568
|
+
let market = undefined;
|
|
2569
|
+
if (symbol !== undefined) {
|
|
2570
|
+
market = this.market(symbol);
|
|
2571
|
+
}
|
|
2572
|
+
let type = undefined;
|
|
2573
|
+
[type, params] = this.handleMarketTypeAndParams('fetchSettlementHistory', market, params);
|
|
2574
|
+
this.checkRequiredArgument('fetchSettlementHistory', type, 'type', ['future', 'option', 'WARRANT', 'FUTURE']);
|
|
2575
|
+
if (type === 'option') {
|
|
2576
|
+
type = 'WARRANT';
|
|
2577
|
+
}
|
|
2578
|
+
const request = {
|
|
2579
|
+
'instrument_type': type.toUpperCase(),
|
|
2580
|
+
};
|
|
2581
|
+
const response = await this.v1PublicGetPublicGetExpiredSettlementPrice(this.extend(request, params));
|
|
2582
|
+
//
|
|
2583
|
+
// {
|
|
2584
|
+
// "id": -1,
|
|
2585
|
+
// "method": "public/get-expired-settlement-price",
|
|
2586
|
+
// "code": 0,
|
|
2587
|
+
// "result": {
|
|
2588
|
+
// "data": [
|
|
2589
|
+
// {
|
|
2590
|
+
// "i": "BTCUSD-230526",
|
|
2591
|
+
// "x": 1685088000000,
|
|
2592
|
+
// "v": "26464.1",
|
|
2593
|
+
// "t": 1685087999500
|
|
2594
|
+
// }
|
|
2595
|
+
// ]
|
|
2596
|
+
// }
|
|
2597
|
+
// }
|
|
2598
|
+
//
|
|
2599
|
+
const result = this.safeValue(response, 'result', {});
|
|
2600
|
+
const data = this.safeValue(result, 'data', []);
|
|
2601
|
+
const settlements = this.parseSettlements(data, market);
|
|
2602
|
+
const sorted = this.sortBy(settlements, 'timestamp');
|
|
2603
|
+
return this.filterBySymbolSinceLimit(sorted, symbol, since, limit);
|
|
2604
|
+
}
|
|
2605
|
+
parseSettlement(settlement, market) {
|
|
2606
|
+
//
|
|
2607
|
+
// {
|
|
2608
|
+
// "i": "BTCUSD-230526",
|
|
2609
|
+
// "x": 1685088000000,
|
|
2610
|
+
// "v": "26464.1",
|
|
2611
|
+
// "t": 1685087999500
|
|
2612
|
+
// }
|
|
2613
|
+
//
|
|
2614
|
+
const timestamp = this.safeInteger(settlement, 'x');
|
|
2615
|
+
const marketId = this.safeString(settlement, 'i');
|
|
2616
|
+
return {
|
|
2617
|
+
'info': settlement,
|
|
2618
|
+
'symbol': this.safeSymbol(marketId, market),
|
|
2619
|
+
'price': this.safeNumber(settlement, 'v'),
|
|
2620
|
+
'timestamp': timestamp,
|
|
2621
|
+
'datetime': this.iso8601(timestamp),
|
|
2622
|
+
};
|
|
2623
|
+
}
|
|
2624
|
+
parseSettlements(settlements, market) {
|
|
2625
|
+
//
|
|
2626
|
+
// [
|
|
2627
|
+
// {
|
|
2628
|
+
// "i": "BTCUSD-230526",
|
|
2629
|
+
// "x": 1685088000000,
|
|
2630
|
+
// "v": "26464.1",
|
|
2631
|
+
// "t": 1685087999500
|
|
2632
|
+
// }
|
|
2633
|
+
// ]
|
|
2634
|
+
//
|
|
2635
|
+
const result = [];
|
|
2636
|
+
for (let i = 0; i < settlements.length; i++) {
|
|
2637
|
+
result.push(this.parseSettlement(settlements[i], market));
|
|
2638
|
+
}
|
|
2639
|
+
return result;
|
|
2640
|
+
}
|
|
2641
|
+
async fetchFundingRateHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
2642
|
+
/**
|
|
2643
|
+
* @method
|
|
2644
|
+
* @name cryptocom#fetchFundingRateHistory
|
|
2645
|
+
* @description fetches historical funding rates
|
|
2646
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-valuations
|
|
2647
|
+
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
|
|
2648
|
+
* @param {int} [since] timestamp in ms of the earliest funding rate to fetch
|
|
2649
|
+
* @param {int} [limit] the maximum amount of [funding rate structures] to fetch
|
|
2650
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2651
|
+
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
|
|
2652
|
+
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
|
|
2653
|
+
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure}
|
|
2654
|
+
*/
|
|
2655
|
+
if (symbol === undefined) {
|
|
2656
|
+
throw new errors.ArgumentsRequired(this.id + ' fetchFundingRateHistory() requires a symbol argument');
|
|
2657
|
+
}
|
|
2658
|
+
await this.loadMarkets();
|
|
2659
|
+
let paginate = false;
|
|
2660
|
+
[paginate, params] = this.handleOptionAndParams(params, 'fetchFundingRateHistory', 'paginate');
|
|
2661
|
+
if (paginate) {
|
|
2662
|
+
return await this.fetchPaginatedCallDeterministic('fetchFundingRateHistory', symbol, since, limit, '8h', params);
|
|
2663
|
+
}
|
|
2664
|
+
const market = this.market(symbol);
|
|
2665
|
+
if (!market['swap']) {
|
|
2666
|
+
throw new errors.BadSymbol(this.id + ' fetchFundingRateHistory() supports swap contracts only');
|
|
2667
|
+
}
|
|
2668
|
+
const request = {
|
|
2669
|
+
'instrument_name': market['id'],
|
|
2670
|
+
'valuation_type': 'funding_hist',
|
|
2671
|
+
};
|
|
2672
|
+
if (since !== undefined) {
|
|
2673
|
+
request['start_ts'] = since;
|
|
2674
|
+
}
|
|
2675
|
+
if (limit !== undefined) {
|
|
2676
|
+
request['count'] = limit;
|
|
2677
|
+
}
|
|
2678
|
+
const until = this.safeInteger2(params, 'until', 'till');
|
|
2679
|
+
params = this.omit(params, ['until', 'till']);
|
|
2680
|
+
if (until !== undefined) {
|
|
2681
|
+
request['end_ts'] = until;
|
|
2682
|
+
}
|
|
2683
|
+
const response = await this.v1PublicGetPublicGetValuations(this.extend(request, params));
|
|
2684
|
+
//
|
|
2685
|
+
// {
|
|
2686
|
+
// "id": -1,
|
|
2687
|
+
// "method": "public/get-valuations",
|
|
2688
|
+
// "code": 0,
|
|
2689
|
+
// "result": {
|
|
2690
|
+
// "data": [
|
|
2691
|
+
// {
|
|
2692
|
+
// "v": "-0.000001884",
|
|
2693
|
+
// "t": 1687892400000
|
|
2694
|
+
// },
|
|
2695
|
+
// ],
|
|
2696
|
+
// "instrument_name": "BTCUSD-PERP"
|
|
2697
|
+
// }
|
|
2698
|
+
// }
|
|
2699
|
+
//
|
|
2700
|
+
const result = this.safeValue(response, 'result', {});
|
|
2701
|
+
const data = this.safeValue(result, 'data', []);
|
|
2702
|
+
const marketId = this.safeString(result, 'instrument_name');
|
|
2703
|
+
const rates = [];
|
|
2704
|
+
for (let i = 0; i < data.length; i++) {
|
|
2705
|
+
const entry = data[i];
|
|
2706
|
+
const timestamp = this.safeInteger(entry, 't');
|
|
2707
|
+
rates.push({
|
|
2708
|
+
'info': entry,
|
|
2709
|
+
'symbol': this.safeSymbol(marketId, market),
|
|
2710
|
+
'fundingRate': this.safeNumber(entry, 'v'),
|
|
2711
|
+
'timestamp': timestamp,
|
|
2712
|
+
'datetime': this.iso8601(timestamp),
|
|
2713
|
+
});
|
|
2714
|
+
}
|
|
2715
|
+
const sorted = this.sortBy(rates, 'timestamp');
|
|
2716
|
+
return this.filterBySymbolSinceLimit(sorted, market['symbol'], since, limit);
|
|
2717
|
+
}
|
|
2718
|
+
async fetchPosition(symbol, params = {}) {
|
|
2719
|
+
/**
|
|
2720
|
+
* @method
|
|
2721
|
+
* @name cryptocom#fetchPosition
|
|
2722
|
+
* @description fetch data on a single open contract trade position
|
|
2723
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-positions
|
|
2724
|
+
* @param {string} symbol unified market symbol of the market the position is held in
|
|
2725
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2726
|
+
* @returns {object} a [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
|
|
2727
|
+
*/
|
|
2728
|
+
await this.loadMarkets();
|
|
2729
|
+
const market = this.market(symbol);
|
|
2730
|
+
const request = {
|
|
2731
|
+
'instrument_name': market['id'],
|
|
2732
|
+
};
|
|
2733
|
+
const response = await this.v1PrivatePostPrivateGetPositions(this.extend(request, params));
|
|
2734
|
+
//
|
|
2735
|
+
// {
|
|
2736
|
+
// "id": 1688015952050,
|
|
2737
|
+
// "method": "private/get-positions",
|
|
2738
|
+
// "code": 0,
|
|
2739
|
+
// "result": {
|
|
2740
|
+
// "data": [
|
|
2741
|
+
// {
|
|
2742
|
+
// "account_id": "ce075bef-b600-4277-bd6e-ff9007251e63",
|
|
2743
|
+
// "quantity": "0.0001",
|
|
2744
|
+
// "cost": "3.02392",
|
|
2745
|
+
// "open_pos_cost": "3.02392",
|
|
2746
|
+
// "open_position_pnl": "-0.0010281328",
|
|
2747
|
+
// "session_pnl": "-0.0010281328",
|
|
2748
|
+
// "update_timestamp_ms": 1688015919091,
|
|
2749
|
+
// "instrument_name": "BTCUSD-PERP",
|
|
2750
|
+
// "type": "PERPETUAL_SWAP"
|
|
2751
|
+
// }
|
|
2752
|
+
// ]
|
|
2753
|
+
// }
|
|
2754
|
+
// }
|
|
2755
|
+
//
|
|
2756
|
+
const result = this.safeValue(response, 'result', {});
|
|
2757
|
+
const data = this.safeValue(result, 'data', []);
|
|
2758
|
+
return this.parsePosition(data[0], market);
|
|
2759
|
+
}
|
|
2760
|
+
async fetchPositions(symbols = undefined, params = {}) {
|
|
2761
|
+
/**
|
|
2762
|
+
* @method
|
|
2763
|
+
* @name cryptocom#fetchPositions
|
|
2764
|
+
* @description fetch all open positions
|
|
2765
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-positions
|
|
2766
|
+
* @param {string[]|undefined} symbols list of unified market symbols
|
|
2767
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2768
|
+
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
|
|
2769
|
+
*/
|
|
2770
|
+
await this.loadMarkets();
|
|
2771
|
+
symbols = this.marketSymbols(symbols);
|
|
2772
|
+
const request = {};
|
|
2773
|
+
let market = undefined;
|
|
2774
|
+
if (symbols !== undefined) {
|
|
2775
|
+
let symbol = undefined;
|
|
2776
|
+
if (Array.isArray(symbols)) {
|
|
2777
|
+
const symbolsLength = symbols.length;
|
|
2778
|
+
if (symbolsLength > 1) {
|
|
2779
|
+
throw new errors.BadRequest(this.id + ' fetchPositions() symbols argument cannot contain more than 1 symbol');
|
|
2780
|
+
}
|
|
2781
|
+
symbol = symbols[0];
|
|
2782
|
+
}
|
|
2783
|
+
else {
|
|
2784
|
+
symbol = symbols;
|
|
2785
|
+
}
|
|
2786
|
+
market = this.market(symbol);
|
|
2787
|
+
request['instrument_name'] = market['id'];
|
|
2788
|
+
}
|
|
2789
|
+
const response = await this.v1PrivatePostPrivateGetPositions(this.extend(request, params));
|
|
2790
|
+
//
|
|
2791
|
+
// {
|
|
2792
|
+
// "id": 1688015952050,
|
|
2793
|
+
// "method": "private/get-positions",
|
|
2794
|
+
// "code": 0,
|
|
2795
|
+
// "result": {
|
|
2796
|
+
// "data": [
|
|
2797
|
+
// {
|
|
2798
|
+
// "account_id": "ce075bef-b600-4277-bd6e-ff9007251e63",
|
|
2799
|
+
// "quantity": "0.0001",
|
|
2800
|
+
// "cost": "3.02392",
|
|
2801
|
+
// "open_pos_cost": "3.02392",
|
|
2802
|
+
// "open_position_pnl": "-0.0010281328",
|
|
2803
|
+
// "session_pnl": "-0.0010281328",
|
|
2804
|
+
// "update_timestamp_ms": 1688015919091,
|
|
2805
|
+
// "instrument_name": "BTCUSD-PERP",
|
|
2806
|
+
// "type": "PERPETUAL_SWAP"
|
|
2807
|
+
// }
|
|
2808
|
+
// ]
|
|
2809
|
+
// }
|
|
2810
|
+
// }
|
|
2811
|
+
//
|
|
2812
|
+
const responseResult = this.safeValue(response, 'result', {});
|
|
2813
|
+
const positions = this.safeValue(responseResult, 'data', []);
|
|
2814
|
+
const result = [];
|
|
2815
|
+
for (let i = 0; i < positions.length; i++) {
|
|
2816
|
+
const entry = positions[i];
|
|
2817
|
+
const marketId = this.safeString(entry, 'instrument_name');
|
|
2818
|
+
const marketInner = this.safeMarket(marketId, undefined, undefined, 'contract');
|
|
2819
|
+
result.push(this.parsePosition(entry, marketInner));
|
|
2820
|
+
}
|
|
2821
|
+
return this.filterByArrayPositions(result, 'symbol', undefined, false);
|
|
2822
|
+
}
|
|
2823
|
+
parsePosition(position, market = undefined) {
|
|
2824
|
+
//
|
|
2825
|
+
// {
|
|
2826
|
+
// "account_id": "ce075bef-b600-4277-bd6e-ff9007251e63",
|
|
2827
|
+
// "quantity": "0.0001",
|
|
2828
|
+
// "cost": "3.02392",
|
|
2829
|
+
// "open_pos_cost": "3.02392",
|
|
2830
|
+
// "open_position_pnl": "-0.0010281328",
|
|
2831
|
+
// "session_pnl": "-0.0010281328",
|
|
2832
|
+
// "update_timestamp_ms": 1688015919091,
|
|
2833
|
+
// "instrument_name": "BTCUSD-PERP",
|
|
2834
|
+
// "type": "PERPETUAL_SWAP"
|
|
2835
|
+
// }
|
|
2836
|
+
//
|
|
2837
|
+
const marketId = this.safeString(position, 'instrument_name');
|
|
2838
|
+
market = this.safeMarket(marketId, market, undefined, 'contract');
|
|
2839
|
+
const symbol = this.safeSymbol(marketId, market, undefined, 'contract');
|
|
2840
|
+
const timestamp = this.safeInteger(position, 'update_timestamp_ms');
|
|
2841
|
+
const amount = this.safeString(position, 'quantity');
|
|
2842
|
+
return this.safePosition({
|
|
2843
|
+
'info': position,
|
|
2844
|
+
'id': undefined,
|
|
2845
|
+
'symbol': symbol,
|
|
2846
|
+
'timestamp': timestamp,
|
|
2847
|
+
'datetime': this.iso8601(timestamp),
|
|
2848
|
+
'hedged': undefined,
|
|
2849
|
+
'side': Precise["default"].stringGt(amount, '0') ? 'buy' : 'sell',
|
|
2850
|
+
'contracts': Precise["default"].stringAbs(amount),
|
|
2851
|
+
'contractSize': market['contractSize'],
|
|
2852
|
+
'entryPrice': undefined,
|
|
2853
|
+
'markPrice': undefined,
|
|
2854
|
+
'notional': undefined,
|
|
2855
|
+
'leverage': undefined,
|
|
2856
|
+
'collateral': this.safeNumber(position, 'open_pos_cost'),
|
|
2857
|
+
'initialMargin': this.safeNumber(position, 'cost'),
|
|
2858
|
+
'maintenanceMargin': undefined,
|
|
2859
|
+
'initialMarginPercentage': undefined,
|
|
2860
|
+
'maintenanceMarginPercentage': undefined,
|
|
2861
|
+
'unrealizedPnl': this.safeNumber(position, 'open_position_pnl'),
|
|
2862
|
+
'liquidationPrice': undefined,
|
|
2863
|
+
'marginMode': undefined,
|
|
2864
|
+
'percentage': undefined,
|
|
2865
|
+
'marginRatio': undefined,
|
|
2866
|
+
'stopLossPrice': undefined,
|
|
2867
|
+
'takeProfitPrice': undefined,
|
|
2868
|
+
});
|
|
2869
|
+
}
|
|
2870
|
+
nonce() {
|
|
2871
|
+
return this.milliseconds();
|
|
2872
|
+
}
|
|
2873
|
+
paramsToString(object, level) {
|
|
2874
|
+
const maxLevel = 3;
|
|
2875
|
+
if (level >= maxLevel) {
|
|
2876
|
+
return object.toString();
|
|
2877
|
+
}
|
|
2878
|
+
if (typeof object === 'string') {
|
|
2879
|
+
return object;
|
|
2880
|
+
}
|
|
2881
|
+
let returnString = '';
|
|
2882
|
+
let paramsKeys = undefined;
|
|
2883
|
+
if (Array.isArray(object)) {
|
|
2884
|
+
paramsKeys = object;
|
|
2885
|
+
}
|
|
2886
|
+
else {
|
|
2887
|
+
const sorted = this.keysort(object);
|
|
2888
|
+
paramsKeys = Object.keys(sorted);
|
|
2889
|
+
}
|
|
2890
|
+
for (let i = 0; i < paramsKeys.length; i++) {
|
|
2891
|
+
const key = paramsKeys[i];
|
|
2892
|
+
returnString += key;
|
|
2893
|
+
const value = object[key];
|
|
2894
|
+
if (value === 'undefined') {
|
|
2895
|
+
returnString += 'null';
|
|
2896
|
+
}
|
|
2897
|
+
else if (Array.isArray(value)) {
|
|
2898
|
+
for (let j = 0; j < value.length; j++) {
|
|
2899
|
+
returnString += this.paramsToString(value[j], level + 1);
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
else {
|
|
2903
|
+
returnString += value.toString();
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
return returnString;
|
|
2907
|
+
}
|
|
2908
|
+
async closePosition(symbol, side = undefined, params = {}) {
|
|
2909
|
+
/**
|
|
2910
|
+
* @method
|
|
2911
|
+
* @name cryptocom#closePositions
|
|
2912
|
+
* @description closes open positions for a market
|
|
2913
|
+
* @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-close-position
|
|
2914
|
+
* @param {string} symbol Unified CCXT market symbol
|
|
2915
|
+
* @param {string} [marginMode] not used by cryptocom.closePositions
|
|
2916
|
+
* @param {string} [side] not used by cryptocom.closePositions
|
|
2917
|
+
* @param {object} [params] extra parameters specific to the okx api endpoint
|
|
2918
|
+
*
|
|
2919
|
+
* EXCHANGE SPECIFIC PARAMETERS
|
|
2920
|
+
* @param {string} [params.type] LIMIT or MARKET
|
|
2921
|
+
* @param {number} [params.price] for limit orders only
|
|
2922
|
+
* @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
|
|
2923
|
+
*/
|
|
2924
|
+
await this.loadMarkets();
|
|
2925
|
+
const market = this.market(symbol);
|
|
2926
|
+
const request = {
|
|
2927
|
+
'instrument_name': market['id'],
|
|
2928
|
+
'type': 'MARKET',
|
|
2929
|
+
};
|
|
2930
|
+
const type = this.safeStringUpper(params, 'type');
|
|
2931
|
+
const price = this.safeString(params, 'price');
|
|
2932
|
+
if (type !== undefined) {
|
|
2933
|
+
request['type'] = type;
|
|
2934
|
+
}
|
|
2935
|
+
if (price !== undefined) {
|
|
2936
|
+
request['price'] = this.priceToPrecision(market['symbol'], price);
|
|
2937
|
+
}
|
|
2938
|
+
const response = await this.v1PrivatePostPrivateClosePosition(this.extend(request, params));
|
|
2939
|
+
//
|
|
2940
|
+
// {
|
|
2941
|
+
// "id" : 1700830813298,
|
|
2942
|
+
// "method" : "private/close-position",
|
|
2943
|
+
// "code" : 0,
|
|
2944
|
+
// "result" : {
|
|
2945
|
+
// "client_oid" : "179a909d-5614-655b-0d0e-9e85c9a25c85",
|
|
2946
|
+
// "order_id" : "6142909897021751347"
|
|
2947
|
+
// }
|
|
2948
|
+
// }
|
|
2949
|
+
//
|
|
2950
|
+
const result = this.safeValue(response, 'result');
|
|
2951
|
+
return this.parseOrder(result, market);
|
|
2952
|
+
}
|
|
2953
|
+
sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
|
|
2954
|
+
const type = this.safeString(api, 0);
|
|
2955
|
+
const access = this.safeString(api, 1);
|
|
2956
|
+
let url = this.urls['api'][type] + '/' + path;
|
|
2957
|
+
const query = this.omit(params, this.extractParams(path));
|
|
2958
|
+
if (access === 'public') {
|
|
2959
|
+
if (Object.keys(query).length) {
|
|
2960
|
+
url += '?' + this.urlencode(query);
|
|
2961
|
+
}
|
|
2962
|
+
}
|
|
2963
|
+
else {
|
|
2964
|
+
this.checkRequiredCredentials();
|
|
2965
|
+
const nonce = this.nonce().toString();
|
|
2966
|
+
const requestParams = this.extend({}, params);
|
|
2967
|
+
const paramsKeys = Object.keys(requestParams);
|
|
2968
|
+
const strSortKey = this.paramsToString(requestParams, 0);
|
|
2969
|
+
const payload = path + nonce + this.apiKey + strSortKey + nonce;
|
|
2970
|
+
const signature = this.hmac(this.encode(payload), this.encode(this.secret), sha256.sha256);
|
|
2971
|
+
const paramsKeysLength = paramsKeys.length;
|
|
2972
|
+
body = this.json({
|
|
2973
|
+
'id': nonce,
|
|
2974
|
+
'method': path,
|
|
2975
|
+
'params': params,
|
|
2976
|
+
'api_key': this.apiKey,
|
|
2977
|
+
'sig': signature,
|
|
2978
|
+
'nonce': nonce,
|
|
2979
|
+
});
|
|
2980
|
+
// fix issue https://github.com/ccxt/ccxt/issues/11179
|
|
2981
|
+
// php always encodes dictionaries as arrays
|
|
2982
|
+
// if an array is empty, php will put it in square brackets
|
|
2983
|
+
// python and js will put it in curly brackets
|
|
2984
|
+
// the code below checks and replaces those brackets in empty requests
|
|
2985
|
+
if (paramsKeysLength === 0) {
|
|
2986
|
+
const paramsString = '{}';
|
|
2987
|
+
const arrayString = '[]';
|
|
2988
|
+
body = body.replace(arrayString, paramsString);
|
|
2989
|
+
}
|
|
2990
|
+
headers = {
|
|
2991
|
+
'Content-Type': 'application/json',
|
|
2992
|
+
};
|
|
2993
|
+
}
|
|
2994
|
+
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
|
|
2995
|
+
}
|
|
2996
|
+
handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
|
|
2997
|
+
const errorCode = this.safeString(response, 'code');
|
|
2998
|
+
if (errorCode !== '0') {
|
|
2999
|
+
const feedback = this.id + ' ' + body;
|
|
3000
|
+
this.throwExactlyMatchedException(this.exceptions['exact'], errorCode, feedback);
|
|
3001
|
+
throw new errors.ExchangeError(this.id + ' ' + body);
|
|
3002
|
+
}
|
|
3003
|
+
return undefined;
|
|
3004
|
+
}
|
|
3005
|
+
}
|
|
3006
|
+
|
|
3007
|
+
module.exports = cryptocom;
|