ccxt-look 1.81.50

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.
Files changed (264) hide show
  1. package/.cache/eslintcache +1 -0
  2. package/.dockerignore +6 -0
  3. package/.eslintignore +1 -0
  4. package/.gitattributes +5 -0
  5. package/.readthedocs.yaml +16 -0
  6. package/CONTRIBUTING.md +1049 -0
  7. package/LICENSE.txt +21 -0
  8. package/README.md +537 -0
  9. package/SECURITY.md +5 -0
  10. package/build/cleanup-old-tags.js +94 -0
  11. package/build/countries.js +256 -0
  12. package/build/export-exchanges.js +520 -0
  13. package/build/fs.js +51 -0
  14. package/build/transpile.js +1772 -0
  15. package/build/vss.js +78 -0
  16. package/ccxt.browser.js +7 -0
  17. package/ccxt.d.ts +692 -0
  18. package/ccxt.js +171 -0
  19. package/cleanup.sh +2 -0
  20. package/composer-install.sh +20 -0
  21. package/dist/ccxt.browser.js +208383 -0
  22. package/gource.sh +3 -0
  23. package/index.html +7 -0
  24. package/js/.eslintrc +87 -0
  25. package/js/aax.js +2686 -0
  26. package/js/ascendex.js +2584 -0
  27. package/js/base/.eslintrc.js +43 -0
  28. package/js/base/Exchange.js +2371 -0
  29. package/js/base/Precise.js +283 -0
  30. package/js/base/errorHierarchy.js +47 -0
  31. package/js/base/errors.js +55 -0
  32. package/js/base/functions/crypto.js +158 -0
  33. package/js/base/functions/encode.js +118 -0
  34. package/js/base/functions/generic.js +270 -0
  35. package/js/base/functions/misc.js +138 -0
  36. package/js/base/functions/number.js +329 -0
  37. package/js/base/functions/platform.js +38 -0
  38. package/js/base/functions/string.js +21 -0
  39. package/js/base/functions/throttle.js +79 -0
  40. package/js/base/functions/time.js +210 -0
  41. package/js/base/functions/type.js +66 -0
  42. package/js/base/functions.js +28 -0
  43. package/js/bequant.js +32 -0
  44. package/js/bibox.js +1407 -0
  45. package/js/bigone.js +1366 -0
  46. package/js/binance.js +5652 -0
  47. package/js/binancecoinm.js +46 -0
  48. package/js/binanceus.js +46 -0
  49. package/js/binanceusdm.js +49 -0
  50. package/js/bit2c.js +535 -0
  51. package/js/bitbank.js +842 -0
  52. package/js/bitbay.js +16 -0
  53. package/js/bitbns.js +1073 -0
  54. package/js/bitcoincom.js +15 -0
  55. package/js/bitfinex.js +1433 -0
  56. package/js/bitfinex2.js +2025 -0
  57. package/js/bitflyer.js +840 -0
  58. package/js/bitforex.js +614 -0
  59. package/js/bitget.js +2397 -0
  60. package/js/bithumb.js +980 -0
  61. package/js/bitmart.js +2516 -0
  62. package/js/bitmex.js +1809 -0
  63. package/js/bitopro.js +1443 -0
  64. package/js/bitpanda.js +1782 -0
  65. package/js/bitrue.js +1747 -0
  66. package/js/bitso.js +1062 -0
  67. package/js/bitstamp.js +1757 -0
  68. package/js/bitstamp1.js +343 -0
  69. package/js/bittrex.js +1876 -0
  70. package/js/bitvavo.js +1579 -0
  71. package/js/bkex.js +1233 -0
  72. package/js/bl3p.js +346 -0
  73. package/js/blockchaincom.js +969 -0
  74. package/js/btcalpha.js +680 -0
  75. package/js/btcbox.js +477 -0
  76. package/js/btcmarkets.js +1022 -0
  77. package/js/btctradeua.js +466 -0
  78. package/js/btcturk.js +734 -0
  79. package/js/buda.js +946 -0
  80. package/js/bw.js +1265 -0
  81. package/js/bybit.js +3372 -0
  82. package/js/bytetrade.js +1336 -0
  83. package/js/cdax.js +1646 -0
  84. package/js/cex.js +1410 -0
  85. package/js/coinbase.js +1342 -0
  86. package/js/coinbaseprime.js +31 -0
  87. package/js/coinbasepro.js +1466 -0
  88. package/js/coincheck.js +755 -0
  89. package/js/coinex.js +3400 -0
  90. package/js/coinfalcon.js +880 -0
  91. package/js/coinmate.js +794 -0
  92. package/js/coinone.js +816 -0
  93. package/js/coinspot.js +345 -0
  94. package/js/crex24.js +1636 -0
  95. package/js/cryptocom.js +1832 -0
  96. package/js/currencycom.js +1748 -0
  97. package/js/delta.js +1547 -0
  98. package/js/deribit.js +2148 -0
  99. package/js/digifinex.js +1585 -0
  100. package/js/eqonex.js +1660 -0
  101. package/js/exmo.js +1670 -0
  102. package/js/fairdesk.js +1231 -0
  103. package/js/flowbtc.js +35 -0
  104. package/js/fmfwio.js +34 -0
  105. package/js/ftx.js +2751 -0
  106. package/js/ftxus.js +38 -0
  107. package/js/gateio.js +4174 -0
  108. package/js/gemini.js +1397 -0
  109. package/js/hitbtc.js +1343 -0
  110. package/js/hitbtc3.js +2329 -0
  111. package/js/hollaex.js +1486 -0
  112. package/js/huobi.js +5706 -0
  113. package/js/huobijp.js +1710 -0
  114. package/js/huobipro.js +18 -0
  115. package/js/idex.js +1439 -0
  116. package/js/independentreserve.js +649 -0
  117. package/js/indodax.js +742 -0
  118. package/js/itbit.js +722 -0
  119. package/js/kraken.js +2179 -0
  120. package/js/kucoin.js +2571 -0
  121. package/js/kucoinfutures.js +1771 -0
  122. package/js/kuna.js +809 -0
  123. package/js/latoken.js +1445 -0
  124. package/js/lbank.js +760 -0
  125. package/js/liquid.js +1432 -0
  126. package/js/luno.js +873 -0
  127. package/js/lykke.js +1147 -0
  128. package/js/mercado.js +771 -0
  129. package/js/mexc.js +3151 -0
  130. package/js/ndax.js +2233 -0
  131. package/js/novadax.js +1318 -0
  132. package/js/oceanex.js +816 -0
  133. package/js/okcoin.js +3841 -0
  134. package/js/okex.js +16 -0
  135. package/js/okex5.js +16 -0
  136. package/js/okx.js +4795 -0
  137. package/js/paymium.js +498 -0
  138. package/js/phemex.js +2957 -0
  139. package/js/poloniex.js +1674 -0
  140. package/js/probit.js +1346 -0
  141. package/js/qtrade.js +1588 -0
  142. package/js/ripio.js +1061 -0
  143. package/js/static_dependencies/BN/bn.js +3526 -0
  144. package/js/static_dependencies/README.md +1 -0
  145. package/js/static_dependencies/crypto-js/crypto-js.js +5988 -0
  146. package/js/static_dependencies/elliptic/lib/elliptic/curve/base.js +375 -0
  147. package/js/static_dependencies/elliptic/lib/elliptic/curve/edwards.js +433 -0
  148. package/js/static_dependencies/elliptic/lib/elliptic/curve/index.js +8 -0
  149. package/js/static_dependencies/elliptic/lib/elliptic/curve/mont.js +180 -0
  150. package/js/static_dependencies/elliptic/lib/elliptic/curve/short.js +938 -0
  151. package/js/static_dependencies/elliptic/lib/elliptic/curves.js +204 -0
  152. package/js/static_dependencies/elliptic/lib/elliptic/ec/index.js +240 -0
  153. package/js/static_dependencies/elliptic/lib/elliptic/ec/key.js +119 -0
  154. package/js/static_dependencies/elliptic/lib/elliptic/ec/signature.js +24 -0
  155. package/js/static_dependencies/elliptic/lib/elliptic/eddsa/index.js +145 -0
  156. package/js/static_dependencies/elliptic/lib/elliptic/eddsa/key.js +100 -0
  157. package/js/static_dependencies/elliptic/lib/elliptic/eddsa/signature.js +65 -0
  158. package/js/static_dependencies/elliptic/lib/elliptic/precomputed/secp256k1.js +780 -0
  159. package/js/static_dependencies/elliptic/lib/elliptic/utils.js +214 -0
  160. package/js/static_dependencies/elliptic/lib/elliptic.js +22 -0
  161. package/js/static_dependencies/elliptic/lib/hmac-drbg/hmac-drbg.js +114 -0
  162. package/js/static_dependencies/fetch-ponyfill/fetch-node.js +39 -0
  163. package/js/static_dependencies/node-fetch/index.js +1564 -0
  164. package/js/static_dependencies/node-rsa/NodeRSA.js +223 -0
  165. package/js/static_dependencies/node-rsa/asn1/ber/errors.js +13 -0
  166. package/js/static_dependencies/node-rsa/asn1/ber/index.js +21 -0
  167. package/js/static_dependencies/node-rsa/asn1/ber/reader.js +262 -0
  168. package/js/static_dependencies/node-rsa/asn1/ber/types.js +36 -0
  169. package/js/static_dependencies/node-rsa/asn1/index.js +17 -0
  170. package/js/static_dependencies/node-rsa/encryptEngines/js.js +34 -0
  171. package/js/static_dependencies/node-rsa/formats/components.js +71 -0
  172. package/js/static_dependencies/node-rsa/formats/formats.js +31 -0
  173. package/js/static_dependencies/node-rsa/formats/pkcs1.js +148 -0
  174. package/js/static_dependencies/node-rsa/formats/pkcs8.js +187 -0
  175. package/js/static_dependencies/node-rsa/libs/jsbn.js +1252 -0
  176. package/js/static_dependencies/node-rsa/libs/rsa.js +147 -0
  177. package/js/static_dependencies/node-rsa/schemes/pkcs1.js +176 -0
  178. package/js/static_dependencies/node-rsa/schemes/schemes.js +21 -0
  179. package/js/static_dependencies/node-rsa/utils.js +98 -0
  180. package/js/static_dependencies/qs/formats.js +18 -0
  181. package/js/static_dependencies/qs/index.js +11 -0
  182. package/js/static_dependencies/qs/parse.js +242 -0
  183. package/js/static_dependencies/qs/stringify.js +269 -0
  184. package/js/static_dependencies/qs/utils.js +230 -0
  185. package/js/stex.js +1925 -0
  186. package/js/test/.eslintrc.js +42 -0
  187. package/js/test/Exchange/test.balance.js +61 -0
  188. package/js/test/Exchange/test.borrowRate.js +32 -0
  189. package/js/test/Exchange/test.currency.js +52 -0
  190. package/js/test/Exchange/test.fetchBalance.js +23 -0
  191. package/js/test/Exchange/test.fetchBorrowInterest.js +59 -0
  192. package/js/test/Exchange/test.fetchBorrowRate.js +32 -0
  193. package/js/test/Exchange/test.fetchBorrowRates.js +28 -0
  194. package/js/test/Exchange/test.fetchClosedOrders.js +32 -0
  195. package/js/test/Exchange/test.fetchCurrencies.js +35 -0
  196. package/js/test/Exchange/test.fetchDeposits.js +31 -0
  197. package/js/test/Exchange/test.fetchFundingFees.js +19 -0
  198. package/js/test/Exchange/test.fetchFundingRateHistory.js +40 -0
  199. package/js/test/Exchange/test.fetchL2OrderBook.js +23 -0
  200. package/js/test/Exchange/test.fetchLedger.js +42 -0
  201. package/js/test/Exchange/test.fetchLeverageTiers.js +33 -0
  202. package/js/test/Exchange/test.fetchMarketLeverageTiers.js +22 -0
  203. package/js/test/Exchange/test.fetchMarkets.js +33 -0
  204. package/js/test/Exchange/test.fetchMyTrades.js +42 -0
  205. package/js/test/Exchange/test.fetchOHLCV.js +46 -0
  206. package/js/test/Exchange/test.fetchOpenOrders.js +36 -0
  207. package/js/test/Exchange/test.fetchOrderBook.js +25 -0
  208. package/js/test/Exchange/test.fetchOrderBooks.js +35 -0
  209. package/js/test/Exchange/test.fetchOrders.js +41 -0
  210. package/js/test/Exchange/test.fetchPositions.js +47 -0
  211. package/js/test/Exchange/test.fetchStatus.js +35 -0
  212. package/js/test/Exchange/test.fetchTicker.js +38 -0
  213. package/js/test/Exchange/test.fetchTickers.js +49 -0
  214. package/js/test/Exchange/test.fetchTrades.js +39 -0
  215. package/js/test/Exchange/test.fetchTradingFee.js +18 -0
  216. package/js/test/Exchange/test.fetchTradingFees.js +22 -0
  217. package/js/test/Exchange/test.fetchTransactions.js +31 -0
  218. package/js/test/Exchange/test.fetchWithdrawals.js +31 -0
  219. package/js/test/Exchange/test.ledgerItem.js +46 -0
  220. package/js/test/Exchange/test.leverageTier.js +33 -0
  221. package/js/test/Exchange/test.loadMarkets.js +35 -0
  222. package/js/test/Exchange/test.market.js +129 -0
  223. package/js/test/Exchange/test.ohlcv.js +33 -0
  224. package/js/test/Exchange/test.order.js +62 -0
  225. package/js/test/Exchange/test.orderbook.js +61 -0
  226. package/js/test/Exchange/test.position.js +21 -0
  227. package/js/test/Exchange/test.throttle.js +94 -0
  228. package/js/test/Exchange/test.ticker.js +95 -0
  229. package/js/test/Exchange/test.trade.js +68 -0
  230. package/js/test/Exchange/test.tradingFee.js +34 -0
  231. package/js/test/Exchange/test.transaction.js +35 -0
  232. package/js/test/base/.eslintrc +38 -0
  233. package/js/test/base/functions/test.crypto.js +110 -0
  234. package/js/test/base/functions/test.datetime.js +62 -0
  235. package/js/test/base/functions/test.generic.js +152 -0
  236. package/js/test/base/functions/test.number.js +362 -0
  237. package/js/test/base/functions/test.time.js +56 -0
  238. package/js/test/base/functions/test.type.js +53 -0
  239. package/js/test/base/test.base.js +193 -0
  240. package/js/test/errors/test.InsufficientFunds.js +86 -0
  241. package/js/test/errors/test.InvalidNonce.js +64 -0
  242. package/js/test/errors/test.InvalidOrder.js +35 -0
  243. package/js/test/errors/test.OrderNotFound.js +39 -0
  244. package/js/test/test.js +426 -0
  245. package/js/test/test.timeout_hang.js +12 -0
  246. package/js/therock.js +1431 -0
  247. package/js/tidebit.js +632 -0
  248. package/js/tidex.js +939 -0
  249. package/js/timex.js +1283 -0
  250. package/js/upbit.js +1622 -0
  251. package/js/vcc.js +1353 -0
  252. package/js/wavesexchange.js +2185 -0
  253. package/js/wazirx.js +732 -0
  254. package/js/whitebit.js +1352 -0
  255. package/js/woo.js +1577 -0
  256. package/js/xena.js +1948 -0
  257. package/js/yobit.js +1129 -0
  258. package/js/zaif.js +647 -0
  259. package/js/zb.js +4088 -0
  260. package/js/zipmex.js +40 -0
  261. package/js/zonda.js +1497 -0
  262. package/multilang.sh +159 -0
  263. package/package.json +591 -0
  264. package/postinstall.js +103 -0
@@ -0,0 +1,1832 @@
1
+ 'use strict';
2
+
3
+ // ---------------------------------------------------------------------------
4
+
5
+ const Exchange = require ('./base/Exchange');
6
+ const { AuthenticationError, ArgumentsRequired, ExchangeError, InsufficientFunds, DDoSProtection, InvalidNonce, PermissionDenied, BadRequest, BadSymbol, NotSupported, AccountNotEnabled } = require ('./base/errors');
7
+ const Precise = require ('./base/Precise');
8
+
9
+ module.exports = class cryptocom extends Exchange {
10
+ describe () {
11
+ return this.deepExtend (super.describe (), {
12
+ 'id': 'cryptocom',
13
+ 'name': 'Crypto.com',
14
+ 'countries': [ 'MT' ],
15
+ 'version': 'v2',
16
+ 'rateLimit': 10, // 100 requests per second
17
+ 'has': {
18
+ 'CORS': false,
19
+ 'spot': true,
20
+ 'margin': undefined, // has but not fully implemented
21
+ 'swap': undefined, // has but not fully implemented
22
+ 'future': undefined, // has but not fully implemented
23
+ 'option': undefined,
24
+ 'cancelAllOrders': true,
25
+ 'cancelOrder': true,
26
+ 'createOrder': true,
27
+ 'fetchBalance': true,
28
+ 'fetchBidsAsks': false,
29
+ 'fetchClosedOrders': 'emulated',
30
+ 'fetchCurrencies': false,
31
+ 'fetchDepositAddress': true,
32
+ 'fetchDepositAddressesByNetwork': true,
33
+ 'fetchDeposits': true,
34
+ 'fetchFundingFees': false,
35
+ 'fetchFundingHistory': false,
36
+ 'fetchFundingRate': false,
37
+ 'fetchFundingRates': false,
38
+ 'fetchMarkets': true,
39
+ 'fetchMyTrades': true,
40
+ 'fetchOHLCV': true,
41
+ 'fetchOpenOrders': true,
42
+ 'fetchOrder': true,
43
+ 'fetchOrderBook': true,
44
+ 'fetchOrders': true,
45
+ 'fetchPositions': false,
46
+ 'fetchStatus': false,
47
+ 'fetchTicker': true,
48
+ 'fetchTickers': true,
49
+ 'fetchTime': false,
50
+ 'fetchTrades': true,
51
+ 'fetchTradingFee': false,
52
+ 'fetchTradingFees': false,
53
+ 'fetchTransactions': false,
54
+ 'fetchTransfers': true,
55
+ 'fetchWithdrawals': true,
56
+ 'setLeverage': false,
57
+ 'setMarginMode': false,
58
+ 'transfer': true,
59
+ 'withdraw': true,
60
+ },
61
+ 'timeframes': {
62
+ '1m': '1m',
63
+ '5m': '5m',
64
+ '15m': '15m',
65
+ '30m': '30m',
66
+ '1h': '1h',
67
+ '4h': '4h',
68
+ '6h': '6h',
69
+ '12h': '12h',
70
+ '1d': '1D',
71
+ '1w': '7D',
72
+ '2w': '14D',
73
+ '1M': '1M',
74
+ },
75
+ 'urls': {
76
+ 'logo': 'https://user-images.githubusercontent.com/1294454/147792121-38ed5e36-c229-48d6-b49a-48d05fc19ed4.jpeg',
77
+ 'test': 'https://uat-api.3ona.co/v2',
78
+ 'api': {
79
+ 'spot': 'https://api.crypto.com/v2',
80
+ 'derivatives': 'https://deriv-api.crypto.com/v1',
81
+ },
82
+ 'www': 'https://crypto.com/',
83
+ 'referral': 'https://crypto.com/exch/5835vstech',
84
+ 'doc': 'https://exchange-docs.crypto.com/',
85
+ 'fees': 'https://crypto.com/exchange/document/fees-limits',
86
+ },
87
+ 'api': {
88
+ 'spot': {
89
+ 'public': {
90
+ 'get': {
91
+ 'public/auth': 1,
92
+ 'public/get-instruments': 1,
93
+ 'public/get-book': 1,
94
+ 'public/get-candlestick': 1,
95
+ 'public/get-ticker': 1,
96
+ 'public/get-trades': 1,
97
+ 'public/margin/get-transfer-currencies': 1,
98
+ 'public/margin/get-load-currenices': 1,
99
+ 'public/respond-heartbeat': 1,
100
+ },
101
+ },
102
+ 'private': {
103
+ 'post': {
104
+ 'private/set-cancel-on-disconnect': 10 / 3,
105
+ 'private/get-cancel-on-disconnect': 10 / 3,
106
+ 'private/create-withdrawal': 10 / 3,
107
+ 'private/get-withdrawal-history': 10 / 3,
108
+ 'private/get-deposit-history': 10 / 3,
109
+ 'private/get-deposit-address': 10 / 3,
110
+ 'private/get-account-summary': 10 / 3,
111
+ 'private/create-order': 2 / 3,
112
+ 'private/cancel-order': 2 / 3,
113
+ 'private/cancel-all-orders': 2 / 3,
114
+ 'private/get-order-history': 10 / 3,
115
+ 'private/get-open-orders': 10 / 3,
116
+ 'private/get-order-detail': 1 / 3,
117
+ 'private/get-trades': 100,
118
+ 'private/margin/get-user-config': 10 / 3,
119
+ 'private/margin/get-account-summary': 10 / 3,
120
+ 'private/margin/transfer': 10 / 3,
121
+ 'private/margin/borrow': 10 / 3,
122
+ 'private/margin/repay': 10 / 3,
123
+ 'private/margin/get-transfer-history': 10 / 3,
124
+ 'private/margin/get-borrow-history': 10 / 3,
125
+ 'private/margin/get-interest-history': 10 / 3,
126
+ 'private/margin/get-repay-history': 10 / 3,
127
+ 'private/margin/get-liquidation-history': 10 / 3,
128
+ 'private/margin/get-liquidation-orders': 10 / 3,
129
+ 'private/margin/create-order': 2 / 3,
130
+ 'private/margin/cancel-order': 2 / 3,
131
+ 'private/margin/cancel-all-orders': 2 / 3,
132
+ 'private/margin/get-order-history': 10 / 3,
133
+ 'private/margin/get-open-orders': 10 / 3,
134
+ 'private/margin/get-order-detail': 1 / 3,
135
+ 'private/margin/get-trades': 100,
136
+ 'private/deriv/transfer': 10 / 3,
137
+ 'private/deriv/get-transfer-history': 10 / 3,
138
+ 'private/subaccount/get-sub-accounts': 10 / 3,
139
+ 'private/subaccount/get-transfer-history': 10 / 3,
140
+ 'private/subaccount/transfer': 10 / 3,
141
+ },
142
+ },
143
+ },
144
+ 'derivatives': {
145
+ 'public': {
146
+ 'get': {
147
+ 'public/auth': 10 / 3,
148
+ 'public/get-instruments': 10 / 3,
149
+ 'public/get-book': 1,
150
+ 'public/get-candlestick': 1,
151
+ 'public/get-trades': 1,
152
+ 'public/get-tickers': 1,
153
+ 'public/get-valuations': 1,
154
+ 'public/get-expired-settlement-price': 10 / 3,
155
+ 'public/get-insurance': 1,
156
+ },
157
+ },
158
+ 'private': {
159
+ 'post': {
160
+ 'private/set-cancel-on-disconnect': 10 / 3,
161
+ 'private/get-cancel-on-disconnect': 10 / 3,
162
+ 'private/user-balance': 10 / 3,
163
+ 'private/user-balance-history': 10 / 3,
164
+ 'private/get-positions': 10 / 3,
165
+ 'private/create-order': 2 / 3,
166
+ 'private/cancel-order': 2 / 3,
167
+ 'private/cancel-all-orders': 2 / 3,
168
+ 'private/close-position': 10 / 3,
169
+ 'private/convert-collateral': 10 / 3,
170
+ 'private/get-order-history': 100,
171
+ 'private/get-open-orders': 10 / 3,
172
+ 'private/get-order-detail': 1 / 3,
173
+ 'private/get-trades': 100,
174
+ 'private/change-account-leverage': 10 / 3,
175
+ 'private/get-transactions': 10 / 3,
176
+ },
177
+ },
178
+ },
179
+ },
180
+ 'fees': {
181
+ 'trading': {
182
+ 'maker': this.parseNumber ('0.004'),
183
+ 'taker': this.parseNumber ('0.004'),
184
+ 'tiers': {
185
+ 'maker': [
186
+ [ this.parseNumber ('0'), this.parseNumber ('0.004') ],
187
+ [ this.parseNumber ('25000'), this.parseNumber ('0.0035') ],
188
+ [ this.parseNumber ('50000'), this.parseNumber ('0.0015') ],
189
+ [ this.parseNumber ('100000'), this.parseNumber ('0.001') ],
190
+ [ this.parseNumber ('250000'), this.parseNumber ('0.0009') ],
191
+ [ this.parseNumber ('1000000'), this.parseNumber ('0.0008') ],
192
+ [ this.parseNumber ('20000000'), this.parseNumber ('0.0007') ],
193
+ [ this.parseNumber ('100000000'), this.parseNumber ('0.0006') ],
194
+ [ this.parseNumber ('200000000'), this.parseNumber ('0.0004') ],
195
+ ],
196
+ 'taker': [
197
+ [ this.parseNumber ('0'), this.parseNumber ('0.004') ],
198
+ [ this.parseNumber ('25000'), this.parseNumber ('0.0035') ],
199
+ [ this.parseNumber ('50000'), this.parseNumber ('0.0025') ],
200
+ [ this.parseNumber ('100000'), this.parseNumber ('0.0016') ],
201
+ [ this.parseNumber ('250000'), this.parseNumber ('0.00015') ],
202
+ [ this.parseNumber ('1000000'), this.parseNumber ('0.00014') ],
203
+ [ this.parseNumber ('20000000'), this.parseNumber ('0.00013') ],
204
+ [ this.parseNumber ('100000000'), this.parseNumber ('0.00012') ],
205
+ [ this.parseNumber ('200000000'), this.parseNumber ('0.0001') ],
206
+ ],
207
+ },
208
+ },
209
+ },
210
+ 'options': {
211
+ 'defaultType': 'spot',
212
+ 'accountsByType': {
213
+ 'funding': 'SPOT',
214
+ 'spot': 'SPOT',
215
+ 'derivatives': 'DERIVATIVES',
216
+ 'swap': 'DERIVATIVES',
217
+ 'future': 'DERIVATIVES',
218
+ },
219
+ },
220
+ // https://exchange-docs.crypto.com/spot/index.html#response-and-reason-codes
221
+ 'commonCurrencies': {
222
+ 'USD_STABLE_COIN': 'USDC',
223
+ },
224
+ 'exceptions': {
225
+ 'exact': {
226
+ '10001': ExchangeError,
227
+ '10002': PermissionDenied,
228
+ '10003': PermissionDenied,
229
+ '10004': BadRequest,
230
+ '10005': PermissionDenied,
231
+ '10006': DDoSProtection,
232
+ '10007': InvalidNonce,
233
+ '10008': BadRequest,
234
+ '10009': BadRequest,
235
+ '20001': BadRequest,
236
+ '20002': InsufficientFunds,
237
+ '20005': AccountNotEnabled, // {"id":"123xxx","method":"private/margin/xxx","code":"20005","message":"ACCOUNT_NOT_FOUND"}
238
+ '30003': BadSymbol,
239
+ '30004': BadRequest,
240
+ '30005': BadRequest,
241
+ '30006': BadRequest,
242
+ '30007': BadRequest,
243
+ '30008': BadRequest,
244
+ '30009': BadRequest,
245
+ '30010': BadRequest,
246
+ '30013': BadRequest,
247
+ '30014': BadRequest,
248
+ '30016': BadRequest,
249
+ '30017': BadRequest,
250
+ '30023': BadRequest,
251
+ '30024': BadRequest,
252
+ '30025': BadRequest,
253
+ '40001': BadRequest,
254
+ '40002': BadRequest,
255
+ '40003': BadRequest,
256
+ '40004': BadRequest,
257
+ '40005': BadRequest,
258
+ '40006': BadRequest,
259
+ '40007': BadRequest,
260
+ '40101': AuthenticationError,
261
+ '50001': BadRequest,
262
+ },
263
+ },
264
+ });
265
+ }
266
+
267
+ async fetchMarkets (params = {}) {
268
+ //
269
+ // {
270
+ // id: 11,
271
+ // method: 'public/get-instruments',
272
+ // code: 0,
273
+ // result: {
274
+ // 'instruments': [
275
+ // {
276
+ // instrument_name: 'NEAR_BTC',
277
+ // quote_currency: 'BTC',
278
+ // base_currency: 'NEAR',
279
+ // price_decimals: '8',
280
+ // quantity_decimals: '2',
281
+ // margin_trading_enabled: true,
282
+ // margin_trading_enabled_5x: true,
283
+ // margin_trading_enabled_10x: true,
284
+ // max_quantity: '100000000',
285
+ // min_quantity: '0.01'
286
+ // },
287
+ // ]
288
+ // }
289
+ // }
290
+ //
291
+ const response = await this.spotPublicGetPublicGetInstruments (params);
292
+ const resultResponse = this.safeValue (response, 'result', {});
293
+ const markets = this.safeValue (resultResponse, 'instruments', []);
294
+ const result = [];
295
+ for (let i = 0; i < markets.length; i++) {
296
+ const market = markets[i];
297
+ const id = this.safeString (market, 'instrument_name');
298
+ const baseId = this.safeString (market, 'base_currency');
299
+ const quoteId = this.safeString (market, 'quote_currency');
300
+ const base = this.safeCurrencyCode (baseId);
301
+ const quote = this.safeCurrencyCode (quoteId);
302
+ const priceDecimals = this.safeString (market, 'price_decimals');
303
+ const minPrice = this.parsePrecision (priceDecimals);
304
+ const minQuantity = this.safeString (market, 'min_quantity');
305
+ let maxLeverage = this.parseNumber ('1');
306
+ const margin_trading_enabled_5x = this.safeValue (market, 'margin_trading_enabled_5x');
307
+ if (margin_trading_enabled_5x) {
308
+ maxLeverage = this.parseNumber ('5');
309
+ }
310
+ const margin_trading_enabled_10x = this.safeValue (market, 'margin_trading_enabled_10x');
311
+ if (margin_trading_enabled_10x) {
312
+ maxLeverage = this.parseNumber ('10');
313
+ }
314
+ result.push ({
315
+ 'id': id,
316
+ 'symbol': base + '/' + quote,
317
+ 'base': base,
318
+ 'quote': quote,
319
+ 'settle': undefined,
320
+ 'baseId': baseId,
321
+ 'quoteId': quoteId,
322
+ 'settleId': undefined,
323
+ 'type': 'spot',
324
+ 'spot': true,
325
+ 'margin': this.safeValue (market, 'margin_trading_enabled'),
326
+ 'swap': false,
327
+ 'future': false,
328
+ 'option': false,
329
+ 'active': undefined,
330
+ 'contract': false,
331
+ 'linear': undefined,
332
+ 'inverse': undefined,
333
+ 'contractSize': undefined,
334
+ 'expiry': undefined,
335
+ 'expiryDatetime': undefined,
336
+ 'strike': undefined,
337
+ 'optionType': undefined,
338
+ 'precision': {
339
+ 'amount': this.safeInteger (market, 'quantity_decimals'),
340
+ 'price': parseInt (priceDecimals),
341
+ },
342
+ 'limits': {
343
+ 'leverage': {
344
+ 'min': this.parseNumber ('1'),
345
+ 'max': maxLeverage,
346
+ },
347
+ 'amount': {
348
+ 'min': this.parseNumber (minQuantity),
349
+ 'max': this.safeNumber (market, 'max_quantity'),
350
+ },
351
+ 'price': {
352
+ 'min': this.parseNumber (minPrice),
353
+ 'max': undefined,
354
+ },
355
+ 'cost': {
356
+ 'min': this.parseNumber (Precise.stringMul (minQuantity, minPrice)),
357
+ 'max': undefined,
358
+ },
359
+ },
360
+ 'info': market,
361
+ });
362
+ }
363
+ const futuresResponse = await this.derivativesPublicGetPublicGetInstruments ();
364
+ //
365
+ // {
366
+ // id: -1,
367
+ // method: 'public/get-instruments',
368
+ // code: 0,
369
+ // result: {
370
+ // data: [
371
+ // {
372
+ // symbol: '1INCHUSD-PERP',
373
+ // inst_type: 'PERPETUAL_SWAP',
374
+ // display_name: '1INCHUSD Perpetual',
375
+ // base_ccy: '1INCH',
376
+ // quote_ccy: 'USD_Stable_Coin',
377
+ // quote_decimals: 4,
378
+ // quantity_decimals: 0,
379
+ // price_tick_size: '0.0001',
380
+ // qty_tick_size: '1',
381
+ // max_leverage: '50',
382
+ // tradable: true,
383
+ // expiry_timestamp_ms: 0,
384
+ // beta_product: false,
385
+ // underlying_symbol: '1INCHUSD-INDEX',
386
+ // put_call: 'UNDEFINED',
387
+ // strike: '0',
388
+ // contract_size: '1'
389
+ // },
390
+ // ]
391
+ // }
392
+ // }
393
+ //
394
+ const futuresResult = this.safeValue (futuresResponse, 'result', {});
395
+ const data = this.safeValue (futuresResult, 'data', []);
396
+ for (let i = 0; i < data.length; i++) {
397
+ const market = data[i];
398
+ const inst_type = this.safeString (market, 'inst_type');
399
+ const swap = inst_type === 'PERPETUAL_SWAP';
400
+ const future = inst_type === 'FUTURE';
401
+ const baseId = this.safeString (market, 'base_ccy');
402
+ const quoteId = this.safeString (market, 'quote_ccy');
403
+ const base = this.safeCurrencyCode (baseId);
404
+ const quote = this.safeCurrencyCode (quoteId);
405
+ let symbol = base + '/' + quote + ':' + quote;
406
+ let expiry = this.safeInteger (market, 'expiry_timestamp_ms');
407
+ if (expiry === 0) {
408
+ expiry = undefined;
409
+ }
410
+ let type = 'swap';
411
+ if (future) {
412
+ type = 'future';
413
+ symbol = symbol + '-' + this.yymmdd (expiry);
414
+ }
415
+ const contractSize = this.safeNumber (market, 'contract_size');
416
+ result.push ({
417
+ 'id': this.safeString (market, 'symbol'),
418
+ 'symbol': symbol,
419
+ 'base': base,
420
+ 'quote': quote,
421
+ 'settle': quote,
422
+ 'baseId': baseId,
423
+ 'quoteId': quoteId,
424
+ 'settleId': quoteId,
425
+ 'type': type,
426
+ 'spot': false,
427
+ 'margin': false,
428
+ 'swap': swap,
429
+ 'future': future,
430
+ 'option': false,
431
+ 'active': this.safeValue (market, 'tradable'),
432
+ 'contract': true,
433
+ 'linear': true,
434
+ 'inverse': false,
435
+ 'contractSize': contractSize,
436
+ 'expiry': expiry,
437
+ 'expiryDatetime': this.iso8601 (expiry),
438
+ 'strike': undefined,
439
+ 'optionType': undefined,
440
+ 'precision': {
441
+ 'price': this.safeInteger (market, 'quote_decimals'),
442
+ 'amount': this.safeInteger (market, 'quantity_decimals'),
443
+ },
444
+ 'limits': {
445
+ 'leverage': {
446
+ 'min': this.parseNumber ('1'),
447
+ 'max': this.safeNumber (market, 'max_leverage'),
448
+ },
449
+ 'amount': {
450
+ 'min': this.parseNumber (contractSize),
451
+ 'max': undefined,
452
+ },
453
+ 'price': {
454
+ 'min': undefined,
455
+ 'max': undefined,
456
+ },
457
+ 'cost': {
458
+ 'min': undefined,
459
+ 'max': undefined,
460
+ },
461
+ },
462
+ 'info': market,
463
+ });
464
+ }
465
+ return result;
466
+ }
467
+
468
+ async fetchTickers (symbols = undefined, params = {}) {
469
+ await this.loadMarkets ();
470
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchTickers', undefined, params);
471
+ const method = this.getSupportedMapping (marketType, {
472
+ 'spot': 'spotPublicGetPublicGetTicker',
473
+ 'future': 'derivativesPublicGetPublicGetTickers',
474
+ 'swap': 'derivativesPublicGetPublicGetTickers',
475
+ });
476
+ const response = await this[method] (query);
477
+ // {
478
+ // "code":0,
479
+ // "method":"public/get-ticker",
480
+ // "result":{
481
+ // "data": [
482
+ // {"i":"CRO_BTC","b":0.00000890,"k":0.00001179,"a":0.00001042,"t":1591770793901,"v":14905879.59,"h":0.00,"l":0.00,"c":0.00},
483
+ // {"i":"EOS_USDT","b":2.7676,"k":2.7776,"a":2.7693,"t":1591770798500,"v":774.51,"h":0.05,"l":0.05,"c":0.00},
484
+ // {"i":"BCH_USDT","b":247.49,"k":251.73,"a":251.67,"t":1591770797601,"v":1.01693,"h":0.01292,"l":0.01231,"c":-0.00047},
485
+ // {"i":"ETH_USDT","b":239.92,"k":242.59,"a":240.30,"t":1591770798701,"v":0.97575,"h":0.01236,"l":0.01199,"c":-0.00018},
486
+ // {"i":"ETH_CRO","b":2693.11,"k":2699.84,"a":2699.55,"t":1591770795053,"v":95.680,"h":8.218,"l":7.853,"c":-0.050}
487
+ // ]
488
+ // }
489
+ // }
490
+ const resultResponse = this.safeValue (response, 'result', {});
491
+ const tickers = this.safeValue (resultResponse, 'data', []);
492
+ const result = {};
493
+ for (let i = 0; i < tickers.length; i++) {
494
+ const ticker = tickers[i];
495
+ const marketId = this.safeString (ticker, 'i');
496
+ const market = this.safeMarket (marketId, undefined, '_');
497
+ const symbol = market['symbol'];
498
+ result[symbol] = this.parseTicker (ticker, market);
499
+ }
500
+ return result;
501
+ }
502
+
503
+ async fetchTicker (symbol, params = {}) {
504
+ await this.loadMarkets ();
505
+ const market = this.market (symbol);
506
+ const request = {
507
+ 'instrument_name': market['id'],
508
+ };
509
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchTicker', market, params);
510
+ if (marketType !== 'spot') {
511
+ throw new NotSupported (this.id + ' fetchTicker() only supports spot markets');
512
+ }
513
+ const response = await this.spotPublicGetPublicGetTicker (this.extend (request, query));
514
+ // {
515
+ // "code":0,
516
+ // "method":"public/get-ticker",
517
+ // "result":{
518
+ // "data": {"i":"CRO_BTC","b":0.00000890,"k":0.00001179,"a":0.00001042,"t":1591770793901,"v":14905879.59,"h":0.00,"l":0.00,"c":0.00}
519
+ // }
520
+ // }
521
+ const resultResponse = this.safeValue (response, 'result', {});
522
+ const data = this.safeValue (resultResponse, 'data', {});
523
+ return this.parseTicker (data, market);
524
+ }
525
+
526
+ async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
527
+ if (symbol === undefined) {
528
+ throw new ArgumentsRequired (this.id + ' fetchClosedOrders() requires a symbol argument');
529
+ }
530
+ await this.loadMarkets ();
531
+ const market = this.market (symbol);
532
+ const request = {
533
+ 'instrument_name': market['id'],
534
+ };
535
+ if (since !== undefined) {
536
+ // maximum date range is one day
537
+ request['start_ts'] = since;
538
+ }
539
+ if (limit !== undefined) {
540
+ request['page_size'] = limit;
541
+ }
542
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchOrders', market, params);
543
+ const method = this.getSupportedMapping (marketType, {
544
+ 'spot': 'spotPrivatePostPrivateGetOrderHistory',
545
+ 'future': 'derivativesPrivatePostPrivateGetOrderHistory',
546
+ 'swap': 'derivativesPrivatePostPrivateGetOrderHistory',
547
+ });
548
+ const response = await this[method] (this.extend (request, query));
549
+ //
550
+ // spot
551
+ // {
552
+ // id: 1641026542065,
553
+ // method: 'private/get-order-history',
554
+ // code: 0,
555
+ // result: {
556
+ // order_list: [
557
+ // {
558
+ // status: 'FILLED',
559
+ // side: 'BUY',
560
+ // price: 0,
561
+ // quantity: 110,
562
+ // order_id: '2120246337927715937',
563
+ // client_oid: '',
564
+ // create_time: 1641025064904,
565
+ // update_time: 1641025064958,
566
+ // type: 'MARKET',
567
+ // instrument_name: 'USDC_USDT',
568
+ // avg_price: 1.0001,
569
+ // cumulative_quantity: 110,
570
+ // cumulative_value: 110.011,
571
+ // fee_currency: 'USDC',
572
+ // exec_inst: '',
573
+ // time_in_force: 'GOOD_TILL_CANCEL'
574
+ // }
575
+ // ]
576
+ // }
577
+ // }
578
+ //
579
+ // swap
580
+ // {
581
+ // id: 1641026373106,
582
+ // method: 'private/get-order-history',
583
+ // code: 0,
584
+ // result: {
585
+ // data: [
586
+ // {
587
+ // account_id: '85ff689a-7508-4b96-aa79-dc0545d6e637',
588
+ // order_id: 13191401932,
589
+ // client_oid: '1641025941461',
590
+ // order_type: 'LIMIT',
591
+ // time_in_force: 'GOOD_TILL_CANCEL',
592
+ // side: 'BUY',
593
+ // exec_inst: [],
594
+ // quantity: '0.0001',
595
+ // limit_price: '48000.0',
596
+ // order_value: '4.80000000',
597
+ // maker_fee_rate: '0.00050',
598
+ // taker_fee_rate: '0.00070',
599
+ // avg_price: '47253.5',
600
+ // trigger_price: '0.0',
601
+ // ref_price_type: 'NULL_VAL',
602
+ // cumulative_quantity: '0.0001',
603
+ // cumulative_value: '4.72535000',
604
+ // cumulative_fee: '0.00330775',
605
+ // status: 'FILLED',
606
+ // update_user_id: 'ce075bef-b600-4277-bd6e-ff9007251e63',
607
+ // order_date: '2022-01-01',
608
+ // instrument_name: 'BTCUSD-PERP',
609
+ // fee_instrument_name: 'USD_Stable_Coin',
610
+ // create_time: 1641025941827,
611
+ // create_time_ns: '1641025941827994756',
612
+ // update_time: 1641025941827
613
+ // }
614
+ // ]
615
+ // }
616
+ // }
617
+ //
618
+ const data = this.safeValue (response, 'result', {});
619
+ const orderList = this.safeValue2 (data, 'order_list', 'data', []);
620
+ return this.parseOrders (orderList, market, since, limit);
621
+ }
622
+
623
+ async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
624
+ await this.loadMarkets ();
625
+ const market = this.market (symbol);
626
+ const request = {
627
+ 'instrument_name': market['id'],
628
+ };
629
+ if (since !== undefined) {
630
+ // maximum date range is one day
631
+ request['start_ts'] = since;
632
+ }
633
+ if (limit !== undefined) {
634
+ request['page_size'] = limit;
635
+ }
636
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchTrades', market, params);
637
+ const method = this.getSupportedMapping (marketType, {
638
+ 'spot': 'spotPublicGetPublicGetTrades',
639
+ 'future': 'derivativesPublicGetPublicGetTrades',
640
+ 'swap': 'derivativesPublicGetPublicGetTrades',
641
+ });
642
+ const response = await this[method] (this.extend (request, query));
643
+ // {
644
+ // "code":0,
645
+ // "method":"public/get-trades",
646
+ // "result": {
647
+ // "instrument_name": "BTC_USDT",
648
+ // "data:": [
649
+ // {"dataTime":1591710781947,"d":465533583799589409,"s":"BUY","p":2.96,"q":16.0,"t":1591710781946,"i":"ICX_CRO"},
650
+ // {"dataTime":1591707701899,"d":465430234542863152,"s":"BUY","p":0.007749,"q":115.0,"t":1591707701898,"i":"VET_USDT"},
651
+ // {"dataTime":1591710786155,"d":465533724976458209,"s":"SELL","p":25.676,"q":0.55,"t":1591710786154,"i":"XTZ_CRO"},
652
+ // {"dataTime":1591710783300,"d":465533629172286576,"s":"SELL","p":2.9016,"q":0.6,"t":1591710783298,"i":"XTZ_USDT"},
653
+ // {"dataTime":1591710784499,"d":465533669425626384,"s":"SELL","p":2.7662,"q":0.58,"t":1591710784498,"i":"EOS_USDT"},
654
+ // {"dataTime":1591710784700,"d":465533676120104336,"s":"SELL","p":243.21,"q":0.01647,"t":1591710784698,"i":"ETH_USDT"},
655
+ // {"dataTime":1591710786600,"d":465533739878620208,"s":"SELL","p":253.06,"q":0.00516,"t":1591710786598,"i":"BCH_USDT"},
656
+ // {"dataTime":1591710786900,"d":465533749959572464,"s":"BUY","p":0.9999,"q":0.2,"t":1591710786898,"i":"USDC_USDT"},
657
+ // {"dataTime":1591710787500,"d":465533770081010000,"s":"BUY","p":3.159,"q":1.65,"t":1591710787498,"i":"ATOM_USDT"},
658
+ // ]
659
+ // }
660
+ // }
661
+ const resultResponse = this.safeValue (response, 'result', {});
662
+ const data = this.safeValue (resultResponse, 'data', []);
663
+ return this.parseTrades (data, market, since, limit);
664
+ }
665
+
666
+ async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
667
+ await this.loadMarkets ();
668
+ const market = this.market (symbol);
669
+ const request = {
670
+ 'instrument_name': market['id'],
671
+ 'timeframe': this.timeframes[timeframe],
672
+ };
673
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchOHLCV', market, params);
674
+ const method = this.getSupportedMapping (marketType, {
675
+ 'spot': 'spotPublicGetPublicGetCandlestick',
676
+ 'future': 'derivativesPublicGetPublicGetCandlestick',
677
+ 'swap': 'derivativesPublicGetPublicGetCandlestick',
678
+ });
679
+ const response = await this[method] (this.extend (request, query));
680
+ // {
681
+ // "code":0,
682
+ // "method":"public/get-candlestick",
683
+ // "result":{
684
+ // "instrument_name":"BTC_USDT",
685
+ // "interval":"5m",
686
+ // "data":[
687
+ // {"t":1596944700000,"o":11752.38,"h":11754.77,"l":11746.65,"c":11753.64,"v":3.694583},
688
+ // {"t":1596945000000,"o":11753.63,"h":11754.77,"l":11739.83,"c":11746.17,"v":2.073019},
689
+ // {"t":1596945300000,"o":11746.16,"h":11753.24,"l":11738.1,"c":11740.65,"v":0.867247},
690
+ // ...
691
+ // ]
692
+ // }
693
+ // }
694
+ const resultResponse = this.safeValue (response, 'result', {});
695
+ const data = this.safeValue (resultResponse, 'data', []);
696
+ return this.parseOHLCVs (data, market, timeframe, since, limit);
697
+ }
698
+
699
+ async fetchOrderBook (symbol, limit = undefined, params = {}) {
700
+ await this.loadMarkets ();
701
+ const market = this.market (symbol);
702
+ const request = {
703
+ 'instrument_name': market['id'],
704
+ };
705
+ if (limit) {
706
+ request['depth'] = limit;
707
+ }
708
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchOrderBook', market, params);
709
+ const method = this.getSupportedMapping (marketType, {
710
+ 'spot': 'spotPublicGetPublicGetBook',
711
+ 'future': 'derivativesPublicGetPublicGetBook',
712
+ 'swap': 'derivativesPublicGetPublicGetBook',
713
+ });
714
+ const response = await this[method] (this.extend (request, query));
715
+ // {
716
+ // "code":0,
717
+ // "method":"public/get-book",
718
+ // "result":{
719
+ // "bids":[[9668.44,0.006325,1.0],[9659.75,0.006776,1.0],[9653.14,0.011795,1.0],[9647.13,0.019434,1.0],[9634.62,0.013765,1.0],[9633.81,0.021395,1.0],[9628.46,0.037834,1.0],[9627.6,0.020909,1.0],[9621.51,0.026235,1.0],[9620.83,0.026701,1.0]],
720
+ // "asks":[[9697.0,0.68251,1.0],[9697.6,1.722864,2.0],[9699.2,1.664177,2.0],[9700.8,1.824953,2.0],[9702.4,0.85778,1.0],[9704.0,0.935792,1.0],[9713.32,0.002926,1.0],[9716.42,0.78923,1.0],[9732.19,0.00645,1.0],[9737.88,0.020216,1.0]],
721
+ // "t":1591704180270
722
+ // }
723
+ // }
724
+ const result = this.safeValue (response, 'result');
725
+ const data = this.safeValue (result, 'data');
726
+ const orderBook = this.safeValue (data, 0);
727
+ const timestamp = this.safeInteger (orderBook, 't');
728
+ return this.parseOrderBook (orderBook, symbol, timestamp);
729
+ }
730
+
731
+ parseSwapBalance (response) {
732
+ const responseResult = this.safeValue (response, 'result', {});
733
+ const data = this.safeValue (responseResult, 'data', []);
734
+ const result = { 'info': response };
735
+ for (let i = 0; i < data.length; i++) {
736
+ const balance = data[i];
737
+ const currencyId = this.safeString (balance, 'instrument_name');
738
+ const code = this.safeCurrencyCode (currencyId);
739
+ const account = this.account ();
740
+ account['total'] = this.safeString (balance, 'total_cash_balance');
741
+ account['free'] = this.safeString (balance, 'total_available_balance');
742
+ result[code] = account;
743
+ }
744
+ return this.safeBalance (result);
745
+ }
746
+
747
+ parseSpotBalance (response) {
748
+ const data = this.safeValue (response, 'result', {});
749
+ const coinList = this.safeValue (data, 'accounts', []);
750
+ const result = { 'info': response };
751
+ for (let i = 0; i < coinList.length; i++) {
752
+ const balance = coinList[i];
753
+ const currencyId = this.safeString (balance, 'currency');
754
+ const code = this.safeCurrencyCode (currencyId);
755
+ const account = this.account ();
756
+ account['total'] = this.safeString (balance, 'balance');
757
+ account['free'] = this.safeString (balance, 'available');
758
+ account['used'] = this.safeString (balance, 'order');
759
+ result[code] = account;
760
+ }
761
+ return this.safeBalance (result);
762
+ }
763
+
764
+ async fetchBalance (params = {}) {
765
+ await this.loadMarkets ();
766
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchBalance', undefined, params);
767
+ const method = this.getSupportedMapping (marketType, {
768
+ 'spot': 'spotPrivatePostPrivateGetAccountSummary',
769
+ 'future': 'derivativesPrivatePostPrivateUserBalance',
770
+ 'swap': 'derivativesPrivatePostPrivateUserBalance',
771
+ });
772
+ const response = await this[method] (query);
773
+ // spot
774
+ // {
775
+ // "id": 11,
776
+ // "method": "private/get-account-summary",
777
+ // "code": 0,
778
+ // "result": {
779
+ // "accounts": [
780
+ // {
781
+ // "balance": 99999999.905000000000000000,
782
+ // "available": 99999996.905000000000000000,
783
+ // "order": 3.000000000000000000,
784
+ // "stake": 0,
785
+ // "currency": "CRO"
786
+ // }
787
+ // ]
788
+ // }
789
+ // }
790
+ //
791
+ // swap
792
+ // {
793
+ // "id" : 1641025392400,
794
+ // "method" : "private/user-balance",
795
+ // "code" : 0,
796
+ // "result" : {
797
+ // "data" : [ {
798
+ // "total_available_balance" : "109.56000000",
799
+ // "total_margin_balance" : "109.56000000",
800
+ // "total_initial_margin" : "0.00000000",
801
+ // "total_maintenance_margin" : "0.00000000",
802
+ // "total_position_cost" : "0.00000000",
803
+ // "total_cash_balance" : "109.56000000",
804
+ // "total_collateral_value" : "109.56000000",
805
+ // "total_session_unrealized_pnl" : "0.00000000",
806
+ // "instrument_name" : "USD_Stable_Coin",
807
+ // "total_session_realized_pnl" : "0.00000000",
808
+ // "position_balances" : [ {
809
+ // "quantity" : "109.56000000",
810
+ // "collateral_weight" : "1.000000",
811
+ // "collateral_amount" : "109.56000000",
812
+ // "market_value" : "109.56000000",
813
+ // "max_withdrawal_balance" : "109.56000000",
814
+ // "instrument_name" : "USD_Stable_Coin"
815
+ // } ],
816
+ // "total_effective_leverage" : "0.000000",
817
+ // "position_limit" : "3000000.00000000",
818
+ // "used_position_limit" : "0.00000000",
819
+ // "is_liquidating" : false
820
+ // } ]
821
+ // }
822
+ // }
823
+ //
824
+ const parser = this.getSupportedMapping (marketType, {
825
+ 'spot': 'parseSpotBalance',
826
+ 'future': 'parseSwapBalance',
827
+ 'swap': 'parseSwapBalance',
828
+ });
829
+ return this[parser] (response);
830
+ }
831
+
832
+ async fetchOrder (id, symbol = undefined, params = {}) {
833
+ await this.loadMarkets ();
834
+ let market = undefined;
835
+ if (symbol !== undefined) {
836
+ market = this.market (symbol);
837
+ }
838
+ const request = {};
839
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchOrder', market, params);
840
+ if (marketType === 'spot') {
841
+ request['order_id'] = id.toString ();
842
+ } else {
843
+ request['order_id'] = parseInt (id);
844
+ }
845
+ const method = this.getSupportedMapping (marketType, {
846
+ 'spot': 'spotPrivatePostPrivateGetOrderDetail',
847
+ 'future': 'derivativesPrivatePostPrivateGetOrderDetail',
848
+ 'swap': 'derivativesPrivatePostPrivateGetOrderDetail',
849
+ });
850
+ const response = await this[method] (this.extend (request, query));
851
+ // {
852
+ // "id": 11,
853
+ // "method": "private/get-order-detail",
854
+ // "code": 0,
855
+ // "result": {
856
+ // "trade_list": [
857
+ // {
858
+ // "side": "BUY",
859
+ // "instrument_name": "ETH_CRO",
860
+ // "fee": 0.007,
861
+ // "trade_id": "371303044218155296",
862
+ // "create_time": 1588902493045,
863
+ // "traded_price": 7,
864
+ // "traded_quantity": 7,
865
+ // "fee_currency": "CRO",
866
+ // "order_id": "371302913889488619"
867
+ // }
868
+ // ],
869
+ // "order_info": {
870
+ // "status": "FILLED",
871
+ // "side": "BUY",
872
+ // "order_id": "371302913889488619",
873
+ // "client_oid": "9_yMYJDNEeqHxLqtD_2j3g",
874
+ // "create_time": 1588902489144,
875
+ // "update_time": 1588902493024,
876
+ // "type": "LIMIT",
877
+ // "instrument_name": "ETH_CRO",
878
+ // "cumulative_quantity": 7,
879
+ // "cumulative_value": 7,
880
+ // "avg_price": 7,
881
+ // "fee_currency": "CRO",
882
+ // "time_in_force": "GOOD_TILL_CANCEL",
883
+ // "exec_inst": "POST_ONLY"
884
+ // }
885
+ // }
886
+ // }
887
+ const result = this.safeValue (response, 'result', {});
888
+ const order = this.safeValue (result, 'order_info', result);
889
+ return this.parseOrder (order, market);
890
+ }
891
+
892
+ async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
893
+ await this.loadMarkets ();
894
+ const market = this.market (symbol);
895
+ const uppercaseType = type.toUpperCase ();
896
+ const request = {
897
+ 'instrument_name': market['id'],
898
+ 'side': side.toUpperCase (),
899
+ 'type': uppercaseType,
900
+ 'quantity': this.amountToPrecision (symbol, amount),
901
+ };
902
+ if ((uppercaseType === 'LIMIT') || (uppercaseType === 'STOP_LIMIT')) {
903
+ request['price'] = this.priceToPrecision (symbol, price);
904
+ }
905
+ const postOnly = this.safeValue (params, 'postOnly', false);
906
+ if (postOnly) {
907
+ request['exec_inst'] = 'POST_ONLY';
908
+ params = this.omit (params, [ 'postOnly' ]);
909
+ }
910
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('createOrder', market, params);
911
+ const method = this.getSupportedMapping (marketType, {
912
+ 'spot': 'spotPrivatePostPrivateCreateOrder',
913
+ 'future': 'derivativesPrivatePostPrivateCreateOrder',
914
+ 'swap': 'derivativesPrivatePostPrivateCreateOrder',
915
+ });
916
+ const response = await this[method] (this.extend (request, query));
917
+ // {
918
+ // "id": 11,
919
+ // "method": "private/create-order",
920
+ // "result": {
921
+ // "order_id": "337843775021233500",
922
+ // "client_oid": "my_order_0002"
923
+ // }
924
+ // }
925
+ const result = this.safeValue (response, 'result', {});
926
+ return this.parseOrder (result, market);
927
+ }
928
+
929
+ async cancelAllOrders (symbol = undefined, params = {}) {
930
+ await this.loadMarkets ();
931
+ let market = undefined;
932
+ if (symbol !== undefined) {
933
+ market = this.market (symbol);
934
+ }
935
+ const request = {};
936
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('cancelAllOrders', market, params);
937
+ if (marketType === 'spot') {
938
+ if (symbol === undefined) {
939
+ throw new ArgumentsRequired (this.id + ' cancelAllOrders() requires a symbol argument for ' + marketType + ' orders');
940
+ }
941
+ request['instrument_name'] = market['id'];
942
+ }
943
+ const method = this.getSupportedMapping (marketType, {
944
+ 'spot': 'spotPrivatePostPrivateCancelAllOrders',
945
+ 'future': 'derivativesPrivatePostPrivateCancelAllOrders',
946
+ 'swap': 'derivativesPrivatePostPrivateCancelAllOrders',
947
+ });
948
+ return await this[method] (this.extend (request, query));
949
+ }
950
+
951
+ async cancelOrder (id, symbol = undefined, params = {}) {
952
+ await this.loadMarkets ();
953
+ let market = undefined;
954
+ if (symbol !== undefined) {
955
+ market = this.market (symbol);
956
+ }
957
+ const request = {};
958
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('cancelOrder', market, params);
959
+ if (marketType === 'spot') {
960
+ if (symbol === undefined) {
961
+ throw new ArgumentsRequired (this.id + ' cancelOrder() requires a symbol argument for ' + marketType + ' orders');
962
+ }
963
+ request['instrument_name'] = market['id'];
964
+ request['order_id'] = id.toString ();
965
+ } else {
966
+ request['order_id'] = parseInt (id);
967
+ }
968
+ const method = this.getSupportedMapping (marketType, {
969
+ 'spot': 'spotPrivatePostPrivateCancelOrder',
970
+ 'future': 'derivativesPrivatePostPrivateCancelOrder',
971
+ 'swap': 'derivativesPrivatePostPrivateCancelOrder',
972
+ });
973
+ const response = await this[method] (this.extend (request, query));
974
+ const result = this.safeValue (response, 'result', response);
975
+ return this.parseOrder (result);
976
+ }
977
+
978
+ async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
979
+ await this.loadMarkets ();
980
+ let market = undefined;
981
+ const request = {};
982
+ if (symbol !== undefined) {
983
+ market = this.market (symbol);
984
+ request['instrument_name'] = market['id'];
985
+ }
986
+ if (limit !== undefined) {
987
+ request['page_size'] = limit;
988
+ }
989
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchOpenOrders', market, params);
990
+ const method = this.getSupportedMapping (marketType, {
991
+ 'spot': 'spotPrivatePostPrivateGetOpenOrders',
992
+ 'future': 'derivativesPrivatePostPrivateGetOpenOrders',
993
+ 'swap': 'derivativesPrivatePostPrivateGetOpenOrders',
994
+ });
995
+ const response = await this[method] (this.extend (request, query));
996
+ // {
997
+ // "id": 11,
998
+ // "method": "private/get-open-orders",
999
+ // "code": 0,
1000
+ // "result": {
1001
+ // "count": 1177,
1002
+ // "order_list": [
1003
+ // {
1004
+ // "status": "ACTIVE",
1005
+ // "side": "BUY",
1006
+ // "price": 1,
1007
+ // "quantity": 1,
1008
+ // "order_id": "366543374673423753",
1009
+ // "client_oid": "my_order_0002",
1010
+ // "create_time": 1588760643829,
1011
+ // "update_time": 1588760644292,
1012
+ // "type": "LIMIT",
1013
+ // "instrument_name": "ETH_CRO",
1014
+ // "cumulative_quantity": 0,
1015
+ // "cumulative_value": 0,
1016
+ // "avg_price": 0,
1017
+ // "fee_currency": "CRO",
1018
+ // "time_in_force": "GOOD_TILL_CANCEL"
1019
+ // },
1020
+ // {
1021
+ // "status": "ACTIVE",
1022
+ // "side": "BUY",
1023
+ // "price": 1,
1024
+ // "quantity": 1,
1025
+ // "order_id": "366455245775097673",
1026
+ // "client_oid": "my_order_0002",
1027
+ // "create_time": 1588758017375,
1028
+ // "update_time": 1588758017411,
1029
+ // "type": "LIMIT",
1030
+ // "instrument_name": "ETH_CRO",
1031
+ // "cumulative_quantity": 0,
1032
+ // "cumulative_value": 0,
1033
+ // "avg_price": 0,
1034
+ // "fee_currency": "CRO",
1035
+ // "time_in_force": "GOOD_TILL_CANCEL"
1036
+ // }
1037
+ // ]
1038
+ // }
1039
+ // }
1040
+ const data = this.safeValue (response, 'result', {});
1041
+ const resultList = this.safeValue2 (data, 'order_list', 'data', []);
1042
+ return this.parseOrders (resultList, market, since, limit);
1043
+ }
1044
+
1045
+ async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
1046
+ await this.loadMarkets ();
1047
+ const request = {};
1048
+ let market = undefined;
1049
+ if (symbol !== undefined) {
1050
+ market = this.market (symbol);
1051
+ request['instrument_name'] = market['id'];
1052
+ }
1053
+ if (since !== undefined) {
1054
+ // maximum date range is one day
1055
+ request['start_ts'] = since;
1056
+ const endTimestamp = this.sum (since, 24 * 60 * 60 * 1000);
1057
+ request['end_ts'] = endTimestamp;
1058
+ }
1059
+ if (limit !== undefined) {
1060
+ request['page_size'] = limit;
1061
+ }
1062
+ const [ marketType, query ] = this.handleMarketTypeAndParams ('fetchMyTrades', market, params);
1063
+ const method = this.getSupportedMapping (marketType, {
1064
+ 'spot': 'spotPrivatePostPrivateGetTrades',
1065
+ 'future': 'derivativesPrivatePostPrivateGetTrades',
1066
+ 'swap': 'derivativesPrivatePostPrivateGetTrades',
1067
+ });
1068
+ const response = await this[method] (this.extend (request, query));
1069
+ // {
1070
+ // "id": 11,
1071
+ // "method": "private/get-trades",
1072
+ // "code": 0,
1073
+ // "result": {
1074
+ // "trade_list": [
1075
+ // {
1076
+ // "side": "SELL",
1077
+ // "instrument_name": "ETH_CRO",
1078
+ // "fee": 0.014,
1079
+ // "trade_id": "367107655537806900",
1080
+ // "create_time": 1588777459755,
1081
+ // "traded_price": 7,
1082
+ // "traded_quantity": 1,
1083
+ // "fee_currency": "CRO",
1084
+ // "order_id": "367107623521528450"
1085
+ // }
1086
+ // ]
1087
+ // }
1088
+ // }
1089
+ const data = this.safeValue (response, 'result', {});
1090
+ const resultList = this.safeValue2 (data, 'trade_list', 'data', []);
1091
+ return this.parseTrades (resultList, market, since, limit);
1092
+ }
1093
+
1094
+ parseAddress (addressString) {
1095
+ let address = undefined;
1096
+ let tag = undefined;
1097
+ let rawTag = undefined;
1098
+ if (addressString.indexOf ('?') > 0) {
1099
+ [ address, rawTag ] = addressString.split ('?');
1100
+ const splitted = rawTag.split ('=');
1101
+ tag = splitted[1];
1102
+ } else {
1103
+ address = addressString;
1104
+ }
1105
+ return [ address, tag ];
1106
+ }
1107
+
1108
+ async withdraw (code, amount, address, tag = undefined, params = {}) {
1109
+ [ tag, params ] = this.handleWithdrawTagAndParams (tag, params);
1110
+ await this.loadMarkets ();
1111
+ const currency = this.currency (code);
1112
+ const request = {
1113
+ 'currency': currency['id'],
1114
+ 'amount': amount,
1115
+ 'address': address,
1116
+ };
1117
+ if (tag !== undefined) {
1118
+ request['address_tag'] = tag;
1119
+ }
1120
+ const response = await this.spotPrivatePostPrivateCreateWithdrawal (this.extend (request, params));
1121
+ //
1122
+ // {
1123
+ // "id":-1,
1124
+ // "method":"private/create-withdrawal",
1125
+ // "code":0,
1126
+ // "result": {
1127
+ // "id": 2220,
1128
+ // "amount": 1,
1129
+ // "fee": 0.0004,
1130
+ // "symbol": "BTC",
1131
+ // "address": "2NBqqD5GRJ8wHy1PYyCXTe9ke5226FhavBf",
1132
+ // "client_wid": "my_withdrawal_002",
1133
+ // "create_time":1607063412000
1134
+ // }
1135
+ // }
1136
+ //
1137
+ const result = this.safeValue (response, 'result');
1138
+ return this.parseTransaction (result, currency);
1139
+ }
1140
+
1141
+ async fetchDepositAddressesByNetwork (code, params = {}) {
1142
+ await this.loadMarkets ();
1143
+ const currency = this.currency (code);
1144
+ const request = {
1145
+ 'currency': currency['id'],
1146
+ };
1147
+ const response = await this.spotPrivatePostPrivateGetDepositAddress (this.extend (request, params));
1148
+ // {
1149
+ // "id": 11,
1150
+ // "method": "private/get-deposit-address",
1151
+ // "code": 0,
1152
+ // "result": {
1153
+ // "deposit_address_list": [
1154
+ // {
1155
+ // "currency": "CRO",
1156
+ // "create_time": 1615886328000,
1157
+ // "id": "12345",
1158
+ // "address": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
1159
+ // "status": "1",
1160
+ // "network": "CRO"
1161
+ // },
1162
+ // {
1163
+ // "currency": "CRO",
1164
+ // "create_time": 1615886332000,
1165
+ // "id": "12346",
1166
+ // "address": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
1167
+ // "status": "1",
1168
+ // "network": "ETH"
1169
+ // }
1170
+ // ]
1171
+ // }
1172
+ // }
1173
+ const data = this.safeValue (response, 'result', {});
1174
+ const addresses = this.safeValue (data, 'deposit_address_list', []);
1175
+ if (addresses.length === 0) {
1176
+ throw new ExchangeError (this.id + ' fetchDepositAddressesByNetwork() generating address...');
1177
+ }
1178
+ const result = {};
1179
+ for (let i = 0; i < addresses.length; i++) {
1180
+ const value = this.safeValue (addresses, i);
1181
+ const addressString = this.safeString (value, 'address');
1182
+ const currencyId = this.safeString (value, 'currency');
1183
+ const responseCode = this.safeCurrencyCode (currencyId);
1184
+ const [ address, tag ] = this.parseAddress (addressString);
1185
+ this.checkAddress (address);
1186
+ const networkId = this.safeString (value, 'network');
1187
+ const network = this.safeNetwork (networkId);
1188
+ result[network] = {
1189
+ 'info': value,
1190
+ 'currency': responseCode,
1191
+ 'address': address,
1192
+ 'tag': tag,
1193
+ 'network': network,
1194
+ };
1195
+ }
1196
+ return result;
1197
+ }
1198
+
1199
+ async fetchDepositAddress (code, params = {}) {
1200
+ const network = this.safeStringUpper (params, 'network');
1201
+ params = this.omit (params, [ 'network' ]);
1202
+ const depositAddresses = await this.fetchDepositAddressesByNetwork (code, params);
1203
+ if (network in depositAddresses) {
1204
+ return depositAddresses[network];
1205
+ } else {
1206
+ const keys = Object.keys (depositAddresses);
1207
+ return depositAddresses[keys[0]];
1208
+ }
1209
+ }
1210
+
1211
+ safeNetwork (networkId) {
1212
+ // stub for now
1213
+ // TODO: figure out which networks are supported on cryptocom
1214
+ return networkId;
1215
+ }
1216
+
1217
+ async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) {
1218
+ await this.loadMarkets ();
1219
+ let currency = undefined;
1220
+ const request = {};
1221
+ if (code !== undefined) {
1222
+ currency = this.currency (code);
1223
+ request['currency'] = currency['id'];
1224
+ }
1225
+ if (since !== undefined) {
1226
+ // 90 days date range
1227
+ request['start_ts'] = since;
1228
+ }
1229
+ if (limit !== undefined) {
1230
+ request['page_size'] = limit;
1231
+ }
1232
+ const response = await this.spotPrivatePostPrivateGetDepositHistory (this.extend (request, params));
1233
+ // {
1234
+ // "id": 11,
1235
+ // "method": "private/get-deposit-history",
1236
+ // "code": 0,
1237
+ // "result": {
1238
+ // "deposit_list": [
1239
+ // {
1240
+ // "currency": "XRP",
1241
+ // "fee": 1.0,
1242
+ // "create_time": 1607063412000,
1243
+ // "id": "2220",
1244
+ // "update_time": 1607063460000,
1245
+ // "amount": 100,
1246
+ // "address": "2NBqqD5GRJ8wHy1PYyCXTe9ke5226FhavBf?1234567890",
1247
+ // "status": "1"
1248
+ // }
1249
+ // ]
1250
+ // }
1251
+ // }
1252
+ const data = this.safeValue (response, 'result', {});
1253
+ const depositList = this.safeValue (data, 'deposit_list', []);
1254
+ return this.parseTransactions (depositList, currency, since, limit);
1255
+ }
1256
+
1257
+ async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) {
1258
+ await this.loadMarkets ();
1259
+ let currency = undefined;
1260
+ const request = {};
1261
+ if (code !== undefined) {
1262
+ currency = this.currency (code);
1263
+ request['currency'] = currency['id'];
1264
+ }
1265
+ if (since !== undefined) {
1266
+ // 90 days date range
1267
+ request['start_ts'] = since;
1268
+ }
1269
+ if (limit !== undefined) {
1270
+ request['page_size'] = limit;
1271
+ }
1272
+ const response = await this.spotPrivatePostPrivateGetWithdrawalHistory (this.extend (request, params));
1273
+ //
1274
+ // {
1275
+ // id: 1640704829096,
1276
+ // method: 'private/get-withdrawal-history',
1277
+ // code: 0,
1278
+ // result: {
1279
+ // withdrawal_list: [
1280
+ // {
1281
+ // currency: 'DOGE',
1282
+ // client_wid: '',
1283
+ // fee: 50,
1284
+ // create_time: 1640425168000,
1285
+ // id: '3180557',
1286
+ // update_time: 1640425168000,
1287
+ // amount: 1102.64092,
1288
+ // address: 'DDrGGqmp5Ddo1QH9tUvDfoL4u4rqys5975',
1289
+ // status: '5',
1290
+ // txid: 'ce23e9e21b6c38eef953070a05110e6dca2fd2bcc76d3381000547b9ff5290b2/0'
1291
+ // }
1292
+ // ]
1293
+ // }
1294
+ // }
1295
+ //
1296
+ const data = this.safeValue (response, 'result', {});
1297
+ const withdrawalList = this.safeValue (data, 'withdrawal_list', []);
1298
+ return this.parseTransactions (withdrawalList, currency, since, limit);
1299
+ }
1300
+
1301
+ async transfer (code, amount, fromAccount, toAccount, params = {}) {
1302
+ await this.loadMarkets ();
1303
+ const currency = this.currency (code);
1304
+ fromAccount = fromAccount.toLowerCase ();
1305
+ toAccount = toAccount.toLowerCase ();
1306
+ const accountsById = this.safeValue (this.options, 'accountsByType', {});
1307
+ const fromId = this.safeString (accountsById, fromAccount, fromAccount);
1308
+ const toId = this.safeString (accountsById, toAccount, toAccount);
1309
+ const request = {
1310
+ 'currency': currency['id'],
1311
+ 'amount': parseFloat (amount),
1312
+ 'from': fromId,
1313
+ 'to': toId,
1314
+ };
1315
+ const repsonse = await this.spotPrivatePostPrivateDerivTransfer (this.extend (request, params));
1316
+ //
1317
+ // {
1318
+ // "id": 11,
1319
+ // "method": "private/deriv/transfer",
1320
+ // "code": 0
1321
+ // }
1322
+ //
1323
+ return this.parseTransfer (repsonse, currency);
1324
+ }
1325
+
1326
+ async fetchTransfers (code = undefined, since = undefined, limit = undefined, params = {}) {
1327
+ if (!('direction' in params)) {
1328
+ throw new ArgumentsRequired (this.id + ' fetchTransfers() requires a direction param to be either "IN" or "OUT"');
1329
+ }
1330
+ await this.loadMarkets ();
1331
+ let currency = undefined;
1332
+ const request = {
1333
+ 'direction': 'OUT',
1334
+ };
1335
+ if (code !== undefined) {
1336
+ currency = this.currency (code);
1337
+ request['currency'] = currency['id'];
1338
+ }
1339
+ const response = await this.spotPrivatePostPrivateDerivGetTransferHistory (this.extend (request, params));
1340
+ //
1341
+ // {
1342
+ // id: '1641032709328',
1343
+ // method: 'private/deriv/get-transfer-history',
1344
+ // code: '0',
1345
+ // result: {
1346
+ // transfer_list: [
1347
+ // {
1348
+ // direction: 'IN',
1349
+ // time: '1641025185223',
1350
+ // amount: '109.56',
1351
+ // status: 'COMPLETED',
1352
+ // information: 'From Spot Wallet',
1353
+ // currency: 'USDC'
1354
+ // }
1355
+ // ]
1356
+ // }
1357
+ // }
1358
+ //
1359
+ const result = this.safeValue (response, 'result', {});
1360
+ const transferList = this.safeValue (result, 'transfer_list', []);
1361
+ return this.parseTransfers (transferList, currency, since, limit, params);
1362
+ }
1363
+
1364
+ parseTransferStatus (status) {
1365
+ const statuses = {
1366
+ 'COMPLETED': 'ok',
1367
+ 'PROCESSING': 'pending',
1368
+ };
1369
+ return this.safeString (statuses, status, status);
1370
+ }
1371
+
1372
+ parseTransfer (transfer, currency = undefined) {
1373
+ //
1374
+ // {
1375
+ // direction: 'IN',
1376
+ // time: '1641025185223',
1377
+ // amount: '109.56',
1378
+ // status: 'COMPLETED',
1379
+ // information: 'From Spot Wallet',
1380
+ // currency: 'USDC'
1381
+ // }
1382
+ //
1383
+ const timestamp = this.safeInteger (transfer, 'time');
1384
+ const amount = this.safeNumber (transfer, 'amount');
1385
+ const currencyId = this.safeString (transfer, 'currency');
1386
+ const code = this.safeCurrencyCode (currencyId);
1387
+ const information = this.safeString (transfer, 'information');
1388
+ let fromAccount = undefined;
1389
+ let toAccount = undefined;
1390
+ if (information !== undefined) {
1391
+ const parts = information.split (' ');
1392
+ fromAccount = this.safeStringLower (parts, 1);
1393
+ toAccount = (fromAccount === 'spot') ? 'derivative' : 'spot';
1394
+ }
1395
+ const rawStatus = this.safeString (transfer, 'status');
1396
+ const status = this.parseTransferStatus (rawStatus);
1397
+ return {
1398
+ 'info': transfer,
1399
+ 'id': this.safeString (transfer, 'id'),
1400
+ 'timestamp': timestamp,
1401
+ 'datetime': this.iso8601 (timestamp),
1402
+ 'currency': code,
1403
+ 'amount': amount,
1404
+ 'fromAccount': fromAccount,
1405
+ 'toAccount': toAccount,
1406
+ 'status': status,
1407
+ };
1408
+ }
1409
+
1410
+ parseTicker (ticker, market = undefined) {
1411
+ // {
1412
+ // "i":"CRO_BTC",
1413
+ // "b":0.00000890,
1414
+ // "k":0.00001179,
1415
+ // "a":0.00001042,
1416
+ // "t":1591770793901,
1417
+ // "v":14905879.59,
1418
+ // "h":0.00,
1419
+ // "l":0.00,
1420
+ // "c":0.00
1421
+ // }
1422
+ const timestamp = this.safeInteger (ticker, 't');
1423
+ const marketId = this.safeString (ticker, 'i');
1424
+ market = this.safeMarket (marketId, market, '_');
1425
+ const symbol = market['symbol'];
1426
+ const last = this.safeString (ticker, 'a');
1427
+ const relativeChange = this.safeString (ticker, 'c');
1428
+ return this.safeTicker ({
1429
+ 'symbol': symbol,
1430
+ 'timestamp': timestamp,
1431
+ 'datetime': this.iso8601 (timestamp),
1432
+ 'high': this.safeString (ticker, 'h'),
1433
+ 'low': this.safeString (ticker, 'l'),
1434
+ 'bid': this.safeString (ticker, 'b'),
1435
+ 'bidVolume': undefined,
1436
+ 'ask': this.safeString (ticker, 'k'),
1437
+ 'askVolume': undefined,
1438
+ 'vwap': undefined,
1439
+ 'open': undefined,
1440
+ 'close': last,
1441
+ 'last': last,
1442
+ 'previousClose': undefined,
1443
+ 'change': relativeChange,
1444
+ 'percentage': undefined,
1445
+ 'average': undefined,
1446
+ 'baseVolume': this.safeString (ticker, 'v'),
1447
+ 'quoteVolume': undefined,
1448
+ 'info': ticker,
1449
+ }, market, false);
1450
+ }
1451
+
1452
+ parseTrade (trade, market = undefined) {
1453
+ //
1454
+ // public/get-trades
1455
+ //
1456
+ // {"dataTime":1591710781947,"d":465533583799589409,"s":"BUY","p":2.96,"q":16.0,"t":1591710781946,"i":"ICX_CRO"},
1457
+ //
1458
+ // private/get-trades
1459
+ //
1460
+ // {
1461
+ // "side": "SELL",
1462
+ // "instrument_name": "ETH_CRO",
1463
+ // "fee": 0.014,
1464
+ // "trade_id": "367107655537806900",
1465
+ // "create_time": 1588777459755,
1466
+ // "traded_price": 7,
1467
+ // "traded_quantity": 1,
1468
+ // "fee_currency": "CRO",
1469
+ // "order_id": "367107623521528450"
1470
+ // }
1471
+ const timestamp = this.safeInteger2 (trade, 't', 'create_time');
1472
+ const marketId = this.safeString2 (trade, 'i', 'instrument_name');
1473
+ market = this.safeMarket (marketId, market, '_');
1474
+ const symbol = market['symbol'];
1475
+ const price = this.safeString2 (trade, 'p', 'traded_price');
1476
+ const amount = this.safeString2 (trade, 'q', 'traded_quantity');
1477
+ let side = this.safeString2 (trade, 's', 'side');
1478
+ if (side !== undefined) {
1479
+ side = side.toLowerCase ();
1480
+ }
1481
+ const id = this.safeString2 (trade, 'd', 'trade_id');
1482
+ const takerOrMaker = this.safeStringLower2 (trade, 'liquidity_indicator', 'taker_side');
1483
+ const order = this.safeString (trade, 'order_id');
1484
+ let fee = undefined;
1485
+ let feeCost = this.safeString2 (trade, 'fee', 'fees');
1486
+ if (feeCost !== undefined) {
1487
+ const contract = this.safeValue (market, 'contract', false);
1488
+ if (contract) {
1489
+ feeCost = Precise.stringNeg (feeCost);
1490
+ }
1491
+ let feeCurrency = undefined;
1492
+ if (market['spot']) {
1493
+ feeCurrency = this.safeString (trade, 'fee_currency');
1494
+ } else if (market['linear']) {
1495
+ feeCurrency = market['quote'];
1496
+ }
1497
+ fee = {
1498
+ 'currency': feeCurrency,
1499
+ 'cost': feeCost,
1500
+ };
1501
+ }
1502
+ return this.safeTrade ({
1503
+ 'info': trade,
1504
+ 'id': id,
1505
+ 'timestamp': timestamp,
1506
+ 'datetime': this.iso8601 (timestamp),
1507
+ 'symbol': symbol,
1508
+ 'side': side,
1509
+ 'price': price,
1510
+ 'amount': amount,
1511
+ 'cost': undefined,
1512
+ 'order': order,
1513
+ 'takerOrMaker': takerOrMaker,
1514
+ 'type': undefined,
1515
+ 'fee': fee,
1516
+ }, market);
1517
+ }
1518
+
1519
+ parseOHLCV (ohlcv, market = undefined) {
1520
+ // {"t":1596944700000,"o":11752.38,"h":11754.77,"l":11746.65,"c":11753.64,"v":3.694583}
1521
+ return [
1522
+ this.safeInteger (ohlcv, 't'),
1523
+ this.safeNumber (ohlcv, 'o'),
1524
+ this.safeNumber (ohlcv, 'h'),
1525
+ this.safeNumber (ohlcv, 'l'),
1526
+ this.safeNumber (ohlcv, 'c'),
1527
+ this.safeNumber (ohlcv, 'v'),
1528
+ ];
1529
+ }
1530
+
1531
+ parseOrderStatus (status) {
1532
+ const statuses = {
1533
+ 'ACTIVE': 'open',
1534
+ 'CANCELED': 'canceled',
1535
+ 'FILLED': 'closed',
1536
+ 'REJECTED': 'rejected',
1537
+ 'EXPIRED': 'expired',
1538
+ };
1539
+ return this.safeString (statuses, status, status);
1540
+ }
1541
+
1542
+ parseTimeInForce (timeInForce) {
1543
+ const timeInForces = {
1544
+ 'GOOD_TILL_CANCEL': 'GTC',
1545
+ 'IMMEDIATE_OR_CANCEL': 'IOC',
1546
+ 'FILL_OR_KILL': 'FOK',
1547
+ };
1548
+ return this.safeString (timeInForces, timeInForce, timeInForce);
1549
+ }
1550
+
1551
+ parseOrder (order, market = undefined) {
1552
+ // {
1553
+ // "status": "FILLED",
1554
+ // "side": "BUY",
1555
+ // "order_id": "371302913889488619",
1556
+ // "client_oid": "9_yMYJDNEeqHxLqtD_2j3g",
1557
+ // "create_time": 1588902489144,
1558
+ // "update_time": 1588902493024,
1559
+ // "type": "LIMIT",
1560
+ // "instrument_name": "ETH_CRO",
1561
+ // "cumulative_quantity": 7,
1562
+ // "cumulative_value": 7,
1563
+ // "avg_price": 7,
1564
+ // "fee_currency": "CRO",
1565
+ // "time_in_force": "GOOD_TILL_CANCEL",
1566
+ // "exec_inst": "POST_ONLY"
1567
+ // }
1568
+ //
1569
+ // {
1570
+ // id: 1641026373106,
1571
+ // method: 'private/get-order-history',
1572
+ // code: 0,
1573
+ // result: {
1574
+ // data: [
1575
+ // {
1576
+ // account_id: '85ff689a-7508-4b96-aa79-dc0545d6e637',
1577
+ // order_id: 13191401932,
1578
+ // client_oid: '1641025941461',
1579
+ // order_type: 'LIMIT',
1580
+ // time_in_force: 'GOOD_TILL_CANCEL',
1581
+ // side: 'BUY',
1582
+ // exec_inst: [],
1583
+ // quantity: '0.0001',
1584
+ // limit_price: '48000.0',
1585
+ // order_value: '4.80000000',
1586
+ // maker_fee_rate: '0.00050',
1587
+ // taker_fee_rate: '0.00070',
1588
+ // avg_price: '47253.5',
1589
+ // trigger_price: '0.0',
1590
+ // ref_price_type: 'NULL_VAL',
1591
+ // cumulative_quantity: '0.0001',
1592
+ // cumulative_value: '4.72535000',
1593
+ // cumulative_fee: '0.00330775',
1594
+ // status: 'FILLED',
1595
+ // update_user_id: 'ce075bef-b600-4277-bd6e-ff9007251e63',
1596
+ // order_date: '2022-01-01',
1597
+ // instrument_name: 'BTCUSD-PERP',
1598
+ // fee_instrument_name: 'USD_Stable_Coin',
1599
+ // create_time: 1641025941827,
1600
+ // create_time_ns: '1641025941827994756',
1601
+ // update_time: 1641025941827
1602
+ // }
1603
+ // ]
1604
+ // }
1605
+ // }
1606
+ //
1607
+ const created = this.safeInteger (order, 'create_time');
1608
+ const updated = this.safeInteger (order, 'update_time');
1609
+ const marketId = this.safeString (order, 'instrument_name');
1610
+ const symbol = this.safeSymbol (marketId, market);
1611
+ const amount = this.safeString (order, 'quantity');
1612
+ const filled = this.safeString (order, 'cumulative_quantity');
1613
+ const status = this.parseOrderStatus (this.safeString (order, 'status'));
1614
+ const id = this.safeString (order, 'order_id');
1615
+ let clientOrderId = this.safeString (order, 'client_oid');
1616
+ if (clientOrderId === '') {
1617
+ clientOrderId = undefined;
1618
+ }
1619
+ const price = this.safeString2 (order, 'price', 'limit_price');
1620
+ const average = this.safeString (order, 'avg_price');
1621
+ const type = this.safeStringLower2 (order, 'type', 'order_type');
1622
+ const side = this.safeStringLower (order, 'side');
1623
+ const timeInForce = this.parseTimeInForce (this.safeString (order, 'time_in_force'));
1624
+ const execInst = this.safeString (order, 'exec_inst');
1625
+ let postOnly = undefined;
1626
+ if (execInst !== undefined) {
1627
+ postOnly = (execInst === 'POST_ONLY');
1628
+ }
1629
+ const cost = this.safeString (order, 'cumulative_value');
1630
+ const feeCost = this.safeString (order, 'cumulative_fee');
1631
+ let fee = undefined;
1632
+ if (feeCost !== undefined) {
1633
+ const feeCurrency = this.safeString (order, 'fee_instrument_name');
1634
+ fee = {
1635
+ 'cost': feeCost,
1636
+ 'currency': this.safeCurrencyCode (feeCurrency),
1637
+ };
1638
+ }
1639
+ return this.safeOrder ({
1640
+ 'info': order,
1641
+ 'id': id,
1642
+ 'clientOrderId': clientOrderId,
1643
+ 'timestamp': created,
1644
+ 'datetime': this.iso8601 (created),
1645
+ 'lastTradeTimestamp': updated,
1646
+ 'status': status,
1647
+ 'symbol': symbol,
1648
+ 'type': type,
1649
+ 'timeInForce': timeInForce,
1650
+ 'postOnly': postOnly,
1651
+ 'side': side,
1652
+ 'price': price,
1653
+ 'amount': amount,
1654
+ 'filled': filled,
1655
+ 'remaining': undefined,
1656
+ 'cost': cost,
1657
+ 'fee': fee,
1658
+ 'average': average,
1659
+ 'trades': [],
1660
+ }, market);
1661
+ }
1662
+
1663
+ parseDepositStatus (status) {
1664
+ const statuses = {
1665
+ '0': 'pending',
1666
+ '1': 'ok',
1667
+ '2': 'failed',
1668
+ '3': 'pending',
1669
+ };
1670
+ return this.safeString (statuses, status, status);
1671
+ }
1672
+
1673
+ parseWithdrawalStatus (status) {
1674
+ const statuses = {
1675
+ '0': 'pending',
1676
+ '1': 'pending',
1677
+ '2': 'failed',
1678
+ '3': 'pending',
1679
+ '4': 'failed',
1680
+ '5': 'ok',
1681
+ '6': 'canceled',
1682
+ };
1683
+ return this.safeString (statuses, status, status);
1684
+ }
1685
+
1686
+ parseTransaction (transaction, currency = undefined) {
1687
+ //
1688
+ // fetchDeposits
1689
+ //
1690
+ // {
1691
+ // "currency": "XRP",
1692
+ // "fee": 1.0,
1693
+ // "create_time": 1607063412000,
1694
+ // "id": "2220",
1695
+ // "update_time": 1607063460000,
1696
+ // "amount": 100,
1697
+ // "address": "2NBqqD5GRJ8wHy1PYyCXTe9ke5226FhavBf?1234567890",
1698
+ // "status": "1"
1699
+ // }
1700
+ //
1701
+ // fetchWithdrawals
1702
+ //
1703
+ // {
1704
+ // "currency": "XRP",
1705
+ // "client_wid": "my_withdrawal_002",
1706
+ // "fee": 1.0,
1707
+ // "create_time": 1607063412000,
1708
+ // "id": "2220",
1709
+ // "update_time": 1607063460000,
1710
+ // "amount": 100,
1711
+ // "address": "2NBqqD5GRJ8wHy1PYyCXTe9ke5226FhavBf?1234567890",
1712
+ // "status": "1"
1713
+ // }
1714
+ //
1715
+ // withdraw
1716
+ //
1717
+ // {
1718
+ // "id": 2220,
1719
+ // "amount": 1,
1720
+ // "fee": 0.0004,
1721
+ // "symbol": "BTC",
1722
+ // "address": "2NBqqD5GRJ8wHy1PYyCXTe9ke5226FhavBf",
1723
+ // "client_wid": "my_withdrawal_002",
1724
+ // "create_time":1607063412000
1725
+ // }
1726
+ //
1727
+ let type = undefined;
1728
+ const rawStatus = this.safeString (transaction, 'status');
1729
+ let status = undefined;
1730
+ if ('client_wid' in transaction) {
1731
+ type = 'withdrawal';
1732
+ status = this.parseWithdrawalStatus (rawStatus);
1733
+ } else {
1734
+ type = 'deposit';
1735
+ status = this.parseDepositStatus (rawStatus);
1736
+ }
1737
+ const id = this.safeString (transaction, 'id');
1738
+ const addressString = this.safeString (transaction, 'address');
1739
+ const [ address, tag ] = this.parseAddress (addressString);
1740
+ const currencyId = this.safeString (transaction, 'currency');
1741
+ const code = this.safeCurrencyCode (currencyId, currency);
1742
+ const timestamp = this.safeInteger (transaction, 'create_time');
1743
+ const amount = this.safeNumber (transaction, 'amount');
1744
+ const txId = this.safeString (transaction, 'txid');
1745
+ const feeCost = this.safeNumber (transaction, 'fee');
1746
+ let fee = undefined;
1747
+ if (feeCost !== undefined) {
1748
+ fee = { 'currency': code, 'cost': feeCost };
1749
+ }
1750
+ const updated = this.safeInteger (transaction, 'update_time');
1751
+ return {
1752
+ 'info': transaction,
1753
+ 'id': id,
1754
+ 'txid': txId,
1755
+ 'timestamp': timestamp,
1756
+ 'datetime': this.iso8601 (timestamp),
1757
+ 'network': undefined,
1758
+ 'address': address,
1759
+ 'addressTo': address,
1760
+ 'addressFrom': undefined,
1761
+ 'tag': tag,
1762
+ 'tagTo': tag,
1763
+ 'tagFrom': undefined,
1764
+ 'type': type,
1765
+ 'amount': amount,
1766
+ 'currency': code,
1767
+ 'status': status,
1768
+ 'updated': updated,
1769
+ 'internal': undefined,
1770
+ 'fee': fee,
1771
+ };
1772
+ }
1773
+
1774
+ nonce () {
1775
+ return this.milliseconds ();
1776
+ }
1777
+
1778
+ sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
1779
+ const [ type, access ] = api;
1780
+ let url = this.urls['api'][type] + '/' + path;
1781
+ const query = this.omit (params, this.extractParams (path));
1782
+ if (access === 'public') {
1783
+ if (Object.keys (query).length) {
1784
+ url += '?' + this.urlencode (query);
1785
+ }
1786
+ } else {
1787
+ this.checkRequiredCredentials ();
1788
+ const nonce = this.nonce ().toString ();
1789
+ const requestParams = this.extend ({}, params);
1790
+ const keysorted = this.keysort (requestParams);
1791
+ const paramsKeys = Object.keys (keysorted);
1792
+ let strSortKey = '';
1793
+ for (let i = 0; i < paramsKeys.length; i++) {
1794
+ strSortKey = strSortKey + paramsKeys[i].toString () + requestParams[paramsKeys[i]].toString ();
1795
+ }
1796
+ const payload = path + nonce + this.apiKey + strSortKey + nonce;
1797
+ const signature = this.hmac (this.encode (payload), this.encode (this.secret));
1798
+ const paramsKeysLength = paramsKeys.length;
1799
+ body = this.json ({
1800
+ 'id': nonce,
1801
+ 'method': path,
1802
+ 'params': params,
1803
+ 'api_key': this.apiKey,
1804
+ 'sig': signature,
1805
+ 'nonce': nonce,
1806
+ });
1807
+ // fix issue https://github.com/ccxt/ccxt/issues/11179
1808
+ // php always encodes dictionaries as arrays
1809
+ // if an array is empty, php will put it in square brackets
1810
+ // python and js will put it in curly brackets
1811
+ // the code below checks and replaces those brackets in empty requests
1812
+ if (paramsKeysLength === 0) {
1813
+ const paramsString = '{}';
1814
+ const arrayString = '[]';
1815
+ body = body.replace (arrayString, paramsString);
1816
+ }
1817
+ headers = {
1818
+ 'Content-Type': 'application/json',
1819
+ };
1820
+ }
1821
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
1822
+ }
1823
+
1824
+ handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
1825
+ const errorCode = this.safeString (response, 'code');
1826
+ if (errorCode !== '0') {
1827
+ const feedback = this.id + ' ' + body;
1828
+ this.throwExactlyMatchedException (this.exceptions['exact'], errorCode, feedback);
1829
+ throw new ExchangeError (this.id + ' ' + body);
1830
+ }
1831
+ }
1832
+ };