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
package/js/cdax.js ADDED
@@ -0,0 +1,1646 @@
1
+ 'use strict';
2
+
3
+ // ---------------------------------------------------------------------------
4
+
5
+ const Exchange = require ('./base/Exchange');
6
+ const { AuthenticationError, ExchangeError, PermissionDenied, ExchangeNotAvailable, OnMaintenance, InvalidOrder, OrderNotFound, InsufficientFunds, ArgumentsRequired, BadSymbol, BadRequest, RequestTimeout, NetworkError } = require ('./base/errors');
7
+ const { TRUNCATE } = require ('./base/functions/number');
8
+
9
+ // ---------------------------------------------------------------------------
10
+
11
+ module.exports = class cdax extends Exchange {
12
+ describe () {
13
+ return this.deepExtend (super.describe (), {
14
+ 'id': 'cdax',
15
+ 'name': 'CDAX',
16
+ 'countries': [ 'RU' ],
17
+ 'rateLimit': 100,
18
+ 'userAgent': this.userAgents['chrome39'],
19
+ 'certified': false,
20
+ 'version': 'v1',
21
+ 'accounts': undefined,
22
+ 'accountsById': undefined,
23
+ 'hostname': 'cdax.io',
24
+ 'pro': false,
25
+ 'has': {
26
+ 'CORS': undefined,
27
+ 'spot': true,
28
+ 'margin': undefined, // has but unimplemented
29
+ 'swap': undefined,
30
+ 'future': undefined,
31
+ 'option': undefined,
32
+ 'cancelAllOrders': true,
33
+ 'cancelOrder': true,
34
+ 'cancelOrders': true,
35
+ 'createOrder': true,
36
+ 'fetchAccounts': true,
37
+ 'fetchBalance': true,
38
+ 'fetchClosedOrders': true,
39
+ 'fetchCurrencies': true,
40
+ 'fetchDepositAddress': false,
41
+ 'fetchDepositAddressesByNetwork': false,
42
+ 'fetchDeposits': true,
43
+ 'fetchFundingHistory': false,
44
+ 'fetchFundingRate': false,
45
+ 'fetchFundingRateHistory': false,
46
+ 'fetchFundingRates': false,
47
+ 'fetchIndexOHLCV': false,
48
+ 'fetchMarkets': true,
49
+ 'fetchMarkOHLCV': false,
50
+ 'fetchMyTrades': true,
51
+ 'fetchOHLCV': true,
52
+ 'fetchOpenOrders': true,
53
+ 'fetchOrder': true,
54
+ 'fetchOrderBook': true,
55
+ 'fetchOrders': true,
56
+ 'fetchOrderTrades': true,
57
+ 'fetchPremiumIndexOHLCV': false,
58
+ 'fetchTicker': true,
59
+ 'fetchTickers': true,
60
+ 'fetchTime': true,
61
+ 'fetchTrades': true,
62
+ 'fetchTradingFee': false,
63
+ 'fetchTradingFees': false,
64
+ 'fetchTradingLimits': true,
65
+ 'fetchWithdrawals': true,
66
+ 'withdraw': true,
67
+ },
68
+ 'timeframes': {
69
+ '1m': '1min',
70
+ '5m': '5min',
71
+ '15m': '15min',
72
+ '30m': '30min',
73
+ '1h': '60min',
74
+ '4h': '4hour',
75
+ '1d': '1day',
76
+ '1w': '1week',
77
+ '1M': '1mon',
78
+ '1y': '1year',
79
+ },
80
+ 'urls': {
81
+ 'logo': 'https://user-images.githubusercontent.com/1294454/102157692-fd406280-3e90-11eb-8d46-4511b617cd17.jpg',
82
+ 'api': {
83
+ 'market': 'https://{hostname}/api',
84
+ 'public': 'https://{hostname}/api',
85
+ 'private': 'https://{hostname}/api',
86
+ },
87
+ 'www': 'https://cdax.io',
88
+ 'referral': 'https://cdax.io/invite?invite_code=esc74',
89
+ 'doc': 'https://github.com/cloudapidoc/API_Docs',
90
+ 'fees': 'https://cdax.io/about/fee',
91
+ },
92
+ 'api': {
93
+ 'market': {
94
+ 'get': {
95
+ 'history/kline': 1, // 获取K线数据
96
+ 'detail/merged': 1, // 获取聚合行情(Ticker)
97
+ 'depth': 1, // 获取 Market Depth 数据
98
+ 'trade': 1, // 获取 Trade Detail 数据
99
+ 'history/trade': 1, // 批量获取最近的交易记录
100
+ 'detail': 1, // 获取 Market Detail 24小时成交量数据
101
+ 'tickers': 1,
102
+ 'etp': 1, // 获取杠杆ETP实时净值
103
+ },
104
+ },
105
+ 'public': {
106
+ 'get': {
107
+ 'common/symbols': 1, // 查询系统支持的所有交易对
108
+ 'common/currencys': 1, // 查询系统支持的所有币种
109
+ 'common/timestamp': 1, // 查询系统当前时间
110
+ 'common/exchange': 1, // order limits
111
+ 'settings/currencys': 1, // ?language=en-US
112
+ },
113
+ },
114
+ 'private': {
115
+ 'get': {
116
+ 'account/accounts': 0.2, // 查询当前用户的所有账户(即account-id)
117
+ 'account/accounts/{id}/balance': 0.2, // 查询指定账户的余额
118
+ 'account/accounts/{sub-uid}': 1,
119
+ 'account/history': 4,
120
+ 'cross-margin/loan-info': 1,
121
+ 'margin/loan-info': 1, // 查询借币币息率及额度
122
+ 'fee/fee-rate/get': 1,
123
+ 'order/openOrders': 0.4,
124
+ 'order/orders': 0.4,
125
+ 'order/orders/{id}': 0.4, // 查询某个订单详情
126
+ 'order/orders/{id}/matchresults': 0.4, // 查询某个订单的成交明细
127
+ 'order/orders/getClientOrder': 0.4,
128
+ 'order/history': 1, // 查询当前委托、历史委托
129
+ 'order/matchresults': 1, // 查询当前成交、历史成交
130
+ // 'dw/withdraw-virtual/addresses', // 查询虚拟币提现地址(Deprecated)
131
+ 'query/deposit-withdraw': 1,
132
+ // 'margin/loan-info', // duplicate
133
+ 'margin/loan-orders': 0.2, // 借贷订单
134
+ 'margin/accounts/balance': 0.2, // 借贷账户详情
135
+ 'cross-margin/loan-orders': 1, // 查询借币订单
136
+ 'cross-margin/accounts/balance': 1, // 借币账户详情
137
+ 'points/actions': 1,
138
+ 'points/orders': 1,
139
+ 'subuser/aggregate-balance': 10,
140
+ 'stable-coin/exchange_rate': 1,
141
+ 'stable-coin/quote': 1,
142
+ },
143
+ 'post': {
144
+ 'account/transfer': 1, // 资产划转(该节点为母用户和子用户进行资产划转的通用接口。)
145
+ 'futures/transfer': 1,
146
+ 'order/batch-orders': 0.4,
147
+ 'order/orders/place': 0.2, // 创建并执行一个新订单 (一步下单, 推荐使用)
148
+ 'order/orders/submitCancelClientOrder': 0.2,
149
+ 'order/orders/batchCancelOpenOrders': 0.4,
150
+ // 'order/orders', // 创建一个新的订单请求 (仅创建订单,不执行下单)
151
+ // 'order/orders/{id}/place', // 执行一个订单 (仅执行已创建的订单)
152
+ 'order/orders/{id}/submitcancel': 0.2, // 申请撤销一个订单请求
153
+ 'order/orders/batchcancel': 0.4, // 批量撤销订单
154
+ // 'dw/balance/transfer', // 资产划转
155
+ 'dw/withdraw/api/create': 1, // 申请提现虚拟币
156
+ // 'dw/withdraw-virtual/create', // 申请提现虚拟币
157
+ // 'dw/withdraw-virtual/{id}/place', // 确认申请虚拟币提现(Deprecated)
158
+ 'dw/withdraw-virtual/{id}/cancel': 1, // 申请取消提现虚拟币
159
+ 'dw/transfer-in/margin': 10, // 现货账户划入至借贷账户
160
+ 'dw/transfer-out/margin': 10, // 借贷账户划出至现货账户
161
+ 'margin/orders': 10, // 申请借贷
162
+ 'margin/orders/{id}/repay': 10, // 归还借贷
163
+ 'cross-margin/transfer-in': 1, // 资产划转
164
+ 'cross-margin/transfer-out': 1, // 资产划转
165
+ 'cross-margin/orders': 1, // 申请借币
166
+ 'cross-margin/orders/{id}/repay': 1, // 归还借币
167
+ 'stable-coin/exchange': 1,
168
+ 'subuser/transfer': 10,
169
+ },
170
+ },
171
+ },
172
+ 'fees': {
173
+ 'trading': {
174
+ 'feeSide': 'get',
175
+ 'tierBased': false,
176
+ 'percentage': true,
177
+ 'maker': this.parseNumber ('0.002'),
178
+ 'taker': this.parseNumber ('0.002'),
179
+ },
180
+ },
181
+ 'exceptions': {
182
+ 'broad': {
183
+ 'contract is restricted of closing positions on API. Please contact customer service': OnMaintenance,
184
+ 'maintain': OnMaintenance,
185
+ },
186
+ 'exact': {
187
+ // err-code
188
+ 'bad-request': BadRequest,
189
+ 'base-date-limit-error': BadRequest, // {"status":"error","err-code":"base-date-limit-error","err-msg":"date less than system limit","data":null}
190
+ 'api-not-support-temp-addr': PermissionDenied, // {"status":"error","err-code":"api-not-support-temp-addr","err-msg":"API withdrawal does not support temporary addresses","data":null}
191
+ 'timeout': RequestTimeout, // {"ts":1571653730865,"status":"error","err-code":"timeout","err-msg":"Request Timeout"}
192
+ 'gateway-internal-error': ExchangeNotAvailable, // {"status":"error","err-code":"gateway-internal-error","err-msg":"Failed to load data. Try again later.","data":null}
193
+ 'account-frozen-balance-insufficient-error': InsufficientFunds, // {"status":"error","err-code":"account-frozen-balance-insufficient-error","err-msg":"trade account balance is not enough, left: `0.0027`","data":null}
194
+ 'invalid-amount': InvalidOrder, // eg "Paramemter `amount` is invalid."
195
+ 'order-limitorder-amount-min-error': InvalidOrder, // limit order amount error, min: `0.001`
196
+ 'order-limitorder-amount-max-error': InvalidOrder, // market order amount error, max: `1000000`
197
+ 'order-marketorder-amount-min-error': InvalidOrder, // market order amount error, min: `0.01`
198
+ 'order-limitorder-price-min-error': InvalidOrder, // limit order price error
199
+ 'order-limitorder-price-max-error': InvalidOrder, // limit order price error
200
+ 'order-holding-limit-failed': InvalidOrder, // {"status":"error","err-code":"order-holding-limit-failed","err-msg":"Order failed, exceeded the holding limit of this currency","data":null}
201
+ 'order-orderprice-precision-error': InvalidOrder, // {"status":"error","err-code":"order-orderprice-precision-error","err-msg":"order price precision error, scale: `4`","data":null}
202
+ 'order-etp-nav-price-max-error': InvalidOrder, // {"status":"error","err-code":"order-etp-nav-price-max-error","err-msg":"Order price cannot be higher than 5% of NAV","data":null}
203
+ 'order-orderstate-error': OrderNotFound, // canceling an already canceled order
204
+ 'order-queryorder-invalid': OrderNotFound, // querying a non-existent order
205
+ 'order-update-error': ExchangeNotAvailable, // undocumented error
206
+ 'api-signature-check-failed': AuthenticationError,
207
+ 'api-signature-not-valid': AuthenticationError, // {"status":"error","err-code":"api-signature-not-valid","err-msg":"Signature not valid: Incorrect Access key [Access key错误]","data":null}
208
+ 'base-record-invalid': OrderNotFound, // https://github.com/ccxt/ccxt/issues/5750
209
+ 'base-symbol-trade-disabled': BadSymbol, // {"status":"error","err-code":"base-symbol-trade-disabled","err-msg":"Trading is disabled for this symbol","data":null}
210
+ 'base-symbol-error': BadSymbol, // {"status":"error","err-code":"base-symbol-error","err-msg":"The symbol is invalid","data":null}
211
+ 'system-maintenance': OnMaintenance, // {"status": "error", "err-code": "system-maintenance", "err-msg": "System is in maintenance!", "data": null}
212
+ // err-msg
213
+ 'invalid symbol': BadSymbol, // {"ts":1568813334794,"status":"error","err-code":"invalid-parameter","err-msg":"invalid symbol"}
214
+ 'symbol trade not open now': BadSymbol, // {"ts":1576210479343,"status":"error","err-code":"invalid-parameter","err-msg":"symbol trade not open now"}
215
+ },
216
+ },
217
+ 'options': {
218
+ 'defaultNetwork': 'ERC20',
219
+ 'networks': {
220
+ 'ETH': 'erc20',
221
+ 'TRX': 'trc20',
222
+ 'HRC20': 'hrc20',
223
+ 'HECO': 'hrc20',
224
+ 'HT': 'hrc20',
225
+ 'ALGO': 'algo',
226
+ 'OMNI': '',
227
+ },
228
+ // https://github.com/ccxt/ccxt/issues/5376
229
+ 'fetchOrdersByStatesMethod': 'private_get_order_orders', // 'private_get_order_history' // https://github.com/ccxt/ccxt/pull/5392
230
+ 'fetchOpenOrdersMethod': 'fetch_open_orders_v1', // 'fetch_open_orders_v2' // https://github.com/ccxt/ccxt/issues/5388
231
+ 'createMarketBuyOrderRequiresPrice': true,
232
+ 'fetchBalanceMethod': 'privateGetAccountAccountsIdBalance',
233
+ 'createOrderMethod': 'privatePostOrderOrdersPlace',
234
+ 'language': 'en-US',
235
+ },
236
+ 'commonCurrencies': {
237
+ // https://github.com/ccxt/ccxt/issues/6081
238
+ // https://github.com/ccxt/ccxt/issues/3365
239
+ // https://github.com/ccxt/ccxt/issues/2873
240
+ 'GET': 'Themis', // conflict with GET (Guaranteed Entrance Token, GET Protocol)
241
+ 'GTC': 'Game.com', // conflict with Gitcoin and Gastrocoin
242
+ 'HIT': 'HitChain',
243
+ 'HOT': 'Hydro Protocol', // conflict with HOT (Holo) https://github.com/ccxt/ccxt/issues/4929
244
+ // https://github.com/ccxt/ccxt/issues/7399
245
+ // https://coinmarketcap.com/currencies/pnetwork/
246
+ // https://coinmarketcap.com/currencies/penta/markets/
247
+ // https://en.cryptonomist.ch/blog/eidoo/the-edo-to-pnt-upgrade-what-you-need-to-know-updated/
248
+ 'PNT': 'Penta',
249
+ 'SBTC': 'Super Bitcoin',
250
+ 'BIFI': 'Bitcoin File', // conflict with Beefy.Finance https://github.com/ccxt/ccxt/issues/8706
251
+ },
252
+ });
253
+ }
254
+
255
+ async fetchTime (params = {}) {
256
+ const response = await this.publicGetCommonTimestamp (params);
257
+ return this.safeInteger (response, 'data');
258
+ }
259
+
260
+ async fetchTradingLimits (symbols = undefined, params = {}) {
261
+ // this method should not be called directly, use loadTradingLimits () instead
262
+ // by default it will try load withdrawal fees of all currencies (with separate requests)
263
+ // however if you define symbols = [ 'ETH/BTC', 'LTC/BTC' ] in args it will only load those
264
+ await this.loadMarkets ();
265
+ if (symbols === undefined) {
266
+ symbols = this.symbols;
267
+ }
268
+ const result = {};
269
+ for (let i = 0; i < symbols.length; i++) {
270
+ const symbol = symbols[i];
271
+ result[symbol] = await this.fetchTradingLimitsById (this.marketId (symbol), params);
272
+ }
273
+ return result;
274
+ }
275
+
276
+ async fetchTradingLimitsById (id, params = {}) {
277
+ const request = {
278
+ 'symbol': id,
279
+ };
280
+ const response = await this.publicGetCommonExchange (this.extend (request, params));
281
+ //
282
+ // {
283
+ // status: "ok",
284
+ // data: {
285
+ // 'symbol': "aidocbtc",
286
+ // 'buy-limit-must-less-than': 1.1,
287
+ // 'sell-limit-must-greater-than': 0.9,
288
+ // 'limit-order-must-greater-than': 1,
289
+ // 'limit-order-must-less-than': 5000000,
290
+ // 'market-buy-order-must-greater-than': 0.0001,
291
+ // 'market-buy-order-must-less-than': 100,
292
+ // 'market-sell-order-must-greater-than': 1,
293
+ // 'market-sell-order-must-less-than': 500000,
294
+ // 'circuit-break-when-greater-than': 10000,
295
+ // 'circuit-break-when-less-than': 10,
296
+ // 'market-sell-order-rate-must-less-than': 0.1,
297
+ // 'market-buy-order-rate-must-less-than': 0.1
298
+ // }
299
+ // }
300
+ //
301
+ return this.parseTradingLimits (this.safeValue (response, 'data', {}));
302
+ }
303
+
304
+ parseTradingLimits (limits, symbol = undefined, params = {}) {
305
+ //
306
+ // {
307
+ // 'symbol': "aidocbtc",
308
+ // 'buy-limit-must-less-than': 1.1,
309
+ // 'sell-limit-must-greater-than': 0.9,
310
+ // 'limit-order-must-greater-than': 1,
311
+ // 'limit-order-must-less-than': 5000000,
312
+ // 'market-buy-order-must-greater-than': 0.0001,
313
+ // 'market-buy-order-must-less-than': 100,
314
+ // 'market-sell-order-must-greater-than': 1,
315
+ // 'market-sell-order-must-less-than': 500000,
316
+ // 'circuit-break-when-greater-than': 10000,
317
+ // 'circuit-break-when-less-than': 10,
318
+ // 'market-sell-order-rate-must-less-than': 0.1,
319
+ // 'market-buy-order-rate-must-less-than': 0.1
320
+ // }
321
+ //
322
+ return {
323
+ 'info': limits,
324
+ 'limits': {
325
+ 'amount': {
326
+ 'min': this.safeNumber (limits, 'limit-order-must-greater-than'),
327
+ 'max': this.safeNumber (limits, 'limit-order-must-less-than'),
328
+ },
329
+ },
330
+ };
331
+ }
332
+
333
+ costToPrecision (symbol, cost) {
334
+ return this.decimalToPrecision (cost, TRUNCATE, this.markets[symbol]['precision']['cost'], this.precisionMode);
335
+ }
336
+
337
+ async fetchMarkets (params = {}) {
338
+ const response = await this.publicGetCommonSymbols (params);
339
+ //
340
+ // {
341
+ // "status": "ok",
342
+ // "data": [
343
+ // {
344
+ // "base-currency": "ckb",
345
+ // "quote-currency": "usdt",
346
+ // "price-precision": 6,
347
+ // "amount-precision": 2,
348
+ // "symbol-partition": "default",
349
+ // "symbol": "ckbusdt",
350
+ // "state": "online",
351
+ // "value-precision": 8,
352
+ // "min-order-amt": 1,
353
+ // "max-order-amt": 140000000,
354
+ // "min-order-value": 5,
355
+ // "limit-order-min-order-amt": 1,
356
+ // "limit-order-max-order-amt": 140000000,
357
+ // "limit-order-max-buy-amt": 140000000,
358
+ // "limit-order-max-sell-amt": 140000000,
359
+ // "sell-market-min-order-amt": 1,
360
+ // "sell-market-max-order-amt": 14000000,
361
+ // "buy-market-max-order-value": 200000,
362
+ // "api-trading": "enabled",
363
+ // "tags": ""
364
+ // },
365
+ // ]
366
+ // }
367
+ //
368
+ const markets = this.safeValue (response, 'data');
369
+ const numMarkets = markets.length;
370
+ if (numMarkets < 1) {
371
+ throw new NetworkError (this.id + ' fetchMarkets() returned empty response: ' + this.json (markets));
372
+ }
373
+ const result = [];
374
+ for (let i = 0; i < markets.length; i++) {
375
+ const market = markets[i];
376
+ const baseId = this.safeString (market, 'base-currency');
377
+ const quoteId = this.safeString (market, 'quote-currency');
378
+ const base = this.safeCurrencyCode (baseId);
379
+ const quote = this.safeCurrencyCode (quoteId);
380
+ const state = this.safeString (market, 'state');
381
+ result.push ({
382
+ 'id': baseId + quoteId,
383
+ 'symbol': base + '/' + quote,
384
+ 'base': base,
385
+ 'quote': quote,
386
+ 'settle': undefined,
387
+ 'baseId': baseId,
388
+ 'quoteId': quoteId,
389
+ 'settleId': undefined,
390
+ 'type': 'spot',
391
+ 'spot': true,
392
+ 'margin': undefined,
393
+ 'swap': false,
394
+ 'future': false,
395
+ 'option': false,
396
+ 'active': (state === 'online'),
397
+ 'contract': false,
398
+ 'linear': undefined,
399
+ 'inverse': undefined,
400
+ 'taker': (base === 'OMG') ? 0 : 0.002,
401
+ 'maker': (base === 'OMG') ? 0 : 0.002,
402
+ 'contractSize': undefined,
403
+ 'expiry': undefined,
404
+ 'expiryDatetime': undefined,
405
+ 'strike': undefined,
406
+ 'optionType': undefined,
407
+ 'precision': {
408
+ 'amount': this.safeInteger (market, 'amount-precision'),
409
+ 'price': this.safeInteger (market, 'price-precision'),
410
+ 'cost': this.safeInteger (market, 'value-precision'),
411
+ },
412
+ 'limits': {
413
+ 'leverage': {
414
+ 'min': this.parseNumber ('1'),
415
+ 'max': this.safeNumber (market, 'leverage-ratio', 1),
416
+ 'superMax': this.safeNumber (market, 'super-margin-leverage-ratio', 1),
417
+ },
418
+ 'amount': {
419
+ 'min': this.safeNumber (market, 'min-order-amt'),
420
+ 'max': this.safeNumber (market, 'max-order-amt'),
421
+ },
422
+ 'price': {
423
+ 'min': undefined,
424
+ 'max': undefined,
425
+ },
426
+ 'cost': {
427
+ 'min': this.safeNumber (market, 'min-order-value', 0),
428
+ 'max': undefined,
429
+ },
430
+ },
431
+ 'info': market,
432
+ });
433
+ }
434
+ return result;
435
+ }
436
+
437
+ parseTicker (ticker, market = undefined) {
438
+ //
439
+ // fetchTicker
440
+ //
441
+ // {
442
+ // "amount": 26228.672978342216,
443
+ // "open": 9078.95,
444
+ // "close": 9146.86,
445
+ // "high": 9155.41,
446
+ // "id": 209988544334,
447
+ // "count": 265846,
448
+ // "low": 8988.0,
449
+ // "version": 209988544334,
450
+ // "ask": [ 9146.87, 0.156134 ],
451
+ // "vol": 2.3822168242201668E8,
452
+ // "bid": [ 9146.86, 0.080758 ],
453
+ // }
454
+ //
455
+ // fetchTickers
456
+ // {
457
+ // symbol: "bhdht",
458
+ // open: 2.3938,
459
+ // high: 2.4151,
460
+ // low: 2.3323,
461
+ // close: 2.3909,
462
+ // amount: 628.992,
463
+ // vol: 1493.71841095,
464
+ // count: 2088,
465
+ // bid: 2.3643,
466
+ // bidSize: 0.7136,
467
+ // ask: 2.4061,
468
+ // askSize: 0.4156
469
+ // }
470
+ //
471
+ const symbol = this.safeSymbol (undefined, market);
472
+ const timestamp = this.safeInteger (ticker, 'ts');
473
+ let bid = undefined;
474
+ let bidVolume = undefined;
475
+ let ask = undefined;
476
+ let askVolume = undefined;
477
+ if ('bid' in ticker) {
478
+ if (Array.isArray (ticker['bid'])) {
479
+ bid = this.safeString (ticker['bid'], 0);
480
+ bidVolume = this.safeString (ticker['bid'], 1);
481
+ } else {
482
+ bid = this.safeString (ticker, 'bid');
483
+ bidVolume = this.safeString (ticker, 'bidSize');
484
+ }
485
+ }
486
+ if ('ask' in ticker) {
487
+ if (Array.isArray (ticker['ask'])) {
488
+ ask = this.safeString (ticker['ask'], 0);
489
+ askVolume = this.safeString (ticker['ask'], 1);
490
+ } else {
491
+ ask = this.safeString (ticker, 'ask');
492
+ askVolume = this.safeString (ticker, 'askSize');
493
+ }
494
+ }
495
+ const open = this.safeString (ticker, 'open');
496
+ const close = this.safeString (ticker, 'close');
497
+ const baseVolume = this.safeString (ticker, 'amount');
498
+ const quoteVolume = this.safeString (ticker, 'vol');
499
+ return this.safeTicker ({
500
+ 'symbol': symbol,
501
+ 'timestamp': timestamp,
502
+ 'datetime': this.iso8601 (timestamp),
503
+ 'high': this.safeString (ticker, 'high'),
504
+ 'low': this.safeString (ticker, 'low'),
505
+ 'bid': bid,
506
+ 'bidVolume': bidVolume,
507
+ 'ask': ask,
508
+ 'askVolume': askVolume,
509
+ 'vwap': undefined,
510
+ 'open': open,
511
+ 'close': close,
512
+ 'last': close,
513
+ 'previousClose': undefined,
514
+ 'change': undefined,
515
+ 'percentage': undefined,
516
+ 'average': undefined,
517
+ 'baseVolume': baseVolume,
518
+ 'quoteVolume': quoteVolume,
519
+ 'info': ticker,
520
+ }, market, false);
521
+ }
522
+
523
+ async fetchOrderBook (symbol, limit = undefined, params = {}) {
524
+ await this.loadMarkets ();
525
+ const market = this.market (symbol);
526
+ const request = {
527
+ 'symbol': market['id'],
528
+ 'type': 'step0',
529
+ };
530
+ const response = await this.marketGetDepth (this.extend (request, params));
531
+ //
532
+ // {
533
+ // "status": "ok",
534
+ // "ch": "market.btcusdt.depth.step0",
535
+ // "ts": 1583474832790,
536
+ // "tick": {
537
+ // "bids": [
538
+ // [ 9100.290000000000000000, 0.200000000000000000 ],
539
+ // [ 9099.820000000000000000, 0.200000000000000000 ],
540
+ // [ 9099.610000000000000000, 0.205000000000000000 ],
541
+ // ],
542
+ // "asks": [
543
+ // [ 9100.640000000000000000, 0.005904000000000000 ],
544
+ // [ 9101.010000000000000000, 0.287311000000000000 ],
545
+ // [ 9101.030000000000000000, 0.012121000000000000 ],
546
+ // ],
547
+ // "ts":1583474832008,
548
+ // "version":104999698780
549
+ // }
550
+ // }
551
+ //
552
+ if ('tick' in response) {
553
+ if (!response['tick']) {
554
+ throw new BadSymbol (this.id + ' fetchOrderBook() returned empty response: ' + this.json (response));
555
+ }
556
+ const tick = this.safeValue (response, 'tick');
557
+ const timestamp = this.safeInteger (tick, 'ts', this.safeInteger (response, 'ts'));
558
+ const result = this.parseOrderBook (tick, symbol, timestamp);
559
+ result['nonce'] = this.safeInteger (tick, 'version');
560
+ return result;
561
+ }
562
+ throw new ExchangeError (this.id + ' fetchOrderBook() returned unrecognized response: ' + this.json (response));
563
+ }
564
+
565
+ async fetchTicker (symbol, params = {}) {
566
+ await this.loadMarkets ();
567
+ const market = this.market (symbol);
568
+ const request = {
569
+ 'symbol': market['id'],
570
+ };
571
+ const response = await this.marketGetDetailMerged (this.extend (request, params));
572
+ //
573
+ // {
574
+ // "status": "ok",
575
+ // "ch": "market.btcusdt.detail.merged",
576
+ // "ts": 1583494336669,
577
+ // "tick": {
578
+ // "amount": 26228.672978342216,
579
+ // "open": 9078.95,
580
+ // "close": 9146.86,
581
+ // "high": 9155.41,
582
+ // "id": 209988544334,
583
+ // "count": 265846,
584
+ // "low": 8988.0,
585
+ // "version": 209988544334,
586
+ // "ask": [ 9146.87, 0.156134 ],
587
+ // "vol": 2.3822168242201668E8,
588
+ // "bid": [ 9146.86, 0.080758 ],
589
+ // }
590
+ // }
591
+ //
592
+ const ticker = this.parseTicker (response['tick'], market);
593
+ const timestamp = this.safeInteger (response, 'ts');
594
+ ticker['timestamp'] = timestamp;
595
+ ticker['datetime'] = this.iso8601 (timestamp);
596
+ return ticker;
597
+ }
598
+
599
+ async fetchTickers (symbols = undefined, params = {}) {
600
+ await this.loadMarkets ();
601
+ const response = await this.marketGetTickers (params);
602
+ const tickers = this.safeValue (response, 'data');
603
+ const timestamp = this.safeInteger (response, 'ts');
604
+ const result = {};
605
+ for (let i = 0; i < tickers.length; i++) {
606
+ const marketId = this.safeString (tickers[i], 'symbol');
607
+ const market = this.safeMarket (marketId);
608
+ const symbol = market['symbol'];
609
+ const ticker = this.parseTicker (tickers[i], market);
610
+ ticker['timestamp'] = timestamp;
611
+ ticker['datetime'] = this.iso8601 (timestamp);
612
+ result[symbol] = ticker;
613
+ }
614
+ return this.filterByArray (result, 'symbol', symbols);
615
+ }
616
+
617
+ parseTrade (trade, market = undefined) {
618
+ //
619
+ // fetchTrades (public)
620
+ //
621
+ // {
622
+ // "id": "112522757755423628681413936",
623
+ // "ts": "1638457111917",
624
+ // "trade-id": "100454385963",
625
+ // "amount": "13.7962",
626
+ // "price": "1.697867",
627
+ // "direction": "buy"
628
+ // }
629
+ //
630
+ // fetchMyTrades (private)
631
+ //
632
+ // {
633
+ // "symbol": "adausdt",
634
+ // "fee-currency": "usdt",
635
+ // "source": "spot-api",
636
+ // "order-id": "423628498050504",
637
+ // "created-at": "1638455779233",
638
+ // "role": "taker",
639
+ // "price": "1.672487",
640
+ // "match-id": "112521868633",
641
+ // "trade-id": "100454375614",
642
+ // "filled-amount": "6.8",
643
+ // "filled-fees": "0.0227458232",
644
+ // "filled-points": "0.0",
645
+ // "fee-deduct-currency": "",
646
+ // "fee-deduct-state": "done",
647
+ // "id": "422419583501532",
648
+ // "type": "sell-market"
649
+ // },
650
+ //
651
+ // fetchOrderTrades (private)
652
+ //
653
+ // {
654
+ // "symbol": "adausdt",
655
+ // "fee-currency": "usdt",
656
+ // "source": "spot-api",
657
+ // "match-id": "112521868633",
658
+ // "trade-id": "100454375614",
659
+ // "role": "taker",
660
+ // "order-id": "423628498050504",
661
+ // "price": "1.672487",
662
+ // "created-at": "1638455779233",
663
+ // "filled-amount": "6.8",
664
+ // "filled-fees": "0.0227458232",
665
+ // "filled-points": "0.0",
666
+ // "fee-deduct-currency": "",
667
+ // "fee-deduct-state": "done",
668
+ // "id": "422419583501532",
669
+ // "type": "sell-market"
670
+ // }
671
+ //
672
+ const marketId = this.safeString (trade, 'symbol');
673
+ const symbol = this.safeSymbol (marketId, market);
674
+ const timestamp = this.safeInteger2 (trade, 'ts', 'created-at');
675
+ const order = this.safeString (trade, 'order-id');
676
+ let side = this.safeString (trade, 'direction');
677
+ let type = this.safeString (trade, 'type');
678
+ if (type !== undefined) {
679
+ const typeParts = type.split ('-');
680
+ side = typeParts[0];
681
+ type = typeParts[1];
682
+ }
683
+ const takerOrMaker = this.safeString (trade, 'role');
684
+ const priceString = this.safeString (trade, 'price');
685
+ const amountString = this.safeString2 (trade, 'filled-amount', 'amount');
686
+ let fee = undefined;
687
+ let feeCostString = this.safeString (trade, 'filled-fees');
688
+ let feeCurrency = this.safeCurrencyCode (this.safeString (trade, 'fee-currency'));
689
+ const filledPoints = this.safeString (trade, 'filled-points');
690
+ if (filledPoints !== undefined) {
691
+ if ((feeCostString === undefined) || (feeCostString === '0.0')) {
692
+ feeCostString = filledPoints;
693
+ feeCurrency = this.safeCurrencyCode (this.safeString (trade, 'fee-deduct-currency'));
694
+ }
695
+ }
696
+ if (feeCostString !== undefined) {
697
+ fee = {
698
+ 'cost': feeCostString,
699
+ 'currency': feeCurrency,
700
+ };
701
+ }
702
+ const tradeId = this.safeString2 (trade, 'trade-id', 'tradeId');
703
+ const id = this.safeString (trade, 'id', tradeId);
704
+ return this.safeTrade ({
705
+ 'id': id,
706
+ 'info': trade,
707
+ 'order': order,
708
+ 'timestamp': timestamp,
709
+ 'datetime': this.iso8601 (timestamp),
710
+ 'symbol': symbol,
711
+ 'type': type,
712
+ 'side': side,
713
+ 'takerOrMaker': takerOrMaker,
714
+ 'price': priceString,
715
+ 'amount': amountString,
716
+ 'cost': undefined,
717
+ 'fee': fee,
718
+ }, market);
719
+ }
720
+
721
+ async fetchOrderTrades (id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
722
+ await this.loadMarkets ();
723
+ const request = {
724
+ 'id': id,
725
+ };
726
+ const response = await this.privateGetOrderOrdersIdMatchresults (this.extend (request, params));
727
+ return this.parseTrades (response['data'], undefined, since, limit);
728
+ }
729
+
730
+ async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
731
+ await this.loadMarkets ();
732
+ let market = undefined;
733
+ const request = {};
734
+ if (symbol !== undefined) {
735
+ market = this.market (symbol);
736
+ request['symbol'] = market['id'];
737
+ }
738
+ if (limit !== undefined) {
739
+ request['size'] = limit; // 1-100 orders, default is 100
740
+ }
741
+ if (since !== undefined) {
742
+ request['start-time'] = since; // a date within 120 days from today
743
+ // request['end-time'] = this.sum (since, 172800000); // 48 hours window
744
+ }
745
+ const response = await this.privateGetOrderMatchresults (this.extend (request, params));
746
+ return this.parseTrades (response['data'], market, since, limit);
747
+ }
748
+
749
+ async fetchTrades (symbol, since = undefined, limit = 1000, params = {}) {
750
+ await this.loadMarkets ();
751
+ const market = this.market (symbol);
752
+ const request = {
753
+ 'symbol': market['id'],
754
+ };
755
+ if (limit !== undefined) {
756
+ request['size'] = limit;
757
+ }
758
+ const response = await this.marketGetHistoryTrade (this.extend (request, params));
759
+ //
760
+ // {
761
+ // "status": "ok",
762
+ // "ch": "market.btcusdt.trade.detail",
763
+ // "ts": 1583497692365,
764
+ // "data": [
765
+ // {
766
+ // "id": 105005170342,
767
+ // "ts": 1583497692182,
768
+ // "data": [
769
+ // {
770
+ // "amount": 0.010411000000000000,
771
+ // "trade-id": 102090736910,
772
+ // "ts": 1583497692182,
773
+ // "id": 10500517034273194594947,
774
+ // "price": 9096.050000000000000000,
775
+ // "direction": "sell"
776
+ // }
777
+ // ]
778
+ // },
779
+ // // ...
780
+ // ]
781
+ // }
782
+ //
783
+ const data = this.safeValue (response, 'data');
784
+ let result = [];
785
+ for (let i = 0; i < data.length; i++) {
786
+ const trades = this.safeValue (data[i], 'data', []);
787
+ for (let j = 0; j < trades.length; j++) {
788
+ const trade = this.parseTrade (trades[j], market);
789
+ result.push (trade);
790
+ }
791
+ }
792
+ result = this.sortBy (result, 'timestamp');
793
+ return this.filterBySymbolSinceLimit (result, market['symbol'], since, limit);
794
+ }
795
+
796
+ parseOHLCV (ohlcv, market = undefined) {
797
+ //
798
+ // {
799
+ // "amount":1.2082,
800
+ // "open":0.025096,
801
+ // "close":0.025095,
802
+ // "high":0.025096,
803
+ // "id":1591515300,
804
+ // "count":6,
805
+ // "low":0.025095,
806
+ // "vol":0.0303205097
807
+ // }
808
+ //
809
+ return [
810
+ this.safeTimestamp (ohlcv, 'id'),
811
+ this.safeNumber (ohlcv, 'open'),
812
+ this.safeNumber (ohlcv, 'high'),
813
+ this.safeNumber (ohlcv, 'low'),
814
+ this.safeNumber (ohlcv, 'close'),
815
+ this.safeNumber (ohlcv, 'amount'),
816
+ ];
817
+ }
818
+
819
+ async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = 1000, params = {}) {
820
+ await this.loadMarkets ();
821
+ const market = this.market (symbol);
822
+ const request = {
823
+ 'symbol': market['id'],
824
+ 'period': this.timeframes[timeframe],
825
+ };
826
+ if (limit !== undefined) {
827
+ request['size'] = limit;
828
+ }
829
+ const response = await this.marketGetHistoryKline (this.extend (request, params));
830
+ //
831
+ // {
832
+ // "status":"ok",
833
+ // "ch":"market.ethbtc.kline.1min",
834
+ // "ts":1591515374371,
835
+ // "data":[
836
+ // {"amount":0.0,"open":0.025095,"close":0.025095,"high":0.025095,"id":1591515360,"count":0,"low":0.025095,"vol":0.0},
837
+ // {"amount":1.2082,"open":0.025096,"close":0.025095,"high":0.025096,"id":1591515300,"count":6,"low":0.025095,"vol":0.0303205097},
838
+ // {"amount":0.0648,"open":0.025096,"close":0.025096,"high":0.025096,"id":1591515240,"count":2,"low":0.025096,"vol":0.0016262208},
839
+ // ]
840
+ // }
841
+ //
842
+ const data = this.safeValue (response, 'data', []);
843
+ return this.parseOHLCVs (data, market, timeframe, since, limit);
844
+ }
845
+
846
+ async fetchAccounts (params = {}) {
847
+ await this.loadMarkets ();
848
+ const response = await this.privateGetAccountAccounts (params);
849
+ return response['data'];
850
+ }
851
+
852
+ async fetchCurrencies (params = {}) {
853
+ const request = {
854
+ 'language': this.options['language'],
855
+ };
856
+ const response = await this.publicGetSettingsCurrencys (this.extend (request, params));
857
+ //
858
+ // {
859
+ // "status":"ok",
860
+ // "data":[
861
+ // {
862
+ // "currency-addr-with-tag":false,
863
+ // "fast-confirms":12,
864
+ // "safe-confirms":12,
865
+ // "currency-type":"eth",
866
+ // "quote-currency":true,
867
+ // "withdraw-enable-timestamp":1609430400000,
868
+ // "deposit-enable-timestamp":1609430400000,
869
+ // "currency-partition":"all",
870
+ // "support-sites":["OTC","INSTITUTION","MINEPOOL"],
871
+ // "withdraw-precision":6,
872
+ // "visible-assets-timestamp":1508839200000,
873
+ // "deposit-min-amount":"1",
874
+ // "withdraw-min-amount":"10",
875
+ // "show-precision":"8",
876
+ // "tags":"",
877
+ // "weight":23,
878
+ // "full-name":"Tether USDT",
879
+ // "otc-enable":1,
880
+ // "visible":true,
881
+ // "white-enabled":false,
882
+ // "country-disabled":false,
883
+ // "deposit-enabled":true,
884
+ // "withdraw-enabled":true,
885
+ // "name":"usdt",
886
+ // "state":"online",
887
+ // "display-name":"USDT",
888
+ // "suspend-withdraw-desc":null,
889
+ // "withdraw-desc":"Minimum withdrawal amount: 10 USDT (ERC20). !>_<!To ensure the safety of your funds, your withdrawal request will be manually reviewed if your security strategy or password is changed. Please wait for phone calls or emails from our staff.!>_<!Please make sure that your computer and browser are secure and your information is protected from being tampered or leaked.",
890
+ // "suspend-deposit-desc":null,
891
+ // "deposit-desc":"Please don’t deposit any other digital assets except USDT to the above address. Otherwise, you may lose your assets permanently. !>_<!Depositing to the above address requires confirmations of the entire network. It will arrive after 12 confirmations, and it will be available to withdraw after 12 confirmations. !>_<!Minimum deposit amount: 1 USDT. Any deposits less than the minimum will not be credited or refunded.!>_<!Your deposit address won’t change often. If there are any changes, we will notify you via announcement or email.!>_<!Please make sure that your computer and browser are secure and your information is protected from being tampered or leaked.",
892
+ // "suspend-visible-desc":null
893
+ // }
894
+ // ]
895
+ // }
896
+ //
897
+ const currencies = this.safeValue (response, 'data');
898
+ const result = {};
899
+ for (let i = 0; i < currencies.length; i++) {
900
+ const currency = currencies[i];
901
+ const id = this.safeValue (currency, 'name');
902
+ const precision = this.safeInteger (currency, 'withdraw-precision');
903
+ const code = this.safeCurrencyCode (id);
904
+ const depositEnabled = this.safeValue (currency, 'deposit-enabled');
905
+ const withdrawEnabled = this.safeValue (currency, 'withdraw-enabled');
906
+ const countryDisabled = this.safeValue (currency, 'country-disabled');
907
+ const visible = this.safeValue (currency, 'visible', false);
908
+ const state = this.safeString (currency, 'state');
909
+ const active = visible && depositEnabled && withdrawEnabled && (state === 'online') && !countryDisabled;
910
+ const name = this.safeString (currency, 'display-name');
911
+ result[code] = {
912
+ 'id': id,
913
+ 'code': code,
914
+ 'type': 'crypto',
915
+ // 'payin': currency['deposit-enabled'],
916
+ // 'payout': currency['withdraw-enabled'],
917
+ // 'transfer': undefined,
918
+ 'name': name,
919
+ 'active': active,
920
+ 'deposit': depositEnabled,
921
+ 'withdraw': withdrawEnabled,
922
+ 'fee': undefined, // todo need to fetch from fee endpoint
923
+ 'precision': precision,
924
+ 'limits': {
925
+ 'amount': {
926
+ 'min': Math.pow (10, -precision),
927
+ 'max': Math.pow (10, precision),
928
+ },
929
+ 'deposit': {
930
+ 'min': this.safeNumber (currency, 'deposit-min-amount'),
931
+ 'max': Math.pow (10, precision),
932
+ },
933
+ 'withdraw': {
934
+ 'min': this.safeNumber (currency, 'withdraw-min-amount'),
935
+ 'max': Math.pow (10, precision),
936
+ },
937
+ },
938
+ 'info': currency,
939
+ };
940
+ }
941
+ return result;
942
+ }
943
+
944
+ parseBalance (response) {
945
+ const balances = this.safeValue (response['data'], 'list', []);
946
+ const result = { 'info': response };
947
+ for (let i = 0; i < balances.length; i++) {
948
+ const balance = balances[i];
949
+ const currencyId = this.safeString (balance, 'currency');
950
+ const code = this.safeCurrencyCode (currencyId);
951
+ let account = undefined;
952
+ if (code in result) {
953
+ account = result[code];
954
+ } else {
955
+ account = this.account ();
956
+ }
957
+ if (balance['type'] === 'trade') {
958
+ account['free'] = this.safeString (balance, 'balance');
959
+ }
960
+ if (balance['type'] === 'frozen') {
961
+ account['used'] = this.safeString (balance, 'balance');
962
+ }
963
+ result[code] = account;
964
+ }
965
+ return this.safeBalance (result);
966
+ }
967
+
968
+ async fetchBalance (params = {}) {
969
+ await this.loadMarkets ();
970
+ await this.loadAccounts ();
971
+ const method = this.options['fetchBalanceMethod'];
972
+ const request = {
973
+ 'id': this.accounts[0]['id'],
974
+ };
975
+ const response = await this[method] (this.extend (request, params));
976
+ return this.parseBalance (response);
977
+ }
978
+
979
+ async fetchOrdersByStates (states, symbol = undefined, since = undefined, limit = undefined, params = {}) {
980
+ await this.loadMarkets ();
981
+ const request = {
982
+ 'states': states,
983
+ };
984
+ let market = undefined;
985
+ if (symbol !== undefined) {
986
+ market = this.market (symbol);
987
+ request['symbol'] = market['id'];
988
+ }
989
+ const method = this.safeString (this.options, 'fetchOrdersByStatesMethod', 'private_get_order_orders');
990
+ const response = await this[method] (this.extend (request, params));
991
+ //
992
+ // { status: "ok",
993
+ // data: [ { id: 13997833014,
994
+ // symbol: "ethbtc",
995
+ // 'account-id': 3398321,
996
+ // amount: "0.045000000000000000",
997
+ // price: "0.034014000000000000",
998
+ // 'created-at': 1545836976871,
999
+ // type: "sell-limit",
1000
+ // 'field-amount': "0.045000000000000000",
1001
+ // 'field-cash-amount': "0.001530630000000000",
1002
+ // 'field-fees': "0.000003061260000000",
1003
+ // 'finished-at': 1545837948214,
1004
+ // source: "spot-api",
1005
+ // state: "filled",
1006
+ // 'canceled-at': 0 } ] }
1007
+ //
1008
+ return this.parseOrders (response['data'], market, since, limit);
1009
+ }
1010
+
1011
+ async fetchOrder (id, symbol = undefined, params = {}) {
1012
+ await this.loadMarkets ();
1013
+ const request = {
1014
+ 'id': id,
1015
+ };
1016
+ const response = await this.privateGetOrderOrdersId (this.extend (request, params));
1017
+ const order = this.safeValue (response, 'data');
1018
+ return this.parseOrder (order);
1019
+ }
1020
+
1021
+ async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
1022
+ return await this.fetchOrdersByStates ('pre-submitted,submitted,partial-filled,filled,partial-canceled,canceled', symbol, since, limit, params);
1023
+ }
1024
+
1025
+ async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
1026
+ const method = this.safeString (this.options, 'fetchOpenOrdersMethod', 'fetch_open_orders_v1');
1027
+ return await this[method] (symbol, since, limit, params);
1028
+ }
1029
+
1030
+ async fetchOpenOrdersV1 (symbol = undefined, since = undefined, limit = undefined, params = {}) {
1031
+ if (symbol === undefined) {
1032
+ throw new ArgumentsRequired (this.id + ' fetchOpenOrdersV1() requires a symbol argument');
1033
+ }
1034
+ return await this.fetchOrdersByStates ('pre-submitted,submitted,partial-filled', symbol, since, limit, params);
1035
+ }
1036
+
1037
+ async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
1038
+ return await this.fetchOrdersByStates ('filled,partial-canceled,canceled', symbol, since, limit, params);
1039
+ }
1040
+
1041
+ async fetchOpenOrdersV2 (symbol = undefined, since = undefined, limit = undefined, params = {}) {
1042
+ await this.loadMarkets ();
1043
+ const request = {};
1044
+ let market = undefined;
1045
+ if (symbol !== undefined) {
1046
+ market = this.market (symbol);
1047
+ request['symbol'] = market['id'];
1048
+ }
1049
+ let accountId = this.safeString (params, 'account-id');
1050
+ if (accountId === undefined) {
1051
+ // pick the first account
1052
+ await this.loadAccounts ();
1053
+ for (let i = 0; i < this.accounts.length; i++) {
1054
+ const account = this.accounts[i];
1055
+ if (account['type'] === 'spot') {
1056
+ accountId = this.safeString (account, 'id');
1057
+ if (accountId !== undefined) {
1058
+ break;
1059
+ }
1060
+ }
1061
+ }
1062
+ }
1063
+ request['account-id'] = accountId;
1064
+ if (limit !== undefined) {
1065
+ request['size'] = limit;
1066
+ }
1067
+ const omitted = this.omit (params, 'account-id');
1068
+ const response = await this.privateGetOrderOpenOrders (this.extend (request, omitted));
1069
+ //
1070
+ // {
1071
+ // "status":"ok",
1072
+ // "data":[
1073
+ // {
1074
+ // "symbol":"ethusdt",
1075
+ // "source":"api",
1076
+ // "amount":"0.010000000000000000",
1077
+ // "account-id":1528640,
1078
+ // "created-at":1561597491963,
1079
+ // "price":"400.000000000000000000",
1080
+ // "filled-amount":"0.0",
1081
+ // "filled-cash-amount":"0.0",
1082
+ // "filled-fees":"0.0",
1083
+ // "id":38477101630,
1084
+ // "state":"submitted",
1085
+ // "type":"sell-limit"
1086
+ // }
1087
+ // ]
1088
+ // }
1089
+ //
1090
+ const data = this.safeValue (response, 'data', []);
1091
+ return this.parseOrders (data, market, since, limit);
1092
+ }
1093
+
1094
+ parseOrderStatus (status) {
1095
+ const statuses = {
1096
+ 'partial-filled': 'open',
1097
+ 'partial-canceled': 'canceled',
1098
+ 'filled': 'closed',
1099
+ 'canceled': 'canceled',
1100
+ 'submitted': 'open',
1101
+ };
1102
+ return this.safeString (statuses, status, status);
1103
+ }
1104
+
1105
+ parseOrder (order, market = undefined) {
1106
+ //
1107
+ // { id: 13997833014,
1108
+ // symbol: "ethbtc",
1109
+ // 'account-id': 3398321,
1110
+ // amount: "0.045000000000000000",
1111
+ // price: "0.034014000000000000",
1112
+ // 'created-at': 1545836976871,
1113
+ // type: "sell-limit",
1114
+ // 'field-amount': "0.045000000000000000", // they have fixed it for filled-amount
1115
+ // 'field-cash-amount': "0.001530630000000000", // they have fixed it for filled-cash-amount
1116
+ // 'field-fees': "0.000003061260000000", // they have fixed it for filled-fees
1117
+ // 'finished-at': 1545837948214,
1118
+ // source: "spot-api",
1119
+ // state: "filled",
1120
+ // 'canceled-at': 0 }
1121
+ //
1122
+ // { id: 20395337822,
1123
+ // symbol: "ethbtc",
1124
+ // 'account-id': 5685075,
1125
+ // amount: "0.001000000000000000",
1126
+ // price: "0.0",
1127
+ // 'created-at': 1545831584023,
1128
+ // type: "buy-market",
1129
+ // 'field-amount': "0.029100000000000000", // they have fixed it for filled-amount
1130
+ // 'field-cash-amount': "0.000999788700000000", // they have fixed it for filled-cash-amount
1131
+ // 'field-fees': "0.000058200000000000", // they have fixed it for filled-fees
1132
+ // 'finished-at': 1545831584181,
1133
+ // source: "spot-api",
1134
+ // state: "filled",
1135
+ // 'canceled-at': 0 }
1136
+ //
1137
+ const id = this.safeString (order, 'id');
1138
+ let side = undefined;
1139
+ let type = undefined;
1140
+ const status = this.parseOrderStatus (this.safeString (order, 'state'));
1141
+ const orderType = this.safeString (order, 'type');
1142
+ if (orderType !== undefined) {
1143
+ const parts = orderType.split ('-');
1144
+ side = this.safeString (parts, 0);
1145
+ type = this.safeString (parts, 1);
1146
+ }
1147
+ const marketId = this.safeString (order, 'symbol');
1148
+ market = this.safeMarket (marketId, market);
1149
+ const timestamp = this.safeInteger (order, 'created-at');
1150
+ const clientOrderId = this.safeString (order, 'client-order-id');
1151
+ const filledString = this.safeString2 (order, 'filled-amount', 'field-amount'); // typo in their API, filled amount
1152
+ const priceString = this.safeString (order, 'price');
1153
+ const costString = this.safeString2 (order, 'filled-cash-amount', 'field-cash-amount'); // same typo
1154
+ let amountString = this.safeString (order, 'amount');
1155
+ if (orderType === 'buy-market') {
1156
+ amountString = undefined;
1157
+ }
1158
+ const feeCostString = this.safeString2 (order, 'filled-fees', 'field-fees'); // typo in their API, filled fees
1159
+ let fee = undefined;
1160
+ if (feeCostString !== undefined) {
1161
+ const feeCurrency = (side === 'sell') ? market['quote'] : market['base'];
1162
+ fee = {
1163
+ 'cost': feeCostString,
1164
+ 'currency': feeCurrency,
1165
+ };
1166
+ }
1167
+ return this.safeOrder ({
1168
+ 'info': order,
1169
+ 'id': id,
1170
+ 'clientOrderId': clientOrderId,
1171
+ 'timestamp': timestamp,
1172
+ 'datetime': this.iso8601 (timestamp),
1173
+ 'lastTradeTimestamp': undefined,
1174
+ 'symbol': market['symbol'],
1175
+ 'type': type,
1176
+ 'timeInForce': undefined,
1177
+ 'postOnly': undefined,
1178
+ 'side': side,
1179
+ 'price': priceString,
1180
+ 'stopPrice': undefined,
1181
+ 'average': undefined,
1182
+ 'cost': costString,
1183
+ 'amount': amountString,
1184
+ 'filled': filledString,
1185
+ 'remaining': undefined,
1186
+ 'status': status,
1187
+ 'fee': fee,
1188
+ 'trades': undefined,
1189
+ }, market);
1190
+ }
1191
+
1192
+ async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
1193
+ await this.loadMarkets ();
1194
+ await this.loadAccounts ();
1195
+ const market = this.market (symbol);
1196
+ const request = {
1197
+ 'account-id': this.accounts[0]['id'],
1198
+ 'symbol': market['id'],
1199
+ 'type': side + '-' + type,
1200
+ };
1201
+ const clientOrderId = this.safeString2 (params, 'clientOrderId', 'client-order-id'); // must be 64 chars max and unique within 24 hours
1202
+ if (clientOrderId === undefined) {
1203
+ const broker = this.safeValue (this.options, 'broker', {});
1204
+ const brokerId = this.safeString (broker, 'id');
1205
+ request['client-order-id'] = brokerId + this.uuid ();
1206
+ } else {
1207
+ request['client-order-id'] = clientOrderId;
1208
+ }
1209
+ params = this.omit (params, [ 'clientOrderId', 'client-order-id' ]);
1210
+ if ((type === 'market') && (side === 'buy')) {
1211
+ if (this.options['createMarketBuyOrderRequiresPrice']) {
1212
+ if (price === undefined) {
1213
+ throw new InvalidOrder (this.id + " market buy order requires price argument to calculate cost (total amount of quote currency to spend for buying, amount * price). To switch off this warning exception and specify cost in the amount argument, set .options['createMarketBuyOrderRequiresPrice'] = false. Make sure you know what you're doing.");
1214
+ } else {
1215
+ // despite that cost = amount * price is in quote currency and should have quote precision
1216
+ // the exchange API requires the cost supplied in 'amount' to be of base precision
1217
+ // more about it here:
1218
+ // https://github.com/ccxt/ccxt/pull/4395
1219
+ // https://github.com/ccxt/ccxt/issues/7611
1220
+ // we use amountToPrecision here because the exchange requires cost in base precision
1221
+ request['amount'] = this.costToPrecision (symbol, parseFloat (amount) * parseFloat (price));
1222
+ }
1223
+ } else {
1224
+ request['amount'] = this.costToPrecision (symbol, amount);
1225
+ }
1226
+ } else {
1227
+ request['amount'] = this.amountToPrecision (symbol, amount);
1228
+ }
1229
+ if (type === 'limit' || type === 'ioc' || type === 'limit-maker' || type === 'stop-limit' || type === 'stop-limit-fok') {
1230
+ request['price'] = this.priceToPrecision (symbol, price);
1231
+ }
1232
+ const method = this.options['createOrderMethod'];
1233
+ const response = await this[method] (this.extend (request, params));
1234
+ const timestamp = this.milliseconds ();
1235
+ const id = this.safeString (response, 'data');
1236
+ return {
1237
+ 'info': response,
1238
+ 'id': id,
1239
+ 'timestamp': timestamp,
1240
+ 'datetime': this.iso8601 (timestamp),
1241
+ 'lastTradeTimestamp': undefined,
1242
+ 'status': undefined,
1243
+ 'symbol': symbol,
1244
+ 'type': type,
1245
+ 'side': side,
1246
+ 'price': price,
1247
+ 'amount': amount,
1248
+ 'filled': undefined,
1249
+ 'remaining': undefined,
1250
+ 'cost': undefined,
1251
+ 'trades': undefined,
1252
+ 'fee': undefined,
1253
+ 'clientOrderId': undefined,
1254
+ 'average': undefined,
1255
+ };
1256
+ }
1257
+
1258
+ async cancelOrder (id, symbol = undefined, params = {}) {
1259
+ const response = await this.privatePostOrderOrdersIdSubmitcancel ({ 'id': id });
1260
+ //
1261
+ // {
1262
+ // 'status': 'ok',
1263
+ // 'data': '10138899000',
1264
+ // }
1265
+ //
1266
+ return this.extend (this.parseOrder (response), {
1267
+ 'id': id,
1268
+ 'status': 'canceled',
1269
+ });
1270
+ }
1271
+
1272
+ async cancelOrders (ids, symbol = undefined, params = {}) {
1273
+ await this.loadMarkets ();
1274
+ const clientOrderIds = this.safeValue2 (params, 'clientOrderIds', 'client-order-ids');
1275
+ params = this.omit (params, [ 'clientOrderIds', 'client-order-ids' ]);
1276
+ const request = {};
1277
+ if (clientOrderIds === undefined) {
1278
+ request['order-ids'] = ids;
1279
+ } else {
1280
+ request['client-order-ids'] = clientOrderIds;
1281
+ }
1282
+ const response = await this.privatePostOrderOrdersBatchcancel (this.extend (request, params));
1283
+ //
1284
+ // {
1285
+ // "status": "ok",
1286
+ // "data": {
1287
+ // "success": [
1288
+ // "5983466"
1289
+ // ],
1290
+ // "failed": [
1291
+ // {
1292
+ // "err-msg": "Incorrect order state",
1293
+ // "order-state": 7,
1294
+ // "order-id": "",
1295
+ // "err-code": "order-orderstate-error",
1296
+ // "client-order-id": "first"
1297
+ // },
1298
+ // {
1299
+ // "err-msg": "Incorrect order state",
1300
+ // "order-state": 7,
1301
+ // "order-id": "",
1302
+ // "err-code": "order-orderstate-error",
1303
+ // "client-order-id": "second"
1304
+ // },
1305
+ // {
1306
+ // "err-msg": "The record is not found.",
1307
+ // "order-id": "",
1308
+ // "err-code": "base-not-found",
1309
+ // "client-order-id": "third"
1310
+ // }
1311
+ // ]
1312
+ // }
1313
+ // }
1314
+ //
1315
+ return response;
1316
+ }
1317
+
1318
+ async cancelAllOrders (symbol = undefined, params = {}) {
1319
+ await this.loadMarkets ();
1320
+ const request = {
1321
+ // 'account-id' string false NA The account id used for this cancel Refer to GET /v1/account/accounts
1322
+ // 'symbol': market['id'], // a list of comma-separated symbols, all symbols by default
1323
+ // 'types' 'string', buy-market, sell-market, buy-limit, sell-limit, buy-ioc, sell-ioc, buy-stop-limit, sell-stop-limit, buy-limit-fok, sell-limit-fok, buy-stop-limit-fok, sell-stop-limit-fok
1324
+ // 'side': 'buy', // or 'sell'
1325
+ // 'size': 100, // the number of orders to cancel 1-100
1326
+ };
1327
+ let market = undefined;
1328
+ if (symbol !== undefined) {
1329
+ market = this.market (symbol);
1330
+ request['symbol'] = market['id'];
1331
+ }
1332
+ const response = await this.privatePostOrderOrdersBatchCancelOpenOrders (this.extend (request, params));
1333
+ //
1334
+ // {
1335
+ // code: 200,
1336
+ // data: {
1337
+ // "success-count": 2,
1338
+ // "failed-count": 0,
1339
+ // "next-id": 5454600
1340
+ // }
1341
+ // }
1342
+ //
1343
+ return response;
1344
+ }
1345
+
1346
+ currencyToPrecision (code, fee) {
1347
+ return this.decimalToPrecision (fee, 0, this.currencies[code]['precision']);
1348
+ }
1349
+
1350
+ safeNetwork (networkId) {
1351
+ const lastCharacterIndex = networkId.length - 1;
1352
+ const lastCharacter = networkId[lastCharacterIndex];
1353
+ if (lastCharacter === '1') {
1354
+ networkId = networkId.slice (0, lastCharacterIndex);
1355
+ }
1356
+ const networksById = {};
1357
+ return this.safeString (networksById, networkId, networkId);
1358
+ }
1359
+
1360
+ parseDepositAddress (depositAddress, currency = undefined) {
1361
+ //
1362
+ // {
1363
+ // currency: "usdt",
1364
+ // address: "0xf7292eb9ba7bc50358e27f0e025a4d225a64127b",
1365
+ // addressTag: "",
1366
+ // chain: "usdterc20", // trc20usdt, hrc20usdt, usdt, algousdt
1367
+ // }
1368
+ //
1369
+ const address = this.safeString (depositAddress, 'address');
1370
+ let tag = this.safeString (depositAddress, 'addressTag');
1371
+ if (tag === '') {
1372
+ tag = undefined;
1373
+ }
1374
+ const currencyId = this.safeString (depositAddress, 'currency');
1375
+ currency = this.safeCurrency (currencyId, currency);
1376
+ const code = this.safeCurrencyCode (currencyId, currency);
1377
+ const networkId = this.safeString (depositAddress, 'chain');
1378
+ const networks = this.safeValue (currency, 'networks', {});
1379
+ const networksById = this.indexBy (networks, 'id');
1380
+ const networkValue = this.safeValue (networksById, networkId, networkId);
1381
+ const network = this.safeString (networkValue, 'network');
1382
+ this.checkAddress (address);
1383
+ return {
1384
+ 'currency': code,
1385
+ 'address': address,
1386
+ 'tag': tag,
1387
+ 'network': network,
1388
+ 'info': depositAddress,
1389
+ };
1390
+ }
1391
+
1392
+ async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) {
1393
+ if (limit === undefined || limit > 100) {
1394
+ limit = 100;
1395
+ }
1396
+ await this.loadMarkets ();
1397
+ let currency = undefined;
1398
+ if (code !== undefined) {
1399
+ currency = this.currency (code);
1400
+ }
1401
+ const request = {
1402
+ 'type': 'deposit',
1403
+ 'from': 0, // From 'id' ... if you want to get results after a particular transaction id, pass the id in params.from
1404
+ };
1405
+ if (currency !== undefined) {
1406
+ request['currency'] = currency['id'];
1407
+ }
1408
+ if (limit !== undefined) {
1409
+ request['size'] = limit; // max 100
1410
+ }
1411
+ const response = await this.privateGetQueryDepositWithdraw (this.extend (request, params));
1412
+ // return response
1413
+ return this.parseTransactions (response['data'], currency, since, limit);
1414
+ }
1415
+
1416
+ async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) {
1417
+ if (limit === undefined || limit > 100) {
1418
+ limit = 100;
1419
+ }
1420
+ await this.loadMarkets ();
1421
+ let currency = undefined;
1422
+ if (code !== undefined) {
1423
+ currency = this.currency (code);
1424
+ }
1425
+ const request = {
1426
+ 'type': 'withdraw',
1427
+ 'from': 0, // From 'id' ... if you want to get results after a particular transaction id, pass the id in params.from
1428
+ };
1429
+ if (currency !== undefined) {
1430
+ request['currency'] = currency['id'];
1431
+ }
1432
+ if (limit !== undefined) {
1433
+ request['size'] = limit; // max 100
1434
+ }
1435
+ const response = await this.privateGetQueryDepositWithdraw (this.extend (request, params));
1436
+ // return response
1437
+ return this.parseTransactions (response['data'], currency, since, limit);
1438
+ }
1439
+
1440
+ parseTransaction (transaction, currency = undefined) {
1441
+ //
1442
+ // fetchDeposits
1443
+ //
1444
+ // {
1445
+ // 'id': 8211029,
1446
+ // 'type': 'deposit',
1447
+ // 'currency': 'eth',
1448
+ // 'chain': 'eth',
1449
+ // 'tx-hash': 'bd315....',
1450
+ // 'amount': 0.81162421,
1451
+ // 'address': '4b8b....',
1452
+ // 'address-tag': '',
1453
+ // 'fee': 0,
1454
+ // 'state': 'safe',
1455
+ // 'created-at': 1542180380965,
1456
+ // 'updated-at': 1542180788077
1457
+ // }
1458
+ //
1459
+ // fetchWithdrawals
1460
+ //
1461
+ // {
1462
+ // 'id': 6908275,
1463
+ // 'type': 'withdraw',
1464
+ // 'currency': 'btc',
1465
+ // 'chain': 'btc',
1466
+ // 'tx-hash': 'c1a1a....',
1467
+ // 'amount': 0.80257005,
1468
+ // 'address': '1QR....',
1469
+ // 'address-tag': '',
1470
+ // 'fee': 0.0005,
1471
+ // 'state': 'confirmed',
1472
+ // 'created-at': 1552107295685,
1473
+ // 'updated-at': 1552108032859
1474
+ // }
1475
+ //
1476
+ const timestamp = this.safeInteger (transaction, 'created-at');
1477
+ const updated = this.safeInteger (transaction, 'updated-at');
1478
+ const code = this.safeCurrencyCode (this.safeString (transaction, 'currency'));
1479
+ let type = this.safeString (transaction, 'type');
1480
+ if (type === 'withdraw') {
1481
+ type = 'withdrawal';
1482
+ }
1483
+ const status = this.parseTransactionStatus (this.safeString (transaction, 'state'));
1484
+ const tag = this.safeString (transaction, 'address-tag');
1485
+ let feeCost = this.safeNumber (transaction, 'fee');
1486
+ if (feeCost !== undefined) {
1487
+ feeCost = Math.abs (feeCost);
1488
+ }
1489
+ const address = this.safeString (transaction, 'address');
1490
+ const network = this.safeStringUpper (transaction, 'chain');
1491
+ return {
1492
+ 'info': transaction,
1493
+ 'id': this.safeString2 (transaction, 'id', 'data'),
1494
+ 'txid': this.safeString (transaction, 'tx-hash'),
1495
+ 'timestamp': timestamp,
1496
+ 'datetime': this.iso8601 (timestamp),
1497
+ 'network': network,
1498
+ 'address': address,
1499
+ 'addressTo': undefined,
1500
+ 'addressFrom': undefined,
1501
+ 'tag': tag,
1502
+ 'tagTo': undefined,
1503
+ 'tagFrom': undefined,
1504
+ 'type': type,
1505
+ 'amount': this.safeNumber (transaction, 'amount'),
1506
+ 'currency': code,
1507
+ 'status': status,
1508
+ 'updated': updated,
1509
+ 'fee': {
1510
+ 'currency': code,
1511
+ 'cost': feeCost,
1512
+ 'rate': undefined,
1513
+ },
1514
+ };
1515
+ }
1516
+
1517
+ parseTransactionStatus (status) {
1518
+ const statuses = {
1519
+ // deposit statuses
1520
+ 'unknown': 'failed',
1521
+ 'confirming': 'pending',
1522
+ 'confirmed': 'ok',
1523
+ 'safe': 'ok',
1524
+ 'orphan': 'failed',
1525
+ // withdrawal statuses
1526
+ 'submitted': 'pending',
1527
+ 'canceled': 'canceled',
1528
+ 'reexamine': 'pending',
1529
+ 'reject': 'failed',
1530
+ 'pass': 'pending',
1531
+ 'wallet-reject': 'failed',
1532
+ // 'confirmed': 'ok', // present in deposit statuses
1533
+ 'confirm-error': 'failed',
1534
+ 'repealed': 'failed',
1535
+ 'wallet-transfer': 'pending',
1536
+ 'pre-transfer': 'pending',
1537
+ };
1538
+ return this.safeString (statuses, status, status);
1539
+ }
1540
+
1541
+ async withdraw (code, amount, address, tag = undefined, params = {}) {
1542
+ [ tag, params ] = this.handleWithdrawTagAndParams (tag, params);
1543
+ await this.loadMarkets ();
1544
+ this.checkAddress (address);
1545
+ const currency = this.currency (code);
1546
+ const request = {
1547
+ 'address': address, // only supports existing addresses in your withdraw address list
1548
+ 'amount': amount,
1549
+ 'currency': currency['id'].toLowerCase (),
1550
+ };
1551
+ if (tag !== undefined) {
1552
+ request['addr-tag'] = tag; // only for XRP?
1553
+ }
1554
+ const networks = this.safeValue (this.options, 'networks', {});
1555
+ let network = this.safeStringUpper (params, 'network'); // this line allows the user to specify either ERC20 or ETH
1556
+ network = this.safeStringLower (networks, network, network); // handle ETH>ERC20 alias
1557
+ if (network !== undefined) {
1558
+ // possible chains - usdterc20, trc20usdt, hrc20usdt, usdt, algousdt
1559
+ if (network === 'erc20') {
1560
+ request['chain'] = currency['id'] + network;
1561
+ } else {
1562
+ request['chain'] = network + currency['id'];
1563
+ }
1564
+ params = this.omit (params, 'network');
1565
+ }
1566
+ const response = await this.privatePostDwWithdrawApiCreate (this.extend (request, params));
1567
+ return this.parseTransaction (response, currency);
1568
+ }
1569
+
1570
+ sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
1571
+ let url = '/';
1572
+ if (api === 'market') {
1573
+ url += api;
1574
+ } else if ((api === 'public') || (api === 'private')) {
1575
+ url += this.version;
1576
+ } else if ((api === 'v2Public') || (api === 'v2Private')) {
1577
+ url += 'v2';
1578
+ }
1579
+ url += '/' + this.implodeParams (path, params);
1580
+ const query = this.omit (params, this.extractParams (path));
1581
+ if (api === 'private' || api === 'v2Private') {
1582
+ this.checkRequiredCredentials ();
1583
+ const timestamp = this.ymdhms (this.milliseconds (), 'T');
1584
+ let request = {
1585
+ 'SignatureMethod': 'HmacSHA256',
1586
+ 'SignatureVersion': '2',
1587
+ 'AccessKeyId': this.apiKey,
1588
+ 'Timestamp': timestamp,
1589
+ };
1590
+ if (method !== 'POST') {
1591
+ request = this.extend (request, query);
1592
+ }
1593
+ request = this.keysort (request);
1594
+ let auth = this.urlencode (request);
1595
+ // unfortunately, PHP demands double quotes for the escaped newline symbol
1596
+ // eslint-disable-next-line quotes
1597
+ const payload = [ method, this.hostname, url, auth ].join ("\n");
1598
+ const signature = this.hmac (this.encode (payload), this.encode (this.secret), 'sha256', 'base64');
1599
+ auth += '&' + this.urlencode ({ 'Signature': signature });
1600
+ url += '?' + auth;
1601
+ if (method === 'POST') {
1602
+ body = this.json (query);
1603
+ headers = {
1604
+ 'Content-Type': 'application/json',
1605
+ };
1606
+ } else {
1607
+ headers = {
1608
+ 'Content-Type': 'application/x-www-form-urlencoded',
1609
+ };
1610
+ }
1611
+ } else {
1612
+ if (Object.keys (params).length) {
1613
+ url += '?' + this.urlencode (params);
1614
+ }
1615
+ }
1616
+ url = this.implodeParams (this.urls['api'][api], {
1617
+ 'hostname': this.hostname,
1618
+ }) + url;
1619
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
1620
+ }
1621
+
1622
+ calculateRateLimiterCost (api, method, path, params, config = {}, context = {}) {
1623
+ return this.safeInteger (config, 'cost', 1);
1624
+ }
1625
+
1626
+ handleErrors (httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
1627
+ if (response === undefined) {
1628
+ return; // fallback to default error handler
1629
+ }
1630
+ if ('status' in response) {
1631
+ //
1632
+ // {"status":"error","err-code":"order-limitorder-amount-min-error","err-msg":"limit order amount error, min: `0.001`","data":null}
1633
+ //
1634
+ const status = this.safeString (response, 'status');
1635
+ if (status === 'error') {
1636
+ const code = this.safeString (response, 'err-code');
1637
+ const feedback = this.id + ' ' + body;
1638
+ this.throwBroadlyMatchedException (this.exceptions['broad'], body, feedback);
1639
+ this.throwExactlyMatchedException (this.exceptions['exact'], code, feedback);
1640
+ const message = this.safeString (response, 'err-msg');
1641
+ this.throwExactlyMatchedException (this.exceptions['exact'], message, feedback);
1642
+ throw new ExchangeError (feedback);
1643
+ }
1644
+ }
1645
+ }
1646
+ };