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/timex.js ADDED
@@ -0,0 +1,1283 @@
1
+ 'use strict';
2
+
3
+ const Exchange = require ('./base/Exchange');
4
+ const { ExchangeError, PermissionDenied, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, RateLimitExceeded, NotSupported, BadRequest, AuthenticationError } = require ('./base/errors');
5
+ const Precise = require ('./base/Precise');
6
+
7
+ module.exports = class timex extends Exchange {
8
+ describe () {
9
+ return this.deepExtend (super.describe (), {
10
+ 'id': 'timex',
11
+ 'name': 'TimeX',
12
+ 'countries': [ 'AU' ],
13
+ 'version': 'v1',
14
+ 'rateLimit': 1500,
15
+ 'has': {
16
+ 'CORS': undefined,
17
+ 'spot': true,
18
+ 'margin': false,
19
+ 'swap': false,
20
+ 'future': false,
21
+ 'option': false,
22
+ 'addMargin': false,
23
+ 'cancelOrder': true,
24
+ 'cancelOrders': true,
25
+ 'createOrder': true,
26
+ 'createReduceOnlyOrder': false,
27
+ 'editOrder': true,
28
+ 'fetchBalance': true,
29
+ 'fetchBorrowRate': false,
30
+ 'fetchBorrowRateHistories': false,
31
+ 'fetchBorrowRateHistory': false,
32
+ 'fetchBorrowRates': false,
33
+ 'fetchBorrowRatesPerSymbol': false,
34
+ 'fetchClosedOrders': true,
35
+ 'fetchCurrencies': true,
36
+ 'fetchFundingHistory': false,
37
+ 'fetchFundingRate': false,
38
+ 'fetchFundingRateHistory': false,
39
+ 'fetchFundingRates': false,
40
+ 'fetchIndexOHLCV': false,
41
+ 'fetchLeverage': false,
42
+ 'fetchLeverageTiers': false,
43
+ 'fetchMarkets': true,
44
+ 'fetchMarkOHLCV': false,
45
+ 'fetchMyTrades': true,
46
+ 'fetchOHLCV': true,
47
+ 'fetchOpenOrders': true,
48
+ 'fetchOrder': true,
49
+ 'fetchOrderBook': true,
50
+ 'fetchPosition': false,
51
+ 'fetchPositions': false,
52
+ 'fetchPositionsRisk': false,
53
+ 'fetchPremiumIndexOHLCV': false,
54
+ 'fetchTicker': true,
55
+ 'fetchTickers': true,
56
+ 'fetchTrades': true,
57
+ 'fetchTradingFee': true, // maker fee only
58
+ 'reduceMargin': false,
59
+ 'setLeverage': false,
60
+ 'setMarginMode': false,
61
+ 'setPositionMode': false,
62
+ },
63
+ 'timeframes': {
64
+ '1m': 'I1',
65
+ '5m': 'I5',
66
+ '15m': 'I15',
67
+ '30m': 'I30',
68
+ '1h': 'H1',
69
+ '2h': 'H2',
70
+ '4h': 'H4',
71
+ '6h': 'H6',
72
+ '12h': 'H12',
73
+ '1d': 'D1',
74
+ '1w': 'W1',
75
+ },
76
+ 'urls': {
77
+ 'logo': 'https://user-images.githubusercontent.com/1294454/70423869-6839ab00-1a7f-11ea-8f94-13ae72c31115.jpg',
78
+ 'api': 'https://plasma-relay-backend.timex.io',
79
+ 'www': 'https://timex.io',
80
+ 'doc': 'https://docs.timex.io',
81
+ 'referral': 'https://timex.io/?refcode=1x27vNkTbP1uwkCck',
82
+ },
83
+ 'api': {
84
+ 'custody': {
85
+ 'get': [
86
+ 'credentials', // Get api key for address
87
+ 'credentials/h/{hash}', // Get api key by hash
88
+ 'credentials/k/{key}', // Get api key by key
89
+ 'credentials/me/address', // Get api key by hash
90
+ 'deposit-addresses', // Get deposit addresses list
91
+ 'deposit-addresses/h/{hash}', // Get deposit address by hash
92
+ ],
93
+ },
94
+ 'history': {
95
+ 'get': [
96
+ 'orders', // Gets historical orders
97
+ 'orders/details', // Gets order details
98
+ 'orders/export/csv', // Export orders to csv
99
+ 'trades', // Gets historical trades
100
+ 'trades/export/csv', // Export trades to csv
101
+ ],
102
+ },
103
+ 'currencies': {
104
+ 'get': [
105
+ 'a/{address}', // Gets currency by address
106
+ 'i/{id}', // Gets currency by id
107
+ 's/{symbol}', // Gets currency by symbol
108
+ ],
109
+ 'post': [
110
+ 'perform', // Creates new currency
111
+ 'prepare', // Prepare creates new currency
112
+ 'remove/perform', // Removes currency by symbol
113
+ 's/{symbol}/remove/prepare', // Prepare remove currency by symbol
114
+ 's/{symbol}/update/perform', // Prepare update currency by symbol
115
+ 's/{symbol}/update/prepare', // Prepare update currency by symbol
116
+ ],
117
+ },
118
+ 'markets': {
119
+ 'get': [
120
+ 'i/{id}', // Gets market by id
121
+ 's/{symbol}', // Gets market by symbol
122
+ ],
123
+ 'post': [
124
+ 'perform', // Creates new market
125
+ 'prepare', // Prepare creates new market
126
+ 'remove/perform', // Removes market by symbol
127
+ 's/{symbol}/remove/prepare', // Prepare remove market by symbol
128
+ 's/{symbol}/update/perform', // Prepare update market by symbol
129
+ 's/{symbol}/update/prepare', // Prepare update market by symbol
130
+ ],
131
+ },
132
+ 'public': {
133
+ 'get': [
134
+ 'candles', // Gets candles
135
+ 'currencies', // Gets all the currencies
136
+ 'markets', // Gets all the markets
137
+ 'orderbook', // Gets orderbook
138
+ 'orderbook/raw', // Gets raw orderbook
139
+ 'orderbook/v2', // Gets orderbook v2
140
+ 'tickers', // Gets all the tickers
141
+ 'trades', // Gets trades
142
+ ],
143
+ },
144
+ 'statistics': {
145
+ 'get': [
146
+ 'address', // calculateAddressStatistics
147
+ ],
148
+ },
149
+ 'trading': {
150
+ 'get': [
151
+ 'balances', // Get trading balances for all (or selected) currencies
152
+ 'fees', // Get trading fee rates for all (or selected) markets
153
+ 'orders', // Gets open orders
154
+ ],
155
+ 'post': [
156
+ 'orders', // Create new order
157
+ 'orders/json', // Create orders
158
+ ],
159
+ 'put': [
160
+ 'orders', // Cancel or update orders
161
+ 'orders/json', // Update orders
162
+ ],
163
+ 'delete': [
164
+ 'orders', // Delete orders
165
+ 'orders/json', // Delete orders
166
+ ],
167
+ },
168
+ 'tradingview': {
169
+ 'get': [
170
+ 'config', // Gets config
171
+ 'history', // Gets history
172
+ 'symbol_info', // Gets symbol info
173
+ 'time', // Gets time
174
+ ],
175
+ },
176
+ },
177
+ 'exceptions': {
178
+ 'exact': {
179
+ '0': ExchangeError,
180
+ '1': NotSupported,
181
+ '4000': BadRequest,
182
+ '4001': BadRequest,
183
+ '4002': InsufficientFunds,
184
+ '4003': AuthenticationError,
185
+ '4004': AuthenticationError,
186
+ '4005': BadRequest,
187
+ '4006': BadRequest,
188
+ '4007': BadRequest,
189
+ '4300': PermissionDenied,
190
+ '4100': AuthenticationError,
191
+ '4400': OrderNotFound,
192
+ '5001': InvalidOrder,
193
+ '5002': ExchangeError,
194
+ '400': BadRequest,
195
+ '401': AuthenticationError,
196
+ '403': PermissionDenied,
197
+ '404': OrderNotFound,
198
+ '429': RateLimitExceeded,
199
+ '500': ExchangeError,
200
+ '503': ExchangeNotAvailable,
201
+ },
202
+ 'broad': {
203
+ 'Insufficient': InsufficientFunds,
204
+ },
205
+ },
206
+ 'options': {
207
+ 'expireIn': 31536000, // 365 × 24 × 60 × 60
208
+ 'fetchTickers': {
209
+ 'period': '1d',
210
+ },
211
+ 'fetchTrades': {
212
+ 'sort': 'timestamp,asc',
213
+ },
214
+ 'fetchMyTrades': {
215
+ 'sort': 'timestamp,asc',
216
+ },
217
+ 'fetchOpenOrders': {
218
+ 'sort': 'createdAt,asc',
219
+ },
220
+ 'fetchClosedOrders': {
221
+ 'sort': 'createdAt,asc',
222
+ },
223
+ 'defaultSort': 'timestamp,asc',
224
+ 'defaultSortOrders': 'createdAt,asc',
225
+ },
226
+ });
227
+ }
228
+
229
+ async fetchMarkets (params = {}) {
230
+ const response = await this.publicGetMarkets (params);
231
+ //
232
+ // [
233
+ // {
234
+ // "symbol": "ETHBTC",
235
+ // "name": "ETH/BTC",
236
+ // "baseCurrency": "ETH",
237
+ // "baseTokenAddress": "0x45932db54b38af1f5a57136302eeba66a5975c15",
238
+ // "quoteCurrency": "BTC",
239
+ // "quoteTokenAddress": "0x8370fbc6ddec1e18b4e41e72ed943e238458487c",
240
+ // "feeCurrency": "BTC",
241
+ // "feeTokenAddress": "0x8370fbc6ddec1e18b4e41e72ed943e238458487c",
242
+ // "quantityIncrement": "0.0000001",
243
+ // "takerFee": "0.005",
244
+ // "makerFee": "0.0025",
245
+ // "tickSize": "0.00000001",
246
+ // "baseMinSize": "0.0001",
247
+ // "quoteMinSize": "0.00001",
248
+ // "locked": false
249
+ // }
250
+ // ]
251
+ //
252
+ const result = [];
253
+ for (let i = 0; i < response.length; i++) {
254
+ result.push (this.parseMarket (response[i]));
255
+ }
256
+ return result;
257
+ }
258
+
259
+ async fetchCurrencies (params = {}) {
260
+ const response = await this.publicGetCurrencies (params);
261
+ //
262
+ // [
263
+ // {
264
+ // "symbol": "BTC",
265
+ // "name": "Bitcoin",
266
+ // "address": "0x8370fbc6ddec1e18b4e41e72ed943e238458487c",
267
+ // "icon": "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjAiIGhlaWdodD0iNjAiIHZpZXdCb3g9IjAgMCA2MCA2MCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggb3BhY2l0eT0iMC41IiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTMwIDUzQzQyLjcwMjUgNTMgNTMgNDIuNzAyNSA1MyAzMEM1MyAxNy4yOTc1IDQyLjcwMjUgNyAzMCA3QzE3LjI5NzUgNyA3IDE3LjI5NzUgNyAzMEM3IDQyLjcwMjUgMTcuMjk3NSA1MyAzMCA1M1pNMzAgNTVDNDMuODA3MSA1NSA1NSA0My44MDcxIDU1IDMwQzU1IDE2LjE5MjkgNDMuODA3MSA1IDMwIDVDMTYuMTkyOSA1IDUgMTYuMTkyOSA1IDMwQzUgNDMuODA3MSAxNi4xOTI5IDU1IDMwIDU1WiIvPgo8cGF0aCBkPSJNNDAuOTQyNSAyNi42NTg1QzQxLjQwMDMgMjMuNjExMyAzOS4wNzA1IDIxLjk3MzIgMzUuODg0OCAyMC44ODA0TDM2LjkxODIgMTYuNzUyNkwzNC4zOTUxIDE2LjEyNjRMMzMuMzg5IDIwLjE0NTVDMzIuNzI1OCAxOS45ODA5IDMyLjA0NDUgMTkuODI1NiAzMS4zNjc1IDE5LjY3MTdMMzIuMzgwOCAxNS42MjYyTDI5Ljg1OTEgMTVMMjguODI1IDE5LjEyNjRDMjguMjc2IDE5LjAwMTkgMjcuNzM3IDE4Ljg3ODggMjcuMjEzOSAxOC43NDkzTDI3LjIxNjggMTguNzM2NEwyMy43MzcyIDE3Ljg3MTJMMjMuMDY2IDIwLjU1NDhDMjMuMDY2IDIwLjU1NDggMjQuOTM4IDIwLjk4MjEgMjQuODk4NSAyMS4wMDg1QzI1LjkyMDQgMjEuMjYyNiAyNi4xMDUgMjEuOTM2IDI2LjA3NDEgMjIuNDY5OUwyNC44OTcgMjcuMTcyNEMyNC45Njc1IDI3LjE5MDMgMjUuMDU4NyAyNy4yMTYgMjUuMTU5MyAyNy4yNTYxQzI1LjA3NTMgMjcuMjM1NCAyNC45ODU0IDI3LjIxMjQgMjQuODkyNyAyNy4xOTAzTDIzLjI0MjggMzMuNzc3OEMyMy4xMTc3IDM0LjA4NjkgMjIuODAwOCAzNC41NTA2IDIyLjA4NjUgMzQuMzc0NkMyMi4xMTE3IDM0LjQxMTEgMjAuMjUyNiAzMy45MTg3IDIwLjI1MjYgMzMuOTE4N0wxOSAzNi43OTQ5TDIyLjI4MzQgMzcuNjFDMjIuODk0MiAzNy43NjI0IDIzLjQ5MjggMzcuOTIyIDI0LjA4MjEgMzguMDcyM0wyMy4wMzggNDIuMjQ3NEwyNS41NTgyIDQyLjg3MzZMMjYuNTkyMyAzOC43NDI5QzI3LjI4MDcgMzguOTI5IDI3Ljk0OSAzOS4xMDA3IDI4LjYwMyAzOS4yNjI0TDI3LjU3MjUgNDMuMzczOEwzMC4wOTU2IDQ0TDMxLjEzOTcgMzkuODMyOEMzNS40NDIyIDQwLjY0MzYgMzguNjc3NCA0MC4zMTY2IDQwLjAzOTIgMzYuNDQxNEM0MS4xMzY1IDMzLjMyMTIgMzkuOTg0NiAzMS41MjEzIDM3LjcyMDkgMzAuMzQ3N0MzOS4zNjk0IDI5Ljk2OTEgNDAuNjExMiAyOC44ODkyIDQwLjk0MjUgMjYuNjU4NVYyNi42NTg1Wk0zNS4xNzc3IDM0LjcwODhDMzQuMzk4IDM3LjgyOSAyOS4xMjI2IDM2LjE0MjIgMjcuNDEyMiAzNS43MTkzTDI4Ljc5NzcgMzAuMTg4MUMzMC41MDgxIDMwLjYxMzIgMzUuOTkyNiAzMS40NTQ4IDM1LjE3NzcgMzQuNzA4OFpNMzUuOTU4MSAyNi42MTM0QzM1LjI0NjcgMjkuNDUxNyAzMC44NTU5IDI4LjAwOTcgMjkuNDMxNiAyNy42NTYxTDMwLjY4NzcgMjIuNjM5NUMzMi4xMTIgMjIuOTkzIDM2LjY5OSAyMy42NTI4IDM1Ljk1ODEgMjYuNjEzNFoiLz4KPC9zdmc+Cg==",
268
+ // "background": "transparent",
269
+ // "fiatSymbol": "BTC",
270
+ // "decimals": 8,
271
+ // "tradeDecimals": 20,
272
+ // "displayDecimals": 4,
273
+ // "crypto": true,
274
+ // "depositEnabled": true,
275
+ // "withdrawalEnabled": true,
276
+ // "transferEnabled": true,
277
+ // "buyEnabled": false,
278
+ // "purchaseEnabled": false,
279
+ // "redeemEnabled": false,
280
+ // "active": true,
281
+ // "withdrawalFee": "50000000000000000",
282
+ // "purchaseCommissions": []
283
+ // },
284
+ // ]
285
+ //
286
+ const result = [];
287
+ for (let i = 0; i < response.length; i++) {
288
+ const currency = response[i];
289
+ result.push (this.parseCurrency (currency));
290
+ }
291
+ return this.indexBy (result, 'code');
292
+ }
293
+
294
+ async fetchTickers (symbols = undefined, params = {}) {
295
+ await this.loadMarkets ();
296
+ const period = this.safeString (this.options['fetchTickers'], 'period', '1d');
297
+ const request = {
298
+ 'period': this.timeframes[period], // I1, I5, I15, I30, H1, H2, H4, H6, H12, D1, W1
299
+ };
300
+ const response = await this.publicGetTickers (this.extend (request, params));
301
+ //
302
+ // [
303
+ // {
304
+ // "ask": 0.017,
305
+ // "bid": 0.016,
306
+ // "high": 0.019,
307
+ // "last": 0.017,
308
+ // "low": 0.015,
309
+ // "market": "TIME/ETH",
310
+ // "open": 0.016,
311
+ // "period": "H1",
312
+ // "timestamp": "2018-12-14T20:50:36.134Z",
313
+ // "volume": 4.57,
314
+ // "volumeQuote": 0.07312
315
+ // }
316
+ // ]
317
+ //
318
+ return this.parseTickers (response, symbols);
319
+ }
320
+
321
+ async fetchTicker (symbol, params = {}) {
322
+ await this.loadMarkets ();
323
+ const market = this.market (symbol);
324
+ const period = this.safeString (this.options['fetchTickers'], 'period', '1d');
325
+ const request = {
326
+ 'market': market['id'],
327
+ 'period': this.timeframes[period], // I1, I5, I15, I30, H1, H2, H4, H6, H12, D1, W1
328
+ };
329
+ const response = await this.publicGetTickers (this.extend (request, params));
330
+ //
331
+ // [
332
+ // {
333
+ // "ask": 0.017,
334
+ // "bid": 0.016,
335
+ // "high": 0.019,
336
+ // "last": 0.017,
337
+ // "low": 0.015,
338
+ // "market": "TIME/ETH",
339
+ // "open": 0.016,
340
+ // "period": "H1",
341
+ // "timestamp": "2018-12-14T20:50:36.134Z",
342
+ // "volume": 4.57,
343
+ // "volumeQuote": 0.07312
344
+ // }
345
+ // ]
346
+ //
347
+ const ticker = this.safeValue (response, 0);
348
+ return this.parseTicker (ticker, market);
349
+ }
350
+
351
+ async fetchOrderBook (symbol, limit = undefined, params = {}) {
352
+ await this.loadMarkets ();
353
+ const market = this.market (symbol);
354
+ const request = {
355
+ 'market': market['id'],
356
+ };
357
+ if (limit !== undefined) {
358
+ request['limit'] = limit;
359
+ }
360
+ const response = await this.publicGetOrderbookV2 (this.extend (request, params));
361
+ //
362
+ // {
363
+ // "timestamp":"2019-12-05T00:21:09.538",
364
+ // "bid":[
365
+ // {
366
+ // "index":"2",
367
+ // "price":"0.02024007",
368
+ // "baseTokenAmount":"0.0096894",
369
+ // "baseTokenCumulativeAmount":"0.0096894",
370
+ // "quoteTokenAmount":"0.000196114134258",
371
+ // "quoteTokenCumulativeAmount":"0.000196114134258"
372
+ // },
373
+ // "ask":[
374
+ // {
375
+ // "index":"-3",
376
+ // "price":"0.02024012",
377
+ // "baseTokenAmount":"0.005",
378
+ // "baseTokenCumulativeAmount":"0.005",
379
+ // "quoteTokenAmount":"0.0001012006",
380
+ // "quoteTokenCumulativeAmount":"0.0001012006"
381
+ // },
382
+ // ]
383
+ // }
384
+ //
385
+ const timestamp = this.parse8601 (this.safeString (response, 'timestamp'));
386
+ return this.parseOrderBook (response, symbol, timestamp, 'bid', 'ask', 'price', 'baseTokenAmount');
387
+ }
388
+
389
+ async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
390
+ await this.loadMarkets ();
391
+ const market = this.market (symbol);
392
+ const options = this.safeValue (this.options, 'fetchTrades', {});
393
+ const defaultSort = this.safeValue (options, 'sort', 'timestamp,asc');
394
+ const sort = this.safeString (params, 'sort', defaultSort);
395
+ const query = this.omit (params, 'sort');
396
+ const request = {
397
+ // 'address': 'string', // trade’s member account (?)
398
+ // 'cursor': 1234, // int64 (?)
399
+ // 'from': this.iso8601 (since),
400
+ 'market': market['id'],
401
+ // 'page': 0, // results page you want to retrieve 0 .. N
402
+ // 'size': limit, // number of records per page, 100 by default
403
+ 'sort': sort, // array[string], sorting criteria in the format "property,asc" or "property,desc", default is ascending
404
+ // 'till': this.iso8601 (this.milliseconds ()),
405
+ };
406
+ if (since !== undefined) {
407
+ request['from'] = this.iso8601 (since);
408
+ }
409
+ if (limit !== undefined) {
410
+ request['size'] = limit; // default is 100
411
+ }
412
+ const response = await this.publicGetTrades (this.extend (request, query));
413
+ //
414
+ // [
415
+ // {
416
+ // "id":1,
417
+ // "timestamp":"2019-06-25T17:01:50.309",
418
+ // "direction":"BUY",
419
+ // "price":"0.027",
420
+ // "quantity":"0.001"
421
+ // }
422
+ // ]
423
+ //
424
+ return this.parseTrades (response, market, since, limit);
425
+ }
426
+
427
+ async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
428
+ await this.loadMarkets ();
429
+ const market = this.market (symbol);
430
+ const request = {
431
+ 'market': market['id'],
432
+ 'period': this.timeframes[timeframe],
433
+ };
434
+ // if since and limit are not specified
435
+ const duration = this.parseTimeframe (timeframe);
436
+ if (since !== undefined) {
437
+ request['from'] = this.iso8601 (since);
438
+ if (limit !== undefined) {
439
+ request['till'] = this.iso8601 (this.sum (since, this.sum (limit, 1) * duration * 1000));
440
+ }
441
+ } else if (limit !== undefined) {
442
+ const now = this.milliseconds ();
443
+ request['till'] = this.iso8601 (now);
444
+ request['from'] = this.iso8601 (now - limit * duration * 1000 - 1);
445
+ } else {
446
+ request['till'] = this.iso8601 (this.milliseconds ());
447
+ }
448
+ const response = await this.publicGetCandles (this.extend (request, params));
449
+ //
450
+ // [
451
+ // {
452
+ // "timestamp":"2019-12-04T23:00:00",
453
+ // "open":"0.02024009",
454
+ // "high":"0.02024009",
455
+ // "low":"0.02024009",
456
+ // "close":"0.02024009",
457
+ // "volume":"0.00008096036",
458
+ // "volumeQuote":"0.004",
459
+ // },
460
+ // ]
461
+ //
462
+ return this.parseOHLCVs (response, market, timeframe, since, limit);
463
+ }
464
+
465
+ parseBalance (response) {
466
+ const result = {
467
+ 'info': response,
468
+ 'timestamp': undefined,
469
+ 'datetime': undefined,
470
+ };
471
+ for (let i = 0; i < response.length; i++) {
472
+ const balance = response[i];
473
+ const currencyId = this.safeString (balance, 'currency');
474
+ const code = this.safeCurrencyCode (currencyId);
475
+ const account = this.account ();
476
+ account['total'] = this.safeString (balance, 'totalBalance');
477
+ account['used'] = this.safeString (balance, 'lockedBalance');
478
+ result[code] = account;
479
+ }
480
+ return this.safeBalance (result);
481
+ }
482
+
483
+ async fetchBalance (params = {}) {
484
+ await this.loadMarkets ();
485
+ const response = await this.tradingGetBalances (params);
486
+ //
487
+ // [
488
+ // {"currency":"BTC","totalBalance":"0","lockedBalance":"0"},
489
+ // {"currency":"AUDT","totalBalance":"0","lockedBalance":"0"},
490
+ // {"currency":"ETH","totalBalance":"0","lockedBalance":"0"},
491
+ // {"currency":"TIME","totalBalance":"0","lockedBalance":"0"},
492
+ // {"currency":"USDT","totalBalance":"0","lockedBalance":"0"}
493
+ // ]
494
+ //
495
+ return this.parseBalance (response);
496
+ }
497
+
498
+ async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
499
+ await this.loadMarkets ();
500
+ const market = this.market (symbol);
501
+ const uppercaseSide = side.toUpperCase ();
502
+ let uppercaseType = type.toUpperCase ();
503
+ const postOnly = this.safeValue (params, 'postOnly', false);
504
+ if (postOnly) {
505
+ uppercaseType = 'POST_ONLY';
506
+ params = this.omit (params, [ 'postOnly' ]);
507
+ }
508
+ const request = {
509
+ 'symbol': market['id'],
510
+ 'quantity': this.amountToPrecision (symbol, amount),
511
+ 'side': uppercaseSide,
512
+ 'orderTypes': uppercaseType,
513
+ // 'clientOrderId': '123',
514
+ // 'expireIn': 1575523308, // in seconds
515
+ // 'expireTime': 1575523308, // unix timestamp
516
+ };
517
+ let query = params;
518
+ if ((uppercaseType === 'LIMIT') || (uppercaseType === 'POST_ONLY')) {
519
+ request['price'] = this.priceToPrecision (symbol, price);
520
+ const defaultExpireIn = this.safeInteger (this.options, 'expireIn');
521
+ const expireTime = this.safeValue (params, 'expireTime');
522
+ const expireIn = this.safeValue (params, 'expireIn', defaultExpireIn);
523
+ if (expireTime !== undefined) {
524
+ request['expireTime'] = expireTime;
525
+ } else if (expireIn !== undefined) {
526
+ request['expireIn'] = expireIn;
527
+ } else {
528
+ throw new InvalidOrder (this.id + ' createOrder() method requires a expireTime or expireIn param for a ' + type + ' order, you can also set the expireIn exchange-wide option');
529
+ }
530
+ query = this.omit (params, [ 'expireTime', 'expireIn' ]);
531
+ } else {
532
+ request['price'] = 0;
533
+ }
534
+ const response = await this.tradingPostOrders (this.extend (request, query));
535
+ //
536
+ // {
537
+ // "orders": [
538
+ // {
539
+ // "cancelledQuantity": "0.3",
540
+ // "clientOrderId": "my-order-1",
541
+ // "createdAt": "1970-01-01T00:00:00",
542
+ // "cursorId": 50,
543
+ // "expireTime": "1970-01-01T00:00:00",
544
+ // "filledQuantity": "0.3",
545
+ // "id": "string",
546
+ // "price": "0.017",
547
+ // "quantity": "0.3",
548
+ // "side": "BUY",
549
+ // "symbol": "TIMEETH",
550
+ // "type": "LIMIT",
551
+ // "updatedAt": "1970-01-01T00:00:00"
552
+ // }
553
+ // ]
554
+ // }
555
+ //
556
+ const orders = this.safeValue (response, 'orders', []);
557
+ const order = this.safeValue (orders, 0, {});
558
+ return this.parseOrder (order, market);
559
+ }
560
+
561
+ async editOrder (id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
562
+ await this.loadMarkets ();
563
+ const market = this.market (symbol);
564
+ const request = {
565
+ 'id': id,
566
+ };
567
+ if (amount !== undefined) {
568
+ request['quantity'] = this.amountToPrecision (symbol, amount);
569
+ }
570
+ if (price !== undefined) {
571
+ request['price'] = this.priceToPrecision (symbol, price);
572
+ }
573
+ const response = await this.tradingPutOrders (this.extend (request, params));
574
+ //
575
+ // {
576
+ // "changedOrders": [
577
+ // {
578
+ // "newOrder": {
579
+ // "cancelledQuantity": "0.3",
580
+ // "clientOrderId": "my-order-1",
581
+ // "createdAt": "1970-01-01T00:00:00",
582
+ // "cursorId": 50,
583
+ // "expireTime": "1970-01-01T00:00:00",
584
+ // "filledQuantity": "0.3",
585
+ // "id": "string",
586
+ // "price": "0.017",
587
+ // "quantity": "0.3",
588
+ // "side": "BUY",
589
+ // "symbol": "TIMEETH",
590
+ // "type": "LIMIT",
591
+ // "updatedAt": "1970-01-01T00:00:00"
592
+ // },
593
+ // "oldId": "string",
594
+ // },
595
+ // ],
596
+ // "unchangedOrders": [ "string" ],
597
+ // }
598
+ //
599
+ if ('unchangedOrders' in response) {
600
+ const orderIds = this.safeValue (response, 'unchangedOrders', []);
601
+ const orderId = this.safeString (orderIds, 0);
602
+ return {
603
+ 'id': orderId,
604
+ 'info': response,
605
+ };
606
+ }
607
+ const orders = this.safeValue (response, 'changedOrders', []);
608
+ const firstOrder = this.safeValue (orders, 0, {});
609
+ const order = this.safeValue (firstOrder, 'newOrder', {});
610
+ return this.parseOrder (order, market);
611
+ }
612
+
613
+ async cancelOrder (id, symbol = undefined, params = {}) {
614
+ await this.loadMarkets ();
615
+ return await this.cancelOrders ([ id ], symbol, params);
616
+ }
617
+
618
+ async cancelOrders (ids, symbol = undefined, params = {}) {
619
+ await this.loadMarkets ();
620
+ const request = {
621
+ 'id': ids,
622
+ };
623
+ const response = await this.tradingDeleteOrders (this.extend (request, params));
624
+ //
625
+ // {
626
+ // "changedOrders": [
627
+ // {
628
+ // "newOrder": {
629
+ // "cancelledQuantity": "0.3",
630
+ // "clientOrderId": "my-order-1",
631
+ // "createdAt": "1970-01-01T00:00:00",
632
+ // "cursorId": 50,
633
+ // "expireTime": "1970-01-01T00:00:00",
634
+ // "filledQuantity": "0.3",
635
+ // "id": "string",
636
+ // "price": "0.017",
637
+ // "quantity": "0.3",
638
+ // "side": "BUY",
639
+ // "symbol": "TIMEETH",
640
+ // "type": "LIMIT",
641
+ // "updatedAt": "1970-01-01T00:00:00"
642
+ // },
643
+ // "oldId": "string",
644
+ // },
645
+ // ],
646
+ // "unchangedOrders": [ "string" ],
647
+ // }
648
+ return response;
649
+ }
650
+
651
+ async fetchOrder (id, symbol = undefined, params = {}) {
652
+ await this.loadMarkets ();
653
+ const request = {
654
+ 'orderHash': id,
655
+ };
656
+ const response = await this.historyGetOrdersDetails (request);
657
+ //
658
+ // {
659
+ // "order": {
660
+ // "cancelledQuantity": "0.3",
661
+ // "clientOrderId": "my-order-1",
662
+ // "createdAt": "1970-01-01T00:00:00",
663
+ // "cursorId": 50,
664
+ // "expireTime": "1970-01-01T00:00:00",
665
+ // "filledQuantity": "0.3",
666
+ // "id": "string",
667
+ // "price": "0.017",
668
+ // "quantity": "0.3",
669
+ // "side": "BUY",
670
+ // "symbol": "TIMEETH",
671
+ // "type": "LIMIT",
672
+ // "updatedAt": "1970-01-01T00:00:00"
673
+ // },
674
+ // "trades": [
675
+ // {
676
+ // "fee": "0.3",
677
+ // "id": 100,
678
+ // "makerOrTaker": "MAKER",
679
+ // "makerOrderId": "string",
680
+ // "price": "0.017",
681
+ // "quantity": "0.3",
682
+ // "side": "BUY",
683
+ // "symbol": "TIMEETH",
684
+ // "takerOrderId": "string",
685
+ // "timestamp": "2019-12-05T07:48:26.310Z"
686
+ // }
687
+ // ]
688
+ // }
689
+ //
690
+ const order = this.safeValue (response, 'order', {});
691
+ const trades = this.safeValue (response, 'trades', []);
692
+ return this.parseOrder (this.extend (order, { 'trades': trades }));
693
+ }
694
+
695
+ async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
696
+ await this.loadMarkets ();
697
+ const options = this.safeValue (this.options, 'fetchOpenOrders', {});
698
+ const defaultSort = this.safeValue (options, 'sort', 'createdAt,asc');
699
+ const sort = this.safeString (params, 'sort', defaultSort);
700
+ const query = this.omit (params, 'sort');
701
+ const request = {
702
+ // 'clientOrderId': '123', // order’s client id list for filter
703
+ // page: 0, // results page you want to retrieve (0 .. N)
704
+ 'sort': sort, // sorting criteria in the format "property,asc" or "property,desc", default order is ascending, multiple sort criteria are supported
705
+ };
706
+ let market = undefined;
707
+ if (symbol !== undefined) {
708
+ market = this.market (symbol);
709
+ request['symbol'] = market['id'];
710
+ }
711
+ if (limit !== undefined) {
712
+ request['size'] = limit;
713
+ }
714
+ const response = await this.tradingGetOrders (this.extend (request, query));
715
+ //
716
+ // {
717
+ // "orders": [
718
+ // {
719
+ // "cancelledQuantity": "0.3",
720
+ // "clientOrderId": "my-order-1",
721
+ // "createdAt": "1970-01-01T00:00:00",
722
+ // "cursorId": 50,
723
+ // "expireTime": "1970-01-01T00:00:00",
724
+ // "filledQuantity": "0.3",
725
+ // "id": "string",
726
+ // "price": "0.017",
727
+ // "quantity": "0.3",
728
+ // "side": "BUY",
729
+ // "symbol": "TIMEETH",
730
+ // "type": "LIMIT",
731
+ // "updatedAt": "1970-01-01T00:00:00"
732
+ // }
733
+ // ]
734
+ // }
735
+ //
736
+ const orders = this.safeValue (response, 'orders', []);
737
+ return this.parseOrders (orders, market, since, limit);
738
+ }
739
+
740
+ async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
741
+ await this.loadMarkets ();
742
+ const options = this.safeValue (this.options, 'fetchClosedOrders', {});
743
+ const defaultSort = this.safeValue (options, 'sort', 'createdAt,asc');
744
+ const sort = this.safeString (params, 'sort', defaultSort);
745
+ const query = this.omit (params, 'sort');
746
+ const request = {
747
+ // 'clientOrderId': '123', // order’s client id list for filter
748
+ // page: 0, // results page you want to retrieve (0 .. N)
749
+ 'sort': sort, // sorting criteria in the format "property,asc" or "property,desc", default order is ascending, multiple sort criteria are supported
750
+ 'side': 'BUY', // or 'SELL'
751
+ // 'till': this.iso8601 (this.milliseconds ()),
752
+ };
753
+ let market = undefined;
754
+ if (symbol !== undefined) {
755
+ market = this.market (symbol);
756
+ request['symbol'] = market['id'];
757
+ }
758
+ if (since !== undefined) {
759
+ request['from'] = this.iso8601 (since);
760
+ }
761
+ if (limit !== undefined) {
762
+ request['size'] = limit;
763
+ }
764
+ const response = await this.historyGetOrders (this.extend (request, query));
765
+ //
766
+ // {
767
+ // "orders": [
768
+ // {
769
+ // "cancelledQuantity": "0.3",
770
+ // "clientOrderId": "my-order-1",
771
+ // "createdAt": "1970-01-01T00:00:00",
772
+ // "cursorId": 50,
773
+ // "expireTime": "1970-01-01T00:00:00",
774
+ // "filledQuantity": "0.3",
775
+ // "id": "string",
776
+ // "price": "0.017",
777
+ // "quantity": "0.3",
778
+ // "side": "BUY",
779
+ // "symbol": "TIMEETH",
780
+ // "type": "LIMIT",
781
+ // "updatedAt": "1970-01-01T00:00:00"
782
+ // }
783
+ // ]
784
+ // }
785
+ //
786
+ const orders = this.safeValue (response, 'orders', []);
787
+ return this.parseOrders (orders, market, since, limit);
788
+ }
789
+
790
+ async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
791
+ await this.loadMarkets ();
792
+ const options = this.safeValue (this.options, 'fetchMyTrades', {});
793
+ const defaultSort = this.safeValue (options, 'sort', 'timestamp,asc');
794
+ const sort = this.safeString (params, 'sort', defaultSort);
795
+ const query = this.omit (params, 'sort');
796
+ const request = {
797
+ // 'cursorId': 123, // int64 (?)
798
+ // 'from': this.iso8601 (since),
799
+ // 'makerOrderId': '1234', // maker order hash
800
+ // 'owner': '...', // owner address (?)
801
+ // 'page': 0, // results page you want to retrieve (0 .. N)
802
+ // 'side': 'BUY', // or 'SELL'
803
+ // 'size': limit,
804
+ 'sort': sort, // sorting criteria in the format "property,asc" or "property,desc", default order is ascending, multiple sort criteria are supported
805
+ // 'symbol': market['id'],
806
+ // 'takerOrderId': '1234',
807
+ // 'till': this.iso8601 (this.milliseconds ()),
808
+ };
809
+ let market = undefined;
810
+ if (symbol !== undefined) {
811
+ market = this.market (symbol);
812
+ request['symbol'] = market['id'];
813
+ }
814
+ if (since !== undefined) {
815
+ request['from'] = this.iso8601 (since);
816
+ }
817
+ if (limit !== undefined) {
818
+ request['size'] = limit;
819
+ }
820
+ const response = await this.historyGetTrades (this.extend (request, query));
821
+ //
822
+ // {
823
+ // "trades": [
824
+ // {
825
+ // "fee": "0.3",
826
+ // "id": 100,
827
+ // "makerOrTaker": "MAKER",
828
+ // "makerOrderId": "string",
829
+ // "price": "0.017",
830
+ // "quantity": "0.3",
831
+ // "side": "BUY",
832
+ // "symbol": "TIMEETH",
833
+ // "takerOrderId": "string",
834
+ // "timestamp": "2019-12-08T04:54:11.171Z"
835
+ // }
836
+ // ]
837
+ // }
838
+ //
839
+ const trades = this.safeValue (response, 'trades', []);
840
+ return this.parseTrades (trades, market, since, limit);
841
+ }
842
+
843
+ parseTradingFee (fee, market = undefined) {
844
+ //
845
+ // {
846
+ // "fee": 0.0075,
847
+ // "market": "ETHBTC"
848
+ // }
849
+ //
850
+ const marketId = this.safeString (fee, 'market');
851
+ const rate = this.safeNumber (fee, 'fee');
852
+ return {
853
+ 'info': fee,
854
+ 'symbol': this.safeSymbol (marketId, market),
855
+ 'maker': rate,
856
+ 'taker': rate,
857
+ };
858
+ }
859
+
860
+ async fetchTradingFee (symbol, params = {}) {
861
+ await this.loadMarkets ();
862
+ const market = this.market (symbol);
863
+ const request = {
864
+ 'markets': market['id'],
865
+ };
866
+ const response = await this.tradingGetFees (this.extend (request, params));
867
+ //
868
+ // [
869
+ // {
870
+ // "fee": 0.0075,
871
+ // "market": "ETHBTC"
872
+ // }
873
+ // ]
874
+ //
875
+ const result = this.safeValue (response, 0, {});
876
+ return this.parseTradingFee (result, market);
877
+ }
878
+
879
+ parseMarket (market) {
880
+ //
881
+ // {
882
+ // "symbol": "ETHBTC",
883
+ // "name": "ETH/BTC",
884
+ // "baseCurrency": "ETH",
885
+ // "baseTokenAddress": "0x45932db54b38af1f5a57136302eeba66a5975c15",
886
+ // "quoteCurrency": "BTC",
887
+ // "quoteTokenAddress": "0x8370fbc6ddec1e18b4e41e72ed943e238458487c",
888
+ // "feeCurrency": "BTC",
889
+ // "feeTokenAddress": "0x8370fbc6ddec1e18b4e41e72ed943e238458487c",
890
+ // "quantityIncrement": "0.0000001",
891
+ // "takerFee": "0.005",
892
+ // "makerFee": "0.0025",
893
+ // "tickSize": "0.00000001",
894
+ // "baseMinSize": "0.0001",
895
+ // "quoteMinSize": "0.00001",
896
+ // "locked": false
897
+ // }
898
+ //
899
+ const locked = this.safeValue (market, 'locked');
900
+ const id = this.safeString (market, 'symbol');
901
+ const baseId = this.safeString (market, 'baseCurrency');
902
+ const quoteId = this.safeString (market, 'quoteCurrency');
903
+ const base = this.safeCurrencyCode (baseId);
904
+ const quote = this.safeCurrencyCode (quoteId);
905
+ const amountIncrement = this.safeString (market, 'quantityIncrement');
906
+ const minBase = this.safeString (market, 'baseMinSize');
907
+ const minAmount = Precise.stringMax (amountIncrement, minBase);
908
+ const priceIncrement = this.safeString (market, 'tickSize');
909
+ const minCost = this.safeString (market, 'quoteMinSize');
910
+ return {
911
+ 'id': id,
912
+ 'symbol': base + '/' + quote,
913
+ 'base': base,
914
+ 'quote': quote,
915
+ 'settle': undefined,
916
+ 'baseId': baseId,
917
+ 'quoteId': quoteId,
918
+ 'settleId': undefined,
919
+ 'type': 'spot',
920
+ 'spot': true,
921
+ 'margin': false,
922
+ 'swap': false,
923
+ 'future': false,
924
+ 'option': false,
925
+ 'active': !locked,
926
+ 'contract': false,
927
+ 'linear': undefined,
928
+ 'inverse': undefined,
929
+ 'taker': this.safeNumber (market, 'takerFee'),
930
+ 'maker': this.safeNumber (market, 'makerFee'),
931
+ 'contractSize': undefined,
932
+ 'expiry': undefined,
933
+ 'expiryDatetime': undefined,
934
+ 'strike': undefined,
935
+ 'optionType': undefined,
936
+ 'precision': {
937
+ 'amount': this.precisionFromString (this.safeString (market, 'quantityIncrement')),
938
+ 'price': this.precisionFromString (this.safeString (market, 'tickSize')),
939
+ },
940
+ 'limits': {
941
+ 'leverage': {
942
+ 'min': undefined,
943
+ 'max': undefined,
944
+ },
945
+ 'amount': {
946
+ 'min': this.parseNumber (minAmount),
947
+ 'max': undefined,
948
+ },
949
+ 'price': {
950
+ 'min': this.parseNumber (priceIncrement),
951
+ 'max': undefined,
952
+ },
953
+ 'cost': {
954
+ 'min': minCost,
955
+ 'max': undefined,
956
+ },
957
+ },
958
+ 'info': market,
959
+ };
960
+ }
961
+
962
+ parseCurrency (currency) {
963
+ //
964
+ // {
965
+ // "symbol": "BTC",
966
+ // "name": "Bitcoin",
967
+ // "address": "0x8370fbc6ddec1e18b4e41e72ed943e238458487c",
968
+ // "icon": "data:image/svg+xml;base64,PHN2ZyB3aWR...mc+Cg==",
969
+ // "background": "transparent",
970
+ // "fiatSymbol": "BTC",
971
+ // "decimals": 8,
972
+ // "tradeDecimals": 20,
973
+ // "displayDecimals": 4,
974
+ // "crypto": true,
975
+ // "depositEnabled": true,
976
+ // "withdrawalEnabled": true,
977
+ // "transferEnabled": true,
978
+ // "buyEnabled": false,
979
+ // "purchaseEnabled": false,
980
+ // "redeemEnabled": false,
981
+ // "active": true,
982
+ // "withdrawalFee": "50000000000000000",
983
+ // "purchaseCommissions": []
984
+ // }
985
+ //
986
+ // https://github.com/ccxt/ccxt/issues/6878
987
+ //
988
+ // {
989
+ // "symbol":"XRP",
990
+ // "name":"Ripple",
991
+ // "address":"0x0dc8882914f3ddeebf4cec6dc20edb99df3def6c",
992
+ // "decimals":6,
993
+ // "tradeDecimals":16,
994
+ // "depositEnabled":true,
995
+ // "withdrawalEnabled":true,
996
+ // "transferEnabled":true,
997
+ // "active":true
998
+ // }
999
+ //
1000
+ const id = this.safeString (currency, 'symbol');
1001
+ const code = this.safeCurrencyCode (id);
1002
+ const name = this.safeString (currency, 'name');
1003
+ const precision = this.safeInteger (currency, 'decimals');
1004
+ const depositEnabled = this.safeValue (currency, 'depositEnabled');
1005
+ const withdrawEnabled = this.safeValue (currency, 'withdrawalEnabled');
1006
+ const isActive = this.safeValue (currency, 'active');
1007
+ const active = depositEnabled && withdrawEnabled && isActive;
1008
+ // const fee = this.safeNumber (currency, 'withdrawalFee');
1009
+ const feeString = this.safeString (currency, 'withdrawalFee');
1010
+ const tradeDecimals = this.safeInteger (currency, 'tradeDecimals');
1011
+ let fee = undefined;
1012
+ if ((feeString !== undefined) && (tradeDecimals !== undefined)) {
1013
+ const feeStringLen = feeString.length;
1014
+ const dotIndex = feeStringLen - tradeDecimals;
1015
+ if (dotIndex > 0) {
1016
+ const whole = feeString.slice (0, dotIndex);
1017
+ const fraction = feeString.slice (-dotIndex);
1018
+ fee = this.parseNumber (whole + '.' + fraction);
1019
+ } else {
1020
+ let fraction = '.';
1021
+ for (let i = 0; i < -dotIndex; i++) {
1022
+ fraction += '0';
1023
+ }
1024
+ fee = this.parseNumber (fraction + feeString);
1025
+ }
1026
+ }
1027
+ return {
1028
+ 'id': code,
1029
+ 'code': code,
1030
+ 'info': currency,
1031
+ 'type': undefined,
1032
+ 'name': name,
1033
+ 'active': active,
1034
+ 'deposit': depositEnabled,
1035
+ 'withdraw': withdrawEnabled,
1036
+ 'fee': fee,
1037
+ 'precision': precision,
1038
+ 'limits': {
1039
+ 'withdraw': { 'min': fee, 'max': undefined },
1040
+ 'amount': { 'min': undefined, 'max': undefined },
1041
+ },
1042
+ };
1043
+ }
1044
+
1045
+ parseTicker (ticker, market = undefined) {
1046
+ //
1047
+ // {
1048
+ // "ask": 0.017,
1049
+ // "bid": 0.016,
1050
+ // "high": 0.019,
1051
+ // "last": 0.017,
1052
+ // "low": 0.015,
1053
+ // "market": "TIME/ETH",
1054
+ // "open": 0.016,
1055
+ // "period": "H1",
1056
+ // "timestamp": "2018-12-14T20:50:36.134Z",
1057
+ // "volume": 4.57,
1058
+ // "volumeQuote": 0.07312
1059
+ // }
1060
+ //
1061
+ const marketId = this.safeString (ticker, 'market');
1062
+ const symbol = this.safeSymbol (marketId, market, '/');
1063
+ const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp'));
1064
+ const last = this.safeString (ticker, 'last');
1065
+ const open = this.safeString (ticker, 'open');
1066
+ return this.safeTicker ({
1067
+ 'symbol': symbol,
1068
+ 'info': ticker,
1069
+ 'timestamp': timestamp,
1070
+ 'datetime': this.iso8601 (timestamp),
1071
+ 'high': this.safeString (ticker, 'high'),
1072
+ 'low': this.safeString (ticker, 'low'),
1073
+ 'bid': this.safeString (ticker, 'bid'),
1074
+ 'bidVolume': undefined,
1075
+ 'ask': this.safeString (ticker, 'ask'),
1076
+ 'askVolume': undefined,
1077
+ 'vwap': undefined,
1078
+ 'open': open,
1079
+ 'close': last,
1080
+ 'last': last,
1081
+ 'previousClose': undefined,
1082
+ 'change': undefined,
1083
+ 'percentage': undefined,
1084
+ 'average': undefined,
1085
+ 'baseVolume': this.safeString (ticker, 'volume'),
1086
+ 'quoteVolume': this.safeString (ticker, 'volumeQuote'),
1087
+ }, market, false);
1088
+ }
1089
+
1090
+ parseTrade (trade, market = undefined) {
1091
+ //
1092
+ // fetchTrades (public)
1093
+ //
1094
+ // {
1095
+ // "id":1,
1096
+ // "timestamp":"2019-06-25T17:01:50.309",
1097
+ // "direction":"BUY",
1098
+ // "price":"0.027",
1099
+ // "quantity":"0.001"
1100
+ // }
1101
+ //
1102
+ // fetchMyTrades, fetchOrder (private)
1103
+ //
1104
+ // {
1105
+ // "id": "7613414",
1106
+ // "makerOrderId": "0x8420af060722f560098f786a2894d4358079b6ea5d14b395969ed77bc87a623a",
1107
+ // "takerOrderId": "0x1235ef158a361815b54c9988b6241c85aedcbc1fe81caf8df8587d5ab0373d1a",
1108
+ // "symbol": "LTCUSDT",
1109
+ // "side": "BUY",
1110
+ // "quantity": "0.2",
1111
+ // "fee": "0.22685",
1112
+ // "feeToken": "USDT",
1113
+ // "price": "226.85",
1114
+ // "makerOrTaker": "TAKER",
1115
+ // "timestamp": "2021-04-09T15:39:45.608"
1116
+ // }
1117
+ //
1118
+ const marketId = this.safeString (trade, 'symbol');
1119
+ const symbol = this.safeSymbol (marketId, market);
1120
+ const timestamp = this.parse8601 (this.safeString (trade, 'timestamp'));
1121
+ const priceString = this.safeString (trade, 'price');
1122
+ const amountString = this.safeString (trade, 'quantity');
1123
+ const price = this.parseNumber (priceString);
1124
+ const amount = this.parseNumber (amountString);
1125
+ const cost = this.parseNumber (Precise.stringMul (priceString, amountString));
1126
+ const id = this.safeString (trade, 'id');
1127
+ const side = this.safeStringLower2 (trade, 'direction', 'side');
1128
+ const takerOrMaker = this.safeStringLower (trade, 'makerOrTaker');
1129
+ let orderId = undefined;
1130
+ if (takerOrMaker !== undefined) {
1131
+ orderId = this.safeString (trade, takerOrMaker + 'OrderId');
1132
+ }
1133
+ let fee = undefined;
1134
+ const feeCost = this.safeNumber (trade, 'fee');
1135
+ const feeCurrency = this.safeCurrencyCode (this.safeString (trade, 'feeToken'));
1136
+ if (feeCost !== undefined) {
1137
+ fee = {
1138
+ 'cost': feeCost,
1139
+ 'currency': feeCurrency,
1140
+ };
1141
+ }
1142
+ return {
1143
+ 'info': trade,
1144
+ 'id': id,
1145
+ 'timestamp': timestamp,
1146
+ 'datetime': this.iso8601 (timestamp),
1147
+ 'symbol': symbol,
1148
+ 'order': orderId,
1149
+ 'type': undefined,
1150
+ 'side': side,
1151
+ 'price': price,
1152
+ 'amount': amount,
1153
+ 'cost': cost,
1154
+ 'takerOrMaker': takerOrMaker,
1155
+ 'fee': fee,
1156
+ };
1157
+ }
1158
+
1159
+ parseOHLCV (ohlcv, market = undefined) {
1160
+ //
1161
+ // {
1162
+ // "timestamp":"2019-12-04T23:00:00",
1163
+ // "open":"0.02024009",
1164
+ // "high":"0.02024009",
1165
+ // "low":"0.02024009",
1166
+ // "close":"0.02024009",
1167
+ // "volume":"0.00008096036",
1168
+ // "volumeQuote":"0.004",
1169
+ // }
1170
+ //
1171
+ return [
1172
+ this.parse8601 (this.safeString (ohlcv, 'timestamp')),
1173
+ this.safeNumber (ohlcv, 'open'),
1174
+ this.safeNumber (ohlcv, 'high'),
1175
+ this.safeNumber (ohlcv, 'low'),
1176
+ this.safeNumber (ohlcv, 'close'),
1177
+ this.safeNumber (ohlcv, 'volume'),
1178
+ ];
1179
+ }
1180
+
1181
+ parseOrder (order, market = undefined) {
1182
+ //
1183
+ // fetchOrder, createOrder, cancelOrder, cancelOrders, fetchOpenOrders, fetchClosedOrders
1184
+ //
1185
+ // {
1186
+ // "cancelledQuantity": "0.3",
1187
+ // "clientOrderId": "my-order-1",
1188
+ // "createdAt": "1970-01-01T00:00:00",
1189
+ // "cursorId": 50,
1190
+ // "expireTime": "1970-01-01T00:00:00",
1191
+ // "filledQuantity": "0.3",
1192
+ // "id": "string",
1193
+ // "price": "0.017",
1194
+ // "quantity": "0.3",
1195
+ // "side": "BUY",
1196
+ // "symbol": "TIMEETH",
1197
+ // "type": "LIMIT",
1198
+ // "updatedAt": "1970-01-01T00:00:00"
1199
+ // "trades": [], // injected from the outside
1200
+ // }
1201
+ //
1202
+ const id = this.safeString (order, 'id');
1203
+ const type = this.safeStringLower (order, 'type');
1204
+ const side = this.safeStringLower (order, 'side');
1205
+ const marketId = this.safeString (order, 'symbol');
1206
+ const symbol = this.safeSymbol (marketId, market);
1207
+ const timestamp = this.parse8601 (this.safeString (order, 'createdAt'));
1208
+ const price = this.safeString (order, 'price');
1209
+ const amount = this.safeString (order, 'quantity');
1210
+ const filled = this.safeString (order, 'filledQuantity');
1211
+ const canceledQuantity = this.omitZero (this.safeString (order, 'cancelledQuantity'));
1212
+ let status = undefined;
1213
+ if (Precise.stringEquals (filled, amount)) {
1214
+ status = 'closed';
1215
+ } else if (canceledQuantity !== undefined) {
1216
+ status = 'canceled';
1217
+ } else {
1218
+ status = 'open';
1219
+ }
1220
+ const rawTrades = this.safeValue (order, 'trades', []);
1221
+ const clientOrderId = this.safeString (order, 'clientOrderId');
1222
+ return this.safeOrder ({
1223
+ 'info': order,
1224
+ 'id': id,
1225
+ 'clientOrderId': clientOrderId,
1226
+ 'timestamp': timestamp,
1227
+ 'datetime': this.iso8601 (timestamp),
1228
+ 'lastTradeTimestamp': undefined,
1229
+ 'symbol': symbol,
1230
+ 'type': type,
1231
+ 'timeInForce': undefined,
1232
+ 'postOnly': undefined,
1233
+ 'side': side,
1234
+ 'price': price,
1235
+ 'stopPrice': undefined,
1236
+ 'amount': amount,
1237
+ 'cost': undefined,
1238
+ 'average': undefined,
1239
+ 'filled': filled,
1240
+ 'remaining': undefined,
1241
+ 'status': status,
1242
+ 'fee': undefined,
1243
+ 'trades': rawTrades,
1244
+ }, market);
1245
+ }
1246
+
1247
+ sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
1248
+ let url = this.urls['api'] + '/' + api + '/' + path;
1249
+ if (Object.keys (params).length) {
1250
+ url += '?' + this.urlencodeWithArrayRepeat (params);
1251
+ }
1252
+ if (api !== 'public') {
1253
+ this.checkRequiredCredentials ();
1254
+ const auth = this.stringToBase64 (this.apiKey + ':' + this.secret);
1255
+ const secret = 'Basic ' + this.decode (auth);
1256
+ headers = { 'authorization': secret };
1257
+ }
1258
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
1259
+ }
1260
+
1261
+ handleErrors (statusCode, statusText, url, method, responseHeaders, responseBody, response, requestHeaders, requestBody) {
1262
+ if (response === undefined) {
1263
+ return;
1264
+ }
1265
+ if (statusCode >= 400) {
1266
+ //
1267
+ // {"error":{"timestamp":"05.12.2019T05:25:43.584+0000","status":"BAD_REQUEST","message":"Insufficient ETH balance. Required: 1, actual: 0.","code":4001}}
1268
+ // {"error":{"timestamp":"05.12.2019T04:03:25.419+0000","status":"FORBIDDEN","message":"Access denied","code":4300}}
1269
+ //
1270
+ const feedback = this.id + ' ' + responseBody;
1271
+ let error = this.safeValue (response, 'error');
1272
+ if (error === undefined) {
1273
+ error = response;
1274
+ }
1275
+ const code = this.safeString2 (error, 'code', 'status');
1276
+ const message = this.safeString2 (error, 'message', 'debugMessage');
1277
+ this.throwBroadlyMatchedException (this.exceptions['broad'], message, feedback);
1278
+ this.throwExactlyMatchedException (this.exceptions['exact'], code, feedback);
1279
+ this.throwExactlyMatchedException (this.exceptions['exact'], message, feedback);
1280
+ throw new ExchangeError (feedback);
1281
+ }
1282
+ }
1283
+ };