ccxt 4.2.11 → 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 +2 -2
- package/dist/ccxt.browser.js +640 -261
- 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/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 +5 -1
- package/js/src/base/Exchange.js +101 -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.js +9 -2
- package/js/src/bitfinex.d.ts +2 -2
- package/js/src/bitfinex.js +2 -3
- package/js/src/bitget.js +21 -8
- 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 +2 -0
- 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/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 +1 -1
- package/skip-tests.json +5 -0
|
@@ -0,0 +1,1866 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var coinbasepro$1 = require('./abstract/coinbasepro.js');
|
|
4
|
+
var errors = require('./base/errors.js');
|
|
5
|
+
var Precise = require('./base/Precise.js');
|
|
6
|
+
var number = require('./base/functions/number.js');
|
|
7
|
+
var sha256 = require('./static_dependencies/noble-hashes/sha256.js');
|
|
8
|
+
|
|
9
|
+
// ----------------------------------------------------------------------------
|
|
10
|
+
// ----------------------------------------------------------------------------
|
|
11
|
+
/**
|
|
12
|
+
* @class coinbasepro
|
|
13
|
+
* @augments Exchange
|
|
14
|
+
*/
|
|
15
|
+
class coinbasepro extends coinbasepro$1 {
|
|
16
|
+
describe() {
|
|
17
|
+
return this.deepExtend(super.describe(), {
|
|
18
|
+
'id': 'coinbasepro',
|
|
19
|
+
'name': 'Coinbase Pro',
|
|
20
|
+
'countries': ['US'],
|
|
21
|
+
'rateLimit': 100,
|
|
22
|
+
'userAgent': this.userAgents['chrome'],
|
|
23
|
+
'pro': true,
|
|
24
|
+
'has': {
|
|
25
|
+
'CORS': true,
|
|
26
|
+
'spot': true,
|
|
27
|
+
'margin': false,
|
|
28
|
+
'swap': false,
|
|
29
|
+
'future': false,
|
|
30
|
+
'option': false,
|
|
31
|
+
'cancelAllOrders': true,
|
|
32
|
+
'cancelOrder': true,
|
|
33
|
+
'createDepositAddress': true,
|
|
34
|
+
'createOrder': true,
|
|
35
|
+
'createStopLimitOrder': true,
|
|
36
|
+
'createStopMarketOrder': true,
|
|
37
|
+
'createStopOrder': true,
|
|
38
|
+
'fetchAccounts': true,
|
|
39
|
+
'fetchBalance': true,
|
|
40
|
+
'fetchClosedOrders': true,
|
|
41
|
+
'fetchCurrencies': true,
|
|
42
|
+
'fetchDepositAddress': false,
|
|
43
|
+
'fetchDeposits': true,
|
|
44
|
+
'fetchDepositsWithdrawals': true,
|
|
45
|
+
'fetchLedger': true,
|
|
46
|
+
'fetchMarginMode': false,
|
|
47
|
+
'fetchMarkets': true,
|
|
48
|
+
'fetchMyTrades': true,
|
|
49
|
+
'fetchOHLCV': true,
|
|
50
|
+
'fetchOpenOrders': true,
|
|
51
|
+
'fetchOrder': true,
|
|
52
|
+
'fetchOrderBook': true,
|
|
53
|
+
'fetchOrders': true,
|
|
54
|
+
'fetchOrderTrades': true,
|
|
55
|
+
'fetchPositionMode': false,
|
|
56
|
+
'fetchTicker': true,
|
|
57
|
+
'fetchTickers': true,
|
|
58
|
+
'fetchTime': true,
|
|
59
|
+
'fetchTrades': true,
|
|
60
|
+
'fetchTradingFee': false,
|
|
61
|
+
'fetchTradingFees': true,
|
|
62
|
+
'fetchTransactions': 'emulated',
|
|
63
|
+
'fetchWithdrawals': true,
|
|
64
|
+
'withdraw': true,
|
|
65
|
+
},
|
|
66
|
+
'timeframes': {
|
|
67
|
+
'1m': 60,
|
|
68
|
+
'5m': 300,
|
|
69
|
+
'15m': 900,
|
|
70
|
+
'1h': 3600,
|
|
71
|
+
'6h': 21600,
|
|
72
|
+
'1d': 86400,
|
|
73
|
+
},
|
|
74
|
+
'hostname': 'pro.coinbase.com',
|
|
75
|
+
'urls': {
|
|
76
|
+
'test': {
|
|
77
|
+
'public': 'https://api-public.sandbox.pro.coinbase.com',
|
|
78
|
+
'private': 'https://api-public.sandbox.pro.coinbase.com',
|
|
79
|
+
},
|
|
80
|
+
'logo': 'https://user-images.githubusercontent.com/1294454/41764625-63b7ffde-760a-11e8-996d-a6328fa9347a.jpg',
|
|
81
|
+
'api': {
|
|
82
|
+
'public': 'https://api.{hostname}',
|
|
83
|
+
'private': 'https://api.{hostname}',
|
|
84
|
+
},
|
|
85
|
+
'www': 'https://pro.coinbase.com/',
|
|
86
|
+
'doc': 'https://docs.pro.coinbase.com',
|
|
87
|
+
'fees': [
|
|
88
|
+
'https://docs.pro.coinbase.com/#fees',
|
|
89
|
+
'https://support.pro.coinbase.com/customer/en/portal/articles/2945310-fees',
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
'requiredCredentials': {
|
|
93
|
+
'apiKey': true,
|
|
94
|
+
'secret': true,
|
|
95
|
+
'password': true,
|
|
96
|
+
},
|
|
97
|
+
'api': {
|
|
98
|
+
'public': {
|
|
99
|
+
'get': [
|
|
100
|
+
'currencies',
|
|
101
|
+
'products',
|
|
102
|
+
'products/{id}',
|
|
103
|
+
'products/{id}/book',
|
|
104
|
+
'products/{id}/candles',
|
|
105
|
+
'products/{id}/stats',
|
|
106
|
+
'products/{id}/ticker',
|
|
107
|
+
'products/{id}/trades',
|
|
108
|
+
'time',
|
|
109
|
+
'products/spark-lines', // experimental
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
'private': {
|
|
113
|
+
'get': [
|
|
114
|
+
'address-book',
|
|
115
|
+
'accounts',
|
|
116
|
+
'accounts/{id}',
|
|
117
|
+
'accounts/{id}/holds',
|
|
118
|
+
'accounts/{id}/ledger',
|
|
119
|
+
'accounts/{id}/transfers',
|
|
120
|
+
'coinbase-accounts',
|
|
121
|
+
'fills',
|
|
122
|
+
'funding',
|
|
123
|
+
'fees',
|
|
124
|
+
'margin/profile_information',
|
|
125
|
+
'margin/buying_power',
|
|
126
|
+
'margin/withdrawal_power',
|
|
127
|
+
'margin/withdrawal_power_all',
|
|
128
|
+
'margin/exit_plan',
|
|
129
|
+
'margin/liquidation_history',
|
|
130
|
+
'margin/position_refresh_amounts',
|
|
131
|
+
'margin/status',
|
|
132
|
+
'oracle',
|
|
133
|
+
'orders',
|
|
134
|
+
'orders/{id}',
|
|
135
|
+
'orders/client:{client_oid}',
|
|
136
|
+
'otc/orders',
|
|
137
|
+
'payment-methods',
|
|
138
|
+
'position',
|
|
139
|
+
'profiles',
|
|
140
|
+
'profiles/{id}',
|
|
141
|
+
'reports/{report_id}',
|
|
142
|
+
'transfers',
|
|
143
|
+
'transfers/{transfer_id}',
|
|
144
|
+
'users/self/exchange-limits',
|
|
145
|
+
'users/self/hold-balances',
|
|
146
|
+
'users/self/trailing-volume',
|
|
147
|
+
'withdrawals/fee-estimate',
|
|
148
|
+
'conversions/{conversion_id}',
|
|
149
|
+
],
|
|
150
|
+
'post': [
|
|
151
|
+
'conversions',
|
|
152
|
+
'deposits/coinbase-account',
|
|
153
|
+
'deposits/payment-method',
|
|
154
|
+
'coinbase-accounts/{id}/addresses',
|
|
155
|
+
'funding/repay',
|
|
156
|
+
'orders',
|
|
157
|
+
'position/close',
|
|
158
|
+
'profiles/margin-transfer',
|
|
159
|
+
'profiles/transfer',
|
|
160
|
+
'reports',
|
|
161
|
+
'withdrawals/coinbase',
|
|
162
|
+
'withdrawals/coinbase-account',
|
|
163
|
+
'withdrawals/crypto',
|
|
164
|
+
'withdrawals/payment-method',
|
|
165
|
+
],
|
|
166
|
+
'delete': [
|
|
167
|
+
'orders',
|
|
168
|
+
'orders/client:{client_oid}',
|
|
169
|
+
'orders/{id}',
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
'commonCurrencies': {
|
|
174
|
+
'CGLD': 'CELO',
|
|
175
|
+
},
|
|
176
|
+
'precisionMode': number.TICK_SIZE,
|
|
177
|
+
'fees': {
|
|
178
|
+
'trading': {
|
|
179
|
+
'tierBased': true,
|
|
180
|
+
'percentage': true,
|
|
181
|
+
'maker': this.parseNumber('0.004'),
|
|
182
|
+
'taker': this.parseNumber('0.006'), // highest fee of all tiers
|
|
183
|
+
},
|
|
184
|
+
'funding': {
|
|
185
|
+
'tierBased': false,
|
|
186
|
+
'percentage': false,
|
|
187
|
+
'withdraw': {
|
|
188
|
+
'BCH': 0,
|
|
189
|
+
'BTC': 0,
|
|
190
|
+
'LTC': 0,
|
|
191
|
+
'ETH': 0,
|
|
192
|
+
'EUR': 0.15,
|
|
193
|
+
'USD': 25,
|
|
194
|
+
},
|
|
195
|
+
'deposit': {
|
|
196
|
+
'BCH': 0,
|
|
197
|
+
'BTC': 0,
|
|
198
|
+
'LTC': 0,
|
|
199
|
+
'ETH': 0,
|
|
200
|
+
'EUR': 0.15,
|
|
201
|
+
'USD': 10,
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
'exceptions': {
|
|
206
|
+
'exact': {
|
|
207
|
+
'Insufficient funds': errors.InsufficientFunds,
|
|
208
|
+
'NotFound': errors.OrderNotFound,
|
|
209
|
+
'Invalid API Key': errors.AuthenticationError,
|
|
210
|
+
'invalid signature': errors.AuthenticationError,
|
|
211
|
+
'Invalid Passphrase': errors.AuthenticationError,
|
|
212
|
+
'Invalid order id': errors.InvalidOrder,
|
|
213
|
+
'Private rate limit exceeded': errors.RateLimitExceeded,
|
|
214
|
+
'Trading pair not available': errors.PermissionDenied,
|
|
215
|
+
'Product not found': errors.InvalidOrder,
|
|
216
|
+
},
|
|
217
|
+
'broad': {
|
|
218
|
+
'Order already done': errors.OrderNotFound,
|
|
219
|
+
'order not found': errors.OrderNotFound,
|
|
220
|
+
'price too small': errors.InvalidOrder,
|
|
221
|
+
'price too precise': errors.InvalidOrder,
|
|
222
|
+
'under maintenance': errors.OnMaintenance,
|
|
223
|
+
'size is too small': errors.InvalidOrder,
|
|
224
|
+
'Cancel only mode': errors.OnMaintenance, // https://github.com/ccxt/ccxt/issues/7690
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
async fetchCurrencies(params = {}) {
|
|
230
|
+
/**
|
|
231
|
+
* @method
|
|
232
|
+
* @name coinbasepro#fetchCurrencies
|
|
233
|
+
* @description fetches all available currencies on an exchange
|
|
234
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getcurrencies
|
|
235
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
236
|
+
* @returns {object} an associative dictionary of currencies
|
|
237
|
+
*/
|
|
238
|
+
const response = await this.publicGetCurrencies(params);
|
|
239
|
+
//
|
|
240
|
+
// [
|
|
241
|
+
// {
|
|
242
|
+
// "id": "XTZ",
|
|
243
|
+
// "name": "Tezos",
|
|
244
|
+
// "min_size": "0.000001",
|
|
245
|
+
// "status": "online",
|
|
246
|
+
// "message": '',
|
|
247
|
+
// "max_precision": "0.000001",
|
|
248
|
+
// "convertible_to": [],
|
|
249
|
+
// "details": {
|
|
250
|
+
// "type": "crypto",
|
|
251
|
+
// "symbol": "Τ",
|
|
252
|
+
// "network_confirmations": 60,
|
|
253
|
+
// "sort_order": 53,
|
|
254
|
+
// "crypto_address_link": "https://tzstats.com/{{address}}",
|
|
255
|
+
// "crypto_transaction_link": "https://tzstats.com/{{txId}}",
|
|
256
|
+
// "push_payment_methods": [ "crypto" ],
|
|
257
|
+
// "group_types": [],
|
|
258
|
+
// "display_name": '',
|
|
259
|
+
// "processing_time_seconds": 0,
|
|
260
|
+
// "min_withdrawal_amount": 1
|
|
261
|
+
// }
|
|
262
|
+
// }
|
|
263
|
+
// ]
|
|
264
|
+
//
|
|
265
|
+
const result = {};
|
|
266
|
+
for (let i = 0; i < response.length; i++) {
|
|
267
|
+
const currency = response[i];
|
|
268
|
+
const id = this.safeString(currency, 'id');
|
|
269
|
+
const name = this.safeString(currency, 'name');
|
|
270
|
+
const code = this.safeCurrencyCode(id);
|
|
271
|
+
const details = this.safeValue(currency, 'details', {});
|
|
272
|
+
const status = this.safeString(currency, 'status');
|
|
273
|
+
const active = (status === 'online');
|
|
274
|
+
result[code] = {
|
|
275
|
+
'id': id,
|
|
276
|
+
'code': code,
|
|
277
|
+
'info': currency,
|
|
278
|
+
'type': this.safeString(details, 'type'),
|
|
279
|
+
'name': name,
|
|
280
|
+
'active': active,
|
|
281
|
+
'deposit': undefined,
|
|
282
|
+
'withdraw': undefined,
|
|
283
|
+
'fee': undefined,
|
|
284
|
+
'precision': this.safeNumber(currency, 'max_precision'),
|
|
285
|
+
'limits': {
|
|
286
|
+
'amount': {
|
|
287
|
+
'min': this.safeNumber(details, 'min_size'),
|
|
288
|
+
'max': undefined,
|
|
289
|
+
},
|
|
290
|
+
'withdraw': {
|
|
291
|
+
'min': this.safeNumber(details, 'min_withdrawal_amount'),
|
|
292
|
+
'max': undefined,
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
'networks': {},
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
return result;
|
|
299
|
+
}
|
|
300
|
+
async fetchMarkets(params = {}) {
|
|
301
|
+
/**
|
|
302
|
+
* @method
|
|
303
|
+
* @name coinbasepro#fetchMarkets
|
|
304
|
+
* @description retrieves data on all markets for coinbasepro
|
|
305
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproducts
|
|
306
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
307
|
+
* @returns {object[]} an array of objects representing market data
|
|
308
|
+
*/
|
|
309
|
+
const response = await this.publicGetProducts(params);
|
|
310
|
+
//
|
|
311
|
+
// [
|
|
312
|
+
// {
|
|
313
|
+
// "id": "BTCAUCTION-USD",
|
|
314
|
+
// "base_currency": "BTC",
|
|
315
|
+
// "quote_currency": "USD",
|
|
316
|
+
// "base_min_size": "0.000016",
|
|
317
|
+
// "base_max_size": "1500",
|
|
318
|
+
// "quote_increment": "0.01",
|
|
319
|
+
// "base_increment": "0.00000001",
|
|
320
|
+
// "display_name": "BTCAUCTION/USD",
|
|
321
|
+
// "min_market_funds": "1",
|
|
322
|
+
// "max_market_funds": "20000000",
|
|
323
|
+
// "margin_enabled": false,
|
|
324
|
+
// "fx_stablecoin": false,
|
|
325
|
+
// "max_slippage_percentage": "0.02000000",
|
|
326
|
+
// "post_only": false,
|
|
327
|
+
// "limit_only": false,
|
|
328
|
+
// "cancel_only": true,
|
|
329
|
+
// "trading_disabled": false,
|
|
330
|
+
// "status": "online",
|
|
331
|
+
// "status_message": '',
|
|
332
|
+
// "auction_mode": false
|
|
333
|
+
// },
|
|
334
|
+
// {
|
|
335
|
+
// "id": "BTC-USD",
|
|
336
|
+
// "base_currency": "BTC",
|
|
337
|
+
// "quote_currency": "USD",
|
|
338
|
+
// "base_min_size": "0.000016",
|
|
339
|
+
// "base_max_size": "1500",
|
|
340
|
+
// "quote_increment": "0.01",
|
|
341
|
+
// "base_increment": "0.00000001",
|
|
342
|
+
// "display_name": "BTC/USD",
|
|
343
|
+
// "min_market_funds": "1",
|
|
344
|
+
// "max_market_funds": "20000000",
|
|
345
|
+
// "margin_enabled": false,
|
|
346
|
+
// "fx_stablecoin": false,
|
|
347
|
+
// "max_slippage_percentage": "0.02000000",
|
|
348
|
+
// "post_only": false,
|
|
349
|
+
// "limit_only": false,
|
|
350
|
+
// "cancel_only": false,
|
|
351
|
+
// "trading_disabled": false,
|
|
352
|
+
// "status": "online",
|
|
353
|
+
// "status_message": '',
|
|
354
|
+
// "auction_mode": false
|
|
355
|
+
// }
|
|
356
|
+
// ]
|
|
357
|
+
//
|
|
358
|
+
const result = [];
|
|
359
|
+
for (let i = 0; i < response.length; i++) {
|
|
360
|
+
const market = response[i];
|
|
361
|
+
const id = this.safeString(market, 'id');
|
|
362
|
+
const [baseId, quoteId] = id.split('-');
|
|
363
|
+
// BTCAUCTION-USD vs BTC-USD conflict workaround, see the output sample above
|
|
364
|
+
// const baseId = this.safeString (market, 'base_currency');
|
|
365
|
+
// const quoteId = this.safeString (market, 'quote_currency');
|
|
366
|
+
const base = this.safeCurrencyCode(baseId);
|
|
367
|
+
const quote = this.safeCurrencyCode(quoteId);
|
|
368
|
+
const status = this.safeString(market, 'status');
|
|
369
|
+
result.push(this.extend(this.fees['trading'], {
|
|
370
|
+
'id': id,
|
|
371
|
+
'symbol': base + '/' + quote,
|
|
372
|
+
'base': base,
|
|
373
|
+
'quote': quote,
|
|
374
|
+
'settle': undefined,
|
|
375
|
+
'baseId': baseId,
|
|
376
|
+
'quoteId': quoteId,
|
|
377
|
+
'settleId': undefined,
|
|
378
|
+
'type': 'spot',
|
|
379
|
+
'spot': true,
|
|
380
|
+
'margin': this.safeValue(market, 'margin_enabled'),
|
|
381
|
+
'swap': false,
|
|
382
|
+
'future': false,
|
|
383
|
+
'option': false,
|
|
384
|
+
'active': (status === 'online'),
|
|
385
|
+
'contract': false,
|
|
386
|
+
'linear': undefined,
|
|
387
|
+
'inverse': undefined,
|
|
388
|
+
'contractSize': undefined,
|
|
389
|
+
'expiry': undefined,
|
|
390
|
+
'expiryDatetime': undefined,
|
|
391
|
+
'strike': undefined,
|
|
392
|
+
'optionType': undefined,
|
|
393
|
+
'precision': {
|
|
394
|
+
'amount': this.safeNumber(market, 'base_increment'),
|
|
395
|
+
'price': this.safeNumber(market, 'quote_increment'),
|
|
396
|
+
},
|
|
397
|
+
'limits': {
|
|
398
|
+
'leverage': {
|
|
399
|
+
'min': undefined,
|
|
400
|
+
'max': undefined,
|
|
401
|
+
},
|
|
402
|
+
'amount': {
|
|
403
|
+
'min': undefined,
|
|
404
|
+
'max': undefined,
|
|
405
|
+
},
|
|
406
|
+
'price': {
|
|
407
|
+
'min': undefined,
|
|
408
|
+
'max': undefined,
|
|
409
|
+
},
|
|
410
|
+
'cost': {
|
|
411
|
+
'min': this.safeNumber(market, 'min_market_funds'),
|
|
412
|
+
'max': undefined,
|
|
413
|
+
},
|
|
414
|
+
},
|
|
415
|
+
'created': undefined,
|
|
416
|
+
'info': market,
|
|
417
|
+
}));
|
|
418
|
+
}
|
|
419
|
+
return result;
|
|
420
|
+
}
|
|
421
|
+
async fetchAccounts(params = {}) {
|
|
422
|
+
/**
|
|
423
|
+
* @method
|
|
424
|
+
* @name coinbasepro#fetchAccounts
|
|
425
|
+
* @description fetch all the accounts associated with a profile
|
|
426
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounts
|
|
427
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
428
|
+
* @returns {object} a dictionary of [account structures]{@link https://docs.ccxt.com/#/?id=account-structure} indexed by the account type
|
|
429
|
+
*/
|
|
430
|
+
await this.loadMarkets();
|
|
431
|
+
const response = await this.privateGetAccounts(params);
|
|
432
|
+
//
|
|
433
|
+
// [
|
|
434
|
+
// {
|
|
435
|
+
// "id": "4aac9c60-cbda-4396-9da4-4aa71e95fba0",
|
|
436
|
+
// "currency": "BTC",
|
|
437
|
+
// "balance": "0.0000000000000000",
|
|
438
|
+
// "available": "0",
|
|
439
|
+
// "hold": "0.0000000000000000",
|
|
440
|
+
// "profile_id": "b709263e-f42a-4c7d-949a-a95c83d065da"
|
|
441
|
+
// },
|
|
442
|
+
// {
|
|
443
|
+
// "id": "f75fa69a-1ad1-4a80-bd61-ee7faa6135a3",
|
|
444
|
+
// "currency": "USDC",
|
|
445
|
+
// "balance": "0.0000000000000000",
|
|
446
|
+
// "available": "0",
|
|
447
|
+
// "hold": "0.0000000000000000",
|
|
448
|
+
// "profile_id": "b709263e-f42a-4c7d-949a-a95c83d065da"
|
|
449
|
+
// },
|
|
450
|
+
// ]
|
|
451
|
+
//
|
|
452
|
+
return this.parseAccounts(response, params);
|
|
453
|
+
}
|
|
454
|
+
parseAccount(account) {
|
|
455
|
+
//
|
|
456
|
+
// {
|
|
457
|
+
// "id": "4aac9c60-cbda-4396-9da4-4aa71e95fba0",
|
|
458
|
+
// "currency": "BTC",
|
|
459
|
+
// "balance": "0.0000000000000000",
|
|
460
|
+
// "available": "0",
|
|
461
|
+
// "hold": "0.0000000000000000",
|
|
462
|
+
// "profile_id": "b709263e-f42a-4c7d-949a-a95c83d065da"
|
|
463
|
+
// }
|
|
464
|
+
//
|
|
465
|
+
const currencyId = this.safeString(account, 'currency');
|
|
466
|
+
return {
|
|
467
|
+
'id': this.safeString(account, 'id'),
|
|
468
|
+
'type': undefined,
|
|
469
|
+
'code': this.safeCurrencyCode(currencyId),
|
|
470
|
+
'info': account,
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
parseBalance(response) {
|
|
474
|
+
const result = { 'info': response };
|
|
475
|
+
for (let i = 0; i < response.length; i++) {
|
|
476
|
+
const balance = response[i];
|
|
477
|
+
const currencyId = this.safeString(balance, 'currency');
|
|
478
|
+
const code = this.safeCurrencyCode(currencyId);
|
|
479
|
+
const account = this.account();
|
|
480
|
+
account['free'] = this.safeString(balance, 'available');
|
|
481
|
+
account['used'] = this.safeString(balance, 'hold');
|
|
482
|
+
account['total'] = this.safeString(balance, 'balance');
|
|
483
|
+
result[code] = account;
|
|
484
|
+
}
|
|
485
|
+
return this.safeBalance(result);
|
|
486
|
+
}
|
|
487
|
+
async fetchBalance(params = {}) {
|
|
488
|
+
/**
|
|
489
|
+
* @method
|
|
490
|
+
* @name coinbasepro#fetchBalance
|
|
491
|
+
* @description query for balance and get the amount of funds available for trading or funds locked in orders
|
|
492
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounts
|
|
493
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
494
|
+
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
|
|
495
|
+
*/
|
|
496
|
+
await this.loadMarkets();
|
|
497
|
+
const response = await this.privateGetAccounts(params);
|
|
498
|
+
return this.parseBalance(response);
|
|
499
|
+
}
|
|
500
|
+
async fetchOrderBook(symbol, limit = undefined, params = {}) {
|
|
501
|
+
/**
|
|
502
|
+
* @method
|
|
503
|
+
* @name coinbasepro#fetchOrderBook
|
|
504
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductbook
|
|
505
|
+
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
|
|
506
|
+
* @param {string} symbol unified symbol of the market to fetch the order book for
|
|
507
|
+
* @param {int} [limit] the maximum amount of order book entries to return
|
|
508
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
509
|
+
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
|
|
510
|
+
*/
|
|
511
|
+
await this.loadMarkets();
|
|
512
|
+
// level 1 - only the best bid and ask
|
|
513
|
+
// level 2 - top 50 bids and asks (aggregated)
|
|
514
|
+
// level 3 - full order book (non aggregated)
|
|
515
|
+
const request = {
|
|
516
|
+
'id': this.marketId(symbol),
|
|
517
|
+
'level': 2, // 1 best bidask, 2 aggregated, 3 full
|
|
518
|
+
};
|
|
519
|
+
const response = await this.publicGetProductsIdBook(this.extend(request, params));
|
|
520
|
+
//
|
|
521
|
+
// {
|
|
522
|
+
// "sequence":1924393896,
|
|
523
|
+
// "bids":[
|
|
524
|
+
// ["0.01825","24.34811287",2],
|
|
525
|
+
// ["0.01824","72.5463",3],
|
|
526
|
+
// ["0.01823","424.54298049",6],
|
|
527
|
+
// ],
|
|
528
|
+
// "asks":[
|
|
529
|
+
// ["0.01826","171.10414904",4],
|
|
530
|
+
// ["0.01827","22.60427028",1],
|
|
531
|
+
// ["0.01828","397.46018784",7],
|
|
532
|
+
// ]
|
|
533
|
+
// }
|
|
534
|
+
//
|
|
535
|
+
const orderbook = this.parseOrderBook(response, symbol);
|
|
536
|
+
orderbook['nonce'] = this.safeInteger(response, 'sequence');
|
|
537
|
+
return orderbook;
|
|
538
|
+
}
|
|
539
|
+
parseTicker(ticker, market = undefined) {
|
|
540
|
+
//
|
|
541
|
+
// fetchTickers
|
|
542
|
+
//
|
|
543
|
+
// [
|
|
544
|
+
// 1639472400, // timestamp
|
|
545
|
+
// 4.26, // low
|
|
546
|
+
// 4.38, // high
|
|
547
|
+
// 4.35, // open
|
|
548
|
+
// 4.27 // close
|
|
549
|
+
// ]
|
|
550
|
+
//
|
|
551
|
+
// fetchTicker
|
|
552
|
+
//
|
|
553
|
+
// publicGetProductsIdTicker
|
|
554
|
+
//
|
|
555
|
+
// {
|
|
556
|
+
// "trade_id":843439,
|
|
557
|
+
// "price":"0.997999",
|
|
558
|
+
// "size":"80.29769",
|
|
559
|
+
// "time":"2020-01-28T02:13:33.012523Z",
|
|
560
|
+
// "bid":"0.997094",
|
|
561
|
+
// "ask":"0.998",
|
|
562
|
+
// "volume":"1903188.03750000"
|
|
563
|
+
// }
|
|
564
|
+
//
|
|
565
|
+
// publicGetProductsIdStats
|
|
566
|
+
//
|
|
567
|
+
// {
|
|
568
|
+
// "open": "34.19000000",
|
|
569
|
+
// "high": "95.70000000",
|
|
570
|
+
// "low": "7.06000000",
|
|
571
|
+
// "volume": "2.41000000"
|
|
572
|
+
// }
|
|
573
|
+
//
|
|
574
|
+
let timestamp = undefined;
|
|
575
|
+
let bid = undefined;
|
|
576
|
+
let ask = undefined;
|
|
577
|
+
let last = undefined;
|
|
578
|
+
let high = undefined;
|
|
579
|
+
let low = undefined;
|
|
580
|
+
let open = undefined;
|
|
581
|
+
let volume = undefined;
|
|
582
|
+
const symbol = (market === undefined) ? undefined : market['symbol'];
|
|
583
|
+
if (Array.isArray(ticker)) {
|
|
584
|
+
last = this.safeString(ticker, 4);
|
|
585
|
+
timestamp = this.milliseconds();
|
|
586
|
+
}
|
|
587
|
+
else {
|
|
588
|
+
timestamp = this.parse8601(this.safeValue(ticker, 'time'));
|
|
589
|
+
bid = this.safeString(ticker, 'bid');
|
|
590
|
+
ask = this.safeString(ticker, 'ask');
|
|
591
|
+
high = this.safeString(ticker, 'high');
|
|
592
|
+
low = this.safeString(ticker, 'low');
|
|
593
|
+
open = this.safeString(ticker, 'open');
|
|
594
|
+
last = this.safeString2(ticker, 'price', 'last');
|
|
595
|
+
volume = this.safeString(ticker, 'volume');
|
|
596
|
+
}
|
|
597
|
+
return this.safeTicker({
|
|
598
|
+
'symbol': symbol,
|
|
599
|
+
'timestamp': timestamp,
|
|
600
|
+
'datetime': this.iso8601(timestamp),
|
|
601
|
+
'high': high,
|
|
602
|
+
'low': low,
|
|
603
|
+
'bid': bid,
|
|
604
|
+
'bidVolume': undefined,
|
|
605
|
+
'ask': ask,
|
|
606
|
+
'askVolume': undefined,
|
|
607
|
+
'vwap': undefined,
|
|
608
|
+
'open': open,
|
|
609
|
+
'close': last,
|
|
610
|
+
'last': last,
|
|
611
|
+
'previousClose': undefined,
|
|
612
|
+
'change': undefined,
|
|
613
|
+
'percentage': undefined,
|
|
614
|
+
'average': undefined,
|
|
615
|
+
'baseVolume': volume,
|
|
616
|
+
'quoteVolume': undefined,
|
|
617
|
+
'info': ticker,
|
|
618
|
+
}, market);
|
|
619
|
+
}
|
|
620
|
+
async fetchTickers(symbols = undefined, params = {}) {
|
|
621
|
+
/**
|
|
622
|
+
* @method
|
|
623
|
+
* @name coinbasepro#fetchTickers
|
|
624
|
+
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
|
|
625
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproduct
|
|
626
|
+
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
|
|
627
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
628
|
+
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
|
|
629
|
+
*/
|
|
630
|
+
await this.loadMarkets();
|
|
631
|
+
symbols = this.marketSymbols(symbols);
|
|
632
|
+
const request = {};
|
|
633
|
+
const response = await this.publicGetProductsSparkLines(this.extend(request, params));
|
|
634
|
+
//
|
|
635
|
+
// {
|
|
636
|
+
// YYY-USD: [
|
|
637
|
+
// [
|
|
638
|
+
// 1639472400, // timestamp
|
|
639
|
+
// 4.26, // low
|
|
640
|
+
// 4.38, // high
|
|
641
|
+
// 4.35, // open
|
|
642
|
+
// 4.27 // close
|
|
643
|
+
// ],
|
|
644
|
+
// [
|
|
645
|
+
// 1639468800,
|
|
646
|
+
// 4.31,
|
|
647
|
+
// 4.45,
|
|
648
|
+
// 4.35,
|
|
649
|
+
// 4.35
|
|
650
|
+
// ],
|
|
651
|
+
// ]
|
|
652
|
+
// }
|
|
653
|
+
//
|
|
654
|
+
const result = {};
|
|
655
|
+
const marketIds = Object.keys(response);
|
|
656
|
+
const delimiter = '-';
|
|
657
|
+
for (let i = 0; i < marketIds.length; i++) {
|
|
658
|
+
const marketId = marketIds[i];
|
|
659
|
+
const entry = this.safeValue(response, marketId, []);
|
|
660
|
+
const first = this.safeValue(entry, 0, []);
|
|
661
|
+
const market = this.safeMarket(marketId, undefined, delimiter);
|
|
662
|
+
const symbol = market['symbol'];
|
|
663
|
+
result[symbol] = this.parseTicker(first, market);
|
|
664
|
+
}
|
|
665
|
+
return this.filterByArrayTickers(result, 'symbol', symbols);
|
|
666
|
+
}
|
|
667
|
+
async fetchTicker(symbol, params = {}) {
|
|
668
|
+
/**
|
|
669
|
+
* @method
|
|
670
|
+
* @name coinbasepro#fetchTicker
|
|
671
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductticker
|
|
672
|
+
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
|
|
673
|
+
* @param {string} symbol unified symbol of the market to fetch the ticker for
|
|
674
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
675
|
+
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
|
|
676
|
+
*/
|
|
677
|
+
await this.loadMarkets();
|
|
678
|
+
const market = this.market(symbol);
|
|
679
|
+
const request = {
|
|
680
|
+
'id': market['id'],
|
|
681
|
+
};
|
|
682
|
+
// publicGetProductsIdTicker or publicGetProductsIdStats
|
|
683
|
+
const method = this.safeString(this.options, 'fetchTickerMethod', 'publicGetProductsIdTicker');
|
|
684
|
+
const response = await this[method](this.extend(request, params));
|
|
685
|
+
//
|
|
686
|
+
// publicGetProductsIdTicker
|
|
687
|
+
//
|
|
688
|
+
// {
|
|
689
|
+
// "trade_id":843439,
|
|
690
|
+
// "price":"0.997999",
|
|
691
|
+
// "size":"80.29769",
|
|
692
|
+
// "time":"2020-01-28T02:13:33.012523Z",
|
|
693
|
+
// "bid":"0.997094",
|
|
694
|
+
// "ask":"0.998",
|
|
695
|
+
// "volume":"1903188.03750000"
|
|
696
|
+
// }
|
|
697
|
+
//
|
|
698
|
+
// publicGetProductsIdStats
|
|
699
|
+
//
|
|
700
|
+
// {
|
|
701
|
+
// "open": "34.19000000",
|
|
702
|
+
// "high": "95.70000000",
|
|
703
|
+
// "low": "7.06000000",
|
|
704
|
+
// "volume": "2.41000000"
|
|
705
|
+
// }
|
|
706
|
+
//
|
|
707
|
+
return this.parseTicker(response, market);
|
|
708
|
+
}
|
|
709
|
+
parseTrade(trade, market = undefined) {
|
|
710
|
+
//
|
|
711
|
+
// {
|
|
712
|
+
// "type": "match",
|
|
713
|
+
// "trade_id": 82047307,
|
|
714
|
+
// "maker_order_id": "0f358725-2134-435e-be11-753912a326e0",
|
|
715
|
+
// "taker_order_id": "252b7002-87a3-425c-ac73-f5b9e23f3caf",
|
|
716
|
+
// "order_id": "d50ec984-77a8-460a-b958-66f114b0de9b",
|
|
717
|
+
// "side": "sell",
|
|
718
|
+
// "size": "0.00513192",
|
|
719
|
+
// "price": "9314.78",
|
|
720
|
+
// "product_id": "BTC-USD",
|
|
721
|
+
// "profile_id": "6244401d-c078-40d9-b305-7ad3551bc3b0",
|
|
722
|
+
// "sequence": 12038915443,
|
|
723
|
+
// "time": "2020-01-31T20:03:41.158814Z"
|
|
724
|
+
// "created_at": "2014-11-07T22:19:28.578544Z",
|
|
725
|
+
// "liquidity": "T",
|
|
726
|
+
// "fee": "0.00025",
|
|
727
|
+
// "settled": true,
|
|
728
|
+
// "usd_volume": "0.0924556000000000",
|
|
729
|
+
// "user_id": "595eb864313c2b02ddf2937d"
|
|
730
|
+
// }
|
|
731
|
+
//
|
|
732
|
+
const timestamp = this.parse8601(this.safeString2(trade, 'time', 'created_at'));
|
|
733
|
+
const marketId = this.safeString(trade, 'product_id');
|
|
734
|
+
market = this.safeMarket(marketId, market, '-');
|
|
735
|
+
let feeRate = undefined;
|
|
736
|
+
let takerOrMaker = undefined;
|
|
737
|
+
let cost = undefined;
|
|
738
|
+
const feeCurrencyId = this.safeStringLower(market, 'quoteId');
|
|
739
|
+
if (feeCurrencyId !== undefined) {
|
|
740
|
+
const costField = feeCurrencyId + '_value';
|
|
741
|
+
cost = this.safeString(trade, costField);
|
|
742
|
+
const liquidity = this.safeString(trade, 'liquidity');
|
|
743
|
+
if (liquidity !== undefined) {
|
|
744
|
+
takerOrMaker = (liquidity === 'T') ? 'taker' : 'maker';
|
|
745
|
+
feeRate = this.safeString(market, takerOrMaker);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
const feeCost = this.safeString2(trade, 'fill_fees', 'fee');
|
|
749
|
+
const fee = {
|
|
750
|
+
'cost': feeCost,
|
|
751
|
+
'currency': market['quote'],
|
|
752
|
+
'rate': feeRate,
|
|
753
|
+
};
|
|
754
|
+
const id = this.safeString(trade, 'trade_id');
|
|
755
|
+
let side = (trade['side'] === 'buy') ? 'sell' : 'buy';
|
|
756
|
+
const orderId = this.safeString(trade, 'order_id');
|
|
757
|
+
// Coinbase Pro returns inverted side to fetchMyTrades vs fetchTrades
|
|
758
|
+
const makerOrderId = this.safeString(trade, 'maker_order_id');
|
|
759
|
+
const takerOrderId = this.safeString(trade, 'taker_order_id');
|
|
760
|
+
if ((orderId !== undefined) || ((makerOrderId !== undefined) && (takerOrderId !== undefined))) {
|
|
761
|
+
side = (trade['side'] === 'buy') ? 'buy' : 'sell';
|
|
762
|
+
}
|
|
763
|
+
const price = this.safeString(trade, 'price');
|
|
764
|
+
const amount = this.safeString(trade, 'size');
|
|
765
|
+
return this.safeTrade({
|
|
766
|
+
'id': id,
|
|
767
|
+
'order': orderId,
|
|
768
|
+
'info': trade,
|
|
769
|
+
'timestamp': timestamp,
|
|
770
|
+
'datetime': this.iso8601(timestamp),
|
|
771
|
+
'symbol': market['symbol'],
|
|
772
|
+
'type': undefined,
|
|
773
|
+
'takerOrMaker': takerOrMaker,
|
|
774
|
+
'side': side,
|
|
775
|
+
'price': price,
|
|
776
|
+
'amount': amount,
|
|
777
|
+
'fee': fee,
|
|
778
|
+
'cost': cost,
|
|
779
|
+
}, market);
|
|
780
|
+
}
|
|
781
|
+
async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
782
|
+
/**
|
|
783
|
+
* @method
|
|
784
|
+
* @name coinbasepro#fetchMyTrades
|
|
785
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getfills
|
|
786
|
+
* @description fetch all trades made by the user
|
|
787
|
+
* @param {string} symbol unified market symbol
|
|
788
|
+
* @param {int} [since] the earliest time in ms to fetch trades for
|
|
789
|
+
* @param {int} [limit] the maximum number of trades structures to retrieve
|
|
790
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
791
|
+
* @param {int} [params.until] the latest time in ms to fetch trades for
|
|
792
|
+
* @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)
|
|
793
|
+
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
|
|
794
|
+
*/
|
|
795
|
+
if (symbol === undefined) {
|
|
796
|
+
throw new errors.ArgumentsRequired(this.id + ' fetchMyTrades() requires a symbol argument');
|
|
797
|
+
}
|
|
798
|
+
let paginate = false;
|
|
799
|
+
[paginate, params] = this.handleOptionAndParams(params, 'fetchMyTrades', 'paginate');
|
|
800
|
+
if (paginate) {
|
|
801
|
+
return await this.fetchPaginatedCallDynamic('fetchMyTrades', symbol, since, limit, params, 100);
|
|
802
|
+
}
|
|
803
|
+
await this.loadMarkets();
|
|
804
|
+
const market = this.market(symbol);
|
|
805
|
+
const request = {
|
|
806
|
+
'product_id': market['id'],
|
|
807
|
+
};
|
|
808
|
+
if (limit !== undefined) {
|
|
809
|
+
request['limit'] = limit;
|
|
810
|
+
}
|
|
811
|
+
if (since !== undefined) {
|
|
812
|
+
request['start_date'] = this.iso8601(since);
|
|
813
|
+
}
|
|
814
|
+
const until = this.safeValue2(params, 'until', 'end_date');
|
|
815
|
+
if (until !== undefined) {
|
|
816
|
+
params = this.omit(params, ['until']);
|
|
817
|
+
request['end_date'] = this.iso8601(until);
|
|
818
|
+
}
|
|
819
|
+
const response = await this.privateGetFills(this.extend(request, params));
|
|
820
|
+
return this.parseTrades(response, market, since, limit);
|
|
821
|
+
}
|
|
822
|
+
async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
|
|
823
|
+
/**
|
|
824
|
+
* @method
|
|
825
|
+
* @name coinbasepro#fetchTrades
|
|
826
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproducttrades
|
|
827
|
+
* @description get the list of most recent trades for a particular symbol
|
|
828
|
+
* @param {string} symbol unified symbol of the market to fetch trades for
|
|
829
|
+
* @param {int} [since] timestamp in ms of the earliest trade to fetch
|
|
830
|
+
* @param {int} [limit] the maximum amount of trades to fetch
|
|
831
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
832
|
+
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
|
|
833
|
+
*/
|
|
834
|
+
await this.loadMarkets();
|
|
835
|
+
const market = this.market(symbol);
|
|
836
|
+
const request = {
|
|
837
|
+
'id': market['id'], // fixes issue #2
|
|
838
|
+
};
|
|
839
|
+
if (limit !== undefined) {
|
|
840
|
+
request['limit'] = limit; // default 100
|
|
841
|
+
}
|
|
842
|
+
const response = await this.publicGetProductsIdTrades(this.extend(request, params));
|
|
843
|
+
//
|
|
844
|
+
// [
|
|
845
|
+
// {
|
|
846
|
+
// "trade_id": "15035219",
|
|
847
|
+
// "side": "sell",
|
|
848
|
+
// "size": "0.27426731",
|
|
849
|
+
// "price": "25820.42000000",
|
|
850
|
+
// "time": "2023-09-10T13:47:41.447577Z"
|
|
851
|
+
// },
|
|
852
|
+
// ]
|
|
853
|
+
//
|
|
854
|
+
return this.parseTrades(response, market, since, limit);
|
|
855
|
+
}
|
|
856
|
+
async fetchTradingFees(params = {}) {
|
|
857
|
+
/**
|
|
858
|
+
* @method
|
|
859
|
+
* @name coinbasepro#fetchTradingFees
|
|
860
|
+
* @description fetch the trading fees for multiple markets
|
|
861
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getfees
|
|
862
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
863
|
+
* @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure} indexed by market symbols
|
|
864
|
+
*/
|
|
865
|
+
await this.loadMarkets();
|
|
866
|
+
const response = await this.privateGetFees(params);
|
|
867
|
+
//
|
|
868
|
+
// {
|
|
869
|
+
// "maker_fee_rate": "0.0050",
|
|
870
|
+
// "taker_fee_rate": "0.0050",
|
|
871
|
+
// "usd_volume": "43806.92"
|
|
872
|
+
// }
|
|
873
|
+
//
|
|
874
|
+
const maker = this.safeNumber(response, 'maker_fee_rate');
|
|
875
|
+
const taker = this.safeNumber(response, 'taker_fee_rate');
|
|
876
|
+
const result = {};
|
|
877
|
+
for (let i = 0; i < this.symbols.length; i++) {
|
|
878
|
+
const symbol = this.symbols[i];
|
|
879
|
+
result[symbol] = {
|
|
880
|
+
'info': response,
|
|
881
|
+
'symbol': symbol,
|
|
882
|
+
'maker': maker,
|
|
883
|
+
'taker': taker,
|
|
884
|
+
'percentage': true,
|
|
885
|
+
'tierBased': true,
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
return result;
|
|
889
|
+
}
|
|
890
|
+
parseOHLCV(ohlcv, market = undefined) {
|
|
891
|
+
//
|
|
892
|
+
// [
|
|
893
|
+
// 1591514160,
|
|
894
|
+
// 0.02507,
|
|
895
|
+
// 0.02507,
|
|
896
|
+
// 0.02507,
|
|
897
|
+
// 0.02507,
|
|
898
|
+
// 0.02816506
|
|
899
|
+
// ]
|
|
900
|
+
//
|
|
901
|
+
return [
|
|
902
|
+
this.safeTimestamp(ohlcv, 0),
|
|
903
|
+
this.safeNumber(ohlcv, 3),
|
|
904
|
+
this.safeNumber(ohlcv, 2),
|
|
905
|
+
this.safeNumber(ohlcv, 1),
|
|
906
|
+
this.safeNumber(ohlcv, 4),
|
|
907
|
+
this.safeNumber(ohlcv, 5),
|
|
908
|
+
];
|
|
909
|
+
}
|
|
910
|
+
async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
|
|
911
|
+
/**
|
|
912
|
+
* @method
|
|
913
|
+
* @name coinbasepro#fetchOHLCV
|
|
914
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductcandles
|
|
915
|
+
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
|
|
916
|
+
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
|
|
917
|
+
* @param {string} timeframe the length of time each candle represents
|
|
918
|
+
* @param {int} [since] timestamp in ms of the earliest candle to fetch
|
|
919
|
+
* @param {int} [limit] the maximum amount of candles to fetch
|
|
920
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
921
|
+
* @param {int} [params.until] the latest time in ms to fetch trades for
|
|
922
|
+
* @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)
|
|
923
|
+
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
|
|
924
|
+
*/
|
|
925
|
+
await this.loadMarkets();
|
|
926
|
+
let paginate = false;
|
|
927
|
+
[paginate, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'paginate', false);
|
|
928
|
+
if (paginate) {
|
|
929
|
+
return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 300);
|
|
930
|
+
}
|
|
931
|
+
const market = this.market(symbol);
|
|
932
|
+
const parsedTimeframe = this.safeInteger(this.timeframes, timeframe);
|
|
933
|
+
const request = {
|
|
934
|
+
'id': market['id'],
|
|
935
|
+
};
|
|
936
|
+
if (parsedTimeframe !== undefined) {
|
|
937
|
+
request['granularity'] = parsedTimeframe;
|
|
938
|
+
}
|
|
939
|
+
else {
|
|
940
|
+
request['granularity'] = timeframe;
|
|
941
|
+
}
|
|
942
|
+
const until = this.safeValue2(params, 'until', 'end');
|
|
943
|
+
params = this.omit(params, ['until']);
|
|
944
|
+
if (since !== undefined) {
|
|
945
|
+
request['start'] = this.iso8601(since);
|
|
946
|
+
if (limit === undefined) {
|
|
947
|
+
// https://docs.pro.coinbase.com/#get-historic-rates
|
|
948
|
+
limit = 300; // max = 300
|
|
949
|
+
}
|
|
950
|
+
else {
|
|
951
|
+
limit = Math.min(300, limit);
|
|
952
|
+
}
|
|
953
|
+
if (until === undefined) {
|
|
954
|
+
const parsedTimeframeMilliseconds = parsedTimeframe * 1000;
|
|
955
|
+
if (this.isRoundNumber(since % parsedTimeframeMilliseconds)) {
|
|
956
|
+
request['end'] = this.iso8601(this.sum((limit - 1) * parsedTimeframeMilliseconds, since));
|
|
957
|
+
}
|
|
958
|
+
else {
|
|
959
|
+
request['end'] = this.iso8601(this.sum(limit * parsedTimeframeMilliseconds, since));
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
else {
|
|
963
|
+
request['end'] = this.iso8601(until);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
const response = await this.publicGetProductsIdCandles(this.extend(request, params));
|
|
967
|
+
//
|
|
968
|
+
// [
|
|
969
|
+
// [1591514160,0.02507,0.02507,0.02507,0.02507,0.02816506],
|
|
970
|
+
// [1591514100,0.02507,0.02507,0.02507,0.02507,1.63830323],
|
|
971
|
+
// [1591514040,0.02505,0.02507,0.02505,0.02507,0.19918178]
|
|
972
|
+
// ]
|
|
973
|
+
//
|
|
974
|
+
return this.parseOHLCVs(response, market, timeframe, since, limit);
|
|
975
|
+
}
|
|
976
|
+
async fetchTime(params = {}) {
|
|
977
|
+
/**
|
|
978
|
+
* @method
|
|
979
|
+
* @name coinbasepro#fetchTime
|
|
980
|
+
* @description fetches the current integer timestamp in milliseconds from the exchange server
|
|
981
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
982
|
+
* @returns {int} the current integer timestamp in milliseconds from the exchange server
|
|
983
|
+
*/
|
|
984
|
+
const response = await this.publicGetTime(params);
|
|
985
|
+
//
|
|
986
|
+
// {
|
|
987
|
+
// "iso":"2020-05-12T08:00:51.504Z",
|
|
988
|
+
// "epoch":1589270451.504
|
|
989
|
+
// }
|
|
990
|
+
//
|
|
991
|
+
return this.safeTimestamp(response, 'epoch');
|
|
992
|
+
}
|
|
993
|
+
parseOrderStatus(status) {
|
|
994
|
+
const statuses = {
|
|
995
|
+
'pending': 'open',
|
|
996
|
+
'active': 'open',
|
|
997
|
+
'open': 'open',
|
|
998
|
+
'done': 'closed',
|
|
999
|
+
'canceled': 'canceled',
|
|
1000
|
+
'canceling': 'open',
|
|
1001
|
+
};
|
|
1002
|
+
return this.safeString(statuses, status, status);
|
|
1003
|
+
}
|
|
1004
|
+
parseOrder(order, market = undefined) {
|
|
1005
|
+
//
|
|
1006
|
+
// createOrder
|
|
1007
|
+
//
|
|
1008
|
+
// {
|
|
1009
|
+
// "id": "d0c5340b-6d6c-49d9-b567-48c4bfca13d2",
|
|
1010
|
+
// "price": "0.10000000",
|
|
1011
|
+
// "size": "0.01000000",
|
|
1012
|
+
// "product_id": "BTC-USD",
|
|
1013
|
+
// "side": "buy",
|
|
1014
|
+
// "stp": "dc",
|
|
1015
|
+
// "type": "limit",
|
|
1016
|
+
// "time_in_force": "GTC",
|
|
1017
|
+
// "post_only": false,
|
|
1018
|
+
// "created_at": "2016-12-08T20:02:28.53864Z",
|
|
1019
|
+
// "fill_fees": "0.0000000000000000",
|
|
1020
|
+
// "filled_size": "0.00000000",
|
|
1021
|
+
// "executed_value": "0.0000000000000000",
|
|
1022
|
+
// "status": "pending",
|
|
1023
|
+
// "settled": false
|
|
1024
|
+
// }
|
|
1025
|
+
//
|
|
1026
|
+
const timestamp = this.parse8601(this.safeString(order, 'created_at'));
|
|
1027
|
+
const marketId = this.safeString(order, 'product_id');
|
|
1028
|
+
market = this.safeMarket(marketId, market, '-');
|
|
1029
|
+
let status = this.parseOrderStatus(this.safeString(order, 'status'));
|
|
1030
|
+
const doneReason = this.safeString(order, 'done_reason');
|
|
1031
|
+
if ((status === 'closed') && (doneReason === 'canceled')) {
|
|
1032
|
+
status = 'canceled';
|
|
1033
|
+
}
|
|
1034
|
+
const price = this.safeString(order, 'price');
|
|
1035
|
+
const filled = this.safeString(order, 'filled_size');
|
|
1036
|
+
const amount = this.safeString(order, 'size', filled);
|
|
1037
|
+
const cost = this.safeString(order, 'executed_value');
|
|
1038
|
+
const feeCost = this.safeNumber(order, 'fill_fees');
|
|
1039
|
+
let fee = undefined;
|
|
1040
|
+
if (feeCost !== undefined) {
|
|
1041
|
+
fee = {
|
|
1042
|
+
'cost': feeCost,
|
|
1043
|
+
'currency': market['quote'],
|
|
1044
|
+
'rate': undefined,
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
const id = this.safeString(order, 'id');
|
|
1048
|
+
const type = this.safeString(order, 'type');
|
|
1049
|
+
const side = this.safeString(order, 'side');
|
|
1050
|
+
const timeInForce = this.safeString(order, 'time_in_force');
|
|
1051
|
+
const postOnly = this.safeValue(order, 'post_only');
|
|
1052
|
+
const stopPrice = this.safeNumber(order, 'stop_price');
|
|
1053
|
+
const clientOrderId = this.safeString(order, 'client_oid');
|
|
1054
|
+
return this.safeOrder({
|
|
1055
|
+
'id': id,
|
|
1056
|
+
'clientOrderId': clientOrderId,
|
|
1057
|
+
'info': order,
|
|
1058
|
+
'timestamp': timestamp,
|
|
1059
|
+
'datetime': this.iso8601(timestamp),
|
|
1060
|
+
'lastTradeTimestamp': undefined,
|
|
1061
|
+
'status': status,
|
|
1062
|
+
'symbol': market['symbol'],
|
|
1063
|
+
'type': type,
|
|
1064
|
+
'timeInForce': timeInForce,
|
|
1065
|
+
'postOnly': postOnly,
|
|
1066
|
+
'side': side,
|
|
1067
|
+
'price': price,
|
|
1068
|
+
'stopPrice': stopPrice,
|
|
1069
|
+
'triggerPrice': stopPrice,
|
|
1070
|
+
'cost': cost,
|
|
1071
|
+
'amount': amount,
|
|
1072
|
+
'filled': filled,
|
|
1073
|
+
'remaining': undefined,
|
|
1074
|
+
'fee': fee,
|
|
1075
|
+
'average': undefined,
|
|
1076
|
+
'trades': undefined,
|
|
1077
|
+
}, market);
|
|
1078
|
+
}
|
|
1079
|
+
async fetchOrder(id, symbol = undefined, params = {}) {
|
|
1080
|
+
/**
|
|
1081
|
+
* @method
|
|
1082
|
+
* @name coinbasepro#fetchOrder
|
|
1083
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getorder
|
|
1084
|
+
* @description fetches information on an order made by the user
|
|
1085
|
+
* @param {string} symbol not used by coinbasepro fetchOrder
|
|
1086
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1087
|
+
* @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1088
|
+
*/
|
|
1089
|
+
await this.loadMarkets();
|
|
1090
|
+
const request = {};
|
|
1091
|
+
const clientOrderId = this.safeString2(params, 'clientOrderId', 'client_oid');
|
|
1092
|
+
let method = undefined;
|
|
1093
|
+
if (clientOrderId === undefined) {
|
|
1094
|
+
method = 'privateGetOrdersId';
|
|
1095
|
+
request['id'] = id;
|
|
1096
|
+
}
|
|
1097
|
+
else {
|
|
1098
|
+
method = 'privateGetOrdersClientClientOid';
|
|
1099
|
+
request['client_oid'] = clientOrderId;
|
|
1100
|
+
params = this.omit(params, ['clientOrderId', 'client_oid']);
|
|
1101
|
+
}
|
|
1102
|
+
const response = await this[method](this.extend(request, params));
|
|
1103
|
+
return this.parseOrder(response);
|
|
1104
|
+
}
|
|
1105
|
+
async fetchOrderTrades(id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1106
|
+
/**
|
|
1107
|
+
* @method
|
|
1108
|
+
* @name coinbasepro#fetchOrderTrades
|
|
1109
|
+
* @description fetch all the trades made from a single order
|
|
1110
|
+
* @param {string} id order id
|
|
1111
|
+
* @param {string} symbol unified market symbol
|
|
1112
|
+
* @param {int} [since] the earliest time in ms to fetch trades for
|
|
1113
|
+
* @param {int} [limit] the maximum number of trades to retrieve
|
|
1114
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1115
|
+
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
|
|
1116
|
+
*/
|
|
1117
|
+
await this.loadMarkets();
|
|
1118
|
+
let market = undefined;
|
|
1119
|
+
if (symbol !== undefined) {
|
|
1120
|
+
market = this.market(symbol);
|
|
1121
|
+
}
|
|
1122
|
+
const request = {
|
|
1123
|
+
'order_id': id,
|
|
1124
|
+
};
|
|
1125
|
+
const response = await this.privateGetFills(this.extend(request, params));
|
|
1126
|
+
return this.parseTrades(response, market, since, limit);
|
|
1127
|
+
}
|
|
1128
|
+
async fetchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1129
|
+
/**
|
|
1130
|
+
* @method
|
|
1131
|
+
* @name coinbasepro#fetchOrders
|
|
1132
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getorders
|
|
1133
|
+
* @description fetches information on multiple orders made by the user
|
|
1134
|
+
* @param {string} symbol unified market symbol of the market orders were made in
|
|
1135
|
+
* @param {int} [since] the earliest time in ms to fetch orders for
|
|
1136
|
+
* @param {int} [limit] the maximum number of order structures to retrieve
|
|
1137
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1138
|
+
* @param {int} [params.until] the latest time in ms to fetch open orders for
|
|
1139
|
+
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1140
|
+
*/
|
|
1141
|
+
const request = {
|
|
1142
|
+
'status': 'all',
|
|
1143
|
+
};
|
|
1144
|
+
return await this.fetchOpenOrders(symbol, since, limit, this.extend(request, params));
|
|
1145
|
+
}
|
|
1146
|
+
async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1147
|
+
/**
|
|
1148
|
+
* @method
|
|
1149
|
+
* @name coinbasepro#fetchOpenOrders
|
|
1150
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getorders
|
|
1151
|
+
* @description fetch all unfilled currently open orders
|
|
1152
|
+
* @param {string} symbol unified market symbol
|
|
1153
|
+
* @param {int} [since] the earliest time in ms to fetch open orders for
|
|
1154
|
+
* @param {int} [limit] the maximum number of open orders structures to retrieve
|
|
1155
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1156
|
+
* @param {int} [params.until] the latest time in ms to fetch open orders for
|
|
1157
|
+
* @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)
|
|
1158
|
+
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1159
|
+
*/
|
|
1160
|
+
await this.loadMarkets();
|
|
1161
|
+
let paginate = false;
|
|
1162
|
+
[paginate, params] = this.handleOptionAndParams(params, 'fetchOpenOrders', 'paginate');
|
|
1163
|
+
if (paginate) {
|
|
1164
|
+
return await this.fetchPaginatedCallDynamic('fetchOpenOrders', symbol, since, limit, params, 100);
|
|
1165
|
+
}
|
|
1166
|
+
const request = {};
|
|
1167
|
+
let market = undefined;
|
|
1168
|
+
if (symbol !== undefined) {
|
|
1169
|
+
market = this.market(symbol);
|
|
1170
|
+
request['product_id'] = market['id'];
|
|
1171
|
+
}
|
|
1172
|
+
if (limit !== undefined) {
|
|
1173
|
+
request['limit'] = limit; // default 100
|
|
1174
|
+
}
|
|
1175
|
+
if (since !== undefined) {
|
|
1176
|
+
request['start_date'] = this.iso8601(since);
|
|
1177
|
+
}
|
|
1178
|
+
const until = this.safeValue2(params, 'until', 'end_date');
|
|
1179
|
+
if (until !== undefined) {
|
|
1180
|
+
params = this.omit(params, ['until']);
|
|
1181
|
+
request['end_date'] = this.iso8601(until);
|
|
1182
|
+
}
|
|
1183
|
+
const response = await this.privateGetOrders(this.extend(request, params));
|
|
1184
|
+
return this.parseOrders(response, market, since, limit);
|
|
1185
|
+
}
|
|
1186
|
+
async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1187
|
+
/**
|
|
1188
|
+
* @method
|
|
1189
|
+
* @name coinbasepro#fetchClosedOrders
|
|
1190
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getorders
|
|
1191
|
+
* @description fetches information on multiple closed orders made by the user
|
|
1192
|
+
* @param {string} symbol unified market symbol of the market orders were made in
|
|
1193
|
+
* @param {int} [since] the earliest time in ms to fetch orders for
|
|
1194
|
+
* @param {int} [limit] the maximum number of order structures to retrieve
|
|
1195
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1196
|
+
* @param {int} [params.until] the latest time in ms to fetch open orders for
|
|
1197
|
+
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1198
|
+
*/
|
|
1199
|
+
const request = {
|
|
1200
|
+
'status': 'done',
|
|
1201
|
+
};
|
|
1202
|
+
return await this.fetchOpenOrders(symbol, since, limit, this.extend(request, params));
|
|
1203
|
+
}
|
|
1204
|
+
async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
|
|
1205
|
+
/**
|
|
1206
|
+
* @method
|
|
1207
|
+
* @name coinbasepro#createOrder
|
|
1208
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postorders
|
|
1209
|
+
* @description create a trade order
|
|
1210
|
+
* @param {string} symbol unified symbol of the market to create an order in
|
|
1211
|
+
* @param {string} type 'market' or 'limit'
|
|
1212
|
+
* @param {string} side 'buy' or 'sell'
|
|
1213
|
+
* @param {float} amount how much of currency you want to trade in units of base currency
|
|
1214
|
+
* @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
|
|
1215
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1216
|
+
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1217
|
+
*/
|
|
1218
|
+
await this.loadMarkets();
|
|
1219
|
+
const market = this.market(symbol);
|
|
1220
|
+
const request = {
|
|
1221
|
+
// common params --------------------------------------------------
|
|
1222
|
+
// 'client_oid': clientOrderId,
|
|
1223
|
+
'type': type,
|
|
1224
|
+
'side': side,
|
|
1225
|
+
'product_id': market['id'],
|
|
1226
|
+
// 'size': this.amountToPrecision (symbol, amount),
|
|
1227
|
+
// 'stp': 'dc', // self-trade prevention, dc = decrease and cancel, co = cancel oldest, cn = cancel newest, cb = cancel both
|
|
1228
|
+
// 'stop': 'loss', // "loss" = stop loss below price, "entry" = take profit above price
|
|
1229
|
+
// 'stop_price': this.priceToPrecision (symbol, price),
|
|
1230
|
+
// limit order params ---------------------------------------------
|
|
1231
|
+
// 'price': this.priceToPrecision (symbol, price),
|
|
1232
|
+
// 'size': this.amountToPrecision (symbol, amount),
|
|
1233
|
+
// 'time_in_force': 'GTC', // GTC, GTT, IOC, or FOK
|
|
1234
|
+
// 'cancel_after' [optional]* min, hour, day, requires time_in_force to be GTT
|
|
1235
|
+
// 'post_only': false, // invalid when time_in_force is IOC or FOK
|
|
1236
|
+
// market order params --------------------------------------------
|
|
1237
|
+
// 'size': this.amountToPrecision (symbol, amount),
|
|
1238
|
+
// 'funds': this.costToPrecision (symbol, amount),
|
|
1239
|
+
};
|
|
1240
|
+
const clientOrderId = this.safeString2(params, 'clientOrderId', 'client_oid');
|
|
1241
|
+
if (clientOrderId !== undefined) {
|
|
1242
|
+
request['client_oid'] = clientOrderId;
|
|
1243
|
+
}
|
|
1244
|
+
const stopPrice = this.safeNumberN(params, ['stopPrice', 'stop_price', 'triggerPrice']);
|
|
1245
|
+
if (stopPrice !== undefined) {
|
|
1246
|
+
request['stop_price'] = this.priceToPrecision(symbol, stopPrice);
|
|
1247
|
+
}
|
|
1248
|
+
const timeInForce = this.safeString2(params, 'timeInForce', 'time_in_force');
|
|
1249
|
+
if (timeInForce !== undefined) {
|
|
1250
|
+
request['time_in_force'] = timeInForce;
|
|
1251
|
+
}
|
|
1252
|
+
const postOnly = this.safeValue2(params, 'postOnly', 'post_only', false);
|
|
1253
|
+
if (postOnly) {
|
|
1254
|
+
request['post_only'] = true;
|
|
1255
|
+
}
|
|
1256
|
+
params = this.omit(params, ['timeInForce', 'time_in_force', 'stopPrice', 'stop_price', 'clientOrderId', 'client_oid', 'postOnly', 'post_only', 'triggerPrice']);
|
|
1257
|
+
if (type === 'limit') {
|
|
1258
|
+
request['price'] = this.priceToPrecision(symbol, price);
|
|
1259
|
+
request['size'] = this.amountToPrecision(symbol, amount);
|
|
1260
|
+
}
|
|
1261
|
+
else if (type === 'market') {
|
|
1262
|
+
let cost = this.safeNumber2(params, 'cost', 'funds');
|
|
1263
|
+
if (cost === undefined) {
|
|
1264
|
+
if (price !== undefined) {
|
|
1265
|
+
cost = amount * price;
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
else {
|
|
1269
|
+
params = this.omit(params, ['cost', 'funds']);
|
|
1270
|
+
}
|
|
1271
|
+
if (cost !== undefined) {
|
|
1272
|
+
request['funds'] = this.costToPrecision(symbol, cost);
|
|
1273
|
+
}
|
|
1274
|
+
else {
|
|
1275
|
+
request['size'] = this.amountToPrecision(symbol, amount);
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
const response = await this.privatePostOrders(this.extend(request, params));
|
|
1279
|
+
//
|
|
1280
|
+
// {
|
|
1281
|
+
// "id": "d0c5340b-6d6c-49d9-b567-48c4bfca13d2",
|
|
1282
|
+
// "price": "0.10000000",
|
|
1283
|
+
// "size": "0.01000000",
|
|
1284
|
+
// "product_id": "BTC-USD",
|
|
1285
|
+
// "side": "buy",
|
|
1286
|
+
// "stp": "dc",
|
|
1287
|
+
// "type": "limit",
|
|
1288
|
+
// "time_in_force": "GTC",
|
|
1289
|
+
// "post_only": false,
|
|
1290
|
+
// "created_at": "2016-12-08T20:02:28.53864Z",
|
|
1291
|
+
// "fill_fees": "0.0000000000000000",
|
|
1292
|
+
// "filled_size": "0.00000000",
|
|
1293
|
+
// "executed_value": "0.0000000000000000",
|
|
1294
|
+
// "status": "pending",
|
|
1295
|
+
// "settled": false
|
|
1296
|
+
// }
|
|
1297
|
+
//
|
|
1298
|
+
return this.parseOrder(response, market);
|
|
1299
|
+
}
|
|
1300
|
+
async cancelOrder(id, symbol = undefined, params = {}) {
|
|
1301
|
+
/**
|
|
1302
|
+
* @method
|
|
1303
|
+
* @name coinbasepro#cancelOrder
|
|
1304
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_deleteorder
|
|
1305
|
+
* @description cancels an open order
|
|
1306
|
+
* @param {string} id order id
|
|
1307
|
+
* @param {string} symbol unified symbol of the market the order was made in
|
|
1308
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1309
|
+
* @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1310
|
+
*/
|
|
1311
|
+
await this.loadMarkets();
|
|
1312
|
+
const request = {
|
|
1313
|
+
// 'product_id': market['id'], // the request will be more performant if you include it
|
|
1314
|
+
};
|
|
1315
|
+
const clientOrderId = this.safeString2(params, 'clientOrderId', 'client_oid');
|
|
1316
|
+
let method = undefined;
|
|
1317
|
+
if (clientOrderId === undefined) {
|
|
1318
|
+
method = 'privateDeleteOrdersId';
|
|
1319
|
+
request['id'] = id;
|
|
1320
|
+
}
|
|
1321
|
+
else {
|
|
1322
|
+
method = 'privateDeleteOrdersClientClientOid';
|
|
1323
|
+
request['client_oid'] = clientOrderId;
|
|
1324
|
+
params = this.omit(params, ['clientOrderId', 'client_oid']);
|
|
1325
|
+
}
|
|
1326
|
+
let market = undefined;
|
|
1327
|
+
if (symbol !== undefined) {
|
|
1328
|
+
market = this.market(symbol);
|
|
1329
|
+
request['product_id'] = market['symbol']; // the request will be more performant if you include it
|
|
1330
|
+
}
|
|
1331
|
+
return await this[method](this.extend(request, params));
|
|
1332
|
+
}
|
|
1333
|
+
async cancelAllOrders(symbol = undefined, params = {}) {
|
|
1334
|
+
/**
|
|
1335
|
+
* @method
|
|
1336
|
+
* @name coinbasepro#cancelAllOrders
|
|
1337
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_deleteorders
|
|
1338
|
+
* @description cancel all open orders
|
|
1339
|
+
* @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
|
|
1340
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1341
|
+
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1342
|
+
*/
|
|
1343
|
+
await this.loadMarkets();
|
|
1344
|
+
const request = {};
|
|
1345
|
+
let market = undefined;
|
|
1346
|
+
if (symbol !== undefined) {
|
|
1347
|
+
market = this.market(symbol);
|
|
1348
|
+
request['product_id'] = market['symbol']; // the request will be more performant if you include it
|
|
1349
|
+
}
|
|
1350
|
+
return await this.privateDeleteOrders(this.extend(request, params));
|
|
1351
|
+
}
|
|
1352
|
+
async fetchPaymentMethods(params = {}) {
|
|
1353
|
+
return await this.privateGetPaymentMethods(params);
|
|
1354
|
+
}
|
|
1355
|
+
async withdraw(code, amount, address, tag = undefined, params = {}) {
|
|
1356
|
+
/**
|
|
1357
|
+
* @method
|
|
1358
|
+
* @name coinbasepro#withdraw
|
|
1359
|
+
* @description make a withdrawal
|
|
1360
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postwithdrawpaymentmethod
|
|
1361
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postwithdrawcoinbaseaccount
|
|
1362
|
+
* @param {string} code unified currency code
|
|
1363
|
+
* @param {float} amount the amount to withdraw
|
|
1364
|
+
* @param {string} address the address to withdraw to
|
|
1365
|
+
* @param {string} tag
|
|
1366
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1367
|
+
* @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
|
|
1368
|
+
*/
|
|
1369
|
+
[tag, params] = this.handleWithdrawTagAndParams(tag, params);
|
|
1370
|
+
this.checkAddress(address);
|
|
1371
|
+
await this.loadMarkets();
|
|
1372
|
+
const currency = this.currency(code);
|
|
1373
|
+
const request = {
|
|
1374
|
+
'currency': currency['id'],
|
|
1375
|
+
'amount': amount,
|
|
1376
|
+
};
|
|
1377
|
+
let method = 'privatePostWithdrawals';
|
|
1378
|
+
if ('payment_method_id' in params) {
|
|
1379
|
+
method += 'PaymentMethod';
|
|
1380
|
+
}
|
|
1381
|
+
else if ('coinbase_account_id' in params) {
|
|
1382
|
+
method += 'CoinbaseAccount';
|
|
1383
|
+
}
|
|
1384
|
+
else {
|
|
1385
|
+
method += 'Crypto';
|
|
1386
|
+
request['crypto_address'] = address;
|
|
1387
|
+
if (tag !== undefined) {
|
|
1388
|
+
request['destination_tag'] = tag;
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
const response = await this[method](this.extend(request, params));
|
|
1392
|
+
if (!response) {
|
|
1393
|
+
throw new errors.ExchangeError(this.id + ' withdraw() error: ' + this.json(response));
|
|
1394
|
+
}
|
|
1395
|
+
return this.parseTransaction(response, currency);
|
|
1396
|
+
}
|
|
1397
|
+
parseLedgerEntryType(type) {
|
|
1398
|
+
const types = {
|
|
1399
|
+
'transfer': 'transfer',
|
|
1400
|
+
'match': 'trade',
|
|
1401
|
+
'fee': 'fee',
|
|
1402
|
+
'rebate': 'rebate',
|
|
1403
|
+
'conversion': 'trade', // Funds converted between fiat currency and a stablecoin
|
|
1404
|
+
};
|
|
1405
|
+
return this.safeString(types, type, type);
|
|
1406
|
+
}
|
|
1407
|
+
parseLedgerEntry(item, currency = undefined) {
|
|
1408
|
+
// {
|
|
1409
|
+
// "id": "12087495079",
|
|
1410
|
+
// "amount": "-0.0100000000000000",
|
|
1411
|
+
// "balance": "0.0645419900000000",
|
|
1412
|
+
// "created_at": "2021-10-28T17:14:32.593168Z",
|
|
1413
|
+
// "type": "transfer",
|
|
1414
|
+
// "details": {
|
|
1415
|
+
// "from": "2f74edf7-1440-4586-86dc-ae58c5693691",
|
|
1416
|
+
// "profile_transfer_id": "3ef093ad-2482-40d1-8ede-2f89cff5099e",
|
|
1417
|
+
// "to": "dda99503-4980-4b60-9549-0b770ee51336"
|
|
1418
|
+
// }
|
|
1419
|
+
// },
|
|
1420
|
+
// {
|
|
1421
|
+
// "id": "11740725774",
|
|
1422
|
+
// "amount": "-1.7565669701255000",
|
|
1423
|
+
// "balance": "0.0016490047745000",
|
|
1424
|
+
// "created_at": "2021-10-22T03:47:34.764122Z",
|
|
1425
|
+
// "type": "fee",
|
|
1426
|
+
// "details": {
|
|
1427
|
+
// "order_id": "ad06abf4-95ab-432a-a1d8-059ef572e296",
|
|
1428
|
+
// "product_id": "ETH-DAI",
|
|
1429
|
+
// "trade_id": "1740617"
|
|
1430
|
+
// }
|
|
1431
|
+
// }
|
|
1432
|
+
const id = this.safeString(item, 'id');
|
|
1433
|
+
let amountString = this.safeString(item, 'amount');
|
|
1434
|
+
let direction = undefined;
|
|
1435
|
+
const afterString = this.safeString(item, 'balance');
|
|
1436
|
+
const beforeString = Precise["default"].stringSub(afterString, amountString);
|
|
1437
|
+
if (Precise["default"].stringLt(amountString, '0')) {
|
|
1438
|
+
direction = 'out';
|
|
1439
|
+
amountString = Precise["default"].stringAbs(amountString);
|
|
1440
|
+
}
|
|
1441
|
+
else {
|
|
1442
|
+
direction = 'in';
|
|
1443
|
+
}
|
|
1444
|
+
const amount = this.parseNumber(amountString);
|
|
1445
|
+
const after = this.parseNumber(afterString);
|
|
1446
|
+
const before = this.parseNumber(beforeString);
|
|
1447
|
+
const timestamp = this.parse8601(this.safeValue(item, 'created_at'));
|
|
1448
|
+
const type = this.parseLedgerEntryType(this.safeString(item, 'type'));
|
|
1449
|
+
const code = this.safeCurrencyCode(undefined, currency);
|
|
1450
|
+
const details = this.safeValue(item, 'details', {});
|
|
1451
|
+
let account = undefined;
|
|
1452
|
+
let referenceAccount = undefined;
|
|
1453
|
+
let referenceId = undefined;
|
|
1454
|
+
if (type === 'transfer') {
|
|
1455
|
+
account = this.safeString(details, 'from');
|
|
1456
|
+
referenceAccount = this.safeString(details, 'to');
|
|
1457
|
+
referenceId = this.safeString(details, 'profile_transfer_id');
|
|
1458
|
+
}
|
|
1459
|
+
else {
|
|
1460
|
+
referenceId = this.safeString(details, 'order_id');
|
|
1461
|
+
}
|
|
1462
|
+
const status = 'ok';
|
|
1463
|
+
return {
|
|
1464
|
+
'id': id,
|
|
1465
|
+
'currency': code,
|
|
1466
|
+
'account': account,
|
|
1467
|
+
'referenceAccount': referenceAccount,
|
|
1468
|
+
'referenceId': referenceId,
|
|
1469
|
+
'status': status,
|
|
1470
|
+
'amount': amount,
|
|
1471
|
+
'before': before,
|
|
1472
|
+
'after': after,
|
|
1473
|
+
'fee': undefined,
|
|
1474
|
+
'direction': direction,
|
|
1475
|
+
'timestamp': timestamp,
|
|
1476
|
+
'datetime': this.iso8601(timestamp),
|
|
1477
|
+
'type': type,
|
|
1478
|
+
'info': item,
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1481
|
+
async fetchLedger(code = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1482
|
+
/**
|
|
1483
|
+
* @method
|
|
1484
|
+
* @name coinbasepro#fetchLedger
|
|
1485
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccountledger
|
|
1486
|
+
* @description fetch the history of changes, actions done by the user or operations that altered balance of the user
|
|
1487
|
+
* @param {string} code unified currency code, default is undefined
|
|
1488
|
+
* @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
|
|
1489
|
+
* @param {int} [limit] max number of ledger entrys to return, default is undefined
|
|
1490
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1491
|
+
* @param {int} [params.until] the latest time in ms to fetch trades for
|
|
1492
|
+
* @returns {object} a [ledger structure]{@link https://docs.ccxt.com/#/?id=ledger-structure}
|
|
1493
|
+
*/
|
|
1494
|
+
// https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccountledger
|
|
1495
|
+
if (code === undefined) {
|
|
1496
|
+
throw new errors.ArgumentsRequired(this.id + ' fetchLedger() requires a code param');
|
|
1497
|
+
}
|
|
1498
|
+
await this.loadMarkets();
|
|
1499
|
+
await this.loadAccounts();
|
|
1500
|
+
const currency = this.currency(code);
|
|
1501
|
+
const accountsByCurrencyCode = this.indexBy(this.accounts, 'code');
|
|
1502
|
+
const account = this.safeValue(accountsByCurrencyCode, code);
|
|
1503
|
+
if (account === undefined) {
|
|
1504
|
+
throw new errors.ExchangeError(this.id + ' fetchLedger() could not find account id for ' + code);
|
|
1505
|
+
}
|
|
1506
|
+
const request = {
|
|
1507
|
+
'id': account['id'],
|
|
1508
|
+
// 'start_date': this.iso8601 (since),
|
|
1509
|
+
// 'end_date': this.iso8601 (this.milliseconds ()),
|
|
1510
|
+
// 'before': 'cursor', // sets start cursor to before date
|
|
1511
|
+
// 'after': 'cursor', // sets end cursor to after date
|
|
1512
|
+
// 'limit': limit, // default 100
|
|
1513
|
+
// 'profile_id': 'string'
|
|
1514
|
+
};
|
|
1515
|
+
if (since !== undefined) {
|
|
1516
|
+
request['start_date'] = this.iso8601(since);
|
|
1517
|
+
}
|
|
1518
|
+
if (limit !== undefined) {
|
|
1519
|
+
request['limit'] = limit; // default 100
|
|
1520
|
+
}
|
|
1521
|
+
const until = this.safeValue2(params, 'until', 'end_date');
|
|
1522
|
+
if (until !== undefined) {
|
|
1523
|
+
params = this.omit(params, ['until']);
|
|
1524
|
+
request['end_date'] = this.iso8601(until);
|
|
1525
|
+
}
|
|
1526
|
+
const response = await this.privateGetAccountsIdLedger(this.extend(request, params));
|
|
1527
|
+
for (let i = 0; i < response.length; i++) {
|
|
1528
|
+
response[i]['currency'] = code;
|
|
1529
|
+
}
|
|
1530
|
+
return this.parseLedger(response, currency, since, limit);
|
|
1531
|
+
}
|
|
1532
|
+
async fetchDepositsWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1533
|
+
/**
|
|
1534
|
+
* @method
|
|
1535
|
+
* @name coinbasepro#fetchDepositsWithdrawals
|
|
1536
|
+
* @description fetch history of deposits and withdrawals
|
|
1537
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_gettransfers
|
|
1538
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounttransfers
|
|
1539
|
+
* @param {string} [code] unified currency code for the currency of the deposit/withdrawals, default is undefined
|
|
1540
|
+
* @param {int} [since] timestamp in ms of the earliest deposit/withdrawal, default is undefined
|
|
1541
|
+
* @param {int} [limit] max number of deposit/withdrawals to return, default is undefined
|
|
1542
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1543
|
+
* @param {string} [params.id] account id, when defined, the endpoint used is '/accounts/{account_id}/transfers/' instead of '/transfers/'
|
|
1544
|
+
* @returns {object} a list of [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
|
|
1545
|
+
*/
|
|
1546
|
+
await this.loadMarkets();
|
|
1547
|
+
await this.loadAccounts();
|
|
1548
|
+
let currency = undefined;
|
|
1549
|
+
let id = this.safeString(params, 'id'); // account id
|
|
1550
|
+
if (id === undefined) {
|
|
1551
|
+
if (code !== undefined) {
|
|
1552
|
+
currency = this.currency(code);
|
|
1553
|
+
const accountsByCurrencyCode = this.indexBy(this.accounts, 'code');
|
|
1554
|
+
const account = this.safeValue(accountsByCurrencyCode, code);
|
|
1555
|
+
if (account === undefined) {
|
|
1556
|
+
throw new errors.ExchangeError(this.id + ' fetchDepositsWithdrawals() could not find account id for ' + code);
|
|
1557
|
+
}
|
|
1558
|
+
id = account['id'];
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
const request = {};
|
|
1562
|
+
if (id !== undefined) {
|
|
1563
|
+
request['id'] = id;
|
|
1564
|
+
}
|
|
1565
|
+
if (limit !== undefined) {
|
|
1566
|
+
request['limit'] = limit;
|
|
1567
|
+
}
|
|
1568
|
+
let response = undefined;
|
|
1569
|
+
if (id === undefined) {
|
|
1570
|
+
response = await this.privateGetTransfers(this.extend(request, params));
|
|
1571
|
+
//
|
|
1572
|
+
// [
|
|
1573
|
+
// {
|
|
1574
|
+
// "id": "bee6fd7c-afb2-4e47-8298-671d09997d16",
|
|
1575
|
+
// "type": "deposit",
|
|
1576
|
+
// "created_at": "2022-12-21 00:48:45.477503+00",
|
|
1577
|
+
// "completed_at": null,
|
|
1578
|
+
// "account_id": "sal3802-36bd-46be-a7b8-alsjf383sldak",
|
|
1579
|
+
// "user_id": "6382048209f92as392039dlks2",
|
|
1580
|
+
// "amount": "0.01000000",
|
|
1581
|
+
// "details": {
|
|
1582
|
+
// "network": "litecoin",
|
|
1583
|
+
// "crypto_address": "MKemtnCFUYKsNWaf5EMYMpwSszcXWFDtTY",
|
|
1584
|
+
// "coinbase_account_id": "fl2b6925-f6ba-403n-jj03-40fl435n430f",
|
|
1585
|
+
// "coinbase_transaction_id": "63a25bb13cb5cf0001d2cf17", // withdrawals only
|
|
1586
|
+
// "crypto_transaction_hash": "752f35570736341e2a253f7041a34cf1e196fc56128c900fd03d99da899d94c1",
|
|
1587
|
+
// "tx_service_transaction_id": "1873249104",
|
|
1588
|
+
// "coinbase_payment_method_id": ""
|
|
1589
|
+
// },
|
|
1590
|
+
// "canceled_at": null,
|
|
1591
|
+
// "processed_at": null,
|
|
1592
|
+
// "user_nonce": null,
|
|
1593
|
+
// "idem": "5e3201b0-e390-5k3k-a913-c32932049242",
|
|
1594
|
+
// "profile_id": "k3k302a8-c4dk-4f49-9d39-3203923wpk39",
|
|
1595
|
+
// "currency": "LTC"
|
|
1596
|
+
// }
|
|
1597
|
+
// ]
|
|
1598
|
+
//
|
|
1599
|
+
for (let i = 0; i < response.length; i++) {
|
|
1600
|
+
const account_id = this.safeString(response[i], 'account_id');
|
|
1601
|
+
const account = this.safeValue(this.accountsById, account_id);
|
|
1602
|
+
const codeInner = this.safeString(account, 'code');
|
|
1603
|
+
response[i]['currency'] = codeInner;
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
else {
|
|
1607
|
+
response = await this.privateGetAccountsIdTransfers(this.extend(request, params));
|
|
1608
|
+
//
|
|
1609
|
+
// [
|
|
1610
|
+
// {
|
|
1611
|
+
// "id": "bee6fd7c-afb2-4e47-8298-671d09997d16",
|
|
1612
|
+
// "type": "deposit",
|
|
1613
|
+
// "created_at": "2022-12-21 00:48:45.477503+00",
|
|
1614
|
+
// "completed_at": null,
|
|
1615
|
+
// "amount": "0.01000000",
|
|
1616
|
+
// "details": {
|
|
1617
|
+
// "network": "litecoin",
|
|
1618
|
+
// "crypto_address": "MKemtnCFUYKsNWaf5EMYMpwSszcXWFDtTY",
|
|
1619
|
+
// "coinbase_account_id": "fl2b6925-f6ba-403n-jj03-40fl435n430f",
|
|
1620
|
+
// "coinbase_transaction_id": "63a25bb13cb5cf0001d2cf17", // withdrawals only
|
|
1621
|
+
// "crypto_transaction_hash": "752f35570736341e2a253f7041a34cf1e196fc56128c900fd03d99da899d94c1",
|
|
1622
|
+
// "tx_service_transaction_id": "1873249104",
|
|
1623
|
+
// "coinbase_payment_method_id": ""
|
|
1624
|
+
// },
|
|
1625
|
+
// "canceled_at": null,
|
|
1626
|
+
// "processed_at": null,
|
|
1627
|
+
// "user_nonce": null,
|
|
1628
|
+
// "idem": "5e3201b0-e390-5k3k-a913-c32932049242",
|
|
1629
|
+
// "profile_id": "k3k302a8-c4dk-4f49-9d39-3203923wpk39",
|
|
1630
|
+
// "currency": "LTC"
|
|
1631
|
+
// }
|
|
1632
|
+
// ]
|
|
1633
|
+
//
|
|
1634
|
+
for (let i = 0; i < response.length; i++) {
|
|
1635
|
+
response[i]['currency'] = code;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
return this.parseTransactions(response, currency, since, limit);
|
|
1639
|
+
}
|
|
1640
|
+
async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1641
|
+
/**
|
|
1642
|
+
* @method
|
|
1643
|
+
* @name coinbasepro#fetchDeposits
|
|
1644
|
+
* @description fetch all deposits made to an account
|
|
1645
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_gettransfers
|
|
1646
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounttransfers
|
|
1647
|
+
* @param {string} code unified currency code
|
|
1648
|
+
* @param {int} [since] the earliest time in ms to fetch deposits for
|
|
1649
|
+
* @param {int} [limit] the maximum number of deposits structures to retrieve
|
|
1650
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1651
|
+
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
|
|
1652
|
+
*/
|
|
1653
|
+
return await this.fetchDepositsWithdrawals(code, since, limit, this.extend({ 'type': 'deposit' }, params));
|
|
1654
|
+
}
|
|
1655
|
+
async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1656
|
+
/**
|
|
1657
|
+
* @method
|
|
1658
|
+
* @name coinbasepro#fetchWithdrawals
|
|
1659
|
+
* @description fetch all withdrawals made from an account
|
|
1660
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_gettransfers
|
|
1661
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounttransfers
|
|
1662
|
+
* @param {string} code unified currency code
|
|
1663
|
+
* @param {int} [since] the earliest time in ms to fetch withdrawals for
|
|
1664
|
+
* @param {int} [limit] the maximum number of withdrawals structures to retrieve
|
|
1665
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1666
|
+
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
|
|
1667
|
+
*/
|
|
1668
|
+
return await this.fetchDepositsWithdrawals(code, since, limit, this.extend({ 'type': 'withdraw' }, params));
|
|
1669
|
+
}
|
|
1670
|
+
parseTransactionStatus(transaction) {
|
|
1671
|
+
const canceled = this.safeValue(transaction, 'canceled_at');
|
|
1672
|
+
if (canceled) {
|
|
1673
|
+
return 'canceled';
|
|
1674
|
+
}
|
|
1675
|
+
const processed = this.safeValue(transaction, 'processed_at');
|
|
1676
|
+
const completed = this.safeValue(transaction, 'completed_at');
|
|
1677
|
+
if (completed) {
|
|
1678
|
+
return 'ok';
|
|
1679
|
+
}
|
|
1680
|
+
else if (processed && !completed) {
|
|
1681
|
+
return 'failed';
|
|
1682
|
+
}
|
|
1683
|
+
else {
|
|
1684
|
+
return 'pending';
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
parseTransaction(transaction, currency = undefined) {
|
|
1688
|
+
//
|
|
1689
|
+
// privateGetTransfers
|
|
1690
|
+
//
|
|
1691
|
+
// [
|
|
1692
|
+
// {
|
|
1693
|
+
// "id": "bee6fd7c-afb2-4e47-8298-671d09997d16",
|
|
1694
|
+
// "type": "deposit",
|
|
1695
|
+
// "created_at": "2022-12-21 00:48:45.477503+00",
|
|
1696
|
+
// "completed_at": null,
|
|
1697
|
+
// "account_id": "sal3802-36bd-46be-a7b8-alsjf383sldak", // only from privateGetTransfers
|
|
1698
|
+
// "user_id": "6382048209f92as392039dlks2", // only from privateGetTransfers
|
|
1699
|
+
// "amount": "0.01000000",
|
|
1700
|
+
// "details": {
|
|
1701
|
+
// "network": "litecoin",
|
|
1702
|
+
// "crypto_address": "MKemtnCFUYKsNWaf5EMYMpwSszcXWFDtTY",
|
|
1703
|
+
// "coinbase_account_id": "fl2b6925-f6ba-403n-jj03-40fl435n430f",
|
|
1704
|
+
// "coinbase_transaction_id": "63a25bb13cb5cf0001d2cf17", // withdrawals only
|
|
1705
|
+
// "crypto_transaction_hash": "752f35570736341e2a253f7041a34cf1e196fc56128c900fd03d99da899d94c1",
|
|
1706
|
+
// "tx_service_transaction_id": "1873249104",
|
|
1707
|
+
// "coinbase_payment_method_id": ""
|
|
1708
|
+
// },
|
|
1709
|
+
// "canceled_at": null,
|
|
1710
|
+
// "processed_at": null,
|
|
1711
|
+
// "user_nonce": null,
|
|
1712
|
+
// "idem": "5e3201b0-e390-5k3k-a913-c32932049242",
|
|
1713
|
+
// "profile_id": "k3k302a8-c4dk-4f49-9d39-3203923wpk39",
|
|
1714
|
+
// "currency": "LTC"
|
|
1715
|
+
// }
|
|
1716
|
+
// ]
|
|
1717
|
+
//
|
|
1718
|
+
const details = this.safeValue(transaction, 'details', {});
|
|
1719
|
+
const timestamp = this.parse8601(this.safeString(transaction, 'created_at'));
|
|
1720
|
+
const currencyId = this.safeString(transaction, 'currency');
|
|
1721
|
+
const code = this.safeCurrencyCode(currencyId, currency);
|
|
1722
|
+
let amount = this.safeNumber(transaction, 'amount');
|
|
1723
|
+
let type = this.safeString(transaction, 'type');
|
|
1724
|
+
let address = this.safeString(details, 'crypto_address');
|
|
1725
|
+
address = this.safeString(transaction, 'crypto_address', address);
|
|
1726
|
+
const fee = {
|
|
1727
|
+
'currency': undefined,
|
|
1728
|
+
'cost': undefined,
|
|
1729
|
+
'rate': undefined,
|
|
1730
|
+
};
|
|
1731
|
+
if (type === 'withdraw') {
|
|
1732
|
+
type = 'withdrawal';
|
|
1733
|
+
address = this.safeString(details, 'sent_to_address', address);
|
|
1734
|
+
const feeCost = this.safeNumber(details, 'fee');
|
|
1735
|
+
if (feeCost !== undefined) {
|
|
1736
|
+
if (amount !== undefined) {
|
|
1737
|
+
amount -= feeCost;
|
|
1738
|
+
}
|
|
1739
|
+
fee['cost'] = feeCost;
|
|
1740
|
+
fee['currency'] = code;
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
const networkId = this.safeString(details, 'network');
|
|
1744
|
+
return {
|
|
1745
|
+
'info': transaction,
|
|
1746
|
+
'id': this.safeString(transaction, 'id'),
|
|
1747
|
+
'txid': this.safeString(details, 'crypto_transaction_hash'),
|
|
1748
|
+
'type': type,
|
|
1749
|
+
'currency': code,
|
|
1750
|
+
'network': this.networkIdToCode(networkId),
|
|
1751
|
+
'amount': amount,
|
|
1752
|
+
'status': this.parseTransactionStatus(transaction),
|
|
1753
|
+
'timestamp': timestamp,
|
|
1754
|
+
'datetime': this.iso8601(timestamp),
|
|
1755
|
+
'address': address,
|
|
1756
|
+
'addressFrom': undefined,
|
|
1757
|
+
'addressTo': this.safeString(details, 'crypto_address'),
|
|
1758
|
+
'tag': this.safeString(details, 'destination_tag'),
|
|
1759
|
+
'tagFrom': undefined,
|
|
1760
|
+
'tagTo': undefined,
|
|
1761
|
+
'updated': this.parse8601(this.safeString(transaction, 'processed_at')),
|
|
1762
|
+
'comment': undefined,
|
|
1763
|
+
'internal': false,
|
|
1764
|
+
'fee': fee,
|
|
1765
|
+
};
|
|
1766
|
+
}
|
|
1767
|
+
async createDepositAddress(code, params = {}) {
|
|
1768
|
+
/**
|
|
1769
|
+
* @method
|
|
1770
|
+
* @name coinbasepro#createDepositAddress
|
|
1771
|
+
* @description create a currency deposit address
|
|
1772
|
+
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postcoinbaseaccountaddresses
|
|
1773
|
+
* @param {string} code unified currency code of the currency for the deposit address
|
|
1774
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1775
|
+
* @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
|
|
1776
|
+
*/
|
|
1777
|
+
await this.loadMarkets();
|
|
1778
|
+
const currency = this.currency(code);
|
|
1779
|
+
let accounts = this.safeValue(this.options, 'coinbaseAccounts');
|
|
1780
|
+
if (accounts === undefined) {
|
|
1781
|
+
accounts = await this.privateGetCoinbaseAccounts();
|
|
1782
|
+
this.options['coinbaseAccounts'] = accounts; // cache it
|
|
1783
|
+
this.options['coinbaseAccountsByCurrencyId'] = this.indexBy(accounts, 'currency');
|
|
1784
|
+
}
|
|
1785
|
+
const currencyId = currency['id'];
|
|
1786
|
+
const account = this.safeValue(this.options['coinbaseAccountsByCurrencyId'], currencyId);
|
|
1787
|
+
if (account === undefined) {
|
|
1788
|
+
// eslint-disable-next-line quotes
|
|
1789
|
+
throw new errors.InvalidAddress(this.id + " createDepositAddress() could not find currency code " + code + " with id = " + currencyId + " in this.options['coinbaseAccountsByCurrencyId']");
|
|
1790
|
+
}
|
|
1791
|
+
const request = {
|
|
1792
|
+
'id': account['id'],
|
|
1793
|
+
};
|
|
1794
|
+
const response = await this.privatePostCoinbaseAccountsIdAddresses(this.extend(request, params));
|
|
1795
|
+
const address = this.safeString(response, 'address');
|
|
1796
|
+
const tag = this.safeString(response, 'destination_tag');
|
|
1797
|
+
return {
|
|
1798
|
+
'currency': code,
|
|
1799
|
+
'address': this.checkAddress(address),
|
|
1800
|
+
'tag': tag,
|
|
1801
|
+
'info': response,
|
|
1802
|
+
};
|
|
1803
|
+
}
|
|
1804
|
+
sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
|
|
1805
|
+
let request = '/' + this.implodeParams(path, params);
|
|
1806
|
+
const query = this.omit(params, this.extractParams(path));
|
|
1807
|
+
if (method === 'GET') {
|
|
1808
|
+
if (Object.keys(query).length) {
|
|
1809
|
+
request += '?' + this.urlencode(query);
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
const url = this.implodeHostname(this.urls['api'][api]) + request;
|
|
1813
|
+
if (api === 'private') {
|
|
1814
|
+
this.checkRequiredCredentials();
|
|
1815
|
+
const nonce = this.nonce().toString();
|
|
1816
|
+
let payload = '';
|
|
1817
|
+
if (method !== 'GET') {
|
|
1818
|
+
if (Object.keys(query).length) {
|
|
1819
|
+
body = this.json(query);
|
|
1820
|
+
payload = body;
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
const what = nonce + method + request + payload;
|
|
1824
|
+
let secret = undefined;
|
|
1825
|
+
try {
|
|
1826
|
+
secret = this.base64ToBinary(this.secret);
|
|
1827
|
+
}
|
|
1828
|
+
catch (e) {
|
|
1829
|
+
throw new errors.AuthenticationError(this.id + ' sign() invalid base64 secret');
|
|
1830
|
+
}
|
|
1831
|
+
const signature = this.hmac(this.encode(what), secret, sha256.sha256, 'base64');
|
|
1832
|
+
headers = {
|
|
1833
|
+
'CB-ACCESS-KEY': this.apiKey,
|
|
1834
|
+
'CB-ACCESS-SIGN': signature,
|
|
1835
|
+
'CB-ACCESS-TIMESTAMP': nonce,
|
|
1836
|
+
'CB-ACCESS-PASSPHRASE': this.password,
|
|
1837
|
+
'Content-Type': 'application/json',
|
|
1838
|
+
};
|
|
1839
|
+
}
|
|
1840
|
+
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
|
|
1841
|
+
}
|
|
1842
|
+
handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
|
|
1843
|
+
if ((code === 400) || (code === 404)) {
|
|
1844
|
+
if (body[0] === '{') {
|
|
1845
|
+
const message = this.safeString(response, 'message');
|
|
1846
|
+
const feedback = this.id + ' ' + message;
|
|
1847
|
+
this.throwExactlyMatchedException(this.exceptions['exact'], message, feedback);
|
|
1848
|
+
this.throwBroadlyMatchedException(this.exceptions['broad'], message, feedback);
|
|
1849
|
+
throw new errors.ExchangeError(feedback); // unknown message
|
|
1850
|
+
}
|
|
1851
|
+
throw new errors.ExchangeError(this.id + ' ' + body);
|
|
1852
|
+
}
|
|
1853
|
+
return undefined;
|
|
1854
|
+
}
|
|
1855
|
+
async request(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined, config = {}) {
|
|
1856
|
+
const response = await this.fetch2(path, api, method, params, headers, body, config);
|
|
1857
|
+
if (typeof response !== 'string') {
|
|
1858
|
+
if ('message' in response) {
|
|
1859
|
+
throw new errors.ExchangeError(this.id + ' ' + this.json(response));
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
return response;
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1866
|
+
module.exports = coinbasepro;
|