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