ccxt 4.2.10 → 4.2.12
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 +4 -4
- package/dist/ccxt.browser.js +695 -282
- 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 +2142 -0
- package/dist/cjs/js/src/binance.js +9729 -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 +3737 -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 +8284 -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 +3274 -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 +7054 -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 +9024 -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 +759 -0
- package/dist/cjs/js/src/indodax.js +1069 -0
- package/dist/cjs/js/src/kraken.js +2861 -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 +2825 -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 +7329 -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 +4715 -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 +1558 -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 +1865 -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 +2715 -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/dist/cjs/src/base/Exchange.js +11 -0
- package/dist/cjs/src/bingx.js +0 -10
- package/dist/cjs/src/bitget.js +14 -5
- package/dist/cjs/src/bybit.js +1 -1
- package/dist/cjs/src/kucoin.js +29 -5
- 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/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/alpaca.js +18 -18
- package/js/src/base/Exchange.d.ts +6 -1
- package/js/src/base/Exchange.js +112 -12
- package/js/src/bigone.d.ts +1 -2
- package/js/src/bigone.js +340 -145
- package/js/src/binance.js +15 -8
- package/js/src/bingx.d.ts +0 -1
- package/js/src/bingx.js +9 -12
- package/js/src/bitfinex.d.ts +2 -2
- package/js/src/bitfinex.js +2 -3
- package/js/src/bitget.js +35 -13
- package/js/src/bitmart.d.ts +2 -2
- package/js/src/bitmart.js +3 -3
- package/js/src/bitmex.js +1 -0
- package/js/src/bybit.js +3 -1
- package/js/src/coinlist.js +2 -3
- 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 +22 -3
- package/js/src/hitbtc.d.ts +4 -4
- package/js/src/hitbtc.js +2 -3
- package/js/src/htx.js +4 -7
- package/js/src/huobijp.js +2 -3
- package/js/src/kraken.js +1 -0
- package/js/src/kucoin.js +29 -5
- package/js/src/mexc.js +2 -1
- package/js/src/okx.js +13 -3
- 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/poloniex.d.ts +2 -2
- package/js/src/upbit.d.ts +3 -101
- package/js/src/upbit.js +12 -12
- package/js/src/woo.js +2 -0
- package/package.json +11 -11
- package/skip-tests.json +5 -0
- package/tests-manager.sh +2 -2
|
@@ -0,0 +1,2475 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var errors = require('./base/errors.js');
|
|
4
|
+
var Precise = require('./base/Precise.js');
|
|
5
|
+
var number = require('./base/functions/number.js');
|
|
6
|
+
var kucoinfutures$1 = require('./abstract/kucoinfutures.js');
|
|
7
|
+
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
class kucoinfutures extends kucoinfutures$1 {
|
|
11
|
+
describe() {
|
|
12
|
+
return this.deepExtend(super.describe(), {
|
|
13
|
+
'id': 'kucoinfutures',
|
|
14
|
+
'name': 'KuCoin Futures',
|
|
15
|
+
'countries': ['SC'],
|
|
16
|
+
'rateLimit': 75,
|
|
17
|
+
'version': 'v1',
|
|
18
|
+
'certified': true,
|
|
19
|
+
'pro': true,
|
|
20
|
+
'comment': 'Platform 2.0',
|
|
21
|
+
'quoteJsonNumbers': false,
|
|
22
|
+
'has': {
|
|
23
|
+
'CORS': undefined,
|
|
24
|
+
'spot': false,
|
|
25
|
+
'margin': false,
|
|
26
|
+
'swap': true,
|
|
27
|
+
'future': true,
|
|
28
|
+
'option': false,
|
|
29
|
+
'addMargin': true,
|
|
30
|
+
'cancelAllOrders': true,
|
|
31
|
+
'cancelOrder': true,
|
|
32
|
+
'closePosition': true,
|
|
33
|
+
'closePositions': false,
|
|
34
|
+
'createDepositAddress': true,
|
|
35
|
+
'createOrder': true,
|
|
36
|
+
'createReduceOnlyOrder': true,
|
|
37
|
+
'createStopLimitOrder': true,
|
|
38
|
+
'createStopMarketOrder': true,
|
|
39
|
+
'createStopOrder': true,
|
|
40
|
+
'fetchAccounts': true,
|
|
41
|
+
'fetchBalance': true,
|
|
42
|
+
'fetchBorrowRateHistories': false,
|
|
43
|
+
'fetchBorrowRateHistory': false,
|
|
44
|
+
'fetchClosedOrders': true,
|
|
45
|
+
'fetchCrossBorrowRate': false,
|
|
46
|
+
'fetchCrossBorrowRates': false,
|
|
47
|
+
'fetchCurrencies': false,
|
|
48
|
+
'fetchDepositAddress': true,
|
|
49
|
+
'fetchDeposits': true,
|
|
50
|
+
'fetchDepositWithdrawFee': false,
|
|
51
|
+
'fetchDepositWithdrawFees': false,
|
|
52
|
+
'fetchFundingHistory': true,
|
|
53
|
+
'fetchFundingRate': true,
|
|
54
|
+
'fetchFundingRateHistory': false,
|
|
55
|
+
'fetchIndexOHLCV': false,
|
|
56
|
+
'fetchIsolatedBorrowRate': false,
|
|
57
|
+
'fetchIsolatedBorrowRates': false,
|
|
58
|
+
'fetchL3OrderBook': true,
|
|
59
|
+
'fetchLedger': true,
|
|
60
|
+
'fetchLeverageTiers': false,
|
|
61
|
+
'fetchMarginMode': false,
|
|
62
|
+
'fetchMarketLeverageTiers': true,
|
|
63
|
+
'fetchMarkets': true,
|
|
64
|
+
'fetchMarkOHLCV': false,
|
|
65
|
+
'fetchMyTrades': true,
|
|
66
|
+
'fetchOHLCV': true,
|
|
67
|
+
'fetchOpenOrders': true,
|
|
68
|
+
'fetchOrder': true,
|
|
69
|
+
'fetchOrderBook': true,
|
|
70
|
+
'fetchPosition': true,
|
|
71
|
+
'fetchPositionMode': false,
|
|
72
|
+
'fetchPositions': true,
|
|
73
|
+
'fetchPremiumIndexOHLCV': false,
|
|
74
|
+
'fetchStatus': true,
|
|
75
|
+
'fetchTicker': true,
|
|
76
|
+
'fetchTickers': false,
|
|
77
|
+
'fetchTime': true,
|
|
78
|
+
'fetchTrades': true,
|
|
79
|
+
'fetchTransactionFee': false,
|
|
80
|
+
'fetchWithdrawals': true,
|
|
81
|
+
'setLeverage': false,
|
|
82
|
+
'setMarginMode': false,
|
|
83
|
+
'transfer': true,
|
|
84
|
+
'withdraw': undefined,
|
|
85
|
+
},
|
|
86
|
+
'urls': {
|
|
87
|
+
'logo': 'https://user-images.githubusercontent.com/1294454/147508995-9e35030a-d046-43a1-a006-6fabd981b554.jpg',
|
|
88
|
+
'doc': [
|
|
89
|
+
'https://docs.kucoin.com/futures',
|
|
90
|
+
'https://docs.kucoin.com',
|
|
91
|
+
],
|
|
92
|
+
'www': 'https://futures.kucoin.com/',
|
|
93
|
+
'referral': 'https://futures.kucoin.com/?rcode=E5wkqe',
|
|
94
|
+
'api': {
|
|
95
|
+
'public': 'https://openapi-v2.kucoin.com',
|
|
96
|
+
'private': 'https://openapi-v2.kucoin.com',
|
|
97
|
+
'futuresPrivate': 'https://api-futures.kucoin.com',
|
|
98
|
+
'futuresPublic': 'https://api-futures.kucoin.com',
|
|
99
|
+
'webExchange': 'https://futures.kucoin.com/_api/web-front',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
'requiredCredentials': {
|
|
103
|
+
'apiKey': true,
|
|
104
|
+
'secret': true,
|
|
105
|
+
'password': true,
|
|
106
|
+
},
|
|
107
|
+
'api': {
|
|
108
|
+
'futuresPublic': {
|
|
109
|
+
'get': {
|
|
110
|
+
'contracts/active': 1,
|
|
111
|
+
'contracts/{symbol}': 1,
|
|
112
|
+
'contracts/risk-limit/{symbol}': 1,
|
|
113
|
+
'ticker': 1,
|
|
114
|
+
'level2/snapshot': 1.33,
|
|
115
|
+
'level2/depth{limit}': 1,
|
|
116
|
+
'level2/message/query': 1,
|
|
117
|
+
'level3/message/query': 1,
|
|
118
|
+
'level3/snapshot': 1,
|
|
119
|
+
'trade/history': 1,
|
|
120
|
+
'interest/query': 1,
|
|
121
|
+
'index/query': 1,
|
|
122
|
+
'mark-price/{symbol}/current': 1,
|
|
123
|
+
'premium/query': 1,
|
|
124
|
+
'funding-rate/{symbol}/current': 1,
|
|
125
|
+
'timestamp': 1,
|
|
126
|
+
'status': 1,
|
|
127
|
+
'kline/query': 1,
|
|
128
|
+
},
|
|
129
|
+
'post': {
|
|
130
|
+
'bullet-public': 1,
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
'futuresPrivate': {
|
|
134
|
+
'get': {
|
|
135
|
+
'account-overview': 1.33,
|
|
136
|
+
'transaction-history': 4.44,
|
|
137
|
+
'deposit-address': 1,
|
|
138
|
+
'deposit-list': 1,
|
|
139
|
+
'withdrawals/quotas': 1,
|
|
140
|
+
'withdrawal-list': 1,
|
|
141
|
+
'transfer-list': 1,
|
|
142
|
+
'orders': 1.33,
|
|
143
|
+
'stopOrders': 1,
|
|
144
|
+
'recentDoneOrders': 1,
|
|
145
|
+
'orders/{orderId}': 1,
|
|
146
|
+
'orders/byClientOid': 1,
|
|
147
|
+
'fills': 4.44,
|
|
148
|
+
'recentFills': 4.44,
|
|
149
|
+
'openOrderStatistics': 1,
|
|
150
|
+
'position': 1,
|
|
151
|
+
'positions': 4.44,
|
|
152
|
+
'funding-history': 4.44,
|
|
153
|
+
'sub/api-key': 1,
|
|
154
|
+
'trade-statistics': 1,
|
|
155
|
+
},
|
|
156
|
+
'post': {
|
|
157
|
+
'withdrawals': 1,
|
|
158
|
+
'transfer-out': 1,
|
|
159
|
+
'transfer-in': 1,
|
|
160
|
+
'orders': 1.33,
|
|
161
|
+
'orders/test': 1.33,
|
|
162
|
+
'position/margin/auto-deposit-status': 1,
|
|
163
|
+
'position/margin/deposit-margin': 1,
|
|
164
|
+
'position/risk-limit-level/change': 1,
|
|
165
|
+
'bullet-private': 1,
|
|
166
|
+
'sub/api-key': 1,
|
|
167
|
+
'sub/api-key/update': 1,
|
|
168
|
+
},
|
|
169
|
+
'delete': {
|
|
170
|
+
'withdrawals/{withdrawalId}': 1,
|
|
171
|
+
'cancel/transfer-out': 1,
|
|
172
|
+
'orders/{orderId}': 1,
|
|
173
|
+
'orders': 4.44,
|
|
174
|
+
'stopOrders': 1,
|
|
175
|
+
'sub/api-key': 1,
|
|
176
|
+
'orders/client-order/{clientOid}': 1,
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
'webExchange': {
|
|
180
|
+
'get': {
|
|
181
|
+
'contract/{symbol}/funding-rates': 1,
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
'precisionMode': number.TICK_SIZE,
|
|
186
|
+
'exceptions': {
|
|
187
|
+
'exact': {
|
|
188
|
+
'400': errors.BadRequest,
|
|
189
|
+
'401': errors.AuthenticationError,
|
|
190
|
+
'403': errors.NotSupported,
|
|
191
|
+
'404': errors.NotSupported,
|
|
192
|
+
'405': errors.NotSupported,
|
|
193
|
+
'415': errors.BadRequest,
|
|
194
|
+
'429': errors.RateLimitExceeded,
|
|
195
|
+
'500': errors.ExchangeNotAvailable,
|
|
196
|
+
'503': errors.ExchangeNotAvailable,
|
|
197
|
+
'100001': errors.InvalidOrder,
|
|
198
|
+
'100004': errors.BadRequest,
|
|
199
|
+
'101030': errors.PermissionDenied,
|
|
200
|
+
'200004': errors.InsufficientFunds,
|
|
201
|
+
'230003': errors.InsufficientFunds,
|
|
202
|
+
'260100': errors.InsufficientFunds,
|
|
203
|
+
'300003': errors.InsufficientFunds,
|
|
204
|
+
'300012': errors.InvalidOrder,
|
|
205
|
+
'400001': errors.AuthenticationError,
|
|
206
|
+
'400002': errors.InvalidNonce,
|
|
207
|
+
'400003': errors.AuthenticationError,
|
|
208
|
+
'400004': errors.AuthenticationError,
|
|
209
|
+
'400005': errors.AuthenticationError,
|
|
210
|
+
'400006': errors.AuthenticationError,
|
|
211
|
+
'400007': errors.AuthenticationError,
|
|
212
|
+
'404000': errors.NotSupported,
|
|
213
|
+
'400100': errors.BadRequest,
|
|
214
|
+
'411100': errors.AccountSuspended,
|
|
215
|
+
'500000': errors.ExchangeNotAvailable, // Internal Server Error -- We had a problem with our server. Try again later.
|
|
216
|
+
},
|
|
217
|
+
'broad': {
|
|
218
|
+
'Position does not exist': errors.OrderNotFound, // { "code":"200000", "msg":"Position does not exist" }
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
'fees': {
|
|
222
|
+
'trading': {
|
|
223
|
+
'tierBased': true,
|
|
224
|
+
'percentage': true,
|
|
225
|
+
'taker': this.parseNumber('0.0006'),
|
|
226
|
+
'maker': this.parseNumber('0.0002'),
|
|
227
|
+
'tiers': {
|
|
228
|
+
'taker': [
|
|
229
|
+
[this.parseNumber('0'), this.parseNumber('0.0006')],
|
|
230
|
+
[this.parseNumber('50'), this.parseNumber('0.0006')],
|
|
231
|
+
[this.parseNumber('200'), this.parseNumber('0.0006')],
|
|
232
|
+
[this.parseNumber('500'), this.parseNumber('0.0005')],
|
|
233
|
+
[this.parseNumber('1000'), this.parseNumber('0.0004')],
|
|
234
|
+
[this.parseNumber('2000'), this.parseNumber('0.0004')],
|
|
235
|
+
[this.parseNumber('4000'), this.parseNumber('0.00038')],
|
|
236
|
+
[this.parseNumber('8000'), this.parseNumber('0.00035')],
|
|
237
|
+
[this.parseNumber('15000'), this.parseNumber('0.00032')],
|
|
238
|
+
[this.parseNumber('25000'), this.parseNumber('0.0003')],
|
|
239
|
+
[this.parseNumber('40000'), this.parseNumber('0.0003')],
|
|
240
|
+
[this.parseNumber('60000'), this.parseNumber('0.0003')],
|
|
241
|
+
[this.parseNumber('80000'), this.parseNumber('0.0003')],
|
|
242
|
+
],
|
|
243
|
+
'maker': [
|
|
244
|
+
[this.parseNumber('0'), this.parseNumber('0.02')],
|
|
245
|
+
[this.parseNumber('50'), this.parseNumber('0.015')],
|
|
246
|
+
[this.parseNumber('200'), this.parseNumber('0.01')],
|
|
247
|
+
[this.parseNumber('500'), this.parseNumber('0.01')],
|
|
248
|
+
[this.parseNumber('1000'), this.parseNumber('0.01')],
|
|
249
|
+
[this.parseNumber('2000'), this.parseNumber('0')],
|
|
250
|
+
[this.parseNumber('4000'), this.parseNumber('0')],
|
|
251
|
+
[this.parseNumber('8000'), this.parseNumber('0')],
|
|
252
|
+
[this.parseNumber('15000'), this.parseNumber('-0.003')],
|
|
253
|
+
[this.parseNumber('25000'), this.parseNumber('-0.006')],
|
|
254
|
+
[this.parseNumber('40000'), this.parseNumber('-0.009')],
|
|
255
|
+
[this.parseNumber('60000'), this.parseNumber('-0.012')],
|
|
256
|
+
[this.parseNumber('80000'), this.parseNumber('-0.015')],
|
|
257
|
+
],
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
'funding': {
|
|
261
|
+
'tierBased': false,
|
|
262
|
+
'percentage': false,
|
|
263
|
+
'withdraw': {},
|
|
264
|
+
'deposit': {},
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
'commonCurrencies': {
|
|
268
|
+
'HOT': 'HOTNOW',
|
|
269
|
+
'EDGE': 'DADI',
|
|
270
|
+
'WAX': 'WAXP',
|
|
271
|
+
'TRY': 'Trias',
|
|
272
|
+
'VAI': 'VAIOT',
|
|
273
|
+
'XBT': 'BTC',
|
|
274
|
+
},
|
|
275
|
+
'timeframes': {
|
|
276
|
+
'1m': 1,
|
|
277
|
+
'3m': undefined,
|
|
278
|
+
'5m': 5,
|
|
279
|
+
'15m': 15,
|
|
280
|
+
'30m': 30,
|
|
281
|
+
'1h': 60,
|
|
282
|
+
'2h': 120,
|
|
283
|
+
'4h': 240,
|
|
284
|
+
'6h': undefined,
|
|
285
|
+
'8h': 480,
|
|
286
|
+
'12h': 720,
|
|
287
|
+
'1d': 1440,
|
|
288
|
+
'1w': 10080,
|
|
289
|
+
},
|
|
290
|
+
'options': {
|
|
291
|
+
'version': 'v1',
|
|
292
|
+
'symbolSeparator': '-',
|
|
293
|
+
'defaultType': 'swap',
|
|
294
|
+
'code': 'USDT',
|
|
295
|
+
'marginModes': {},
|
|
296
|
+
'marginTypes': {},
|
|
297
|
+
// endpoint versions
|
|
298
|
+
'versions': {
|
|
299
|
+
'futuresPrivate': {
|
|
300
|
+
'POST': {
|
|
301
|
+
'transfer-out': 'v2',
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
'futuresPublic': {
|
|
305
|
+
'GET': {
|
|
306
|
+
'level3/snapshot': 'v2',
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
'networks': {
|
|
311
|
+
'OMNI': 'omni',
|
|
312
|
+
'ERC20': 'eth',
|
|
313
|
+
'TRC20': 'trx',
|
|
314
|
+
},
|
|
315
|
+
// 'code': 'BTC',
|
|
316
|
+
// 'fetchBalance': {
|
|
317
|
+
// 'code': 'BTC',
|
|
318
|
+
// },
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
async fetchStatus(params = {}) {
|
|
323
|
+
/**
|
|
324
|
+
* @method
|
|
325
|
+
* @name kucoinfutures#fetchStatus
|
|
326
|
+
* @description the latest known information on the availability of the exchange API
|
|
327
|
+
* @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-service-status
|
|
328
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
329
|
+
* @returns {object} a [status structure]{@link https://docs.ccxt.com/#/?id=exchange-status-structure}
|
|
330
|
+
*/
|
|
331
|
+
const response = await this.futuresPublicGetStatus(params);
|
|
332
|
+
//
|
|
333
|
+
// {
|
|
334
|
+
// "code":"200000",
|
|
335
|
+
// "data":{
|
|
336
|
+
// "status": "open", // open, close, cancelonly
|
|
337
|
+
// "msg": "upgrade match engine" // remark for operation when status not open
|
|
338
|
+
// }
|
|
339
|
+
// }
|
|
340
|
+
//
|
|
341
|
+
const data = this.safeValue(response, 'data', {});
|
|
342
|
+
const status = this.safeString(data, 'status');
|
|
343
|
+
return {
|
|
344
|
+
'status': (status === 'open') ? 'ok' : 'maintenance',
|
|
345
|
+
'updated': undefined,
|
|
346
|
+
'eta': undefined,
|
|
347
|
+
'url': undefined,
|
|
348
|
+
'info': response,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
async fetchMarkets(params = {}) {
|
|
352
|
+
/**
|
|
353
|
+
* @method
|
|
354
|
+
* @name kucoinfutures#fetchMarkets
|
|
355
|
+
* @description retrieves data on all markets for kucoinfutures
|
|
356
|
+
* @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-symbols-list
|
|
357
|
+
* @param {object} [params] extra parameters specific to the exchange api endpoint
|
|
358
|
+
* @returns {object[]} an array of objects representing market data
|
|
359
|
+
*/
|
|
360
|
+
const response = await this.futuresPublicGetContractsActive(params);
|
|
361
|
+
//
|
|
362
|
+
// {
|
|
363
|
+
// "code": "200000",
|
|
364
|
+
// "data": {
|
|
365
|
+
// "symbol": "ETHUSDTM",
|
|
366
|
+
// "rootSymbol": "USDT",
|
|
367
|
+
// "type": "FFWCSX",
|
|
368
|
+
// "firstOpenDate": 1591086000000,
|
|
369
|
+
// "expireDate": null,
|
|
370
|
+
// "settleDate": null,
|
|
371
|
+
// "baseCurrency": "ETH",
|
|
372
|
+
// "quoteCurrency": "USDT",
|
|
373
|
+
// "settleCurrency": "USDT",
|
|
374
|
+
// "maxOrderQty": 1000000,
|
|
375
|
+
// "maxPrice": 1000000.0000000000,
|
|
376
|
+
// "lotSize": 1,
|
|
377
|
+
// "tickSize": 0.05,
|
|
378
|
+
// "indexPriceTickSize": 0.01,
|
|
379
|
+
// "multiplier": 0.01,
|
|
380
|
+
// "initialMargin": 0.01,
|
|
381
|
+
// "maintainMargin": 0.005,
|
|
382
|
+
// "maxRiskLimit": 1000000,
|
|
383
|
+
// "minRiskLimit": 1000000,
|
|
384
|
+
// "riskStep": 500000,
|
|
385
|
+
// "makerFeeRate": 0.00020,
|
|
386
|
+
// "takerFeeRate": 0.00060,
|
|
387
|
+
// "takerFixFee": 0.0000000000,
|
|
388
|
+
// "makerFixFee": 0.0000000000,
|
|
389
|
+
// "settlementFee": null,
|
|
390
|
+
// "isDeleverage": true,
|
|
391
|
+
// "isQuanto": true,
|
|
392
|
+
// "isInverse": false,
|
|
393
|
+
// "markMethod": "FairPrice",
|
|
394
|
+
// "fairMethod": "FundingRate",
|
|
395
|
+
// "fundingBaseSymbol": ".ETHINT8H",
|
|
396
|
+
// "fundingQuoteSymbol": ".USDTINT8H",
|
|
397
|
+
// "fundingRateSymbol": ".ETHUSDTMFPI8H",
|
|
398
|
+
// "indexSymbol": ".KETHUSDT",
|
|
399
|
+
// "settlementSymbol": "",
|
|
400
|
+
// "status": "Open",
|
|
401
|
+
// "fundingFeeRate": 0.000535,
|
|
402
|
+
// "predictedFundingFeeRate": 0.002197,
|
|
403
|
+
// "openInterest": "8724443",
|
|
404
|
+
// "turnoverOf24h": 341156641.03354263,
|
|
405
|
+
// "volumeOf24h": 74833.54000000,
|
|
406
|
+
// "markPrice": 4534.07,
|
|
407
|
+
// "indexPrice":4531.92,
|
|
408
|
+
// "lastTradePrice": 4545.4500000000,
|
|
409
|
+
// "nextFundingRateTime": 25481884,
|
|
410
|
+
// "maxLeverage": 100,
|
|
411
|
+
// "sourceExchanges": [ "huobi", "Okex", "Binance", "Kucoin", "Poloniex", "Hitbtc" ],
|
|
412
|
+
// "premiumsSymbol1M": ".ETHUSDTMPI",
|
|
413
|
+
// "premiumsSymbol8H": ".ETHUSDTMPI8H",
|
|
414
|
+
// "fundingBaseSymbol1M": ".ETHINT",
|
|
415
|
+
// "fundingQuoteSymbol1M": ".USDTINT",
|
|
416
|
+
// "lowPrice": 4456.90,
|
|
417
|
+
// "highPrice": 4674.25,
|
|
418
|
+
// "priceChgPct": 0.0046,
|
|
419
|
+
// "priceChg": 21.15
|
|
420
|
+
// }
|
|
421
|
+
// }
|
|
422
|
+
//
|
|
423
|
+
const result = [];
|
|
424
|
+
const data = this.safeValue(response, 'data', []);
|
|
425
|
+
for (let i = 0; i < data.length; i++) {
|
|
426
|
+
const market = data[i];
|
|
427
|
+
const id = this.safeString(market, 'symbol');
|
|
428
|
+
const expiry = this.safeInteger(market, 'expireDate');
|
|
429
|
+
const future = expiry ? true : false;
|
|
430
|
+
const swap = !future;
|
|
431
|
+
const baseId = this.safeString(market, 'baseCurrency');
|
|
432
|
+
const quoteId = this.safeString(market, 'quoteCurrency');
|
|
433
|
+
const settleId = this.safeString(market, 'settleCurrency');
|
|
434
|
+
const base = this.safeCurrencyCode(baseId);
|
|
435
|
+
const quote = this.safeCurrencyCode(quoteId);
|
|
436
|
+
const settle = this.safeCurrencyCode(settleId);
|
|
437
|
+
let symbol = base + '/' + quote + ':' + settle;
|
|
438
|
+
let type = 'swap';
|
|
439
|
+
if (future) {
|
|
440
|
+
symbol = symbol + '-' + this.yymmdd(expiry, '');
|
|
441
|
+
type = 'future';
|
|
442
|
+
}
|
|
443
|
+
const inverse = this.safeValue(market, 'isInverse');
|
|
444
|
+
const status = this.safeString(market, 'status');
|
|
445
|
+
const multiplier = this.safeString(market, 'multiplier');
|
|
446
|
+
const tickSize = this.safeNumber(market, 'tickSize');
|
|
447
|
+
const lotSize = this.safeNumber(market, 'lotSize');
|
|
448
|
+
let limitAmountMin = lotSize;
|
|
449
|
+
if (limitAmountMin === undefined) {
|
|
450
|
+
limitAmountMin = this.safeNumber(market, 'baseMinSize');
|
|
451
|
+
}
|
|
452
|
+
let limitAmountMax = this.safeNumber(market, 'maxOrderQty');
|
|
453
|
+
if (limitAmountMax === undefined) {
|
|
454
|
+
limitAmountMax = this.safeNumber(market, 'baseMaxSize');
|
|
455
|
+
}
|
|
456
|
+
let limitPriceMax = this.safeNumber(market, 'maxPrice');
|
|
457
|
+
if (limitPriceMax === undefined) {
|
|
458
|
+
const baseMinSizeString = this.safeString(market, 'baseMinSize');
|
|
459
|
+
const quoteMaxSizeString = this.safeString(market, 'quoteMaxSize');
|
|
460
|
+
limitPriceMax = this.parseNumber(Precise["default"].stringDiv(quoteMaxSizeString, baseMinSizeString));
|
|
461
|
+
}
|
|
462
|
+
result.push({
|
|
463
|
+
'id': id,
|
|
464
|
+
'symbol': symbol,
|
|
465
|
+
'base': base,
|
|
466
|
+
'quote': quote,
|
|
467
|
+
'settle': settle,
|
|
468
|
+
'baseId': baseId,
|
|
469
|
+
'quoteId': quoteId,
|
|
470
|
+
'settleId': settleId,
|
|
471
|
+
'type': type,
|
|
472
|
+
'spot': false,
|
|
473
|
+
'margin': false,
|
|
474
|
+
'swap': swap,
|
|
475
|
+
'future': future,
|
|
476
|
+
'option': false,
|
|
477
|
+
'active': (status === 'Open'),
|
|
478
|
+
'contract': true,
|
|
479
|
+
'linear': !inverse,
|
|
480
|
+
'inverse': inverse,
|
|
481
|
+
'taker': this.safeNumber(market, 'takerFeeRate'),
|
|
482
|
+
'maker': this.safeNumber(market, 'makerFeeRate'),
|
|
483
|
+
'contractSize': this.parseNumber(Precise["default"].stringAbs(multiplier)),
|
|
484
|
+
'expiry': expiry,
|
|
485
|
+
'expiryDatetime': this.iso8601(expiry),
|
|
486
|
+
'strike': undefined,
|
|
487
|
+
'optionType': undefined,
|
|
488
|
+
'precision': {
|
|
489
|
+
'amount': lotSize,
|
|
490
|
+
'price': tickSize,
|
|
491
|
+
},
|
|
492
|
+
'limits': {
|
|
493
|
+
'leverage': {
|
|
494
|
+
'min': this.parseNumber('1'),
|
|
495
|
+
'max': this.safeNumber(market, 'maxLeverage'),
|
|
496
|
+
},
|
|
497
|
+
'amount': {
|
|
498
|
+
'min': limitAmountMin,
|
|
499
|
+
'max': limitAmountMax,
|
|
500
|
+
},
|
|
501
|
+
'price': {
|
|
502
|
+
'min': tickSize,
|
|
503
|
+
'max': limitPriceMax,
|
|
504
|
+
},
|
|
505
|
+
'cost': {
|
|
506
|
+
'min': this.safeNumber(market, 'quoteMinSize'),
|
|
507
|
+
'max': this.safeNumber(market, 'quoteMaxSize'),
|
|
508
|
+
},
|
|
509
|
+
},
|
|
510
|
+
'created': this.safeInteger(market, 'firstOpenDate'),
|
|
511
|
+
'info': market,
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
return result;
|
|
515
|
+
}
|
|
516
|
+
async fetchTime(params = {}) {
|
|
517
|
+
/**
|
|
518
|
+
* @method
|
|
519
|
+
* @name kucoinfutures#fetchTime
|
|
520
|
+
* @description fetches the current integer timestamp in milliseconds from the exchange server
|
|
521
|
+
* @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-server-time
|
|
522
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
523
|
+
* @returns {int} the current integer timestamp in milliseconds from the exchange server
|
|
524
|
+
*/
|
|
525
|
+
const response = await this.futuresPublicGetTimestamp(params);
|
|
526
|
+
//
|
|
527
|
+
// {
|
|
528
|
+
// "code": "200000",
|
|
529
|
+
// "data": 1637385119302,
|
|
530
|
+
// }
|
|
531
|
+
//
|
|
532
|
+
return this.safeInteger(response, 'data');
|
|
533
|
+
}
|
|
534
|
+
async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
|
|
535
|
+
/**
|
|
536
|
+
* @method
|
|
537
|
+
* @name kucoinfutures#fetchOHLCV
|
|
538
|
+
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
|
|
539
|
+
* @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-klines
|
|
540
|
+
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
|
|
541
|
+
* @param {string} timeframe the length of time each candle represents
|
|
542
|
+
* @param {int} [since] timestamp in ms of the earliest candle to fetch
|
|
543
|
+
* @param {int} [limit] the maximum amount of candles to fetch
|
|
544
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
545
|
+
* @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)
|
|
546
|
+
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
|
|
547
|
+
*/
|
|
548
|
+
await this.loadMarkets();
|
|
549
|
+
let paginate = false;
|
|
550
|
+
[paginate, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'paginate');
|
|
551
|
+
if (paginate) {
|
|
552
|
+
return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 200);
|
|
553
|
+
}
|
|
554
|
+
const market = this.market(symbol);
|
|
555
|
+
const marketId = market['id'];
|
|
556
|
+
const parsedTimeframe = this.safeInteger(this.timeframes, timeframe);
|
|
557
|
+
const request = {
|
|
558
|
+
'symbol': marketId,
|
|
559
|
+
};
|
|
560
|
+
if (parsedTimeframe !== undefined) {
|
|
561
|
+
request['granularity'] = parsedTimeframe;
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
request['granularity'] = timeframe;
|
|
565
|
+
}
|
|
566
|
+
const duration = this.parseTimeframe(timeframe) * 1000;
|
|
567
|
+
let endAt = this.milliseconds();
|
|
568
|
+
if (since !== undefined) {
|
|
569
|
+
request['from'] = since;
|
|
570
|
+
if (limit === undefined) {
|
|
571
|
+
limit = this.safeInteger(this.options, 'fetchOHLCVLimit', 200);
|
|
572
|
+
}
|
|
573
|
+
endAt = this.sum(since, limit * duration);
|
|
574
|
+
}
|
|
575
|
+
else if (limit !== undefined) {
|
|
576
|
+
since = endAt - limit * duration;
|
|
577
|
+
request['from'] = since;
|
|
578
|
+
}
|
|
579
|
+
request['to'] = endAt;
|
|
580
|
+
const response = await this.futuresPublicGetKlineQuery(this.extend(request, params));
|
|
581
|
+
//
|
|
582
|
+
// {
|
|
583
|
+
// "code": "200000",
|
|
584
|
+
// "data": [
|
|
585
|
+
// [1636459200000, 4779.3, 4792.1, 4768.7, 4770.3, 78051],
|
|
586
|
+
// [1636460100000, 4770.25, 4778.55, 4757.55, 4777.25, 80164],
|
|
587
|
+
// [1636461000000, 4777.25, 4791.45, 4774.5, 4791.3, 51555]
|
|
588
|
+
// ]
|
|
589
|
+
// }
|
|
590
|
+
//
|
|
591
|
+
const data = this.safeValue(response, 'data', []);
|
|
592
|
+
return this.parseOHLCVs(data, market, timeframe, since, limit);
|
|
593
|
+
}
|
|
594
|
+
parseOHLCV(ohlcv, market = undefined) {
|
|
595
|
+
//
|
|
596
|
+
// [
|
|
597
|
+
// "1545904980000", // Start time of the candle cycle
|
|
598
|
+
// "0.058", // opening price
|
|
599
|
+
// "0.049", // closing price
|
|
600
|
+
// "0.058", // highest price
|
|
601
|
+
// "0.049", // lowest price
|
|
602
|
+
// "0.018", // base volume
|
|
603
|
+
// "0.000945", // quote volume
|
|
604
|
+
// ]
|
|
605
|
+
//
|
|
606
|
+
return [
|
|
607
|
+
this.safeInteger(ohlcv, 0),
|
|
608
|
+
this.safeNumber(ohlcv, 1),
|
|
609
|
+
this.safeNumber(ohlcv, 2),
|
|
610
|
+
this.safeNumber(ohlcv, 3),
|
|
611
|
+
this.safeNumber(ohlcv, 4),
|
|
612
|
+
this.safeNumber(ohlcv, 5),
|
|
613
|
+
];
|
|
614
|
+
}
|
|
615
|
+
async fetchDepositAddress(code, params = {}) {
|
|
616
|
+
/**
|
|
617
|
+
* @method
|
|
618
|
+
* @name kucoinfutures#fetchDepositAddress
|
|
619
|
+
* @description fetch the deposit address for a currency associated with this account
|
|
620
|
+
* @see https://www.kucoin.com/docs/rest/funding/deposit/get-deposit-address
|
|
621
|
+
* @param {string} code unified currency code
|
|
622
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
623
|
+
* @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
|
|
624
|
+
*/
|
|
625
|
+
await this.loadMarkets();
|
|
626
|
+
const currency = this.currency(code);
|
|
627
|
+
const currencyId = currency['id'];
|
|
628
|
+
const request = {
|
|
629
|
+
'currency': currencyId, // Currency,including XBT,USDT
|
|
630
|
+
};
|
|
631
|
+
const response = await this.futuresPrivateGetDepositAddress(this.extend(request, params));
|
|
632
|
+
//
|
|
633
|
+
// {
|
|
634
|
+
// "code": "200000",
|
|
635
|
+
// "data": {
|
|
636
|
+
// "address": "0x78d3ad1c0aa1bf068e19c94a2d7b16c9c0fcd8b1",//Deposit address
|
|
637
|
+
// "memo": null//Address tag. If the returned value is null, it means that the requested token has no memo. If you are to transfer funds from another platform to KuCoin Futures and if the token to be //transferred has memo(tag), you need to fill in the memo to ensure the transferred funds will be sent //to the address you specified.
|
|
638
|
+
// }
|
|
639
|
+
// }
|
|
640
|
+
//
|
|
641
|
+
const data = this.safeValue(response, 'data', {});
|
|
642
|
+
const address = this.safeString(data, 'address');
|
|
643
|
+
if (currencyId !== 'NIM') {
|
|
644
|
+
// contains spaces
|
|
645
|
+
this.checkAddress(address);
|
|
646
|
+
}
|
|
647
|
+
return {
|
|
648
|
+
'info': response,
|
|
649
|
+
'currency': currencyId,
|
|
650
|
+
'address': address,
|
|
651
|
+
'tag': this.safeString(data, 'memo'),
|
|
652
|
+
'network': this.safeString(data, 'chain'),
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
async fetchOrderBook(symbol, limit = undefined, params = {}) {
|
|
656
|
+
/**
|
|
657
|
+
* @method
|
|
658
|
+
* @name kucoinfutures#fetchOrderBook
|
|
659
|
+
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
|
|
660
|
+
* @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-part-order-book-level-2
|
|
661
|
+
* @param {string} symbol unified symbol of the market to fetch the order book for
|
|
662
|
+
* @param {int} [limit] the maximum amount of order book entries to return
|
|
663
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
664
|
+
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
|
|
665
|
+
*/
|
|
666
|
+
await this.loadMarkets();
|
|
667
|
+
const level = this.safeNumber(params, 'level');
|
|
668
|
+
if (level !== 2 && level !== undefined) {
|
|
669
|
+
throw new errors.BadRequest(this.id + ' fetchOrderBook() can only return level 2');
|
|
670
|
+
}
|
|
671
|
+
const market = this.market(symbol);
|
|
672
|
+
const request = {
|
|
673
|
+
'symbol': market['id'],
|
|
674
|
+
};
|
|
675
|
+
if (limit !== undefined) {
|
|
676
|
+
if ((limit === 20) || (limit === 100)) {
|
|
677
|
+
request['limit'] = limit;
|
|
678
|
+
}
|
|
679
|
+
else {
|
|
680
|
+
throw new errors.BadRequest(this.id + ' fetchOrderBook() limit argument must be 20 or 100');
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
else {
|
|
684
|
+
request['limit'] = 20;
|
|
685
|
+
}
|
|
686
|
+
const response = await this.futuresPublicGetLevel2DepthLimit(this.extend(request, params));
|
|
687
|
+
//
|
|
688
|
+
// {
|
|
689
|
+
// "code": "200000",
|
|
690
|
+
// "data": {
|
|
691
|
+
// "symbol": "XBTUSDM", //Symbol
|
|
692
|
+
// "sequence": 100, //Ticker sequence number
|
|
693
|
+
// "asks": [
|
|
694
|
+
// ["5000.0", 1000], //Price, quantity
|
|
695
|
+
// ["6000.0", 1983] //Price, quantity
|
|
696
|
+
// ],
|
|
697
|
+
// "bids": [
|
|
698
|
+
// ["3200.0", 800], //Price, quantity
|
|
699
|
+
// ["3100.0", 100] //Price, quantity
|
|
700
|
+
// ],
|
|
701
|
+
// "ts": 1604643655040584408 // timestamp
|
|
702
|
+
// }
|
|
703
|
+
// }
|
|
704
|
+
//
|
|
705
|
+
const data = this.safeValue(response, 'data', {});
|
|
706
|
+
const timestamp = this.parseToInt(this.safeInteger(data, 'ts') / 1000000);
|
|
707
|
+
const orderbook = this.parseOrderBook(data, market['symbol'], timestamp, 'bids', 'asks', 0, 1);
|
|
708
|
+
orderbook['nonce'] = this.safeInteger(data, 'sequence');
|
|
709
|
+
return orderbook;
|
|
710
|
+
}
|
|
711
|
+
async fetchTicker(symbol, params = {}) {
|
|
712
|
+
/**
|
|
713
|
+
* @method
|
|
714
|
+
* @name kucoinfutures#fetchTicker
|
|
715
|
+
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
|
|
716
|
+
* @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-ticker
|
|
717
|
+
* @param {string} symbol unified symbol of the market to fetch the ticker for
|
|
718
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
719
|
+
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
|
|
720
|
+
*/
|
|
721
|
+
await this.loadMarkets();
|
|
722
|
+
const market = this.market(symbol);
|
|
723
|
+
const request = {
|
|
724
|
+
'symbol': market['id'],
|
|
725
|
+
};
|
|
726
|
+
const response = await this.futuresPublicGetTicker(this.extend(request, params));
|
|
727
|
+
//
|
|
728
|
+
// {
|
|
729
|
+
// "code": "200000",
|
|
730
|
+
// "data": {
|
|
731
|
+
// "sequence": 1638444978558,
|
|
732
|
+
// "symbol": "ETHUSDTM",
|
|
733
|
+
// "side": "sell",
|
|
734
|
+
// "size": 4,
|
|
735
|
+
// "price": "4229.35",
|
|
736
|
+
// "bestBidSize": 2160,
|
|
737
|
+
// "bestBidPrice": "4229.0",
|
|
738
|
+
// "bestAskPrice": "4229.05",
|
|
739
|
+
// "tradeId": "61aaa8b777a0c43055fe4851",
|
|
740
|
+
// "ts": 1638574296209786785,
|
|
741
|
+
// "bestAskSize": 36,
|
|
742
|
+
// }
|
|
743
|
+
// }
|
|
744
|
+
//
|
|
745
|
+
return this.parseTicker(response['data'], market);
|
|
746
|
+
}
|
|
747
|
+
parseTicker(ticker, market = undefined) {
|
|
748
|
+
//
|
|
749
|
+
// {
|
|
750
|
+
// "code": "200000",
|
|
751
|
+
// "data": {
|
|
752
|
+
// "sequence": 1629930362547,
|
|
753
|
+
// "symbol": "ETHUSDTM",
|
|
754
|
+
// "side": "buy",
|
|
755
|
+
// "size": 130,
|
|
756
|
+
// "price": "4724.7",
|
|
757
|
+
// "bestBidSize": 5,
|
|
758
|
+
// "bestBidPrice": "4724.6",
|
|
759
|
+
// "bestAskPrice": "4724.65",
|
|
760
|
+
// "tradeId": "618d2a5a77a0c4431d2335f4",
|
|
761
|
+
// "ts": 1636641371963227600,
|
|
762
|
+
// "bestAskSize": 1789
|
|
763
|
+
// }
|
|
764
|
+
// }
|
|
765
|
+
//
|
|
766
|
+
const last = this.safeString(ticker, 'price');
|
|
767
|
+
const marketId = this.safeString(ticker, 'symbol');
|
|
768
|
+
market = this.safeMarket(marketId, market, '-');
|
|
769
|
+
const timestamp = this.safeIntegerProduct(ticker, 'ts', 0.000001);
|
|
770
|
+
return this.safeTicker({
|
|
771
|
+
'symbol': market['symbol'],
|
|
772
|
+
'timestamp': timestamp,
|
|
773
|
+
'datetime': this.iso8601(timestamp),
|
|
774
|
+
'high': undefined,
|
|
775
|
+
'low': undefined,
|
|
776
|
+
'bid': this.safeString(ticker, 'bestBidPrice'),
|
|
777
|
+
'bidVolume': this.safeString(ticker, 'bestBidSize'),
|
|
778
|
+
'ask': this.safeString(ticker, 'bestAskPrice'),
|
|
779
|
+
'askVolume': this.safeString(ticker, 'bestAskSize'),
|
|
780
|
+
'vwap': undefined,
|
|
781
|
+
'open': undefined,
|
|
782
|
+
'close': last,
|
|
783
|
+
'last': last,
|
|
784
|
+
'previousClose': undefined,
|
|
785
|
+
'change': undefined,
|
|
786
|
+
'percentage': undefined,
|
|
787
|
+
'average': undefined,
|
|
788
|
+
'baseVolume': undefined,
|
|
789
|
+
'quoteVolume': undefined,
|
|
790
|
+
'info': ticker,
|
|
791
|
+
}, market);
|
|
792
|
+
}
|
|
793
|
+
async fetchFundingHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
794
|
+
/**
|
|
795
|
+
* @method
|
|
796
|
+
* @name kucoinfutures#fetchFundingHistory
|
|
797
|
+
* @description fetch the history of funding payments paid and received on this account
|
|
798
|
+
* @see https://www.kucoin.com/docs/rest/futures-trading/funding-fees/get-funding-history
|
|
799
|
+
* @param {string} symbol unified market symbol
|
|
800
|
+
* @param {int} [since] the earliest time in ms to fetch funding history for
|
|
801
|
+
* @param {int} [limit] the maximum number of funding history structures to retrieve
|
|
802
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
803
|
+
* @returns {object} a [funding history structure]{@link https://docs.ccxt.com/#/?id=funding-history-structure}
|
|
804
|
+
*/
|
|
805
|
+
if (symbol === undefined) {
|
|
806
|
+
throw new errors.ArgumentsRequired(this.id + ' fetchFundingHistory() requires a symbol argument');
|
|
807
|
+
}
|
|
808
|
+
await this.loadMarkets();
|
|
809
|
+
const market = this.market(symbol);
|
|
810
|
+
const request = {
|
|
811
|
+
'symbol': market['id'],
|
|
812
|
+
};
|
|
813
|
+
if (since !== undefined) {
|
|
814
|
+
request['startAt'] = since;
|
|
815
|
+
}
|
|
816
|
+
if (limit !== undefined) {
|
|
817
|
+
// * Since is ignored if limit is defined
|
|
818
|
+
request['maxCount'] = limit;
|
|
819
|
+
}
|
|
820
|
+
const response = await this.futuresPrivateGetFundingHistory(this.extend(request, params));
|
|
821
|
+
//
|
|
822
|
+
// {
|
|
823
|
+
// "code": "200000",
|
|
824
|
+
// "data": {
|
|
825
|
+
// "dataList": [
|
|
826
|
+
// {
|
|
827
|
+
// "id": 239471298749817,
|
|
828
|
+
// "symbol": "ETHUSDTM",
|
|
829
|
+
// "timePoint": 1638532800000,
|
|
830
|
+
// "fundingRate": 0.000100,
|
|
831
|
+
// "markPrice": 4612.8300000000,
|
|
832
|
+
// "positionQty": 12,
|
|
833
|
+
// "positionCost": 553.5396000000,
|
|
834
|
+
// "funding": -0.0553539600,
|
|
835
|
+
// "settleCurrency": "USDT"
|
|
836
|
+
// },
|
|
837
|
+
// ...
|
|
838
|
+
// ],
|
|
839
|
+
// "hasMore": true
|
|
840
|
+
// }
|
|
841
|
+
// }
|
|
842
|
+
//
|
|
843
|
+
const data = this.safeValue(response, 'data');
|
|
844
|
+
const dataList = this.safeValue(data, 'dataList', []);
|
|
845
|
+
const fees = [];
|
|
846
|
+
for (let i = 0; i < dataList.length; i++) {
|
|
847
|
+
const listItem = dataList[i];
|
|
848
|
+
const timestamp = this.safeInteger(listItem, 'timePoint');
|
|
849
|
+
fees.push({
|
|
850
|
+
'info': listItem,
|
|
851
|
+
'symbol': symbol,
|
|
852
|
+
'code': this.safeCurrencyCode(this.safeString(listItem, 'settleCurrency')),
|
|
853
|
+
'timestamp': timestamp,
|
|
854
|
+
'datetime': this.iso8601(timestamp),
|
|
855
|
+
'id': this.safeNumber(listItem, 'id'),
|
|
856
|
+
'amount': this.safeNumber(listItem, 'funding'),
|
|
857
|
+
'fundingRate': this.safeNumber(listItem, 'fundingRate'),
|
|
858
|
+
'markPrice': this.safeNumber(listItem, 'markPrice'),
|
|
859
|
+
'positionQty': this.safeNumber(listItem, 'positionQty'),
|
|
860
|
+
'positionCost': this.safeNumber(listItem, 'positionCost'),
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
return fees;
|
|
864
|
+
}
|
|
865
|
+
async fetchPosition(symbol, params = {}) {
|
|
866
|
+
/**
|
|
867
|
+
* @method
|
|
868
|
+
* @name kucoinfutures#fetchPosition
|
|
869
|
+
* @see https://docs.kucoin.com/futures/#get-position-details
|
|
870
|
+
* @description fetch data on an open position
|
|
871
|
+
* @param {string} symbol unified market symbol of the market the position is held in
|
|
872
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
873
|
+
* @returns {object} a [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
|
|
874
|
+
*/
|
|
875
|
+
await this.loadMarkets();
|
|
876
|
+
const market = this.market(symbol);
|
|
877
|
+
const request = {
|
|
878
|
+
'symbol': market['id'],
|
|
879
|
+
};
|
|
880
|
+
const response = await this.futuresPrivateGetPosition(this.extend(request, params));
|
|
881
|
+
//
|
|
882
|
+
// {
|
|
883
|
+
// "code": "200000",
|
|
884
|
+
// "data": {
|
|
885
|
+
// "id": "6505ee6eaff4070001f651c4",
|
|
886
|
+
// "symbol": "XBTUSDTM",
|
|
887
|
+
// "autoDeposit": false,
|
|
888
|
+
// "maintMarginReq": 0,
|
|
889
|
+
// "riskLimit": 200,
|
|
890
|
+
// "realLeverage": 0.0,
|
|
891
|
+
// "crossMode": false,
|
|
892
|
+
// "delevPercentage": 0.0,
|
|
893
|
+
// "currentTimestamp": 1694887534594,
|
|
894
|
+
// "currentQty": 0,
|
|
895
|
+
// "currentCost": 0.0,
|
|
896
|
+
// "currentComm": 0.0,
|
|
897
|
+
// "unrealisedCost": 0.0,
|
|
898
|
+
// "realisedGrossCost": 0.0,
|
|
899
|
+
// "realisedCost": 0.0,
|
|
900
|
+
// "isOpen": false,
|
|
901
|
+
// "markPrice": 26611.71,
|
|
902
|
+
// "markValue": 0.0,
|
|
903
|
+
// "posCost": 0.0,
|
|
904
|
+
// "posCross": 0,
|
|
905
|
+
// "posInit": 0.0,
|
|
906
|
+
// "posComm": 0.0,
|
|
907
|
+
// "posLoss": 0.0,
|
|
908
|
+
// "posMargin": 0.0,
|
|
909
|
+
// "posMaint": 0.0,
|
|
910
|
+
// "maintMargin": 0.0,
|
|
911
|
+
// "realisedGrossPnl": 0.0,
|
|
912
|
+
// "realisedPnl": 0.0,
|
|
913
|
+
// "unrealisedPnl": 0.0,
|
|
914
|
+
// "unrealisedPnlPcnt": 0,
|
|
915
|
+
// "unrealisedRoePcnt": 0,
|
|
916
|
+
// "avgEntryPrice": 0.0,
|
|
917
|
+
// "liquidationPrice": 0.0,
|
|
918
|
+
// "bankruptPrice": 0.0,
|
|
919
|
+
// "settleCurrency": "USDT",
|
|
920
|
+
// "maintainMargin": 0,
|
|
921
|
+
// "riskLimitLevel": 1
|
|
922
|
+
// }
|
|
923
|
+
// }
|
|
924
|
+
//
|
|
925
|
+
const data = this.safeValue(response, 'data', {});
|
|
926
|
+
return this.parsePosition(data, market);
|
|
927
|
+
}
|
|
928
|
+
async fetchPositions(symbols = undefined, params = {}) {
|
|
929
|
+
/**
|
|
930
|
+
* @method
|
|
931
|
+
* @name kucoinfutures#fetchPositions
|
|
932
|
+
* @description fetch all open positions
|
|
933
|
+
* @see https://docs.kucoin.com/futures/#get-position-list
|
|
934
|
+
* @param {string[]|undefined} symbols list of unified market symbols
|
|
935
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
936
|
+
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
|
|
937
|
+
*/
|
|
938
|
+
await this.loadMarkets();
|
|
939
|
+
const response = await this.futuresPrivateGetPositions(params);
|
|
940
|
+
//
|
|
941
|
+
// {
|
|
942
|
+
// "code": "200000",
|
|
943
|
+
// "data": [
|
|
944
|
+
// {
|
|
945
|
+
// "id": "615ba79f83a3410001cde321",
|
|
946
|
+
// "symbol": "ETHUSDTM",
|
|
947
|
+
// "autoDeposit": false,
|
|
948
|
+
// "maintMarginReq": 0.005,
|
|
949
|
+
// "riskLimit": 1000000,
|
|
950
|
+
// "realLeverage": 18.61,
|
|
951
|
+
// "crossMode": false,
|
|
952
|
+
// "delevPercentage": 0.86,
|
|
953
|
+
// "openingTimestamp": 1638563515618,
|
|
954
|
+
// "currentTimestamp": 1638576872774,
|
|
955
|
+
// "currentQty": 2,
|
|
956
|
+
// "currentCost": 83.64200000,
|
|
957
|
+
// "currentComm": 0.05018520,
|
|
958
|
+
// "unrealisedCost": 83.64200000,
|
|
959
|
+
// "realisedGrossCost": 0.00000000,
|
|
960
|
+
// "realisedCost": 0.05018520,
|
|
961
|
+
// "isOpen": true,
|
|
962
|
+
// "markPrice": 4225.01,
|
|
963
|
+
// "markValue": 84.50020000,
|
|
964
|
+
// "posCost": 83.64200000,
|
|
965
|
+
// "posCross": 0.0000000000,
|
|
966
|
+
// "posInit": 3.63660870,
|
|
967
|
+
// "posComm": 0.05236717,
|
|
968
|
+
// "posLoss": 0.00000000,
|
|
969
|
+
// "posMargin": 3.68897586,
|
|
970
|
+
// "posMaint": 0.50637594,
|
|
971
|
+
// "maintMargin": 4.54717586,
|
|
972
|
+
// "realisedGrossPnl": 0.00000000,
|
|
973
|
+
// "realisedPnl": -0.05018520,
|
|
974
|
+
// "unrealisedPnl": 0.85820000,
|
|
975
|
+
// "unrealisedPnlPcnt": 0.0103,
|
|
976
|
+
// "unrealisedRoePcnt": 0.2360,
|
|
977
|
+
// "avgEntryPrice": 4182.10,
|
|
978
|
+
// "liquidationPrice": 4023.00,
|
|
979
|
+
// "bankruptPrice": 4000.25,
|
|
980
|
+
// "settleCurrency": "USDT",
|
|
981
|
+
// "isInverse": false
|
|
982
|
+
// }
|
|
983
|
+
// ]
|
|
984
|
+
// }
|
|
985
|
+
//
|
|
986
|
+
const data = this.safeValue(response, 'data');
|
|
987
|
+
return this.parsePositions(data, symbols);
|
|
988
|
+
}
|
|
989
|
+
parsePosition(position, market = undefined) {
|
|
990
|
+
//
|
|
991
|
+
// {
|
|
992
|
+
// "code": "200000",
|
|
993
|
+
// "data": [
|
|
994
|
+
// {
|
|
995
|
+
// "id": "615ba79f83a3410001cde321", // Position ID
|
|
996
|
+
// "symbol": "ETHUSDTM", // Symbol
|
|
997
|
+
// "autoDeposit": false, // Auto deposit margin or not
|
|
998
|
+
// "maintMarginReq": 0.005, // Maintenance margin requirement
|
|
999
|
+
// "riskLimit": 1000000, // Risk limit
|
|
1000
|
+
// "realLeverage": 25.92, // Leverage of the order
|
|
1001
|
+
// "crossMode": false, // Cross mode or not
|
|
1002
|
+
// "delevPercentage": 0.76, // ADL ranking percentile
|
|
1003
|
+
// "openingTimestamp": 1638578546031, // Open time
|
|
1004
|
+
// "currentTimestamp": 1638578563580, // Current timestamp
|
|
1005
|
+
// "currentQty": 2, // Current postion quantity
|
|
1006
|
+
// "currentCost": 83.787, // Current postion value
|
|
1007
|
+
// "currentComm": 0.0167574, // Current commission
|
|
1008
|
+
// "unrealisedCost": 83.787, // Unrealised value
|
|
1009
|
+
// "realisedGrossCost": 0.0, // Accumulated realised gross profit value
|
|
1010
|
+
// "realisedCost": 0.0167574, // Current realised position value
|
|
1011
|
+
// "isOpen": true, // Opened position or not
|
|
1012
|
+
// "markPrice": 4183.38, // Mark price
|
|
1013
|
+
// "markValue": 83.6676, // Mark value
|
|
1014
|
+
// "posCost": 83.787, // Position value
|
|
1015
|
+
// "posCross": 0.0, // added margin
|
|
1016
|
+
// "posInit": 3.35148, // Leverage margin
|
|
1017
|
+
// "posComm": 0.05228309, // Bankruptcy cost
|
|
1018
|
+
// "posLoss": 0.0, // Funding fees paid out
|
|
1019
|
+
// "posMargin": 3.40376309, // Position margin
|
|
1020
|
+
// "posMaint": 0.50707892, // Maintenance margin
|
|
1021
|
+
// "maintMargin": 3.28436309, // Position margin
|
|
1022
|
+
// "realisedGrossPnl": 0.0, // Accumulated realised gross profit value
|
|
1023
|
+
// "realisedPnl": -0.0167574, // Realised profit and loss
|
|
1024
|
+
// "unrealisedPnl": -0.1194, // Unrealised profit and loss
|
|
1025
|
+
// "unrealisedPnlPcnt": -0.0014, // Profit-loss ratio of the position
|
|
1026
|
+
// "unrealisedRoePcnt": -0.0356, // Rate of return on investment
|
|
1027
|
+
// "avgEntryPrice": 4189.35, // Average entry price
|
|
1028
|
+
// "liquidationPrice": 4044.55, // Liquidation price
|
|
1029
|
+
// "bankruptPrice": 4021.75, // Bankruptcy price
|
|
1030
|
+
// "settleCurrency": "USDT", // Currency used to clear and settle the trades
|
|
1031
|
+
// "isInverse": false
|
|
1032
|
+
// }
|
|
1033
|
+
// ]
|
|
1034
|
+
// }
|
|
1035
|
+
//
|
|
1036
|
+
const symbol = this.safeString(position, 'symbol');
|
|
1037
|
+
market = this.safeMarket(symbol, market);
|
|
1038
|
+
const timestamp = this.safeInteger(position, 'currentTimestamp');
|
|
1039
|
+
const size = this.safeString(position, 'currentQty');
|
|
1040
|
+
let side = undefined;
|
|
1041
|
+
if (Precise["default"].stringGt(size, '0')) {
|
|
1042
|
+
side = 'long';
|
|
1043
|
+
}
|
|
1044
|
+
else if (Precise["default"].stringLt(size, '0')) {
|
|
1045
|
+
side = 'short';
|
|
1046
|
+
}
|
|
1047
|
+
const notional = Precise["default"].stringAbs(this.safeString(position, 'posCost'));
|
|
1048
|
+
const initialMargin = this.safeString(position, 'posInit');
|
|
1049
|
+
const initialMarginPercentage = Precise["default"].stringDiv(initialMargin, notional);
|
|
1050
|
+
// const marginRatio = Precise.stringDiv (maintenanceRate, collateral);
|
|
1051
|
+
const unrealisedPnl = this.safeString(position, 'unrealisedPnl');
|
|
1052
|
+
const crossMode = this.safeValue(position, 'crossMode');
|
|
1053
|
+
// currently crossMode is always set to false and only isolated positions are supported
|
|
1054
|
+
const marginMode = crossMode ? 'cross' : 'isolated';
|
|
1055
|
+
return this.safePosition({
|
|
1056
|
+
'info': position,
|
|
1057
|
+
'id': this.safeString(position, 'id'),
|
|
1058
|
+
'symbol': this.safeString(market, 'symbol'),
|
|
1059
|
+
'timestamp': timestamp,
|
|
1060
|
+
'datetime': this.iso8601(timestamp),
|
|
1061
|
+
'lastUpdateTimestamp': undefined,
|
|
1062
|
+
'initialMargin': this.parseNumber(initialMargin),
|
|
1063
|
+
'initialMarginPercentage': this.parseNumber(initialMarginPercentage),
|
|
1064
|
+
'maintenanceMargin': this.safeNumber(position, 'posMaint'),
|
|
1065
|
+
'maintenanceMarginPercentage': this.safeNumber(position, 'maintMarginReq'),
|
|
1066
|
+
'entryPrice': this.safeNumber(position, 'avgEntryPrice'),
|
|
1067
|
+
'notional': this.parseNumber(notional),
|
|
1068
|
+
'leverage': this.safeNumber(position, 'realLeverage'),
|
|
1069
|
+
'unrealizedPnl': this.parseNumber(unrealisedPnl),
|
|
1070
|
+
'contracts': this.parseNumber(Precise["default"].stringAbs(size)),
|
|
1071
|
+
'contractSize': this.safeValue(market, 'contractSize'),
|
|
1072
|
+
'realizedPnl': this.safeNumber(position, 'realisedPnl'),
|
|
1073
|
+
'marginRatio': undefined,
|
|
1074
|
+
'liquidationPrice': this.safeNumber(position, 'liquidationPrice'),
|
|
1075
|
+
'markPrice': this.safeNumber(position, 'markPrice'),
|
|
1076
|
+
'lastPrice': undefined,
|
|
1077
|
+
'collateral': this.safeNumber(position, 'maintMargin'),
|
|
1078
|
+
'marginMode': marginMode,
|
|
1079
|
+
'side': side,
|
|
1080
|
+
'percentage': undefined,
|
|
1081
|
+
'stopLossPrice': undefined,
|
|
1082
|
+
'takeProfitPrice': undefined,
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
|
|
1086
|
+
/**
|
|
1087
|
+
* @method
|
|
1088
|
+
* @name kucoinfutures#createOrder
|
|
1089
|
+
* @description Create an order on the exchange
|
|
1090
|
+
* @see https://docs.kucoin.com/futures/#place-an-order
|
|
1091
|
+
* @param {string} symbol Unified CCXT market symbol
|
|
1092
|
+
* @param {string} type 'limit' or 'market'
|
|
1093
|
+
* @param {string} side 'buy' or 'sell'
|
|
1094
|
+
* @param {float} amount the amount of currency to trade
|
|
1095
|
+
* @param {float} [price] *ignored in "market" orders* the price at which the order is to be fullfilled at in units of the quote currency
|
|
1096
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1097
|
+
* @param {float} [params.triggerPrice] The price a trigger order is triggered at
|
|
1098
|
+
* @param {float} [params.stopLossPrice] price to trigger stop-loss orders
|
|
1099
|
+
* @param {float} [params.takeProfitPrice] price to trigger take-profit orders
|
|
1100
|
+
* @param {bool} [params.reduceOnly] A mark to reduce the position size only. Set to false by default. Need to set the position size when reduceOnly is true.
|
|
1101
|
+
* @param {string} [params.timeInForce] GTC, GTT, IOC, or FOK, default is GTC, limit orders only
|
|
1102
|
+
* @param {string} [params.postOnly] Post only flag, invalid when timeInForce is IOC or FOK
|
|
1103
|
+
* ----------------- Exchange Specific Parameters -----------------
|
|
1104
|
+
* @param {float} [params.leverage] Leverage size of the order
|
|
1105
|
+
* @param {string} [params.clientOid] client order id, defaults to uuid if not passed
|
|
1106
|
+
* @param {string} [params.remark] remark for the order, length cannot exceed 100 utf8 characters
|
|
1107
|
+
* @param {string} [params.stop] 'up' or 'down', the direction the stopPrice is triggered from, requires stopPrice. down: Triggers when the price reaches or goes below the stopPrice. up: Triggers when the price reaches or goes above the stopPrice.
|
|
1108
|
+
* @param {string} [params.stopPriceType] TP, IP or MP, defaults to MP: Mark Price
|
|
1109
|
+
* @param {bool} [params.closeOrder] set to true to close position
|
|
1110
|
+
* @param {bool} [params.test] set to true to use the test order endpoint (does not submit order, use to validate params)
|
|
1111
|
+
* @param {bool} [params.forceHold] A mark to forcely hold the funds for an order, even though it's an order to reduce the position size. This helps the order stay on the order book and not get canceled when the position size changes. Set to false by default.
|
|
1112
|
+
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1113
|
+
*/
|
|
1114
|
+
await this.loadMarkets();
|
|
1115
|
+
const market = this.market(symbol);
|
|
1116
|
+
// required param, cannot be used twice
|
|
1117
|
+
const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId', this.uuid());
|
|
1118
|
+
params = this.omit(params, ['clientOid', 'clientOrderId']);
|
|
1119
|
+
if (amount < 1) {
|
|
1120
|
+
throw new errors.InvalidOrder(this.id + ' createOrder() minimum contract order amount is 1');
|
|
1121
|
+
}
|
|
1122
|
+
const preciseAmount = parseInt(this.amountToPrecision(symbol, amount));
|
|
1123
|
+
const request = {
|
|
1124
|
+
'clientOid': clientOrderId,
|
|
1125
|
+
'side': side,
|
|
1126
|
+
'symbol': market['id'],
|
|
1127
|
+
'type': type,
|
|
1128
|
+
'size': preciseAmount,
|
|
1129
|
+
'leverage': 1,
|
|
1130
|
+
};
|
|
1131
|
+
const [triggerPrice, stopLossPrice, takeProfitPrice] = this.handleTriggerPrices(params);
|
|
1132
|
+
const triggerPriceTypes = {
|
|
1133
|
+
'mark': 'MP',
|
|
1134
|
+
'last': 'TP',
|
|
1135
|
+
'index': 'IP',
|
|
1136
|
+
};
|
|
1137
|
+
const triggerPriceType = this.safeString(params, 'triggerPriceType', 'mark');
|
|
1138
|
+
const triggerPriceTypeValue = this.safeString(triggerPriceTypes, triggerPriceType, triggerPriceType);
|
|
1139
|
+
params = this.omit(params, ['stopLossPrice', 'takeProfitPrice', 'triggerPrice', 'stopPrice']);
|
|
1140
|
+
if (triggerPrice) {
|
|
1141
|
+
request['stop'] = (side === 'buy') ? 'up' : 'down';
|
|
1142
|
+
request['stopPrice'] = this.priceToPrecision(symbol, triggerPrice);
|
|
1143
|
+
request['stopPriceType'] = triggerPriceTypeValue;
|
|
1144
|
+
}
|
|
1145
|
+
else if (stopLossPrice || takeProfitPrice) {
|
|
1146
|
+
if (stopLossPrice) {
|
|
1147
|
+
request['stop'] = (side === 'buy') ? 'up' : 'down';
|
|
1148
|
+
request['stopPrice'] = this.priceToPrecision(symbol, stopLossPrice);
|
|
1149
|
+
}
|
|
1150
|
+
else {
|
|
1151
|
+
request['stop'] = (side === 'buy') ? 'down' : 'up';
|
|
1152
|
+
request['stopPrice'] = this.priceToPrecision(symbol, takeProfitPrice);
|
|
1153
|
+
}
|
|
1154
|
+
request['reduceOnly'] = true;
|
|
1155
|
+
request['stopPriceType'] = triggerPriceTypeValue;
|
|
1156
|
+
}
|
|
1157
|
+
const uppercaseType = type.toUpperCase();
|
|
1158
|
+
const timeInForce = this.safeStringUpper(params, 'timeInForce');
|
|
1159
|
+
if (uppercaseType === 'LIMIT') {
|
|
1160
|
+
if (price === undefined) {
|
|
1161
|
+
throw new errors.ArgumentsRequired(this.id + ' createOrder() requires a price argument for limit orders');
|
|
1162
|
+
}
|
|
1163
|
+
else {
|
|
1164
|
+
request['price'] = this.priceToPrecision(symbol, price);
|
|
1165
|
+
}
|
|
1166
|
+
if (timeInForce !== undefined) {
|
|
1167
|
+
request['timeInForce'] = timeInForce;
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
let postOnly = undefined;
|
|
1171
|
+
[postOnly, params] = this.handlePostOnly(type === 'market', false, params);
|
|
1172
|
+
if (postOnly) {
|
|
1173
|
+
request['postOnly'] = true;
|
|
1174
|
+
}
|
|
1175
|
+
const hidden = this.safeValue(params, 'hidden');
|
|
1176
|
+
if (postOnly && (hidden !== undefined)) {
|
|
1177
|
+
throw new errors.BadRequest(this.id + ' createOrder() does not support the postOnly parameter together with a hidden parameter');
|
|
1178
|
+
}
|
|
1179
|
+
const iceberg = this.safeValue(params, 'iceberg');
|
|
1180
|
+
if (iceberg) {
|
|
1181
|
+
const visibleSize = this.safeValue(params, 'visibleSize');
|
|
1182
|
+
if (visibleSize === undefined) {
|
|
1183
|
+
throw new errors.ArgumentsRequired(this.id + ' createOrder() requires a visibleSize parameter for iceberg orders');
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
params = this.omit(params, ['timeInForce', 'stopPrice', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice']); // Time in force only valid for limit orders, exchange error when gtc for market orders
|
|
1187
|
+
let response = undefined;
|
|
1188
|
+
const testOrder = this.safeValue(params, 'test', false);
|
|
1189
|
+
params = this.omit(params, 'test');
|
|
1190
|
+
if (testOrder) {
|
|
1191
|
+
response = await this.futuresPrivatePostOrdersTest(this.extend(request, params));
|
|
1192
|
+
}
|
|
1193
|
+
else {
|
|
1194
|
+
response = await this.futuresPrivatePostOrders(this.extend(request, params));
|
|
1195
|
+
}
|
|
1196
|
+
//
|
|
1197
|
+
// {
|
|
1198
|
+
// "code": "200000",
|
|
1199
|
+
// "data": {
|
|
1200
|
+
// "orderId": "619717484f1d010001510cde",
|
|
1201
|
+
// },
|
|
1202
|
+
// }
|
|
1203
|
+
//
|
|
1204
|
+
const data = this.safeValue(response, 'data', {});
|
|
1205
|
+
return this.safeOrder({
|
|
1206
|
+
'id': this.safeString(data, 'orderId'),
|
|
1207
|
+
'clientOrderId': undefined,
|
|
1208
|
+
'timestamp': undefined,
|
|
1209
|
+
'datetime': undefined,
|
|
1210
|
+
'lastTradeTimestamp': undefined,
|
|
1211
|
+
'symbol': undefined,
|
|
1212
|
+
'type': undefined,
|
|
1213
|
+
'side': undefined,
|
|
1214
|
+
'price': undefined,
|
|
1215
|
+
'amount': undefined,
|
|
1216
|
+
'cost': undefined,
|
|
1217
|
+
'average': undefined,
|
|
1218
|
+
'filled': undefined,
|
|
1219
|
+
'remaining': undefined,
|
|
1220
|
+
'status': undefined,
|
|
1221
|
+
'fee': undefined,
|
|
1222
|
+
'trades': undefined,
|
|
1223
|
+
'timeInForce': undefined,
|
|
1224
|
+
'postOnly': undefined,
|
|
1225
|
+
'stopPrice': undefined,
|
|
1226
|
+
'triggerPrice': undefined,
|
|
1227
|
+
'info': response,
|
|
1228
|
+
}, market);
|
|
1229
|
+
}
|
|
1230
|
+
async cancelOrder(id, symbol = undefined, params = {}) {
|
|
1231
|
+
/**
|
|
1232
|
+
* @method
|
|
1233
|
+
* @name kucoinfutures#cancelOrder
|
|
1234
|
+
* @description cancels an open order
|
|
1235
|
+
* @see https://www.kucoin.com/docs/rest/futures-trading/orders/cancel-futures-order-by-orderid
|
|
1236
|
+
* @param {string} id order id
|
|
1237
|
+
* @param {string} symbol unified symbol of the market the order was made in
|
|
1238
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1239
|
+
* @param {string} [params.clientOrderId] cancel order by client order id
|
|
1240
|
+
* @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1241
|
+
*/
|
|
1242
|
+
await this.loadMarkets();
|
|
1243
|
+
const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId');
|
|
1244
|
+
params = this.omit(params, ['clientOrderId']);
|
|
1245
|
+
const request = {};
|
|
1246
|
+
let response = undefined;
|
|
1247
|
+
if (clientOrderId !== undefined) {
|
|
1248
|
+
if (symbol === undefined) {
|
|
1249
|
+
throw new errors.ArgumentsRequired(this.id + ' cancelOrder() requires a symbol argument when cancelling by clientOrderId');
|
|
1250
|
+
}
|
|
1251
|
+
const market = this.market(symbol);
|
|
1252
|
+
request['symbol'] = market['id'];
|
|
1253
|
+
request['clientOid'] = clientOrderId;
|
|
1254
|
+
response = await this.futuresPrivateDeleteOrdersClientOrderClientOid(this.extend(request, params));
|
|
1255
|
+
}
|
|
1256
|
+
else {
|
|
1257
|
+
request['orderId'] = id;
|
|
1258
|
+
response = await this.futuresPrivateDeleteOrdersOrderId(this.extend(request, params));
|
|
1259
|
+
}
|
|
1260
|
+
//
|
|
1261
|
+
// {
|
|
1262
|
+
// "code": "200000",
|
|
1263
|
+
// "data": {
|
|
1264
|
+
// "cancelledOrderIds": [
|
|
1265
|
+
// "619714b8b6353000014c505a",
|
|
1266
|
+
// ],
|
|
1267
|
+
// },
|
|
1268
|
+
// }
|
|
1269
|
+
//
|
|
1270
|
+
return this.safeValue(response, 'data');
|
|
1271
|
+
}
|
|
1272
|
+
async cancelAllOrders(symbol = undefined, params = {}) {
|
|
1273
|
+
/**
|
|
1274
|
+
* @method
|
|
1275
|
+
* @name kucoinfutures#cancelAllOrders
|
|
1276
|
+
* @description cancel all open orders
|
|
1277
|
+
* @see https://www.kucoin.com/docs/rest/futures-trading/orders/cancel-multiple-futures-limit-orders
|
|
1278
|
+
* @see https://www.kucoin.com/docs/rest/futures-trading/orders/cancel-multiple-futures-stop-orders
|
|
1279
|
+
* @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
|
|
1280
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1281
|
+
* @param {object} [params.trigger] When true, all the trigger orders will be cancelled
|
|
1282
|
+
* @returns Response from the exchange
|
|
1283
|
+
*/
|
|
1284
|
+
await this.loadMarkets();
|
|
1285
|
+
const request = {};
|
|
1286
|
+
if (symbol !== undefined) {
|
|
1287
|
+
request['symbol'] = this.marketId(symbol);
|
|
1288
|
+
}
|
|
1289
|
+
const stop = this.safeValue2(params, 'stop', 'trigger');
|
|
1290
|
+
params = this.omit(params, ['stop', 'trigger']);
|
|
1291
|
+
let response = undefined;
|
|
1292
|
+
if (stop) {
|
|
1293
|
+
response = await this.futuresPrivateDeleteStopOrders(this.extend(request, params));
|
|
1294
|
+
}
|
|
1295
|
+
else {
|
|
1296
|
+
response = await this.futuresPrivateDeleteOrders(this.extend(request, params));
|
|
1297
|
+
}
|
|
1298
|
+
//
|
|
1299
|
+
// {
|
|
1300
|
+
// "code": "200000",
|
|
1301
|
+
// "data": {
|
|
1302
|
+
// "cancelledOrderIds": [
|
|
1303
|
+
// "619714b8b6353000014c505a",
|
|
1304
|
+
// ],
|
|
1305
|
+
// },
|
|
1306
|
+
// }
|
|
1307
|
+
//
|
|
1308
|
+
return this.safeValue(response, 'data');
|
|
1309
|
+
}
|
|
1310
|
+
async addMargin(symbol, amount, params = {}) {
|
|
1311
|
+
/**
|
|
1312
|
+
* @method
|
|
1313
|
+
* @name kucoinfutures#addMargin
|
|
1314
|
+
* @description add margin
|
|
1315
|
+
* @see https://www.kucoin.com/docs/rest/futures-trading/positions/add-margin-manually
|
|
1316
|
+
* @param {string} symbol unified market symbol
|
|
1317
|
+
* @param {float} amount amount of margin to add
|
|
1318
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1319
|
+
* @returns {object} a [margin structure]{@link https://docs.ccxt.com/#/?id=add-margin-structure}
|
|
1320
|
+
*/
|
|
1321
|
+
await this.loadMarkets();
|
|
1322
|
+
const market = this.market(symbol);
|
|
1323
|
+
const uuid = this.uuid();
|
|
1324
|
+
const request = {
|
|
1325
|
+
'symbol': market['id'],
|
|
1326
|
+
'margin': this.amountToPrecision(symbol, amount),
|
|
1327
|
+
'bizNo': uuid,
|
|
1328
|
+
};
|
|
1329
|
+
const response = await this.futuresPrivatePostPositionMarginDepositMargin(this.extend(request, params));
|
|
1330
|
+
//
|
|
1331
|
+
// {
|
|
1332
|
+
// "code": "200000",
|
|
1333
|
+
// "data": {
|
|
1334
|
+
// "id": "62311d26064e8f00013f2c6d",
|
|
1335
|
+
// "symbol": "XRPUSDTM",
|
|
1336
|
+
// "autoDeposit": false,
|
|
1337
|
+
// "maintMarginReq": 0.01,
|
|
1338
|
+
// "riskLimit": 200000,
|
|
1339
|
+
// "realLeverage": 0.88,
|
|
1340
|
+
// "crossMode": false,
|
|
1341
|
+
// "delevPercentage": 0.4,
|
|
1342
|
+
// "openingTimestamp": 1647385894798,
|
|
1343
|
+
// "currentTimestamp": 1647414510672,
|
|
1344
|
+
// "currentQty": -1,
|
|
1345
|
+
// "currentCost": -7.658,
|
|
1346
|
+
// "currentComm": 0.0053561,
|
|
1347
|
+
// "unrealisedCost": -7.658,
|
|
1348
|
+
// "realisedGrossCost": 0,
|
|
1349
|
+
// "realisedCost": 0.0053561,
|
|
1350
|
+
// "isOpen": true,
|
|
1351
|
+
// "markPrice": 0.7635,
|
|
1352
|
+
// "markValue": -7.635,
|
|
1353
|
+
// "posCost": -7.658,
|
|
1354
|
+
// "posCross": 1.00016084,
|
|
1355
|
+
// "posInit": 7.658,
|
|
1356
|
+
// "posComm": 0.00979006,
|
|
1357
|
+
// "posLoss": 0,
|
|
1358
|
+
// "posMargin": 8.6679509,
|
|
1359
|
+
// "posMaint": 0.08637006,
|
|
1360
|
+
// "maintMargin": 8.6909509,
|
|
1361
|
+
// "realisedGrossPnl": 0,
|
|
1362
|
+
// "realisedPnl": -0.0038335,
|
|
1363
|
+
// "unrealisedPnl": 0.023,
|
|
1364
|
+
// "unrealisedPnlPcnt": 0.003,
|
|
1365
|
+
// "unrealisedRoePcnt": 0.003,
|
|
1366
|
+
// "avgEntryPrice": 0.7658,
|
|
1367
|
+
// "liquidationPrice": 1.6239,
|
|
1368
|
+
// "bankruptPrice": 1.6317,
|
|
1369
|
+
// "settleCurrency": "USDT"
|
|
1370
|
+
// }
|
|
1371
|
+
// }
|
|
1372
|
+
//
|
|
1373
|
+
//
|
|
1374
|
+
// {
|
|
1375
|
+
// "code":"200000",
|
|
1376
|
+
// "msg":"Position does not exist"
|
|
1377
|
+
// }
|
|
1378
|
+
//
|
|
1379
|
+
const data = this.safeValue(response, 'data');
|
|
1380
|
+
return this.extend(this.parseMarginModification(data, market), {
|
|
1381
|
+
'amount': this.amountToPrecision(symbol, amount),
|
|
1382
|
+
'direction': 'in',
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
parseMarginModification(info, market = undefined) {
|
|
1386
|
+
//
|
|
1387
|
+
// {
|
|
1388
|
+
// "id": "62311d26064e8f00013f2c6d",
|
|
1389
|
+
// "symbol": "XRPUSDTM",
|
|
1390
|
+
// "autoDeposit": false,
|
|
1391
|
+
// "maintMarginReq": 0.01,
|
|
1392
|
+
// "riskLimit": 200000,
|
|
1393
|
+
// "realLeverage": 0.88,
|
|
1394
|
+
// "crossMode": false,
|
|
1395
|
+
// "delevPercentage": 0.4,
|
|
1396
|
+
// "openingTimestamp": 1647385894798,
|
|
1397
|
+
// "currentTimestamp": 1647414510672,
|
|
1398
|
+
// "currentQty": -1,
|
|
1399
|
+
// "currentCost": -7.658,
|
|
1400
|
+
// "currentComm": 0.0053561,
|
|
1401
|
+
// "unrealisedCost": -7.658,
|
|
1402
|
+
// "realisedGrossCost": 0,
|
|
1403
|
+
// "realisedCost": 0.0053561,
|
|
1404
|
+
// "isOpen": true,
|
|
1405
|
+
// "markPrice": 0.7635,
|
|
1406
|
+
// "markValue": -7.635,
|
|
1407
|
+
// "posCost": -7.658,
|
|
1408
|
+
// "posCross": 1.00016084,
|
|
1409
|
+
// "posInit": 7.658,
|
|
1410
|
+
// "posComm": 0.00979006,
|
|
1411
|
+
// "posLoss": 0,
|
|
1412
|
+
// "posMargin": 8.6679509,
|
|
1413
|
+
// "posMaint": 0.08637006,
|
|
1414
|
+
// "maintMargin": 8.6909509,
|
|
1415
|
+
// "realisedGrossPnl": 0,
|
|
1416
|
+
// "realisedPnl": -0.0038335,
|
|
1417
|
+
// "unrealisedPnl": 0.023,
|
|
1418
|
+
// "unrealisedPnlPcnt": 0.003,
|
|
1419
|
+
// "unrealisedRoePcnt": 0.003,
|
|
1420
|
+
// "avgEntryPrice": 0.7658,
|
|
1421
|
+
// "liquidationPrice": 1.6239,
|
|
1422
|
+
// "bankruptPrice": 1.6317,
|
|
1423
|
+
// "settleCurrency": "USDT"
|
|
1424
|
+
// }
|
|
1425
|
+
//
|
|
1426
|
+
// {
|
|
1427
|
+
// "code":"200000",
|
|
1428
|
+
// "msg":"Position does not exist"
|
|
1429
|
+
// }
|
|
1430
|
+
//
|
|
1431
|
+
const id = this.safeString(info, 'id');
|
|
1432
|
+
market = this.safeMarket(id, market);
|
|
1433
|
+
const currencyId = this.safeString(info, 'settleCurrency');
|
|
1434
|
+
const crossMode = this.safeValue(info, 'crossMode');
|
|
1435
|
+
const mode = crossMode ? 'cross' : 'isolated';
|
|
1436
|
+
const marketId = this.safeString(market, 'symbol');
|
|
1437
|
+
return {
|
|
1438
|
+
'info': info,
|
|
1439
|
+
'direction': undefined,
|
|
1440
|
+
'mode': mode,
|
|
1441
|
+
'amount': undefined,
|
|
1442
|
+
'code': this.safeCurrencyCode(currencyId),
|
|
1443
|
+
'symbol': this.safeSymbol(marketId, market),
|
|
1444
|
+
'status': undefined,
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
async fetchOrdersByStatus(status, symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1448
|
+
/**
|
|
1449
|
+
* @method
|
|
1450
|
+
* @name kucoinfutures#fetchOrdersByStatus
|
|
1451
|
+
* @description fetches a list of orders placed on the exchange
|
|
1452
|
+
* @see https://docs.kucoin.com/futures/#get-order-list
|
|
1453
|
+
* @see https://docs.kucoin.com/futures/#get-untriggered-stop-order-list
|
|
1454
|
+
* @param {string} status 'active' or 'closed', only 'active' is valid for stop orders
|
|
1455
|
+
* @param {string} symbol unified symbol for the market to retrieve orders from
|
|
1456
|
+
* @param {int} [since] timestamp in ms of the earliest order to retrieve
|
|
1457
|
+
* @param {int} [limit] The maximum number of orders to retrieve
|
|
1458
|
+
* @param {object} [params] exchange specific parameters
|
|
1459
|
+
* @param {bool} [params.trigger] set to true to retrieve untriggered stop orders
|
|
1460
|
+
* @param {int} [params.until] End time in ms
|
|
1461
|
+
* @param {string} [params.side] buy or sell
|
|
1462
|
+
* @param {string} [params.type] limit or market
|
|
1463
|
+
* @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)
|
|
1464
|
+
* @returns An [array of order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1465
|
+
*/
|
|
1466
|
+
await this.loadMarkets();
|
|
1467
|
+
let paginate = false;
|
|
1468
|
+
[paginate, params] = this.handleOptionAndParams(params, 'fetchOrdersByStatus', 'paginate');
|
|
1469
|
+
if (paginate) {
|
|
1470
|
+
return await this.fetchPaginatedCallDynamic('fetchOrdersByStatus', symbol, since, limit, params);
|
|
1471
|
+
}
|
|
1472
|
+
const stop = this.safeValue2(params, 'stop', 'trigger');
|
|
1473
|
+
const until = this.safeInteger2(params, 'until', 'till');
|
|
1474
|
+
params = this.omit(params, ['stop', 'until', 'till', 'trigger']);
|
|
1475
|
+
if (status === 'closed') {
|
|
1476
|
+
status = 'done';
|
|
1477
|
+
}
|
|
1478
|
+
else if (status === 'open') {
|
|
1479
|
+
status = 'active';
|
|
1480
|
+
}
|
|
1481
|
+
const request = {};
|
|
1482
|
+
if (!stop) {
|
|
1483
|
+
request['status'] = status;
|
|
1484
|
+
}
|
|
1485
|
+
else if (status !== 'active') {
|
|
1486
|
+
throw new errors.BadRequest(this.id + ' fetchOrdersByStatus() can only fetch untriggered stop orders');
|
|
1487
|
+
}
|
|
1488
|
+
let market = undefined;
|
|
1489
|
+
if (symbol !== undefined) {
|
|
1490
|
+
market = this.market(symbol);
|
|
1491
|
+
request['symbol'] = market['id'];
|
|
1492
|
+
}
|
|
1493
|
+
if (since !== undefined) {
|
|
1494
|
+
request['startAt'] = since;
|
|
1495
|
+
}
|
|
1496
|
+
if (until !== undefined) {
|
|
1497
|
+
request['endAt'] = until;
|
|
1498
|
+
}
|
|
1499
|
+
let response = undefined;
|
|
1500
|
+
if (stop) {
|
|
1501
|
+
response = await this.futuresPrivateGetStopOrders(this.extend(request, params));
|
|
1502
|
+
}
|
|
1503
|
+
else {
|
|
1504
|
+
response = await this.futuresPrivateGetOrders(this.extend(request, params));
|
|
1505
|
+
}
|
|
1506
|
+
//
|
|
1507
|
+
// {
|
|
1508
|
+
// "code": "200000",
|
|
1509
|
+
// "data": {
|
|
1510
|
+
// "currentPage": 1,
|
|
1511
|
+
// "pageSize": 50,
|
|
1512
|
+
// "totalNum": 4,
|
|
1513
|
+
// "totalPage": 1,
|
|
1514
|
+
// "items": [
|
|
1515
|
+
// {
|
|
1516
|
+
// "id": "64507d02921f1c0001ff6892",
|
|
1517
|
+
// "symbol": "XBTUSDTM",
|
|
1518
|
+
// "type": "market",
|
|
1519
|
+
// "side": "buy",
|
|
1520
|
+
// "price": null,
|
|
1521
|
+
// "size": 1,
|
|
1522
|
+
// "value": "27.992",
|
|
1523
|
+
// "dealValue": "27.992",
|
|
1524
|
+
// "dealSize": 1,
|
|
1525
|
+
// "stp": "",
|
|
1526
|
+
// "stop": "",
|
|
1527
|
+
// "stopPriceType": "",
|
|
1528
|
+
// "stopTriggered": false,
|
|
1529
|
+
// "stopPrice": null,
|
|
1530
|
+
// "timeInForce": "GTC",
|
|
1531
|
+
// "postOnly": false,
|
|
1532
|
+
// "hidden": false,
|
|
1533
|
+
// "iceberg": false,
|
|
1534
|
+
// "leverage": "17",
|
|
1535
|
+
// "forceHold": false,
|
|
1536
|
+
// "closeOrder": false,
|
|
1537
|
+
// "visibleSize": null,
|
|
1538
|
+
// "clientOid": null,
|
|
1539
|
+
// "remark": null,
|
|
1540
|
+
// "tags": null,
|
|
1541
|
+
// "isActive": false,
|
|
1542
|
+
// "cancelExist": false,
|
|
1543
|
+
// "createdAt": 1682996482000,
|
|
1544
|
+
// "updatedAt": 1682996483062,
|
|
1545
|
+
// "endAt": 1682996483062,
|
|
1546
|
+
// "orderTime": 1682996482953900677,
|
|
1547
|
+
// "settleCurrency": "USDT",
|
|
1548
|
+
// "status": "done",
|
|
1549
|
+
// "filledValue": "27.992",
|
|
1550
|
+
// "filledSize": 1,
|
|
1551
|
+
// "reduceOnly": false
|
|
1552
|
+
// }
|
|
1553
|
+
// ]
|
|
1554
|
+
// }
|
|
1555
|
+
// }
|
|
1556
|
+
//
|
|
1557
|
+
const responseData = this.safeValue(response, 'data', {});
|
|
1558
|
+
const orders = this.safeValue(responseData, 'items', []);
|
|
1559
|
+
return this.parseOrders(orders, market, since, limit);
|
|
1560
|
+
}
|
|
1561
|
+
async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1562
|
+
/**
|
|
1563
|
+
* @method
|
|
1564
|
+
* @name kucoinfutures#fetchClosedOrders
|
|
1565
|
+
* @description fetches information on multiple closed orders made by the user
|
|
1566
|
+
* @see https://docs.kucoin.com/futures/#get-order-list
|
|
1567
|
+
* @param {string} symbol unified market symbol of the market orders were made in
|
|
1568
|
+
* @param {int} [since] the earliest time in ms to fetch orders for
|
|
1569
|
+
* @param {int} [limit] the maximum number of order structures to retrieve
|
|
1570
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1571
|
+
* @param {int} [params.till] end time in ms
|
|
1572
|
+
* @param {string} [params.side] buy or sell
|
|
1573
|
+
* @param {string} [params.type] limit, or market
|
|
1574
|
+
* @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)
|
|
1575
|
+
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1576
|
+
*/
|
|
1577
|
+
await this.loadMarkets();
|
|
1578
|
+
let paginate = false;
|
|
1579
|
+
[paginate, params] = this.handleOptionAndParams(params, 'fetchClosedOrders', 'paginate');
|
|
1580
|
+
if (paginate) {
|
|
1581
|
+
return await this.fetchPaginatedCallDynamic('fetchClosedOrders', symbol, since, limit, params);
|
|
1582
|
+
}
|
|
1583
|
+
return await this.fetchOrdersByStatus('done', symbol, since, limit, params);
|
|
1584
|
+
}
|
|
1585
|
+
async fetchOrder(id = undefined, symbol = undefined, params = {}) {
|
|
1586
|
+
/**
|
|
1587
|
+
* @method
|
|
1588
|
+
* @name kucoinfutures#fetchOrder
|
|
1589
|
+
* @description fetches information on an order made by the user
|
|
1590
|
+
* @see https://docs.kucoin.com/futures/#get-details-of-a-single-order
|
|
1591
|
+
* @param {string} symbol unified symbol of the market the order was made in
|
|
1592
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1593
|
+
* @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1594
|
+
*/
|
|
1595
|
+
await this.loadMarkets();
|
|
1596
|
+
const request = {};
|
|
1597
|
+
let response = undefined;
|
|
1598
|
+
if (id === undefined) {
|
|
1599
|
+
const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId');
|
|
1600
|
+
if (clientOrderId === undefined) {
|
|
1601
|
+
throw new errors.InvalidOrder(this.id + ' fetchOrder() requires parameter id or params.clientOid');
|
|
1602
|
+
}
|
|
1603
|
+
request['clientOid'] = clientOrderId;
|
|
1604
|
+
params = this.omit(params, ['clientOid', 'clientOrderId']);
|
|
1605
|
+
response = await this.futuresPrivateGetOrdersByClientOid(this.extend(request, params));
|
|
1606
|
+
}
|
|
1607
|
+
else {
|
|
1608
|
+
request['orderId'] = id;
|
|
1609
|
+
response = await this.futuresPrivateGetOrdersOrderId(this.extend(request, params));
|
|
1610
|
+
}
|
|
1611
|
+
//
|
|
1612
|
+
// {
|
|
1613
|
+
// "code": "200000",
|
|
1614
|
+
// "data": {
|
|
1615
|
+
// "id": "64507d02921f1c0001ff6892",
|
|
1616
|
+
// "symbol": "XBTUSDTM",
|
|
1617
|
+
// "type": "market",
|
|
1618
|
+
// "side": "buy",
|
|
1619
|
+
// "price": null,
|
|
1620
|
+
// "size": 1,
|
|
1621
|
+
// "value": "27.992",
|
|
1622
|
+
// "dealValue": "27.992",
|
|
1623
|
+
// "dealSize": 1,
|
|
1624
|
+
// "stp": "",
|
|
1625
|
+
// "stop": "",
|
|
1626
|
+
// "stopPriceType": "",
|
|
1627
|
+
// "stopTriggered": false,
|
|
1628
|
+
// "stopPrice": null,
|
|
1629
|
+
// "timeInForce": "GTC",
|
|
1630
|
+
// "postOnly": false,
|
|
1631
|
+
// "hidden": false,
|
|
1632
|
+
// "iceberg": false,
|
|
1633
|
+
// "leverage": "17",
|
|
1634
|
+
// "forceHold": false,
|
|
1635
|
+
// "closeOrder": false,
|
|
1636
|
+
// "visibleSize": null,
|
|
1637
|
+
// "clientOid": null,
|
|
1638
|
+
// "remark": null,
|
|
1639
|
+
// "tags": null,
|
|
1640
|
+
// "isActive": false,
|
|
1641
|
+
// "cancelExist": false,
|
|
1642
|
+
// "createdAt": 1682996482000,
|
|
1643
|
+
// "updatedAt": 1682996483000,
|
|
1644
|
+
// "endAt": 1682996483000,
|
|
1645
|
+
// "orderTime": 1682996482953900677,
|
|
1646
|
+
// "settleCurrency": "USDT",
|
|
1647
|
+
// "status": "done",
|
|
1648
|
+
// "filledSize": 1,
|
|
1649
|
+
// "filledValue": "27.992",
|
|
1650
|
+
// "reduceOnly": false
|
|
1651
|
+
// }
|
|
1652
|
+
// }
|
|
1653
|
+
//
|
|
1654
|
+
const market = (symbol !== undefined) ? this.market(symbol) : undefined;
|
|
1655
|
+
const responseData = this.safeValue(response, 'data');
|
|
1656
|
+
return this.parseOrder(responseData, market);
|
|
1657
|
+
}
|
|
1658
|
+
parseOrder(order, market = undefined) {
|
|
1659
|
+
//
|
|
1660
|
+
// fetchOrder, fetchOrdersByStatus
|
|
1661
|
+
//
|
|
1662
|
+
// {
|
|
1663
|
+
// "id": "64507d02921f1c0001ff6892",
|
|
1664
|
+
// "symbol": "XBTUSDTM",
|
|
1665
|
+
// "type": "market",
|
|
1666
|
+
// "side": "buy",
|
|
1667
|
+
// "price": null,
|
|
1668
|
+
// "size": 1,
|
|
1669
|
+
// "value": "27.992",
|
|
1670
|
+
// "dealValue": "27.992",
|
|
1671
|
+
// "dealSize": 1,
|
|
1672
|
+
// "stp": "",
|
|
1673
|
+
// "stop": "",
|
|
1674
|
+
// "stopPriceType": "",
|
|
1675
|
+
// "stopTriggered": false,
|
|
1676
|
+
// "stopPrice": null,
|
|
1677
|
+
// "timeInForce": "GTC",
|
|
1678
|
+
// "postOnly": false,
|
|
1679
|
+
// "hidden": false,
|
|
1680
|
+
// "iceberg": false,
|
|
1681
|
+
// "leverage": "17",
|
|
1682
|
+
// "forceHold": false,
|
|
1683
|
+
// "closeOrder": false,
|
|
1684
|
+
// "visibleSize": null,
|
|
1685
|
+
// "clientOid": null,
|
|
1686
|
+
// "remark": null,
|
|
1687
|
+
// "tags": null,
|
|
1688
|
+
// "isActive": false,
|
|
1689
|
+
// "cancelExist": false,
|
|
1690
|
+
// "createdAt": 1682996482000,
|
|
1691
|
+
// "updatedAt": 1682996483062,
|
|
1692
|
+
// "endAt": 1682996483062,
|
|
1693
|
+
// "orderTime": 1682996482953900677,
|
|
1694
|
+
// "settleCurrency": "USDT",
|
|
1695
|
+
// "status": "done",
|
|
1696
|
+
// "filledValue": "27.992",
|
|
1697
|
+
// "filledSize": 1,
|
|
1698
|
+
// "reduceOnly": false
|
|
1699
|
+
// }
|
|
1700
|
+
//
|
|
1701
|
+
const marketId = this.safeString(order, 'symbol');
|
|
1702
|
+
market = this.safeMarket(marketId, market);
|
|
1703
|
+
const symbol = market['symbol'];
|
|
1704
|
+
const orderId = this.safeString(order, 'id');
|
|
1705
|
+
const type = this.safeString(order, 'type');
|
|
1706
|
+
const timestamp = this.safeInteger(order, 'createdAt');
|
|
1707
|
+
const datetime = this.iso8601(timestamp);
|
|
1708
|
+
const price = this.safeString(order, 'price');
|
|
1709
|
+
// price is zero for market order
|
|
1710
|
+
// omitZero is called in safeOrder2
|
|
1711
|
+
const side = this.safeString(order, 'side');
|
|
1712
|
+
const feeCurrencyId = this.safeString(order, 'feeCurrency');
|
|
1713
|
+
const feeCurrency = this.safeCurrencyCode(feeCurrencyId);
|
|
1714
|
+
const feeCost = this.safeNumber(order, 'fee');
|
|
1715
|
+
const amount = this.safeString(order, 'size');
|
|
1716
|
+
const filled = this.safeString(order, 'filledSize');
|
|
1717
|
+
const cost = this.safeString(order, 'filledValue');
|
|
1718
|
+
let average = undefined;
|
|
1719
|
+
if (Precise["default"].stringGt(filled, '0')) {
|
|
1720
|
+
const contractSize = this.safeString(market, 'contractSize');
|
|
1721
|
+
if (market['linear']) {
|
|
1722
|
+
average = Precise["default"].stringDiv(cost, Precise["default"].stringMul(contractSize, filled));
|
|
1723
|
+
}
|
|
1724
|
+
else {
|
|
1725
|
+
average = Precise["default"].stringDiv(Precise["default"].stringMul(contractSize, filled), cost);
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
// precision reported by their api is 8 d.p.
|
|
1729
|
+
// const average = Precise.stringDiv (cost, Precise.stringMul (filled, market['contractSize']));
|
|
1730
|
+
// bool
|
|
1731
|
+
const isActive = this.safeValue(order, 'isActive', false);
|
|
1732
|
+
const cancelExist = this.safeValue(order, 'cancelExist', false);
|
|
1733
|
+
let status = isActive ? 'open' : 'closed';
|
|
1734
|
+
status = cancelExist ? 'canceled' : status;
|
|
1735
|
+
let fee = undefined;
|
|
1736
|
+
if (feeCost !== undefined) {
|
|
1737
|
+
fee = {
|
|
1738
|
+
'currency': feeCurrency,
|
|
1739
|
+
'cost': feeCost,
|
|
1740
|
+
};
|
|
1741
|
+
}
|
|
1742
|
+
const clientOrderId = this.safeString(order, 'clientOid');
|
|
1743
|
+
const timeInForce = this.safeString(order, 'timeInForce');
|
|
1744
|
+
const stopPrice = this.safeNumber(order, 'stopPrice');
|
|
1745
|
+
const postOnly = this.safeValue(order, 'postOnly');
|
|
1746
|
+
const reduceOnly = this.safeValue(order, 'reduceOnly');
|
|
1747
|
+
const lastUpdateTimestamp = this.safeInteger(order, 'updatedAt');
|
|
1748
|
+
return this.safeOrder({
|
|
1749
|
+
'id': orderId,
|
|
1750
|
+
'clientOrderId': clientOrderId,
|
|
1751
|
+
'symbol': symbol,
|
|
1752
|
+
'type': type,
|
|
1753
|
+
'timeInForce': timeInForce,
|
|
1754
|
+
'postOnly': postOnly,
|
|
1755
|
+
'reduceOnly': reduceOnly,
|
|
1756
|
+
'side': side,
|
|
1757
|
+
'amount': amount,
|
|
1758
|
+
'price': price,
|
|
1759
|
+
'stopPrice': stopPrice,
|
|
1760
|
+
'triggerPrice': stopPrice,
|
|
1761
|
+
'cost': cost,
|
|
1762
|
+
'filled': filled,
|
|
1763
|
+
'remaining': undefined,
|
|
1764
|
+
'timestamp': timestamp,
|
|
1765
|
+
'datetime': datetime,
|
|
1766
|
+
'fee': fee,
|
|
1767
|
+
'status': status,
|
|
1768
|
+
'info': order,
|
|
1769
|
+
'lastTradeTimestamp': undefined,
|
|
1770
|
+
'lastUpdateTimestamp': lastUpdateTimestamp,
|
|
1771
|
+
'average': average,
|
|
1772
|
+
'trades': undefined,
|
|
1773
|
+
}, market);
|
|
1774
|
+
}
|
|
1775
|
+
async fetchFundingRate(symbol, params = {}) {
|
|
1776
|
+
/**
|
|
1777
|
+
* @method
|
|
1778
|
+
* @name kucoinfutures#fetchFundingRate
|
|
1779
|
+
* @description fetch the current funding rate
|
|
1780
|
+
* @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-current-funding-rate
|
|
1781
|
+
* @param {string} symbol unified market symbol
|
|
1782
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1783
|
+
* @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
|
|
1784
|
+
*/
|
|
1785
|
+
await this.loadMarkets();
|
|
1786
|
+
const market = this.market(symbol);
|
|
1787
|
+
const request = {
|
|
1788
|
+
'symbol': market['id'],
|
|
1789
|
+
};
|
|
1790
|
+
const response = await this.futuresPublicGetFundingRateSymbolCurrent(this.extend(request, params));
|
|
1791
|
+
//
|
|
1792
|
+
// {
|
|
1793
|
+
// "code": "200000",
|
|
1794
|
+
// "data": {
|
|
1795
|
+
// "symbol": ".ETHUSDTMFPI8H",
|
|
1796
|
+
// "granularity": 28800000,
|
|
1797
|
+
// "timePoint": 1637380800000,
|
|
1798
|
+
// "value": 0.0001,
|
|
1799
|
+
// "predictedValue": 0.0001,
|
|
1800
|
+
// },
|
|
1801
|
+
// }
|
|
1802
|
+
//
|
|
1803
|
+
const data = this.safeValue(response, 'data');
|
|
1804
|
+
const fundingTimestamp = this.safeNumber(data, 'timePoint');
|
|
1805
|
+
// the website displayes the previous funding rate as "funding rate"
|
|
1806
|
+
return {
|
|
1807
|
+
'info': data,
|
|
1808
|
+
'symbol': market['symbol'],
|
|
1809
|
+
'markPrice': undefined,
|
|
1810
|
+
'indexPrice': undefined,
|
|
1811
|
+
'interestRate': undefined,
|
|
1812
|
+
'estimatedSettlePrice': undefined,
|
|
1813
|
+
'timestamp': undefined,
|
|
1814
|
+
'datetime': undefined,
|
|
1815
|
+
'fundingRate': this.safeNumber(data, 'predictedValue'),
|
|
1816
|
+
'fundingTimestamp': undefined,
|
|
1817
|
+
'fundingDatetime': undefined,
|
|
1818
|
+
'nextFundingRate': undefined,
|
|
1819
|
+
'nextFundingTimestamp': undefined,
|
|
1820
|
+
'nextFundingDatetime': undefined,
|
|
1821
|
+
'previousFundingRate': this.safeNumber(data, 'value'),
|
|
1822
|
+
'previousFundingTimestamp': fundingTimestamp,
|
|
1823
|
+
'previousFundingDatetime': this.iso8601(fundingTimestamp),
|
|
1824
|
+
};
|
|
1825
|
+
}
|
|
1826
|
+
parseBalance(response) {
|
|
1827
|
+
const result = {
|
|
1828
|
+
'info': response,
|
|
1829
|
+
'timestamp': undefined,
|
|
1830
|
+
'datetime': undefined,
|
|
1831
|
+
};
|
|
1832
|
+
const data = this.safeValue(response, 'data');
|
|
1833
|
+
const currencyId = this.safeString(data, 'currency');
|
|
1834
|
+
const code = this.safeCurrencyCode(currencyId);
|
|
1835
|
+
const account = this.account();
|
|
1836
|
+
account['free'] = this.safeString(data, 'availableBalance');
|
|
1837
|
+
account['total'] = this.safeString(data, 'accountEquity');
|
|
1838
|
+
result[code] = account;
|
|
1839
|
+
return this.safeBalance(result);
|
|
1840
|
+
}
|
|
1841
|
+
async fetchBalance(params = {}) {
|
|
1842
|
+
/**
|
|
1843
|
+
* @method
|
|
1844
|
+
* @name kucoinfutures#fetchBalance
|
|
1845
|
+
* @description query for balance and get the amount of funds available for trading or funds locked in orders
|
|
1846
|
+
* @see https://www.kucoin.com/docs/rest/funding/funding-overview/get-account-detail-futures
|
|
1847
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1848
|
+
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
|
|
1849
|
+
*/
|
|
1850
|
+
await this.loadMarkets();
|
|
1851
|
+
// only fetches one balance at a time
|
|
1852
|
+
let defaultCode = this.safeString(this.options, 'code');
|
|
1853
|
+
const fetchBalanceOptions = this.safeValue(this.options, 'fetchBalance', {});
|
|
1854
|
+
defaultCode = this.safeString(fetchBalanceOptions, 'code', defaultCode);
|
|
1855
|
+
const code = this.safeString(params, 'code', defaultCode);
|
|
1856
|
+
const currency = this.currency(code);
|
|
1857
|
+
const request = {
|
|
1858
|
+
'currency': currency['id'],
|
|
1859
|
+
};
|
|
1860
|
+
const response = await this.futuresPrivateGetAccountOverview(this.extend(request, params));
|
|
1861
|
+
//
|
|
1862
|
+
// {
|
|
1863
|
+
// "code": "200000",
|
|
1864
|
+
// "data": {
|
|
1865
|
+
// "accountEquity": 0.00005,
|
|
1866
|
+
// "unrealisedPNL": 0,
|
|
1867
|
+
// "marginBalance": 0.00005,
|
|
1868
|
+
// "positionMargin": 0,
|
|
1869
|
+
// "orderMargin": 0,
|
|
1870
|
+
// "frozenFunds": 0,
|
|
1871
|
+
// "availableBalance": 0.00005,
|
|
1872
|
+
// "currency": "XBT"
|
|
1873
|
+
// }
|
|
1874
|
+
// }
|
|
1875
|
+
//
|
|
1876
|
+
return this.parseBalance(response);
|
|
1877
|
+
}
|
|
1878
|
+
async transfer(code, amount, fromAccount, toAccount, params = {}) {
|
|
1879
|
+
/**
|
|
1880
|
+
* @method
|
|
1881
|
+
* @name kucoinfutures#transfer
|
|
1882
|
+
* @description transfer currency internally between wallets on the same account
|
|
1883
|
+
* @param {string} code unified currency code
|
|
1884
|
+
* @param {float} amount amount to transfer
|
|
1885
|
+
* @param {string} fromAccount account to transfer from
|
|
1886
|
+
* @param {string} toAccount account to transfer to
|
|
1887
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1888
|
+
* @returns {object} a [transfer structure]{@link https://docs.ccxt.com/#/?id=transfer-structure}
|
|
1889
|
+
*/
|
|
1890
|
+
if ((toAccount !== 'main' && toAccount !== 'funding') || (fromAccount !== 'futures' && fromAccount !== 'future' && fromAccount !== 'contract')) {
|
|
1891
|
+
throw new errors.BadRequest(this.id + ' transfer() only supports transfers from contract(future) account to main(funding) account');
|
|
1892
|
+
}
|
|
1893
|
+
await this.loadMarkets();
|
|
1894
|
+
const currency = this.currency(code);
|
|
1895
|
+
const amountToPrecision = this.currencyToPrecision(code, amount);
|
|
1896
|
+
const request = {
|
|
1897
|
+
'currency': this.safeString(currency, 'id'),
|
|
1898
|
+
'amount': amountToPrecision,
|
|
1899
|
+
};
|
|
1900
|
+
// transfer from usdm futures wallet to spot wallet
|
|
1901
|
+
const response = await this.futuresPrivatePostTransferOut(this.extend(request, params));
|
|
1902
|
+
//
|
|
1903
|
+
// {
|
|
1904
|
+
// "code": "200000",
|
|
1905
|
+
// "data": {
|
|
1906
|
+
// "applyId": "5bffb63303aa675e8bbe18f9" // Transfer-out request ID
|
|
1907
|
+
// }
|
|
1908
|
+
// }
|
|
1909
|
+
//
|
|
1910
|
+
const data = this.safeValue(response, 'data');
|
|
1911
|
+
return this.extend(this.parseTransfer(data, currency), {
|
|
1912
|
+
'amount': this.parseNumber(amountToPrecision),
|
|
1913
|
+
'fromAccount': 'future',
|
|
1914
|
+
'toAccount': 'spot',
|
|
1915
|
+
});
|
|
1916
|
+
}
|
|
1917
|
+
parseTransfer(transfer, currency = undefined) {
|
|
1918
|
+
//
|
|
1919
|
+
// transfer
|
|
1920
|
+
//
|
|
1921
|
+
// {
|
|
1922
|
+
// "applyId": "5bffb63303aa675e8bbe18f9" // Transfer-out request ID
|
|
1923
|
+
// }
|
|
1924
|
+
//
|
|
1925
|
+
const timestamp = this.safeInteger(transfer, 'updatedAt');
|
|
1926
|
+
return {
|
|
1927
|
+
'id': this.safeString(transfer, 'applyId'),
|
|
1928
|
+
'timestamp': timestamp,
|
|
1929
|
+
'datetime': this.iso8601(timestamp),
|
|
1930
|
+
'currency': this.safeCurrencyCode(undefined, currency),
|
|
1931
|
+
'amount': undefined,
|
|
1932
|
+
'fromAccount': undefined,
|
|
1933
|
+
'toAccount': undefined,
|
|
1934
|
+
'status': this.safeString(transfer, 'status'),
|
|
1935
|
+
'info': transfer,
|
|
1936
|
+
};
|
|
1937
|
+
}
|
|
1938
|
+
parseTransferStatus(status) {
|
|
1939
|
+
const statuses = {
|
|
1940
|
+
'PROCESSING': 'pending',
|
|
1941
|
+
};
|
|
1942
|
+
return this.safeString(statuses, status, status);
|
|
1943
|
+
}
|
|
1944
|
+
async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1945
|
+
/**
|
|
1946
|
+
* @method
|
|
1947
|
+
* @name kucoinfutures#fetchMyTrades
|
|
1948
|
+
* @see https://docs.kucoin.com/futures/#get-fills
|
|
1949
|
+
* @description fetch all trades made by the user
|
|
1950
|
+
* @param {string} symbol unified market symbol
|
|
1951
|
+
* @param {int} [since] the earliest time in ms to fetch trades for
|
|
1952
|
+
* @param {int} [limit] the maximum number of trades structures to retrieve
|
|
1953
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1954
|
+
* @param {int} [params.until] End time in ms
|
|
1955
|
+
* @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)
|
|
1956
|
+
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
|
|
1957
|
+
*/
|
|
1958
|
+
await this.loadMarkets();
|
|
1959
|
+
let paginate = false;
|
|
1960
|
+
[paginate, params] = this.handleOptionAndParams(params, 'fetchMyTrades', 'paginate');
|
|
1961
|
+
if (paginate) {
|
|
1962
|
+
return await this.fetchPaginatedCallDynamic('fetchMyTrades', symbol, since, limit, params);
|
|
1963
|
+
}
|
|
1964
|
+
let request = {
|
|
1965
|
+
// orderId (String) [optional] Fills for a specific order (other parameters can be ignored if specified)
|
|
1966
|
+
// symbol (String) [optional] Symbol of the contract
|
|
1967
|
+
// side (String) [optional] buy or sell
|
|
1968
|
+
// type (String) [optional] limit, market, limit_stop or market_stop
|
|
1969
|
+
// startAt (long) [optional] Start time (milisecond)
|
|
1970
|
+
// endAt (long) [optional] End time (milisecond)
|
|
1971
|
+
};
|
|
1972
|
+
let market = undefined;
|
|
1973
|
+
if (symbol !== undefined) {
|
|
1974
|
+
market = this.market(symbol);
|
|
1975
|
+
request['symbol'] = market['id'];
|
|
1976
|
+
}
|
|
1977
|
+
if (since !== undefined) {
|
|
1978
|
+
request['startAt'] = since;
|
|
1979
|
+
}
|
|
1980
|
+
[request, params] = this.handleUntilOption('endAt', request, params);
|
|
1981
|
+
const response = await this.futuresPrivateGetFills(this.extend(request, params));
|
|
1982
|
+
//
|
|
1983
|
+
// {
|
|
1984
|
+
// "code": "200000",
|
|
1985
|
+
// "data": {
|
|
1986
|
+
// "currentPage": 1,
|
|
1987
|
+
// "pageSize": 1,
|
|
1988
|
+
// "totalNum": 251915,
|
|
1989
|
+
// "totalPage": 251915,
|
|
1990
|
+
// "items": [
|
|
1991
|
+
// {
|
|
1992
|
+
// "symbol": "XBTUSDM", // Ticker symbol of the contract
|
|
1993
|
+
// "tradeId": "5ce24c1f0c19fc3c58edc47c", // Trade ID
|
|
1994
|
+
// "orderId": "5ce24c16b210233c36ee321d", // Order ID
|
|
1995
|
+
// "side": "sell", // Transaction side
|
|
1996
|
+
// "liquidity": "taker", // Liquidity- taker or maker
|
|
1997
|
+
// "price": "8302", // Filled price
|
|
1998
|
+
// "size": 10, // Filled amount
|
|
1999
|
+
// "value": "0.001204529", // Order value
|
|
2000
|
+
// "feeRate": "0.0005", // Floating fees
|
|
2001
|
+
// "fixFee": "0.00000006", // Fixed fees
|
|
2002
|
+
// "feeCurrency": "XBT", // Charging currency
|
|
2003
|
+
// "stop": "", // A mark to the stop order type
|
|
2004
|
+
// "fee": "0.0000012022", // Transaction fee
|
|
2005
|
+
// "orderType": "limit", // Order type
|
|
2006
|
+
// "tradeType": "trade", // Trade type (trade, liquidation, ADL or settlement)
|
|
2007
|
+
// "createdAt": 1558334496000, // Time the order created
|
|
2008
|
+
// "settleCurrency": "XBT", // settlement currency
|
|
2009
|
+
// "tradeTime": 1558334496000000000 // trade time in nanosecond
|
|
2010
|
+
// }
|
|
2011
|
+
// ]
|
|
2012
|
+
// }
|
|
2013
|
+
// }
|
|
2014
|
+
//
|
|
2015
|
+
const data = this.safeValue(response, 'data', {});
|
|
2016
|
+
const trades = this.safeValue(data, 'items', {});
|
|
2017
|
+
return this.parseTrades(trades, market, since, limit);
|
|
2018
|
+
}
|
|
2019
|
+
async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
|
|
2020
|
+
/**
|
|
2021
|
+
* @method
|
|
2022
|
+
* @name kucoinfutures#fetchTrades
|
|
2023
|
+
* @description get the list of most recent trades for a particular symbol
|
|
2024
|
+
* @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-transaction-history
|
|
2025
|
+
* @param {string} symbol unified symbol of the market to fetch trades for
|
|
2026
|
+
* @param {int} [since] timestamp in ms of the earliest trade to fetch
|
|
2027
|
+
* @param {int} [limit] the maximum amount of trades to fetch
|
|
2028
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2029
|
+
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
|
|
2030
|
+
*/
|
|
2031
|
+
await this.loadMarkets();
|
|
2032
|
+
const market = this.market(symbol);
|
|
2033
|
+
const request = {
|
|
2034
|
+
'symbol': market['id'],
|
|
2035
|
+
};
|
|
2036
|
+
const response = await this.futuresPublicGetTradeHistory(this.extend(request, params));
|
|
2037
|
+
//
|
|
2038
|
+
// {
|
|
2039
|
+
// "code": "200000",
|
|
2040
|
+
// "data": [
|
|
2041
|
+
// {
|
|
2042
|
+
// "sequence": 32114961,
|
|
2043
|
+
// "side": "buy",
|
|
2044
|
+
// "size": 39,
|
|
2045
|
+
// "price": "4001.6500000000",
|
|
2046
|
+
// "takerOrderId": "61c20742f172110001e0ebe4",
|
|
2047
|
+
// "makerOrderId": "61c2073fcfc88100010fcb5d",
|
|
2048
|
+
// "tradeId": "61c2074277a0c473e69029b8",
|
|
2049
|
+
// "ts": 1640105794099993896 // filled time
|
|
2050
|
+
// }
|
|
2051
|
+
// ]
|
|
2052
|
+
// }
|
|
2053
|
+
//
|
|
2054
|
+
const trades = this.safeValue(response, 'data', []);
|
|
2055
|
+
return this.parseTrades(trades, market, since, limit);
|
|
2056
|
+
}
|
|
2057
|
+
parseTrade(trade, market = undefined) {
|
|
2058
|
+
//
|
|
2059
|
+
// fetchTrades (public)
|
|
2060
|
+
//
|
|
2061
|
+
// {
|
|
2062
|
+
// "sequence": 32114961,
|
|
2063
|
+
// "side": "buy",
|
|
2064
|
+
// "size": 39,
|
|
2065
|
+
// "price": "4001.6500000000",
|
|
2066
|
+
// "takerOrderId": "61c20742f172110001e0ebe4",
|
|
2067
|
+
// "makerOrderId": "61c2073fcfc88100010fcb5d",
|
|
2068
|
+
// "tradeId": "61c2074277a0c473e69029b8",
|
|
2069
|
+
// "ts": 1640105794099993896 // filled time
|
|
2070
|
+
// }
|
|
2071
|
+
//
|
|
2072
|
+
// fetchMyTrades (private) v2
|
|
2073
|
+
//
|
|
2074
|
+
// {
|
|
2075
|
+
// "symbol":"BTC-USDT",
|
|
2076
|
+
// "tradeId":"5c35c02709e4f67d5266954e",
|
|
2077
|
+
// "orderId":"5c35c02703aa673ceec2a168",
|
|
2078
|
+
// "counterOrderId":"5c1ab46003aa676e487fa8e3",
|
|
2079
|
+
// "side":"buy",
|
|
2080
|
+
// "liquidity":"taker",
|
|
2081
|
+
// "forceTaker":true,
|
|
2082
|
+
// "price":"0.083",
|
|
2083
|
+
// "size":"0.8424304",
|
|
2084
|
+
// "funds":"0.0699217232",
|
|
2085
|
+
// "fee":"0",
|
|
2086
|
+
// "feeRate":"0",
|
|
2087
|
+
// "feeCurrency":"USDT",
|
|
2088
|
+
// "stop":"",
|
|
2089
|
+
// "type":"limit",
|
|
2090
|
+
// "createdAt":1547026472000
|
|
2091
|
+
// }
|
|
2092
|
+
//
|
|
2093
|
+
// fetchMyTrades (private) v1
|
|
2094
|
+
//
|
|
2095
|
+
// {
|
|
2096
|
+
// "symbol":"DOGEUSDTM",
|
|
2097
|
+
// "tradeId":"620ec41a96bab27b5f4ced56",
|
|
2098
|
+
// "orderId":"620ec41a0d1d8a0001560bd0",
|
|
2099
|
+
// "side":"sell",
|
|
2100
|
+
// "liquidity":"taker",
|
|
2101
|
+
// "forceTaker":true,
|
|
2102
|
+
// "price":"0.13969",
|
|
2103
|
+
// "size":1,
|
|
2104
|
+
// "value":"13.969",
|
|
2105
|
+
// "feeRate":"0.0006",
|
|
2106
|
+
// "fixFee":"0",
|
|
2107
|
+
// "feeCurrency":"USDT",
|
|
2108
|
+
// "stop":"",
|
|
2109
|
+
// "tradeTime":1645134874858018058,
|
|
2110
|
+
// "fee":"0.0083814",
|
|
2111
|
+
// "settleCurrency":"USDT",
|
|
2112
|
+
// "orderType":"market",
|
|
2113
|
+
// "tradeType":"trade",
|
|
2114
|
+
// "createdAt":1645134874858
|
|
2115
|
+
// }
|
|
2116
|
+
//
|
|
2117
|
+
// watchTrades
|
|
2118
|
+
//
|
|
2119
|
+
// {
|
|
2120
|
+
// "makerUserId": "62286a4d720edf0001e81961",
|
|
2121
|
+
// "symbol": "ADAUSDTM",
|
|
2122
|
+
// "sequence": 41320766,
|
|
2123
|
+
// "side": "sell",
|
|
2124
|
+
// "size": 2,
|
|
2125
|
+
// "price": 0.35904,
|
|
2126
|
+
// "takerOrderId": "636dd9da9857ba00010cfa44",
|
|
2127
|
+
// "makerOrderId": "636dd9c8df149d0001e62bc8",
|
|
2128
|
+
// "takerUserId": "6180be22b6ab210001fa3371",
|
|
2129
|
+
// "tradeId": "636dd9da0000d400d477eca7",
|
|
2130
|
+
// "ts": 1668143578987357700
|
|
2131
|
+
// }
|
|
2132
|
+
//
|
|
2133
|
+
const marketId = this.safeString(trade, 'symbol');
|
|
2134
|
+
market = this.safeMarket(marketId, market, '-');
|
|
2135
|
+
const id = this.safeString2(trade, 'tradeId', 'id');
|
|
2136
|
+
const orderId = this.safeString(trade, 'orderId');
|
|
2137
|
+
const takerOrMaker = this.safeString(trade, 'liquidity');
|
|
2138
|
+
let timestamp = this.safeInteger(trade, 'ts');
|
|
2139
|
+
if (timestamp !== undefined) {
|
|
2140
|
+
timestamp = this.parseToInt(timestamp / 1000000);
|
|
2141
|
+
}
|
|
2142
|
+
else {
|
|
2143
|
+
timestamp = this.safeInteger(trade, 'createdAt');
|
|
2144
|
+
// if it's a historical v1 trade, the exchange returns timestamp in seconds
|
|
2145
|
+
if (('dealValue' in trade) && (timestamp !== undefined)) {
|
|
2146
|
+
timestamp = timestamp * 1000;
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
const priceString = this.safeString2(trade, 'price', 'dealPrice');
|
|
2150
|
+
const amountString = this.safeString2(trade, 'size', 'amount');
|
|
2151
|
+
const side = this.safeString(trade, 'side');
|
|
2152
|
+
let fee = undefined;
|
|
2153
|
+
const feeCostString = this.safeString(trade, 'fee');
|
|
2154
|
+
if (feeCostString !== undefined) {
|
|
2155
|
+
const feeCurrencyId = this.safeString(trade, 'feeCurrency');
|
|
2156
|
+
let feeCurrency = this.safeCurrencyCode(feeCurrencyId);
|
|
2157
|
+
if (feeCurrency === undefined) {
|
|
2158
|
+
feeCurrency = (side === 'sell') ? market['quote'] : market['base'];
|
|
2159
|
+
}
|
|
2160
|
+
fee = {
|
|
2161
|
+
'cost': feeCostString,
|
|
2162
|
+
'currency': feeCurrency,
|
|
2163
|
+
'rate': this.safeString(trade, 'feeRate'),
|
|
2164
|
+
};
|
|
2165
|
+
}
|
|
2166
|
+
let type = this.safeString2(trade, 'type', 'orderType');
|
|
2167
|
+
if (type === 'match') {
|
|
2168
|
+
type = undefined;
|
|
2169
|
+
}
|
|
2170
|
+
let costString = this.safeString2(trade, 'funds', 'value');
|
|
2171
|
+
if (costString === undefined) {
|
|
2172
|
+
const contractSize = this.safeString(market, 'contractSize');
|
|
2173
|
+
const contractCost = Precise["default"].stringMul(priceString, amountString);
|
|
2174
|
+
costString = Precise["default"].stringMul(contractCost, contractSize);
|
|
2175
|
+
}
|
|
2176
|
+
return this.safeTrade({
|
|
2177
|
+
'info': trade,
|
|
2178
|
+
'id': id,
|
|
2179
|
+
'order': orderId,
|
|
2180
|
+
'timestamp': timestamp,
|
|
2181
|
+
'datetime': this.iso8601(timestamp),
|
|
2182
|
+
'symbol': market['symbol'],
|
|
2183
|
+
'type': type,
|
|
2184
|
+
'takerOrMaker': takerOrMaker,
|
|
2185
|
+
'side': side,
|
|
2186
|
+
'price': priceString,
|
|
2187
|
+
'amount': amountString,
|
|
2188
|
+
'cost': costString,
|
|
2189
|
+
'fee': fee,
|
|
2190
|
+
}, market);
|
|
2191
|
+
}
|
|
2192
|
+
async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
|
|
2193
|
+
/**
|
|
2194
|
+
* @method
|
|
2195
|
+
* @name kucoinfutures#fetchDeposits
|
|
2196
|
+
* @description fetch all deposits made to an account
|
|
2197
|
+
* @param {string} code unified currency code
|
|
2198
|
+
* @param {int} [since] the earliest time in ms to fetch deposits for
|
|
2199
|
+
* @param {int} [limit] the maximum number of deposits structures to retrieve
|
|
2200
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2201
|
+
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
|
|
2202
|
+
*/
|
|
2203
|
+
await this.loadMarkets();
|
|
2204
|
+
const request = {};
|
|
2205
|
+
let currency = undefined;
|
|
2206
|
+
if (code !== undefined) {
|
|
2207
|
+
currency = this.currency(code);
|
|
2208
|
+
request['currency'] = currency['id'];
|
|
2209
|
+
}
|
|
2210
|
+
if (limit !== undefined) {
|
|
2211
|
+
request['pageSize'] = limit;
|
|
2212
|
+
}
|
|
2213
|
+
if (since !== undefined) {
|
|
2214
|
+
request['startAt'] = since;
|
|
2215
|
+
}
|
|
2216
|
+
const response = await this.futuresPrivateGetDepositList(this.extend(request, params));
|
|
2217
|
+
//
|
|
2218
|
+
// {
|
|
2219
|
+
// "code": "200000",
|
|
2220
|
+
// "data": {
|
|
2221
|
+
// "currentPage": 1,
|
|
2222
|
+
// "pageSize": 5,
|
|
2223
|
+
// "totalNum": 2,
|
|
2224
|
+
// "totalPage": 1,
|
|
2225
|
+
// "items": [
|
|
2226
|
+
// {
|
|
2227
|
+
// "address": "0x5f047b29041bcfdbf0e4478cdfa753a336ba6989",
|
|
2228
|
+
// "memo": "5c247c8a03aa677cea2a251d",
|
|
2229
|
+
// "amount": 1,
|
|
2230
|
+
// "fee": 0.0001,
|
|
2231
|
+
// "currency": "KCS",
|
|
2232
|
+
// "isInner": false,
|
|
2233
|
+
// "walletTxId": "5bbb57386d99522d9f954c5a@test004",
|
|
2234
|
+
// "status": "SUCCESS",
|
|
2235
|
+
// "createdAt": 1544178843000,
|
|
2236
|
+
// "updatedAt": 1544178891000
|
|
2237
|
+
// "remark":"foobar"
|
|
2238
|
+
// },
|
|
2239
|
+
// ...
|
|
2240
|
+
// ]
|
|
2241
|
+
// }
|
|
2242
|
+
// }
|
|
2243
|
+
//
|
|
2244
|
+
const responseData = response['data']['items'];
|
|
2245
|
+
return this.parseTransactions(responseData, currency, since, limit, { 'type': 'deposit' });
|
|
2246
|
+
}
|
|
2247
|
+
async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
|
|
2248
|
+
/**
|
|
2249
|
+
* @method
|
|
2250
|
+
* @name kucoinfutures#fetchWithdrawals
|
|
2251
|
+
* @description fetch all withdrawals made from an account
|
|
2252
|
+
* @param {string} code unified currency code
|
|
2253
|
+
* @param {int} [since] the earliest time in ms to fetch withdrawals for
|
|
2254
|
+
* @param {int} [limit] the maximum number of withdrawals structures to retrieve
|
|
2255
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2256
|
+
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
|
|
2257
|
+
*/
|
|
2258
|
+
await this.loadMarkets();
|
|
2259
|
+
const request = {};
|
|
2260
|
+
let currency = undefined;
|
|
2261
|
+
if (code !== undefined) {
|
|
2262
|
+
currency = this.currency(code);
|
|
2263
|
+
request['currency'] = currency['id'];
|
|
2264
|
+
}
|
|
2265
|
+
if (limit !== undefined) {
|
|
2266
|
+
request['pageSize'] = limit;
|
|
2267
|
+
}
|
|
2268
|
+
if (since !== undefined) {
|
|
2269
|
+
request['startAt'] = since;
|
|
2270
|
+
}
|
|
2271
|
+
const response = await this.futuresPrivateGetWithdrawalList(this.extend(request, params));
|
|
2272
|
+
//
|
|
2273
|
+
// {
|
|
2274
|
+
// "code": "200000",
|
|
2275
|
+
// "data": {
|
|
2276
|
+
// "currentPage": 1,
|
|
2277
|
+
// "pageSize": 5,
|
|
2278
|
+
// "totalNum": 2,
|
|
2279
|
+
// "totalPage": 1,
|
|
2280
|
+
// "items": [
|
|
2281
|
+
// {
|
|
2282
|
+
// "id": "5c2dc64e03aa675aa263f1ac",
|
|
2283
|
+
// "address": "0x5bedb060b8eb8d823e2414d82acce78d38be7fe9",
|
|
2284
|
+
// "memo": "",
|
|
2285
|
+
// "currency": "ETH",
|
|
2286
|
+
// "amount": 1.0000000,
|
|
2287
|
+
// "fee": 0.0100000,
|
|
2288
|
+
// "walletTxId": "3e2414d82acce78d38be7fe9",
|
|
2289
|
+
// "isInner": false,
|
|
2290
|
+
// "status": "FAILURE",
|
|
2291
|
+
// "createdAt": 1546503758000,
|
|
2292
|
+
// "updatedAt": 1546504603000
|
|
2293
|
+
// },
|
|
2294
|
+
// ...
|
|
2295
|
+
// ]
|
|
2296
|
+
// }
|
|
2297
|
+
// }
|
|
2298
|
+
//
|
|
2299
|
+
const responseData = response['data']['items'];
|
|
2300
|
+
return this.parseTransactions(responseData, currency, since, limit, { 'type': 'withdrawal' });
|
|
2301
|
+
}
|
|
2302
|
+
async fetchMarketLeverageTiers(symbol, params = {}) {
|
|
2303
|
+
/**
|
|
2304
|
+
* @method
|
|
2305
|
+
* @name kucoinfutures#fetchMarketLeverageTiers
|
|
2306
|
+
* @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes for a single market
|
|
2307
|
+
* @see https://www.kucoin.com/docs/rest/futures-trading/risk-limit/get-futures-risk-limit-level
|
|
2308
|
+
* @param {string} symbol unified market symbol
|
|
2309
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2310
|
+
* @returns {object} a [leverage tiers structure]{@link https://docs.ccxt.com/#/?id=leverage-tiers-structure}
|
|
2311
|
+
*/
|
|
2312
|
+
await this.loadMarkets();
|
|
2313
|
+
const market = this.market(symbol);
|
|
2314
|
+
if (!market['contract']) {
|
|
2315
|
+
throw new errors.BadRequest(this.id + ' fetchMarketLeverageTiers() supports contract markets only');
|
|
2316
|
+
}
|
|
2317
|
+
const request = {
|
|
2318
|
+
'symbol': market['id'],
|
|
2319
|
+
};
|
|
2320
|
+
const response = await this.futuresPublicGetContractsRiskLimitSymbol(this.extend(request, params));
|
|
2321
|
+
//
|
|
2322
|
+
// {
|
|
2323
|
+
// "code": "200000",
|
|
2324
|
+
// "data": [
|
|
2325
|
+
// {
|
|
2326
|
+
// "symbol": "ETHUSDTM",
|
|
2327
|
+
// "level": 1,
|
|
2328
|
+
// "maxRiskLimit": 300000,
|
|
2329
|
+
// "minRiskLimit": 0,
|
|
2330
|
+
// "maxLeverage": 100,
|
|
2331
|
+
// "initialMargin": 0.0100000000,
|
|
2332
|
+
// "maintainMargin": 0.0050000000
|
|
2333
|
+
// },
|
|
2334
|
+
// ...
|
|
2335
|
+
// ]
|
|
2336
|
+
// }
|
|
2337
|
+
//
|
|
2338
|
+
const data = this.safeValue(response, 'data');
|
|
2339
|
+
return this.parseMarketLeverageTiers(data, market);
|
|
2340
|
+
}
|
|
2341
|
+
parseMarketLeverageTiers(info, market = undefined) {
|
|
2342
|
+
/**
|
|
2343
|
+
* @ignore
|
|
2344
|
+
* @method
|
|
2345
|
+
* @param {object} info Exchange market response for 1 market
|
|
2346
|
+
* @param {object} market CCXT market
|
|
2347
|
+
*/
|
|
2348
|
+
//
|
|
2349
|
+
// {
|
|
2350
|
+
// "symbol": "ETHUSDTM",
|
|
2351
|
+
// "level": 1,
|
|
2352
|
+
// "maxRiskLimit": 300000,
|
|
2353
|
+
// "minRiskLimit": 0,
|
|
2354
|
+
// "maxLeverage": 100,
|
|
2355
|
+
// "initialMargin": 0.0100000000,
|
|
2356
|
+
// "maintainMargin": 0.0050000000
|
|
2357
|
+
// }
|
|
2358
|
+
//
|
|
2359
|
+
const tiers = [];
|
|
2360
|
+
for (let i = 0; i < info.length; i++) {
|
|
2361
|
+
const tier = info[i];
|
|
2362
|
+
tiers.push({
|
|
2363
|
+
'tier': this.safeNumber(tier, 'level'),
|
|
2364
|
+
'currency': market['base'],
|
|
2365
|
+
'minNotional': this.safeNumber(tier, 'minRiskLimit'),
|
|
2366
|
+
'maxNotional': this.safeNumber(tier, 'maxRiskLimit'),
|
|
2367
|
+
'maintenanceMarginRate': this.safeNumber(tier, 'maintainMargin'),
|
|
2368
|
+
'maxLeverage': this.safeNumber(tier, 'maxLeverage'),
|
|
2369
|
+
'info': tier,
|
|
2370
|
+
});
|
|
2371
|
+
}
|
|
2372
|
+
return tiers;
|
|
2373
|
+
}
|
|
2374
|
+
async fetchFundingRateHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
2375
|
+
/**
|
|
2376
|
+
* @method
|
|
2377
|
+
* @name kucoinfutures#fetchFundingRateHistory
|
|
2378
|
+
* @description fetches historical funding rate prices
|
|
2379
|
+
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
|
|
2380
|
+
* @param {int} [since] not used by kucuoinfutures
|
|
2381
|
+
* @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure} to fetch
|
|
2382
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2383
|
+
* @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)
|
|
2384
|
+
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure}
|
|
2385
|
+
*/
|
|
2386
|
+
if (symbol === undefined) {
|
|
2387
|
+
throw new errors.ArgumentsRequired(this.id + ' fetchFundingRateHistory() requires a symbol argument');
|
|
2388
|
+
}
|
|
2389
|
+
await this.loadMarkets();
|
|
2390
|
+
let paginate = false;
|
|
2391
|
+
[paginate, params] = this.handleOptionAndParams(params, 'fetchFundingRateHistory', 'paginate');
|
|
2392
|
+
if (paginate) {
|
|
2393
|
+
return await this.fetchPaginatedCallDeterministic('fetchFundingRateHistory', symbol, since, limit, '8h', params);
|
|
2394
|
+
}
|
|
2395
|
+
const market = this.market(symbol);
|
|
2396
|
+
const request = {
|
|
2397
|
+
'symbol': market['id'],
|
|
2398
|
+
};
|
|
2399
|
+
if (limit !== undefined) {
|
|
2400
|
+
request['maxCount'] = limit;
|
|
2401
|
+
}
|
|
2402
|
+
const response = await this.webExchangeGetContractSymbolFundingRates(this.extend(request, params));
|
|
2403
|
+
//
|
|
2404
|
+
// {
|
|
2405
|
+
// "success": true,
|
|
2406
|
+
// "code": "200",
|
|
2407
|
+
// "msg": "success",
|
|
2408
|
+
// "retry": false,
|
|
2409
|
+
// "data": {
|
|
2410
|
+
// "dataList": [
|
|
2411
|
+
// {
|
|
2412
|
+
// "symbol": "XBTUSDTM",
|
|
2413
|
+
// "granularity": 28800000,
|
|
2414
|
+
// "timePoint": 1675108800000,
|
|
2415
|
+
// "value": 0.0001
|
|
2416
|
+
// },
|
|
2417
|
+
// ...
|
|
2418
|
+
// ],
|
|
2419
|
+
// "hasMore": true
|
|
2420
|
+
// }
|
|
2421
|
+
// }
|
|
2422
|
+
//
|
|
2423
|
+
const data = this.safeValue(response, 'data');
|
|
2424
|
+
const dataList = this.safeValue(data, 'dataList');
|
|
2425
|
+
return this.parseFundingRateHistories(dataList, market, since, limit);
|
|
2426
|
+
}
|
|
2427
|
+
parseFundingRateHistory(info, market = undefined) {
|
|
2428
|
+
const timestamp = this.safeInteger(info, 'timePoint');
|
|
2429
|
+
const marketId = this.safeString(info, 'symbol');
|
|
2430
|
+
return {
|
|
2431
|
+
'info': info,
|
|
2432
|
+
'symbol': this.safeSymbol(marketId, market),
|
|
2433
|
+
'fundingRate': this.safeNumber(info, 'value'),
|
|
2434
|
+
'timestamp': timestamp,
|
|
2435
|
+
'datetime': this.iso8601(timestamp),
|
|
2436
|
+
};
|
|
2437
|
+
}
|
|
2438
|
+
async closePosition(symbol, side = undefined, params = {}) {
|
|
2439
|
+
/**
|
|
2440
|
+
* @method
|
|
2441
|
+
* @name kucoinfutures#closePosition
|
|
2442
|
+
* @description closes open positions for a market
|
|
2443
|
+
* @see https://www.kucoin.com/docs/rest/futures-trading/orders/place-order
|
|
2444
|
+
* @param {string} symbol Unified CCXT market symbol
|
|
2445
|
+
* @param {string} side not used by kucoinfutures closePositions
|
|
2446
|
+
* @param {object} [params] extra parameters specific to the okx api endpoint
|
|
2447
|
+
* @param {string} [params.clientOrderId] client order id of the order
|
|
2448
|
+
* @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
|
|
2449
|
+
*/
|
|
2450
|
+
await this.loadMarkets();
|
|
2451
|
+
const market = this.market(symbol);
|
|
2452
|
+
let clientOrderId = this.safeString(params, 'clientOrderId');
|
|
2453
|
+
const testOrder = this.safeValue(params, 'test', false);
|
|
2454
|
+
params = this.omit(params, ['test', 'clientOrderId']);
|
|
2455
|
+
if (clientOrderId === undefined) {
|
|
2456
|
+
clientOrderId = this.numberToString(this.nonce());
|
|
2457
|
+
}
|
|
2458
|
+
const request = {
|
|
2459
|
+
'symbol': market['id'],
|
|
2460
|
+
'closeOrder': true,
|
|
2461
|
+
'clientOid': clientOrderId,
|
|
2462
|
+
'type': 'market',
|
|
2463
|
+
};
|
|
2464
|
+
let response = undefined;
|
|
2465
|
+
if (testOrder) {
|
|
2466
|
+
response = await this.futuresPrivatePostOrdersTest(this.extend(request, params));
|
|
2467
|
+
}
|
|
2468
|
+
else {
|
|
2469
|
+
response = await this.futuresPrivatePostOrders(this.extend(request, params));
|
|
2470
|
+
}
|
|
2471
|
+
return this.parseOrder(response, market);
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
module.exports = kucoinfutures;
|