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,969 @@
1
+ 'use strict';
2
+
3
+ // ---------------------------------------------------------------------------
4
+ const Exchange = require ('./base/Exchange');
5
+ const { ExchangeError, AuthenticationError, OrderNotFound, InsufficientFunds, ArgumentsRequired } = require ('./base/errors');
6
+ const { TICK_SIZE } = require ('./base/functions/number');
7
+ const Precise = require ('./base/Precise');
8
+
9
+ // ---------------------------------------------------------------------------
10
+
11
+ module.exports = class blockchaincom extends Exchange {
12
+ describe () {
13
+ return this.deepExtend (super.describe (), {
14
+ 'id': 'blockchaincom',
15
+ 'secret': undefined,
16
+ 'name': 'Blockchain.com',
17
+ 'countries': [ 'LX' ],
18
+ 'rateLimit': 500, // prev 1000
19
+ 'version': 'v3',
20
+ 'has': {
21
+ 'CORS': false,
22
+ 'spot': true,
23
+ 'margin': undefined, // on exchange but not implemented in CCXT
24
+ 'swap': false,
25
+ 'future': false,
26
+ 'option': false,
27
+ 'cancelOrder': true,
28
+ 'cancelOrders': true,
29
+ 'createOrder': true,
30
+ 'createStopLimitOrder': true,
31
+ 'createStopMarketOrder': true,
32
+ 'createStopOrder': true,
33
+ 'fetchBalance': true,
34
+ 'fetchCanceledOrders': true,
35
+ 'fetchClosedOrders': true,
36
+ 'fetchDeposit': true,
37
+ 'fetchDepositAddress': true,
38
+ 'fetchDeposits': true,
39
+ 'fetchFundingHistory': false,
40
+ 'fetchFundingRate': false,
41
+ 'fetchFundingRateHistory': false,
42
+ 'fetchFundingRates': false,
43
+ 'fetchIndexOHLCV': false,
44
+ 'fetchL2OrderBook': true,
45
+ 'fetchL3OrderBook': true,
46
+ 'fetchLedger': false,
47
+ 'fetchMarkets': true,
48
+ 'fetchMarkOHLCV': false,
49
+ 'fetchMyTrades': true,
50
+ 'fetchOHLCV': false,
51
+ 'fetchOpenOrders': true,
52
+ 'fetchOrder': true,
53
+ 'fetchOrderBook': true,
54
+ 'fetchPremiumIndexOHLCV': false,
55
+ 'fetchTicker': true,
56
+ 'fetchTickers': true,
57
+ 'fetchTrades': false,
58
+ 'fetchTradingFee': false,
59
+ 'fetchTradingFees': true,
60
+ 'fetchTransfer': false,
61
+ 'fetchTransfers': false,
62
+ 'fetchWithdrawal': true,
63
+ 'fetchWithdrawals': true,
64
+ 'fetchWithdrawalWhitelist': true, // fetches exchange specific benficiary-ids needed for withdrawals
65
+ 'transfer': false,
66
+ 'withdraw': true,
67
+ },
68
+ 'timeframes': undefined,
69
+ 'urls': {
70
+ 'logo': 'https://user-images.githubusercontent.com/1294454/147515585-1296e91b-7398-45e5-9d32-f6121538533f.jpeg',
71
+ 'test': {
72
+ 'public': 'https://testnet-api.delta.exchange',
73
+ 'private': 'https://testnet-api.delta.exchange',
74
+ },
75
+ 'api': {
76
+ 'public': 'https://api.blockchain.com/v3/exchange',
77
+ 'private': 'https://api.blockchain.com/v3/exchange',
78
+ },
79
+ 'www': 'https://blockchain.com',
80
+ 'doc': [
81
+ 'https://api.blockchain.com/v3',
82
+ ],
83
+ 'fees': 'https://exchange.blockchain.com/fees',
84
+ },
85
+ 'api': {
86
+ 'public': {
87
+ 'get': {
88
+ 'tickers': 1, // fetchTickers
89
+ 'tickers/{symbol}': 1, // fetchTicker
90
+ 'symbols': 1, // fetchMarkets
91
+ 'symbols/{symbol}': 1, // fetchMarket
92
+ 'l2/{symbol}': 1, // fetchL2OrderBook
93
+ 'l3/{symbol}': 1, // fetchL3OrderBook
94
+ },
95
+ },
96
+ 'private': {
97
+ 'get': {
98
+ 'fees': 1, // fetchFees
99
+ 'orders': 1, // fetchOpenOrders, fetchClosedOrders
100
+ 'orders/{orderId}': 1, // fetchOrder(id)
101
+ 'trades': 1,
102
+ 'fills': 1, // fetchMyTrades
103
+ 'deposits': 1, // fetchDeposits
104
+ 'deposits/{depositId}': 1, // fetchDeposit
105
+ 'accounts': 1, // fetchBalance
106
+ 'accounts/{account}/{currency}': 1,
107
+ 'whitelist': 1, // fetchWithdrawalWhitelist
108
+ 'whitelist/{currency}': 1, // fetchWithdrawalWhitelistByCurrency
109
+ 'withdrawals': 1, // fetchWithdrawalWhitelist
110
+ 'withdrawals/{withdrawalId}': 1, // fetchWithdrawalById
111
+ },
112
+ 'post': {
113
+ 'orders': 1, // createOrder
114
+ 'deposits/{currency}': 1, // fetchDepositAddress by currency (only crypto supported)
115
+ 'withdrawals': 1, // withdraw
116
+ },
117
+ 'delete': {
118
+ 'orders': 1, // cancelOrders
119
+ 'orders/{orderId}': 1, // cancelOrder
120
+ },
121
+ },
122
+ },
123
+ 'fees': {
124
+ 'trading': {
125
+ 'feeSide': 'get',
126
+ 'tierBased': true,
127
+ 'percentage': true,
128
+ 'tiers': {
129
+ 'taker': [
130
+ [ this.parseNumber ('0'), this.parseNumber ('0.004') ],
131
+ [ this.parseNumber ('10000'), this.parseNumber ('0.0022') ],
132
+ [ this.parseNumber ('50000'), this.parseNumber ('0.002') ],
133
+ [ this.parseNumber ('100000'), this.parseNumber ('0.0018') ],
134
+ [ this.parseNumber ('500000'), this.parseNumber ('0.0018') ],
135
+ [ this.parseNumber ('1000000'), this.parseNumber ('0.0018') ],
136
+ [ this.parseNumber ('2500000'), this.parseNumber ('0.0018') ],
137
+ [ this.parseNumber ('5000000'), this.parseNumber ('0.0016') ],
138
+ [ this.parseNumber ('25000000'), this.parseNumber ('0.0014') ],
139
+ [ this.parseNumber ('100000000'), this.parseNumber ('0.0011') ],
140
+ [ this.parseNumber ('500000000'), this.parseNumber ('0.0008') ],
141
+ [ this.parseNumber ('1000000000'), this.parseNumber ('0.0006') ],
142
+ ],
143
+ 'maker': [
144
+ [ this.parseNumber ('0'), this.parseNumber ('0.002') ],
145
+ [ this.parseNumber ('10000'), this.parseNumber ('0.0012') ],
146
+ [ this.parseNumber ('50000'), this.parseNumber ('0.001') ],
147
+ [ this.parseNumber ('100000'), this.parseNumber ('0.0008') ],
148
+ [ this.parseNumber ('500000'), this.parseNumber ('0.0007000000000000001') ],
149
+ [ this.parseNumber ('1000000'), this.parseNumber ('0.0006') ],
150
+ [ this.parseNumber ('2500000'), this.parseNumber ('0.0005') ],
151
+ [ this.parseNumber ('5000000'), this.parseNumber ('0.0004') ],
152
+ [ this.parseNumber ('25000000'), this.parseNumber ('0.0003') ],
153
+ [ this.parseNumber ('100000000'), this.parseNumber ('0.0002') ],
154
+ [ this.parseNumber ('500000000'), this.parseNumber ('0.0001') ],
155
+ [ this.parseNumber ('1000000000'), this.parseNumber ('0') ],
156
+ ],
157
+ },
158
+ },
159
+ },
160
+ 'requiredCredentials': {
161
+ 'apiKey': false,
162
+ 'secret': true,
163
+ },
164
+ 'precisionMode': TICK_SIZE,
165
+ 'exceptions': {
166
+ 'exact': {
167
+ '401': AuthenticationError,
168
+ '404': OrderNotFound,
169
+ },
170
+ 'broad': {},
171
+ },
172
+ });
173
+ }
174
+
175
+ async fetchMarkets (params = {}) {
176
+ //
177
+ // "USDC-GBP": {
178
+ // "base_currency": "USDC",
179
+ // "base_currency_scale": 6,
180
+ // "counter_currency": "GBP",
181
+ // "counter_currency_scale": 2,
182
+ // "min_price_increment": 10000,
183
+ // "min_price_increment_scale": 8,
184
+ // "min_order_size": 500000000,
185
+ // "min_order_size_scale": 8,
186
+ // "max_order_size": 0,
187
+ // "max_order_size_scale": 8,
188
+ // "lot_size": 10000,
189
+ // "lot_size_scale": 8,
190
+ // "status": "open",
191
+ // "id": 68,
192
+ // "auction_price": 0,
193
+ // "auction_size": 0,
194
+ // "auction_time": "",
195
+ // "imbalance": 0
196
+ // }
197
+ //
198
+ const markets = await this.publicGetSymbols (params);
199
+ const marketIds = Object.keys (markets);
200
+ const result = [];
201
+ for (let i = 0; i < marketIds.length; i++) {
202
+ const marketId = marketIds[i];
203
+ const market = this.safeValue (markets, marketId);
204
+ const baseId = this.safeString (market, 'base_currency');
205
+ const quoteId = this.safeString (market, 'counter_currency');
206
+ const base = this.safeCurrencyCode (baseId);
207
+ const quote = this.safeCurrencyCode (quoteId);
208
+ const numericId = this.safeNumber (market, 'id');
209
+ let active = undefined;
210
+ const marketState = this.safeString (market, 'status');
211
+ if (marketState === 'open') {
212
+ active = 'true';
213
+ } else {
214
+ active = 'false';
215
+ }
216
+ // price precision
217
+ const minPriceIncrementString = this.safeString (market, 'min_price_increment');
218
+ const minPriceIncrementScaleString = this.safeString (market, 'min_price_increment_scale');
219
+ const minPriceScalePrecisionString = this.parsePrecision (minPriceIncrementScaleString);
220
+ const pricePrecisionString = Precise.stringMul (minPriceIncrementString, minPriceScalePrecisionString);
221
+ const pricePrecision = this.parseNumber (pricePrecisionString);
222
+ // amount precision
223
+ const lotSizeString = this.safeString (market, 'lot_size');
224
+ const lotSizeScaleString = this.safeString (market, 'lot_size_scale');
225
+ const lotSizeScalePrecisionString = this.parsePrecision (lotSizeScaleString);
226
+ const amountPrecisionString = Precise.stringMul (lotSizeString, lotSizeScalePrecisionString);
227
+ const amountPrecision = this.parseNumber (amountPrecisionString);
228
+ // minimum order size
229
+ const minOrderSizeString = this.safeString (market, 'min_order_size');
230
+ const minOrderSizeScaleString = this.safeString (market, 'min_order_size_scale');
231
+ const minOrderSizeScalePrecisionString = this.parsePrecision (minOrderSizeScaleString);
232
+ const minOrderSizePreciseString = Precise.stringMul (minOrderSizeString, minOrderSizeScalePrecisionString);
233
+ const minOrderSize = this.parseNumber (minOrderSizePreciseString);
234
+ // maximum order size
235
+ let maxOrderSize = undefined;
236
+ maxOrderSize = this.safeString (market, 'max_order_size');
237
+ if (maxOrderSize !== '0') {
238
+ const maxOrderSizeScaleString = this.safeString (market, 'max_order_size_scale');
239
+ const maxOrderSizeScalePrecisionString = this.parsePrecision (maxOrderSizeScaleString);
240
+ const maxOrderSizeString = Precise.stringMul (maxOrderSize, maxOrderSizeScalePrecisionString);
241
+ maxOrderSize = this.parseNumber (maxOrderSizeString);
242
+ } else {
243
+ maxOrderSize = undefined;
244
+ }
245
+ result.push ({
246
+ 'info': market,
247
+ 'id': marketId,
248
+ 'numericId': numericId,
249
+ 'symbol': base + '/' + quote,
250
+ 'base': base,
251
+ 'quote': quote,
252
+ 'settle': undefined,
253
+ 'baseId': baseId,
254
+ 'quoteId': quoteId,
255
+ 'settleId': undefined,
256
+ 'type': 'spot',
257
+ 'spot': true,
258
+ 'margin': false,
259
+ 'swap': false,
260
+ 'future': false,
261
+ 'option': false,
262
+ 'active': active,
263
+ 'contract': false,
264
+ 'linear': undefined,
265
+ 'inverse': undefined,
266
+ 'contractSize': undefined,
267
+ 'expiry': undefined,
268
+ 'expiryDatetime': undefined,
269
+ 'strike': undefined,
270
+ 'optionType': undefined,
271
+ 'precision': {
272
+ 'amount': amountPrecision,
273
+ 'price': pricePrecision,
274
+ },
275
+ 'limits': {
276
+ 'leverage': {
277
+ 'min': undefined,
278
+ 'max': undefined,
279
+ },
280
+ 'amount': {
281
+ 'min': minOrderSize,
282
+ 'max': maxOrderSize,
283
+ },
284
+ 'price': {
285
+ 'min': undefined,
286
+ 'max': undefined,
287
+ },
288
+ 'cost': {
289
+ 'min': undefined,
290
+ 'max': undefined,
291
+ },
292
+ },
293
+ });
294
+ }
295
+ return result;
296
+ }
297
+
298
+ async fetchOrderBook (symbol, limit = undefined, params = {}) {
299
+ return await this.fetchL3OrderBook (symbol, limit, params);
300
+ }
301
+
302
+ async fetchL3OrderBook (symbol, limit = undefined, params = {}) {
303
+ await this.loadMarkets ();
304
+ const request = {
305
+ 'symbol': this.marketId (symbol),
306
+ };
307
+ if (limit !== undefined) {
308
+ request['depth'] = limit;
309
+ }
310
+ const response = await this.publicGetL3Symbol (this.extend (request, params));
311
+ return this.parseOrderBook (response, symbol, undefined, 'bids', 'asks', 'px', 'qty');
312
+ }
313
+
314
+ async fetchL2OrderBook (symbol, limit = undefined, params = {}) {
315
+ await this.loadMarkets ();
316
+ const request = {
317
+ 'symbol': this.marketId (symbol),
318
+ };
319
+ if (limit !== undefined) {
320
+ request['depth'] = limit;
321
+ }
322
+ const response = await this.publicGetL2Symbol (this.extend (request, params));
323
+ return this.parseOrderBook (response, symbol, undefined, 'bids', 'asks', 'px', 'qty');
324
+ }
325
+
326
+ parseTicker (ticker, market = undefined) {
327
+ //
328
+ // {
329
+ // "symbol": "BTC-USD",
330
+ // "price_24h": 47791.86,
331
+ // "volume_24h": 362.88635738,
332
+ // "last_trade_price": 47587.75
333
+ // }
334
+ //
335
+ const marketId = this.safeString (ticker, 'symbol');
336
+ const symbol = this.safeSymbol (marketId, market, '-');
337
+ const last = this.safeString (ticker, 'last_trade_price');
338
+ const baseVolume = this.safeString (ticker, 'volume_24h');
339
+ const open = this.safeString (ticker, 'price_24h');
340
+ return this.safeTicker ({
341
+ 'symbol': symbol,
342
+ 'timestamp': undefined,
343
+ 'datetime': undefined,
344
+ 'high': undefined,
345
+ 'low': undefined,
346
+ 'bid': undefined,
347
+ 'bidVolume': undefined,
348
+ 'ask': undefined,
349
+ 'askVolume': undefined,
350
+ 'vwap': undefined,
351
+ 'open': open,
352
+ 'close': undefined,
353
+ 'last': last,
354
+ 'previousClose': undefined,
355
+ 'change': undefined,
356
+ 'percentage': undefined,
357
+ 'average': undefined,
358
+ 'baseVolume': baseVolume,
359
+ 'quoteVolume': undefined,
360
+ 'info': ticker,
361
+ }, market, false);
362
+ }
363
+
364
+ async fetchTicker (symbol, params = {}) {
365
+ await this.loadMarkets ();
366
+ const market = this.market (symbol);
367
+ const request = {
368
+ 'symbol': market['id'],
369
+ };
370
+ const response = await this.publicGetTickersSymbol (this.extend (request, params));
371
+ return this.parseTicker (response, market);
372
+ }
373
+
374
+ async fetchTickers (symbols = undefined, params = {}) {
375
+ await this.loadMarkets ();
376
+ const tickers = await this.publicGetTickers (params);
377
+ return this.parseTickers (tickers, symbols);
378
+ }
379
+
380
+ parseOrderState (state) {
381
+ const states = {
382
+ 'OPEN': 'open',
383
+ 'REJECTED': 'rejected',
384
+ 'FILLED': 'closed',
385
+ 'CANCELED': 'canceled',
386
+ 'PART_FILLED': 'open',
387
+ 'EXPIRED': 'expired',
388
+ };
389
+ return this.safeString (states, state, state);
390
+ }
391
+
392
+ parseOrder (order, market = undefined) {
393
+ //
394
+ // {
395
+ // clOrdId: '00001',
396
+ // ordType: 'MARKET',
397
+ // ordStatus: 'FILLED',
398
+ // side: 'BUY',
399
+ // symbol: 'USDC-USDT',
400
+ // exOrdId: '281775861306290',
401
+ // price: null,
402
+ // text: 'Fill',
403
+ // lastShares: '30.0',
404
+ // lastPx: '0.9999',
405
+ // leavesQty: '0.0',
406
+ // cumQty: '30.0',
407
+ // avgPx: '0.9999',
408
+ // timestamp: '1633940339619'
409
+ // }
410
+ //
411
+ const clientOrderId = this.safeString (order, 'clOrdId');
412
+ const type = this.safeStringLower (order, 'ordType');
413
+ const statusId = this.safeString (order, 'ordStatus');
414
+ const state = this.parseOrderState (statusId);
415
+ const side = this.safeStringLower (order, 'side');
416
+ const marketId = this.safeString (order, 'symbol');
417
+ const symbol = this.safeSymbol (marketId, market, '-');
418
+ const exchangeOrderId = this.safeString (order, 'exOrdId');
419
+ const price = (type !== 'market') ? this.safeString (order, 'price') : undefined;
420
+ const average = this.safeNumber (order, 'avgPx');
421
+ const timestamp = this.safeInteger (order, 'timestamp');
422
+ const datetime = this.iso8601 (timestamp);
423
+ const filled = this.safeString (order, 'cumQty');
424
+ const remaining = this.safeString (order, 'leavesQty');
425
+ const result = this.safeOrder ({
426
+ 'id': exchangeOrderId,
427
+ 'clientOrderId': clientOrderId,
428
+ 'datetime': datetime,
429
+ 'timestamp': timestamp,
430
+ 'lastTradeTimestamp': undefined,
431
+ 'status': state,
432
+ 'symbol': symbol,
433
+ 'type': type,
434
+ 'timeInForce': undefined,
435
+ 'side': side,
436
+ 'price': price,
437
+ 'average': average,
438
+ 'amount': undefined,
439
+ 'filled': filled,
440
+ 'remaining': remaining,
441
+ 'cost': undefined,
442
+ 'trades': [],
443
+ 'fees': {},
444
+ 'info': order,
445
+ });
446
+ return result;
447
+ }
448
+
449
+ async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
450
+ await this.loadMarkets ();
451
+ const market = this.market (symbol);
452
+ const orderType = this.safeString (params, 'ordType', type);
453
+ const uppercaseOrderType = orderType.toUpperCase ();
454
+ const clientOrderId = this.safeString2 (params, 'clientOrderId', 'clOrdId', this.uuid16 ());
455
+ params = this.omit (params, [ 'ordType', 'clientOrderId', 'clOrdId' ]);
456
+ const request = {
457
+ // 'stopPx' : limit price
458
+ // 'timeInForce' : "GTC" for Good Till Cancel, "IOC" for Immediate or Cancel, "FOK" for Fill or Kill, "GTD" Good Till Date
459
+ // 'expireDate' : expiry date in the format YYYYMMDD
460
+ // 'minQty' : The minimum quantity required for an IOC fill
461
+ 'ordType': uppercaseOrderType,
462
+ 'symbol': market['id'],
463
+ 'side': side.toUpperCase (),
464
+ 'orderQty': this.amountToPrecision (symbol, amount),
465
+ 'clOrdId': clientOrderId,
466
+ };
467
+ const stopPrice = this.safeValue2 (params, 'stopPx', 'stopPrice');
468
+ params = this.omit (params, [ 'stopPx', 'stopPrice' ]);
469
+ if (uppercaseOrderType === 'STOP' || uppercaseOrderType === 'STOPLIMIT') {
470
+ if (stopPrice === undefined) {
471
+ throw new ArgumentsRequired (this.id + ' createOrder() requires a stopPx or stopPrice param for a ' + uppercaseOrderType + ' order');
472
+ }
473
+ }
474
+ if (stopPrice !== undefined) {
475
+ if (uppercaseOrderType === 'MARKET') {
476
+ request['ordType'] = 'STOP';
477
+ } else if (uppercaseOrderType === 'LIMIT') {
478
+ request['ordType'] = 'STOPLIMIT';
479
+ }
480
+ }
481
+ let priceRequired = false;
482
+ let stopPriceRequired = false;
483
+ if (request['ordType'] === 'LIMIT' || request['ordType'] === 'STOPLIMIT') {
484
+ priceRequired = true;
485
+ }
486
+ if (request['ordType'] === 'STOP' || request['ordType'] === 'STOPLIMIT') {
487
+ stopPriceRequired = true;
488
+ }
489
+ if (priceRequired) {
490
+ request['price'] = this.priceToPrecision (symbol, price);
491
+ }
492
+ if (stopPriceRequired) {
493
+ request['stopPx'] = this.priceToPrecision (symbol, stopPrice);
494
+ }
495
+ const response = await this.privatePostOrders (this.extend (request, params));
496
+ return this.parseOrder (response, market);
497
+ }
498
+
499
+ async cancelOrder (id, symbol = undefined, params = {}) {
500
+ const request = {
501
+ 'orderId': id,
502
+ };
503
+ const response = await this.privateDeleteOrdersOrderId (this.extend (request, params));
504
+ return {
505
+ 'id': id,
506
+ 'info': response,
507
+ };
508
+ }
509
+
510
+ async cancelOrders (ids, symbol = undefined, params = {}) {
511
+ // cancels all open orders if no symbol specified
512
+ // cancels all open orders of specified symbol, if symbol is specified
513
+ await this.loadMarkets ();
514
+ const request = {
515
+ // 'symbol': marketId,
516
+ };
517
+ if (symbol !== undefined) {
518
+ const marketId = this.marketId (symbol);
519
+ request['symbol'] = marketId;
520
+ }
521
+ const response = await this.privateDeleteOrders (this.extend (request, params));
522
+ return {
523
+ 'symbol': symbol,
524
+ 'info': response,
525
+ };
526
+ }
527
+
528
+ async fetchTradingFees (params = {}) {
529
+ await this.loadMarkets ();
530
+ const response = await this.privateGetFees (params);
531
+ //
532
+ // {
533
+ // makerRate: "0.002",
534
+ // takerRate: "0.004",
535
+ // volumeInUSD: "0.0"
536
+ // }
537
+ //
538
+ const makerFee = this.safeNumber (response, 'makerRate');
539
+ const takerFee = this.safeNumber (response, 'takerRate');
540
+ const result = {};
541
+ for (let i = 0; i < this.symbols.length; i++) {
542
+ const symbol = this.symbols[i];
543
+ result[symbol] = {
544
+ 'info': response,
545
+ 'symbol': symbol,
546
+ 'maker': makerFee,
547
+ 'taker': takerFee,
548
+ };
549
+ }
550
+ return result;
551
+ }
552
+
553
+ async fetchCanceledOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
554
+ const state = 'CANCELED';
555
+ return await this.fetchOrdersByState (state, symbol, since, limit, params);
556
+ }
557
+
558
+ async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
559
+ const state = 'FILLED';
560
+ return await this.fetchOrdersByState (state, symbol, since, limit, params);
561
+ }
562
+
563
+ async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
564
+ const state = 'OPEN';
565
+ return await this.fetchOrdersByState (state, symbol, since, limit, params);
566
+ }
567
+
568
+ async fetchOrdersByState (state, symbol = undefined, since = undefined, limit = undefined, params = {}) {
569
+ await this.loadMarkets ();
570
+ const request = {
571
+ // 'to': unix epoch ms
572
+ // 'from': unix epoch ms
573
+ 'status': state,
574
+ 'limit': 100,
575
+ };
576
+ let market = undefined;
577
+ if (symbol !== undefined) {
578
+ market = this.market (symbol);
579
+ request['symbol'] = market['id'];
580
+ }
581
+ const response = await this.privateGetOrders (this.extend (request, params));
582
+ return this.parseOrders (response, market, since, limit);
583
+ }
584
+
585
+ parseTrade (trade, market = undefined) {
586
+ //
587
+ // {
588
+ // "exOrdId":281685751028507,
589
+ // "tradeId":281685434947633,
590
+ // "execId":8847494003,
591
+ // "side":"BUY",
592
+ // "symbol":"AAVE-USDT",
593
+ // "price":405.34,
594
+ // "qty":0.1,
595
+ // "fee":0.162136,
596
+ // "timestamp":1634559249687
597
+ // }
598
+ //
599
+ const orderId = this.safeString (trade, 'exOrdId');
600
+ const tradeId = this.safeString (trade, 'tradeId');
601
+ const side = this.safeString (trade, 'side').toLowerCase ();
602
+ const marketId = this.safeString (trade, 'symbol');
603
+ const priceString = this.safeString (trade, 'price');
604
+ const amountString = this.safeString (trade, 'qty');
605
+ const timestamp = this.safeInteger (trade, 'timestamp');
606
+ const datetime = this.iso8601 (timestamp);
607
+ market = this.safeMarket (marketId, market, '-');
608
+ const symbol = market['symbol'];
609
+ let fee = undefined;
610
+ const feeCostString = this.safeString (trade, 'fee');
611
+ if (feeCostString !== undefined) {
612
+ const feeCurrency = market['quote'];
613
+ fee = { 'cost': feeCostString, 'currency': feeCurrency };
614
+ }
615
+ return this.safeTrade ({
616
+ 'id': tradeId,
617
+ 'timestamp': timestamp,
618
+ 'datetime': datetime,
619
+ 'symbol': symbol,
620
+ 'order': orderId,
621
+ 'type': undefined,
622
+ 'side': side,
623
+ 'takerOrMaker': undefined,
624
+ 'price': priceString,
625
+ 'amount': amountString,
626
+ 'cost': undefined,
627
+ 'fee': fee,
628
+ 'info': trade,
629
+ }, market);
630
+ }
631
+
632
+ async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
633
+ await this.loadMarkets ();
634
+ const request = {};
635
+ if (limit !== undefined) {
636
+ request['limit'] = limit;
637
+ }
638
+ let market = undefined;
639
+ if (symbol !== undefined) {
640
+ request['symbol'] = this.marketId (symbol);
641
+ market = this.market (symbol);
642
+ }
643
+ const trades = await this.privateGetFills (this.extend (request, params));
644
+ return this.parseTrades (trades, market, since, limit, params); // need to define
645
+ }
646
+
647
+ async fetchDepositAddress (code, params = {}) {
648
+ await this.loadMarkets ();
649
+ const currency = this.currency (code);
650
+ const request = {
651
+ 'currency': currency['id'],
652
+ };
653
+ const response = await this.privatePostDepositsCurrency (this.extend (request, params));
654
+ const rawAddress = this.safeString (response, 'address');
655
+ let tag = undefined;
656
+ let address = undefined;
657
+ if (rawAddress !== undefined) {
658
+ // if a tag or memo is used it is separated by a colon in the 'address' value
659
+ [ address, tag ] = rawAddress.split (':');
660
+ }
661
+ const result = { 'info': response };
662
+ result['currency'] = currency['code'];
663
+ result['address'] = address;
664
+ if (tag !== undefined) {
665
+ result['tag'] = tag;
666
+ }
667
+ return result;
668
+ }
669
+
670
+ parseTransactionState (state) {
671
+ const states = {
672
+ 'COMPLETED': 'ok', //
673
+ 'REJECTED': 'failed',
674
+ 'PENDING': 'pending',
675
+ 'FAILED': 'failed',
676
+ 'REFUNDED': 'refunded',
677
+ };
678
+ return this.safeString (states, state, state);
679
+ }
680
+
681
+ parseTransaction (transaction, currency = undefined) {
682
+ //
683
+ // deposit
684
+ //
685
+ // {
686
+ // "depositId":"748e9180-be0d-4a80-e175-0156150efc95",
687
+ // "amount":0.009,
688
+ // "currency":"ETH",
689
+ // "address":"0xEC6B5929D454C8D9546d4221ace969E1810Fa92c",
690
+ // "state":"COMPLETED",
691
+ // "txHash":"582114562140e51a80b481c2dfebaf62b4ab9769b8ff54820bb67e34d4a3ab0c",
692
+ // "timestamp":1633697196241
693
+ // }
694
+ //
695
+ // withdrawal
696
+ //
697
+ // {
698
+ // "amount":30.0,
699
+ // "currency":"USDT",
700
+ // "beneficiary":"cab00d11-6e7f-46b7-b453-2e8ef6f101fa", // blockchain specific id
701
+ // "withdrawalId":"99df5ef7-eab6-4033-be49-312930fbd1ea",
702
+ // "fee":34.005078,
703
+ // "state":"COMPLETED",
704
+ // "timestamp":1634218452549
705
+ // }
706
+ //
707
+ let type = undefined;
708
+ let id = undefined;
709
+ const amount = this.safeNumber (transaction, 'amount');
710
+ const timestamp = this.safeInteger (transaction, 'timestamp');
711
+ const currencyId = this.safeString (transaction, 'currency');
712
+ const code = this.safeCurrencyCode (currencyId, currency);
713
+ const state = this.safeString (transaction, 'state');
714
+ if ('depositId' in transaction) {
715
+ type = 'deposit';
716
+ id = this.safeString (transaction, 'depositId');
717
+ } else if ('withdrawalId' in transaction) {
718
+ type = 'withdrawal';
719
+ id = this.safeString (transaction, 'withdrawalId');
720
+ }
721
+ const feeCost = (type === 'withdrawal') ? this.safeNumber (transaction, 'fee') : undefined;
722
+ let fee = undefined;
723
+ if (feeCost !== undefined) {
724
+ fee = { 'currency': code, 'cost': feeCost };
725
+ }
726
+ const address = this.safeString (transaction, 'address');
727
+ const txid = this.safeString (transaction, 'txhash');
728
+ const result = {
729
+ 'info': transaction,
730
+ 'id': id,
731
+ 'txid': txid,
732
+ 'timestamp': timestamp,
733
+ 'datetime': this.iso8601 (timestamp),
734
+ 'network': undefined,
735
+ 'addressFrom': undefined,
736
+ 'address': address,
737
+ 'addressTo': address,
738
+ 'tagFrom': undefined,
739
+ 'tag': undefined,
740
+ 'tagTo': undefined,
741
+ 'type': type,
742
+ 'amount': amount,
743
+ 'currency': code,
744
+ 'status': this.parseTransactionState (state), // 'status': 'pending', // 'ok', 'failed', 'canceled', string
745
+ 'updated': undefined,
746
+ 'comment': undefined,
747
+ 'fee': fee,
748
+ };
749
+ return result;
750
+ }
751
+
752
+ async fetchWithdrawalWhitelist (params = {}) {
753
+ await this.loadMarkets ();
754
+ const response = await this.privateGetWhitelist ();
755
+ const result = [];
756
+ for (let i = 0; i < response.length; i++) {
757
+ const entry = response[i];
758
+ result.push ({
759
+ 'beneficiaryId': this.safeString (entry, 'whitelistId'),
760
+ 'name': this.safeString (entry, 'name'),
761
+ 'currency': this.safeString (entry, 'currency'),
762
+ 'info': entry,
763
+ });
764
+ }
765
+ return result;
766
+ }
767
+
768
+ async fetchWithdrawalWhitelistByCurrency (currency, params = {}) {
769
+ await this.loadMarkets ();
770
+ const request = {
771
+ 'currency': this.currencyId (currency),
772
+ };
773
+ const response = await this.privateGetWhitelistCurrency (this.extend (request, params));
774
+ const result = [];
775
+ for (let i = 0; i < response.length; i++) {
776
+ const entry = response[i];
777
+ result.push ({
778
+ 'beneficiaryId': this.safeString (entry, 'whitelistId'),
779
+ 'name': this.safeString (entry, 'name'),
780
+ 'currency': this.safeString (entry, 'currency'),
781
+ 'info': entry,
782
+ });
783
+ }
784
+ return result;
785
+ }
786
+
787
+ async withdraw (code, amount, address, tag = undefined, params = {}) {
788
+ await this.loadMarkets ();
789
+ const currency = this.currency (code);
790
+ const request = {
791
+ 'amount': amount,
792
+ 'currency': currency['id'],
793
+ // 'beneficiary': address/id,
794
+ 'sendMax': false,
795
+ };
796
+ const response = await this.privatePostWithdrawals (this.extend (request, params));
797
+ //
798
+ // {
799
+ // amount: "30.0",
800
+ // currency: "USDT",
801
+ // beneficiary: "adcd43fb-9ba6-41f7-8c0d-7013482cb88f",
802
+ // withdrawalId: "99df5ef7-eab6-4033-be49-312930fbd1ea",
803
+ // fee: "34.005078",
804
+ // state: "PENDING",
805
+ // timestamp: "1634218452595"
806
+ // },
807
+ //
808
+ return this.parseTransaction (response, currency);
809
+ }
810
+
811
+ async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) {
812
+ await this.loadMarkets ();
813
+ const request = {
814
+ // 'from' : integer timestamp in ms
815
+ // 'to' : integer timestamp in ms
816
+ };
817
+ if (since !== undefined) {
818
+ request['from'] = since;
819
+ }
820
+ const response = await this.privateGetWithdrawals (this.extend (request, params));
821
+ return this.parseTransactions (response, code, since, limit);
822
+ }
823
+
824
+ async fetchWithdrawal (id, code = undefined, params = {}) {
825
+ await this.loadMarkets ();
826
+ const request = {
827
+ 'withdrawalId': id,
828
+ };
829
+ const response = await this.privateGetWithdrawalsWithdrawalId (this.extend (request, params));
830
+ return this.parseTransaction (response);
831
+ }
832
+
833
+ async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) {
834
+ await this.loadMarkets ();
835
+ const request = {
836
+ // 'from' : integer timestamp in ms
837
+ // 'to' : integer timestap in ms
838
+ };
839
+ if (since !== undefined) {
840
+ request['from'] = since;
841
+ }
842
+ const response = await this.privateGetDeposits (this.extend (request, params));
843
+ return this.parseTransactions (response, code, since, limit);
844
+ }
845
+
846
+ async fetchDeposit (id, code = undefined, params = {}) {
847
+ await this.loadMarkets ();
848
+ const depositId = this.safeString (params, 'depositId', id);
849
+ const request = {
850
+ 'depositId': depositId,
851
+ };
852
+ const deposit = await this.privateGetDepositsDepositId (this.extend (request, params));
853
+ return this.parseTransaction (deposit);
854
+ }
855
+
856
+ async fetchBalance (params = {}) {
857
+ await this.loadMarkets ();
858
+ const accountName = this.safeString (params, 'account', 'primary');
859
+ params = this.omit (params, 'account');
860
+ const request = {
861
+ 'account': accountName,
862
+ };
863
+ const response = await this.privateGetAccounts (this.extend (request, params));
864
+ //
865
+ // {
866
+ // "primary": [
867
+ // {
868
+ // "currency":"ETH",
869
+ // "balance":0.009,
870
+ // "available":0.009,
871
+ // "balance_local":30.82869,
872
+ // "available_local":30.82869,
873
+ // "rate":3425.41
874
+ // },
875
+ // ...
876
+ // ]
877
+ // }
878
+ //
879
+ const balances = this.safeValue (response, accountName);
880
+ if (balances === undefined) {
881
+ throw new ExchangeError (this.id + ' fetchBalance() could not find the "' + accountName + '" account');
882
+ }
883
+ const result = { 'info': response };
884
+ for (let i = 0; i < balances.length; i++) {
885
+ const entry = balances[i];
886
+ const currencyId = this.safeString (entry, 'currency');
887
+ const code = this.safeCurrencyCode (currencyId);
888
+ const account = this.account ();
889
+ account['free'] = this.safeString (entry, 'available');
890
+ account['total'] = this.safeString (entry, 'balance');
891
+ result[code] = account;
892
+ }
893
+ return this.safeBalance (result);
894
+ }
895
+
896
+ async fetchOrder (id, symbol = undefined, params = {}) {
897
+ // note: only works with exchange-order-id
898
+ // does not work with clientOrderId
899
+ await this.loadMarkets ();
900
+ const request = {
901
+ 'orderId': id,
902
+ };
903
+ const response = await this.privateGetOrdersOrderId (this.extend (request, params));
904
+ //
905
+ // {
906
+ // "exOrdId": 11111111,
907
+ // "clOrdId": "ABC",
908
+ // "ordType": "MARKET",
909
+ // "ordStatus": "FILLED",
910
+ // "side": "BUY",
911
+ // "price": 0.12345,
912
+ // "text": "string",
913
+ // "symbol": "BTC-USD",
914
+ // "lastShares": 0.5678,
915
+ // "lastPx": 3500.12,
916
+ // "leavesQty": 10,
917
+ // "cumQty": 0.123345,
918
+ // "avgPx": 345.33,
919
+ // "timestamp": 1592830770594
920
+ // }
921
+ //
922
+ return this.parseOrder (response);
923
+ }
924
+
925
+ sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
926
+ const requestPath = '/' + this.implodeParams (path, params);
927
+ let url = this.urls['api'][api] + requestPath;
928
+ const query = this.omit (params, this.extractParams (path));
929
+ if (api === 'public') {
930
+ if (Object.keys (query).length) {
931
+ url += '?' + this.urlencode (query);
932
+ }
933
+ } else if (api === 'private') {
934
+ this.checkRequiredCredentials ();
935
+ headers = {
936
+ 'X-API-Token': this.secret,
937
+ };
938
+ if ((method === 'GET')) {
939
+ if (Object.keys (query).length) {
940
+ url += '?' + this.urlencode (query);
941
+ }
942
+ } else {
943
+ body = this.json (query);
944
+ headers['Content-Type'] = 'application/json';
945
+ }
946
+ }
947
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
948
+ }
949
+
950
+ handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
951
+ // {"timestamp":"2021-10-21T15:13:58.837+00:00","status":404,"error":"Not Found","message":"","path":"/orders/505050"
952
+ if (response === undefined) {
953
+ return;
954
+ }
955
+ const text = this.safeString (response, 'text');
956
+ if (text !== undefined) { // if trade currency account is empty returns 200 with rejected order
957
+ if (text === 'Insufficient Balance') {
958
+ throw new InsufficientFunds (this.id + ' ' + body);
959
+ }
960
+ }
961
+ const errorCode = this.safeString (response, 'status');
962
+ const errorMessage = this.safeString (response, 'error');
963
+ if (code !== undefined) {
964
+ const feedback = this.id + ' ' + this.json (response);
965
+ this.throwExactlyMatchedException (this.exceptions['exact'], errorCode, feedback);
966
+ this.throwBroadlyMatchedException (this.exceptions['broad'], errorMessage, feedback);
967
+ }
968
+ }
969
+ };