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/mercado.js ADDED
@@ -0,0 +1,771 @@
1
+ 'use strict';
2
+
3
+ // ---------------------------------------------------------------------------
4
+
5
+ const Exchange = require ('./base/Exchange');
6
+ const { ExchangeError, ArgumentsRequired, InvalidOrder } = require ('./base/errors');
7
+
8
+ // ---------------------------------------------------------------------------
9
+
10
+ module.exports = class mercado extends Exchange {
11
+ describe () {
12
+ return this.deepExtend (super.describe (), {
13
+ 'id': 'mercado',
14
+ 'name': 'Mercado Bitcoin',
15
+ 'countries': [ 'BR' ], // Brazil
16
+ 'rateLimit': 1000,
17
+ 'version': 'v3',
18
+ 'has': {
19
+ 'CORS': true,
20
+ 'spot': true,
21
+ 'margin': false,
22
+ 'swap': false,
23
+ 'future': false,
24
+ 'option': false,
25
+ 'addMargin': false,
26
+ 'cancelOrder': true,
27
+ 'createMarketOrder': true,
28
+ 'createOrder': true,
29
+ 'createReduceOnlyOrder': false,
30
+ 'fetchBalance': true,
31
+ 'fetchBorrowRate': false,
32
+ 'fetchBorrowRateHistory': false,
33
+ 'fetchBorrowRates': false,
34
+ 'fetchBorrowRatesPerSymbol': false,
35
+ 'fetchFundingHistory': false,
36
+ 'fetchFundingRate': false,
37
+ 'fetchFundingRateHistory': false,
38
+ 'fetchFundingRates': false,
39
+ 'fetchIndexOHLCV': false,
40
+ 'fetchLeverage': false,
41
+ 'fetchLeverageTiers': false,
42
+ 'fetchMarkets': true,
43
+ 'fetchMarkOHLCV': false,
44
+ 'fetchMyTrades': 'emulated',
45
+ 'fetchOHLCV': true,
46
+ 'fetchOpenOrders': true,
47
+ 'fetchOrder': true,
48
+ 'fetchOrderBook': true,
49
+ 'fetchOrders': true,
50
+ 'fetchPosition': false,
51
+ 'fetchPositions': false,
52
+ 'fetchPositionsRisk': false,
53
+ 'fetchPremiumIndexOHLCV': false,
54
+ 'fetchTicker': true,
55
+ 'fetchTickers': undefined,
56
+ 'fetchTrades': true,
57
+ 'fetchTradingFee': false,
58
+ 'fetchTradingFees': false,
59
+ 'reduceMargin': false,
60
+ 'setLeverage': false,
61
+ 'setMarginMode': false,
62
+ 'setPositionMode': false,
63
+ 'withdraw': true,
64
+ },
65
+ 'timeframes': {
66
+ '1m': '1m',
67
+ '5m': '5m',
68
+ '15m': '15m',
69
+ '30m': '30m',
70
+ '1h': '1h',
71
+ '6h': '6h',
72
+ '12h': '12h',
73
+ '1d': '1d',
74
+ '3d': '3d',
75
+ '1w': '1w',
76
+ '2w': '2w',
77
+ },
78
+ 'urls': {
79
+ 'logo': 'https://user-images.githubusercontent.com/1294454/27837060-e7c58714-60ea-11e7-9192-f05e86adb83f.jpg',
80
+ 'api': {
81
+ 'public': 'https://www.mercadobitcoin.net/api',
82
+ 'private': 'https://www.mercadobitcoin.net/tapi',
83
+ 'v4Public': 'https://www.mercadobitcoin.com.br/v4',
84
+ },
85
+ 'www': 'https://www.mercadobitcoin.com.br',
86
+ 'doc': [
87
+ 'https://www.mercadobitcoin.com.br/api-doc',
88
+ 'https://www.mercadobitcoin.com.br/trade-api',
89
+ ],
90
+ },
91
+ 'api': {
92
+ 'public': {
93
+ 'get': [
94
+ 'coins',
95
+ '{coin}/orderbook/', // last slash critical
96
+ '{coin}/ticker/',
97
+ '{coin}/trades/',
98
+ '{coin}/trades/{from}/',
99
+ '{coin}/trades/{from}/{to}',
100
+ '{coin}/day-summary/{year}/{month}/{day}/',
101
+ ],
102
+ },
103
+ 'private': {
104
+ 'post': [
105
+ 'cancel_order',
106
+ 'get_account_info',
107
+ 'get_order',
108
+ 'get_withdrawal',
109
+ 'list_system_messages',
110
+ 'list_orders',
111
+ 'list_orderbook',
112
+ 'place_buy_order',
113
+ 'place_sell_order',
114
+ 'place_market_buy_order',
115
+ 'place_market_sell_order',
116
+ 'withdraw_coin',
117
+ ],
118
+ },
119
+ 'v4Public': {
120
+ 'get': [
121
+ '{coin}/candle/',
122
+ ],
123
+ },
124
+ },
125
+ 'fees': {
126
+ 'trading': {
127
+ 'maker': 0.003,
128
+ 'taker': 0.007,
129
+ },
130
+ },
131
+ 'options': {
132
+ 'limits': {
133
+ 'BTC': 0.001,
134
+ 'BCH': 0.001,
135
+ 'ETH': 0.01,
136
+ 'LTC': 0.01,
137
+ 'XRP': 0.1,
138
+ },
139
+ },
140
+ });
141
+ }
142
+
143
+ async fetchMarkets (params = {}) {
144
+ const response = await this.publicGetCoins (params);
145
+ //
146
+ // [
147
+ // "BCH",
148
+ // "BTC",
149
+ // "ETH",
150
+ // "LTC",
151
+ // "XRP",
152
+ // "MBPRK01",
153
+ // "MBPRK02",
154
+ // "MBPRK03",
155
+ // "MBPRK04",
156
+ // "MBCONS01",
157
+ // "USDC",
158
+ // "WBX",
159
+ // "CHZ",
160
+ // "MBCONS02",
161
+ // "PAXG",
162
+ // "MBVASCO01",
163
+ // "LINK"
164
+ // ]
165
+ //
166
+ const result = [];
167
+ const amountLimits = this.safeValue (this.options, 'limits', {});
168
+ for (let i = 0; i < response.length; i++) {
169
+ const coin = response[i];
170
+ const baseId = coin;
171
+ const quoteId = 'BRL';
172
+ const base = this.safeCurrencyCode (baseId);
173
+ const quote = this.safeCurrencyCode (quoteId);
174
+ const id = quote + base;
175
+ const priceLimit = '1e-5';
176
+ result.push ({
177
+ 'id': id,
178
+ 'symbol': base + '/' + quote,
179
+ 'base': base,
180
+ 'quote': quote,
181
+ 'settle': undefined,
182
+ 'baseId': baseId,
183
+ 'quoteId': quoteId,
184
+ 'settleId': undefined,
185
+ 'type': 'spot',
186
+ 'spot': true,
187
+ 'margin': false,
188
+ 'swap': false,
189
+ 'future': false,
190
+ 'option': false,
191
+ 'active': undefined,
192
+ 'contract': false,
193
+ 'linear': undefined,
194
+ 'inverse': undefined,
195
+ 'contractSize': undefined,
196
+ 'expiry': undefined,
197
+ 'expiryDatetime': undefined,
198
+ 'strike': undefined,
199
+ 'optionType': undefined,
200
+ 'precision': {
201
+ 'amount': parseInt ('8'),
202
+ 'price': parseInt ('5'),
203
+ },
204
+ 'limits': {
205
+ 'leverage': {
206
+ 'min': undefined,
207
+ 'max': undefined,
208
+ },
209
+ 'amount': {
210
+ 'min': this.safeNumber (amountLimits, baseId),
211
+ 'max': undefined,
212
+ },
213
+ 'price': {
214
+ 'min': this.parseNumber (priceLimit),
215
+ 'max': undefined,
216
+ },
217
+ 'cost': {
218
+ 'min': undefined,
219
+ 'max': undefined,
220
+ },
221
+ },
222
+ 'info': coin,
223
+ });
224
+ }
225
+ return result;
226
+ }
227
+
228
+ async fetchOrderBook (symbol, limit = undefined, params = {}) {
229
+ await this.loadMarkets ();
230
+ const market = this.market (symbol);
231
+ const request = {
232
+ 'coin': market['base'],
233
+ };
234
+ const response = await this.publicGetCoinOrderbook (this.extend (request, params));
235
+ return this.parseOrderBook (response, symbol);
236
+ }
237
+
238
+ parseTicker (ticker, market = undefined) {
239
+ //
240
+ // {
241
+ // "high":"103.96000000",
242
+ // "low":"95.00000000",
243
+ // "vol":"2227.67806598",
244
+ // "last":"97.91591000",
245
+ // "buy":"95.52760000",
246
+ // "sell":"97.91475000",
247
+ // "open":"99.79955000",
248
+ // "date":1643382606
249
+ // }
250
+ //
251
+ const symbol = this.safeSymbol (undefined, market);
252
+ const timestamp = this.safeTimestamp (ticker, 'date');
253
+ const last = this.safeString (ticker, 'last');
254
+ return this.safeTicker ({
255
+ 'symbol': symbol,
256
+ 'timestamp': timestamp,
257
+ 'datetime': this.iso8601 (timestamp),
258
+ 'high': this.safeString (ticker, 'high'),
259
+ 'low': this.safeString (ticker, 'low'),
260
+ 'bid': this.safeString (ticker, 'buy'),
261
+ 'bidVolume': undefined,
262
+ 'ask': this.safeString (ticker, 'sell'),
263
+ 'askVolume': undefined,
264
+ 'vwap': undefined,
265
+ 'open': undefined,
266
+ 'close': last,
267
+ 'last': last,
268
+ 'previousClose': undefined,
269
+ 'change': undefined,
270
+ 'percentage': undefined,
271
+ 'average': undefined,
272
+ 'baseVolume': this.safeString (ticker, 'vol'),
273
+ 'quoteVolume': undefined,
274
+ 'info': ticker,
275
+ }, market, false);
276
+ }
277
+
278
+ async fetchTicker (symbol, params = {}) {
279
+ await this.loadMarkets ();
280
+ const market = this.market (symbol);
281
+ const request = {
282
+ 'coin': market['base'],
283
+ };
284
+ const response = await this.publicGetCoinTicker (this.extend (request, params));
285
+ const ticker = this.safeValue (response, 'ticker', {});
286
+ //
287
+ // {
288
+ // "ticker": {
289
+ // "high":"1549.82293000",
290
+ // "low":"1503.00011000",
291
+ // "vol":"81.82827101",
292
+ // "last":"1533.15000000",
293
+ // "buy":"1533.21018000",
294
+ // "sell":"1540.09000000",
295
+ // "open":"1524.71089000",
296
+ // "date":1643691671
297
+ // }
298
+ // }
299
+ //
300
+ return this.parseTicker (ticker, market);
301
+ }
302
+
303
+ parseTrade (trade, market = undefined) {
304
+ const timestamp = this.safeTimestamp2 (trade, 'date', 'executed_timestamp');
305
+ market = this.safeMarket (undefined, market);
306
+ const id = this.safeString2 (trade, 'tid', 'operation_id');
307
+ const type = undefined;
308
+ const side = this.safeString (trade, 'type');
309
+ const price = this.safeString (trade, 'price');
310
+ const amount = this.safeString2 (trade, 'amount', 'quantity');
311
+ const feeCost = this.safeString (trade, 'fee_rate');
312
+ let fee = undefined;
313
+ if (feeCost !== undefined) {
314
+ fee = {
315
+ 'cost': feeCost,
316
+ 'currency': undefined,
317
+ };
318
+ }
319
+ return this.safeTrade ({
320
+ 'id': id,
321
+ 'info': trade,
322
+ 'timestamp': timestamp,
323
+ 'datetime': this.iso8601 (timestamp),
324
+ 'symbol': market['symbol'],
325
+ 'order': undefined,
326
+ 'type': type,
327
+ 'side': side,
328
+ 'takerOrMaker': undefined,
329
+ 'price': price,
330
+ 'amount': amount,
331
+ 'cost': undefined,
332
+ 'fee': fee,
333
+ }, market);
334
+ }
335
+
336
+ async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
337
+ await this.loadMarkets ();
338
+ const market = this.market (symbol);
339
+ let method = 'publicGetCoinTrades';
340
+ const request = {
341
+ 'coin': market['base'],
342
+ };
343
+ if (since !== undefined) {
344
+ method += 'From';
345
+ request['from'] = parseInt (since / 1000);
346
+ }
347
+ const to = this.safeInteger (params, 'to');
348
+ if (to !== undefined) {
349
+ method += 'To';
350
+ }
351
+ const response = await this[method] (this.extend (request, params));
352
+ return this.parseTrades (response, market, since, limit);
353
+ }
354
+
355
+ parseBalance (response) {
356
+ const data = this.safeValue (response, 'response_data', {});
357
+ const balances = this.safeValue (data, 'balance', {});
358
+ const result = { 'info': response };
359
+ const currencyIds = Object.keys (balances);
360
+ for (let i = 0; i < currencyIds.length; i++) {
361
+ const currencyId = currencyIds[i];
362
+ const code = this.safeCurrencyCode (currencyId);
363
+ if (currencyId in balances) {
364
+ const balance = this.safeValue (balances, currencyId, {});
365
+ const account = this.account ();
366
+ account['free'] = this.safeString (balance, 'available');
367
+ account['total'] = this.safeString (balance, 'total');
368
+ result[code] = account;
369
+ }
370
+ }
371
+ return this.safeBalance (result);
372
+ }
373
+
374
+ async fetchBalance (params = {}) {
375
+ await this.loadMarkets ();
376
+ const response = await this.privatePostGetAccountInfo (params);
377
+ return this.parseBalance (response);
378
+ }
379
+
380
+ async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
381
+ await this.loadMarkets ();
382
+ const request = {
383
+ 'coin_pair': this.marketId (symbol),
384
+ };
385
+ let method = this.capitalize (side) + 'Order';
386
+ if (type === 'limit') {
387
+ method = 'privatePostPlace' + method;
388
+ request['limit_price'] = this.priceToPrecision (symbol, price);
389
+ request['quantity'] = this.amountToPrecision (symbol, amount);
390
+ } else {
391
+ method = 'privatePostPlaceMarket' + method;
392
+ if (side === 'buy') {
393
+ if (price === undefined) {
394
+ throw new InvalidOrder (this.id + ' createOrder() requires the price argument with market buy orders to calculate total order cost (amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount');
395
+ }
396
+ request['cost'] = this.priceToPrecision (symbol, amount * price);
397
+ } else {
398
+ request['quantity'] = this.amountToPrecision (symbol, amount);
399
+ }
400
+ }
401
+ const response = await this[method] (this.extend (request, params));
402
+ // TODO: replace this with a call to parseOrder for unification
403
+ return {
404
+ 'info': response,
405
+ 'id': response['response_data']['order']['order_id'].toString (),
406
+ };
407
+ }
408
+
409
+ async cancelOrder (id, symbol = undefined, params = {}) {
410
+ if (symbol === undefined) {
411
+ throw new ArgumentsRequired (this.id + ' cancelOrder() requires a symbol argument');
412
+ }
413
+ await this.loadMarkets ();
414
+ const market = this.market (symbol);
415
+ const request = {
416
+ 'coin_pair': market['id'],
417
+ 'order_id': id,
418
+ };
419
+ const response = await this.privatePostCancelOrder (this.extend (request, params));
420
+ //
421
+ // {
422
+ // response_data: {
423
+ // order: {
424
+ // order_id: 2176769,
425
+ // coin_pair: 'BRLBCH',
426
+ // order_type: 2,
427
+ // status: 3,
428
+ // has_fills: false,
429
+ // quantity: '0.10000000',
430
+ // limit_price: '1996.15999',
431
+ // executed_quantity: '0.00000000',
432
+ // executed_price_avg: '0.00000',
433
+ // fee: '0.00000000',
434
+ // created_timestamp: '1536956488',
435
+ // updated_timestamp: '1536956499',
436
+ // operations: []
437
+ // }
438
+ // },
439
+ // status_code: 100,
440
+ // server_unix_timestamp: '1536956499'
441
+ // }
442
+ //
443
+ const responseData = this.safeValue (response, 'response_data', {});
444
+ const order = this.safeValue (responseData, 'order', {});
445
+ return this.parseOrder (order, market);
446
+ }
447
+
448
+ parseOrderStatus (status) {
449
+ const statuses = {
450
+ '2': 'open',
451
+ '3': 'canceled',
452
+ '4': 'closed',
453
+ };
454
+ return this.safeString (statuses, status, status);
455
+ }
456
+
457
+ parseOrder (order, market = undefined) {
458
+ //
459
+ // {
460
+ // "order_id": 4,
461
+ // "coin_pair": "BRLBTC",
462
+ // "order_type": 1,
463
+ // "status": 2,
464
+ // "has_fills": true,
465
+ // "quantity": "2.00000000",
466
+ // "limit_price": "900.00000",
467
+ // "executed_quantity": "1.00000000",
468
+ // "executed_price_avg": "900.00000",
469
+ // "fee": "0.00300000",
470
+ // "created_timestamp": "1453838494",
471
+ // "updated_timestamp": "1453838494",
472
+ // "operations": [
473
+ // {
474
+ // "operation_id": 1,
475
+ // "quantity": "1.00000000",
476
+ // "price": "900.00000",
477
+ // "fee_rate": "0.30",
478
+ // "executed_timestamp": "1453838494",
479
+ // },
480
+ // ],
481
+ // }
482
+ //
483
+ const id = this.safeString (order, 'order_id');
484
+ const order_type = this.safeString (order, 'order_type');
485
+ let side = undefined;
486
+ if ('order_type' in order) {
487
+ side = (order_type === '1') ? 'buy' : 'sell';
488
+ }
489
+ const status = this.parseOrderStatus (this.safeString (order, 'status'));
490
+ const marketId = this.safeString (order, 'coin_pair');
491
+ market = this.safeMarket (marketId, market);
492
+ const timestamp = this.safeTimestamp (order, 'created_timestamp');
493
+ const fee = {
494
+ 'cost': this.safeString (order, 'fee'),
495
+ 'currency': market['quote'],
496
+ };
497
+ const price = this.safeString (order, 'limit_price');
498
+ // price = this.safeNumber (order, 'executed_price_avg', price);
499
+ const average = this.safeString (order, 'executed_price_avg');
500
+ const amount = this.safeString (order, 'quantity');
501
+ const filled = this.safeString (order, 'executed_quantity');
502
+ const lastTradeTimestamp = this.safeTimestamp (order, 'updated_timestamp');
503
+ const rawTrades = this.safeValue (order, 'operations', []);
504
+ return this.safeOrder ({
505
+ 'info': order,
506
+ 'id': id,
507
+ 'clientOrderId': undefined,
508
+ 'timestamp': timestamp,
509
+ 'datetime': this.iso8601 (timestamp),
510
+ 'lastTradeTimestamp': lastTradeTimestamp,
511
+ 'symbol': market['symbol'],
512
+ 'type': 'limit',
513
+ 'timeInForce': undefined,
514
+ 'postOnly': undefined,
515
+ 'side': side,
516
+ 'price': price,
517
+ 'stopPrice': undefined,
518
+ 'cost': undefined,
519
+ 'average': average,
520
+ 'amount': amount,
521
+ 'filled': filled,
522
+ 'remaining': undefined,
523
+ 'status': status,
524
+ 'fee': fee,
525
+ 'trades': rawTrades,
526
+ }, market);
527
+ }
528
+
529
+ async fetchOrder (id, symbol = undefined, params = {}) {
530
+ if (symbol === undefined) {
531
+ throw new ArgumentsRequired (this.id + ' fetchOrder() requires a symbol argument');
532
+ }
533
+ await this.loadMarkets ();
534
+ const market = this.market (symbol);
535
+ const request = {
536
+ 'coin_pair': market['id'],
537
+ 'order_id': parseInt (id),
538
+ };
539
+ const response = await this.privatePostGetOrder (this.extend (request, params));
540
+ const responseData = this.safeValue (response, 'response_data', {});
541
+ const order = this.safeValue (responseData, 'order');
542
+ return this.parseOrder (order, market);
543
+ }
544
+
545
+ async withdraw (code, amount, address, tag = undefined, params = {}) {
546
+ [ tag, params ] = this.handleWithdrawTagAndParams (tag, params);
547
+ this.checkAddress (address);
548
+ await this.loadMarkets ();
549
+ const currency = this.currency (code);
550
+ const request = {
551
+ 'coin': currency['id'],
552
+ 'quantity': amount.toFixed (10),
553
+ 'address': address,
554
+ };
555
+ if (code === 'BRL') {
556
+ const account_ref = ('account_ref' in params);
557
+ if (!account_ref) {
558
+ throw new ArgumentsRequired (this.id + ' withdraw() requires account_ref parameter to withdraw ' + code);
559
+ }
560
+ } else if (code !== 'LTC') {
561
+ const tx_fee = ('tx_fee' in params);
562
+ if (!tx_fee) {
563
+ throw new ArgumentsRequired (this.id + ' withdraw() requires tx_fee parameter to withdraw ' + code);
564
+ }
565
+ if (code === 'XRP') {
566
+ if (tag === undefined) {
567
+ if (!('destination_tag' in params)) {
568
+ throw new ArgumentsRequired (this.id + ' withdraw() requires a tag argument or destination_tag parameter to withdraw ' + code);
569
+ }
570
+ } else {
571
+ request['destination_tag'] = tag;
572
+ }
573
+ }
574
+ }
575
+ const response = await this.privatePostWithdrawCoin (this.extend (request, params));
576
+ //
577
+ // {
578
+ // "response_data": {
579
+ // "withdrawal": {
580
+ // "id": 1,
581
+ // "coin": "BRL",
582
+ // "quantity": "300.56",
583
+ // "net_quantity": "291.68",
584
+ // "fee": "8.88",
585
+ // "account": "bco: 341, ag: 1111, cta: 23456-X",
586
+ // "status": 1,
587
+ // "created_timestamp": "1453912088",
588
+ // "updated_timestamp": "1453912088"
589
+ // }
590
+ // },
591
+ // "status_code": 100,
592
+ // "server_unix_timestamp": "1453912088"
593
+ // }
594
+ //
595
+ const responseData = this.safeValue (response, 'response_data', {});
596
+ const withdrawal = this.safeValue (responseData, 'withdrawal');
597
+ return this.parseTransaction (withdrawal, currency);
598
+ }
599
+
600
+ parseTransaction (transaction, currency = undefined) {
601
+ //
602
+ // {
603
+ // "id": 1,
604
+ // "coin": "BRL",
605
+ // "quantity": "300.56",
606
+ // "net_quantity": "291.68",
607
+ // "fee": "8.88",
608
+ // "account": "bco: 341, ag: 1111, cta: 23456-X",
609
+ // "status": 1,
610
+ // "created_timestamp": "1453912088",
611
+ // "updated_timestamp": "1453912088"
612
+ // }
613
+ //
614
+ currency = this.safeCurrency (undefined, currency);
615
+ return {
616
+ 'id': this.safeString (transaction, 'id'),
617
+ 'txid': undefined,
618
+ 'timestamp': undefined,
619
+ 'datetime': undefined,
620
+ 'network': undefined,
621
+ 'addressFrom': undefined,
622
+ 'address': undefined,
623
+ 'addressTo': undefined,
624
+ 'amount': undefined,
625
+ 'type': undefined,
626
+ 'currency': currency['code'],
627
+ 'status': undefined,
628
+ 'updated': undefined,
629
+ 'tagFrom': undefined,
630
+ 'tag': undefined,
631
+ 'tagTo': undefined,
632
+ 'comment': undefined,
633
+ 'fee': undefined,
634
+ 'info': transaction,
635
+ };
636
+ }
637
+
638
+ parseOHLCV (ohlcv, market = undefined) {
639
+ return [
640
+ this.safeTimestamp (ohlcv, 'timestamp'),
641
+ this.safeNumber (ohlcv, 'open'),
642
+ this.safeNumber (ohlcv, 'high'),
643
+ this.safeNumber (ohlcv, 'low'),
644
+ this.safeNumber (ohlcv, 'close'),
645
+ this.safeNumber (ohlcv, 'volume'),
646
+ ];
647
+ }
648
+
649
+ async fetchOHLCV (symbol, timeframe = '5m', since = undefined, limit = undefined, params = {}) {
650
+ await this.loadMarkets ();
651
+ const market = this.market (symbol);
652
+ const request = {
653
+ 'precision': this.timeframes[timeframe],
654
+ 'coin': market['id'].toLowerCase (),
655
+ };
656
+ if (limit !== undefined && since !== undefined) {
657
+ request['from'] = parseInt (since / 1000);
658
+ request['to'] = this.sum (request['from'], limit * this.parseTimeframe (timeframe));
659
+ } else if (since !== undefined) {
660
+ request['from'] = parseInt (since / 1000);
661
+ request['to'] = this.sum (this.seconds (), 1);
662
+ } else if (limit !== undefined) {
663
+ request['to'] = this.seconds ();
664
+ request['from'] = request['to'] - (limit * this.parseTimeframe (timeframe));
665
+ }
666
+ const response = await this.v4PublicGetCoinCandle (this.extend (request, params));
667
+ const candles = this.safeValue (response, 'candles', []);
668
+ return this.parseOHLCVs (candles, market, timeframe, since, limit);
669
+ }
670
+
671
+ async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
672
+ if (symbol === undefined) {
673
+ throw new ArgumentsRequired (this.id + ' fetchOrders() requires a symbol argument');
674
+ }
675
+ await this.loadMarkets ();
676
+ const market = this.market (symbol);
677
+ const request = {
678
+ 'coin_pair': market['id'],
679
+ };
680
+ const response = await this.privatePostListOrders (this.extend (request, params));
681
+ const responseData = this.safeValue (response, 'response_data', {});
682
+ const orders = this.safeValue (responseData, 'orders', []);
683
+ return this.parseOrders (orders, market, since, limit);
684
+ }
685
+
686
+ async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
687
+ if (symbol === undefined) {
688
+ throw new ArgumentsRequired (this.id + ' fetchOpenOrders() requires a symbol argument');
689
+ }
690
+ await this.loadMarkets ();
691
+ const market = this.market (symbol);
692
+ const request = {
693
+ 'coin_pair': market['id'],
694
+ 'status_list': '[2]', // open only
695
+ };
696
+ const response = await this.privatePostListOrders (this.extend (request, params));
697
+ const responseData = this.safeValue (response, 'response_data', {});
698
+ const orders = this.safeValue (responseData, 'orders', []);
699
+ return this.parseOrders (orders, market, since, limit);
700
+ }
701
+
702
+ async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
703
+ if (symbol === undefined) {
704
+ throw new ArgumentsRequired (this.id + ' fetchMyTrades() requires a symbol argument');
705
+ }
706
+ await this.loadMarkets ();
707
+ const market = this.market (symbol);
708
+ const request = {
709
+ 'coin_pair': market['id'],
710
+ 'has_fills': true,
711
+ };
712
+ const response = await this.privatePostListOrders (this.extend (request, params));
713
+ const responseData = this.safeValue (response, 'response_data', {});
714
+ const ordersRaw = this.safeValue (responseData, 'orders', []);
715
+ const orders = this.parseOrders (ordersRaw, market, since, limit);
716
+ const trades = this.ordersToTrades (orders);
717
+ return this.filterBySymbolSinceLimit (trades, market['symbol'], since, limit);
718
+ }
719
+
720
+ ordersToTrades (orders) {
721
+ const result = [];
722
+ for (let i = 0; i < orders.length; i++) {
723
+ const trades = this.safeValue (orders[i], 'trades', []);
724
+ for (let y = 0; y < trades.length; y++) {
725
+ result.push (trades[y]);
726
+ }
727
+ }
728
+ return result;
729
+ }
730
+
731
+ sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
732
+ let url = this.urls['api'][api] + '/';
733
+ const query = this.omit (params, this.extractParams (path));
734
+ if (api === 'public' || (api === 'v4Public')) {
735
+ url += this.implodeParams (path, params);
736
+ if (Object.keys (query).length) {
737
+ url += '?' + this.urlencode (query);
738
+ }
739
+ } else {
740
+ this.checkRequiredCredentials ();
741
+ url += this.version + '/';
742
+ const nonce = this.nonce ();
743
+ body = this.urlencode (this.extend ({
744
+ 'tapi_method': path,
745
+ 'tapi_nonce': nonce,
746
+ }, params));
747
+ const auth = '/tapi/' + this.version + '/' + '?' + body;
748
+ headers = {
749
+ 'Content-Type': 'application/x-www-form-urlencoded',
750
+ 'TAPI-ID': this.apiKey,
751
+ 'TAPI-MAC': this.hmac (this.encode (auth), this.encode (this.secret), 'sha512'),
752
+ };
753
+ }
754
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
755
+ }
756
+
757
+ handleErrors (httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
758
+ if (response === undefined) {
759
+ return;
760
+ }
761
+ //
762
+ // todo add a unified standard handleErrors with this.exceptions in describe()
763
+ //
764
+ // {"status":503,"message":"Maintenancing, try again later","result":null}
765
+ //
766
+ const errorMessage = this.safeValue (response, 'error_message');
767
+ if (errorMessage !== undefined) {
768
+ throw new ExchangeError (this.id + ' ' + this.json (response));
769
+ }
770
+ }
771
+ };