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/novadax.js ADDED
@@ -0,0 +1,1318 @@
1
+ 'use strict';
2
+
3
+ // ---------------------------------------------------------------------------
4
+
5
+ const Exchange = require ('./base/Exchange');
6
+ const { AuthenticationError, ExchangeError, PermissionDenied, BadRequest, CancelPending, OrderNotFound, InsufficientFunds, RateLimitExceeded, InvalidOrder, AccountSuspended, BadSymbol, OnMaintenance, ArgumentsRequired, AccountNotEnabled } = require ('./base/errors');
7
+ const { TRUNCATE } = require ('./base/functions/number');
8
+
9
+ // ---------------------------------------------------------------------------
10
+
11
+ module.exports = class novadax extends Exchange {
12
+ describe () {
13
+ return this.deepExtend (super.describe (), {
14
+ 'id': 'novadax',
15
+ 'name': 'NovaDAX',
16
+ 'countries': [ 'BR' ], // Brazil
17
+ // 60 requests per second = 1000ms / 60 = 16.6667ms between requests (public endpoints, limited by IP address)
18
+ // 20 requests per second => cost = 60 / 20 = 3 (private endpoints, limited by API Key)
19
+ 'rateLimit': 16.6667,
20
+ 'version': 'v1',
21
+ // new metainfo interface
22
+ 'has': {
23
+ 'CORS': undefined,
24
+ 'spot': true,
25
+ 'margin': false,
26
+ 'swap': false,
27
+ 'future': false,
28
+ 'option': false,
29
+ 'addMargin': false,
30
+ 'cancelOrder': true,
31
+ 'createOrder': true,
32
+ 'createReduceOnlyOrder': false,
33
+ 'createStopLimitOrder': true,
34
+ 'createStopMarketOrder': true,
35
+ 'createStopOrder': true,
36
+ 'fetchAccounts': true,
37
+ 'fetchBalance': true,
38
+ 'fetchBorrowRate': false,
39
+ 'fetchBorrowRateHistories': false,
40
+ 'fetchBorrowRateHistory': false,
41
+ 'fetchBorrowRates': false,
42
+ 'fetchBorrowRatesPerSymbol': false,
43
+ 'fetchClosedOrders': true,
44
+ 'fetchDeposits': true,
45
+ 'fetchFundingHistory': false,
46
+ 'fetchFundingRate': false,
47
+ 'fetchFundingRateHistories': false,
48
+ 'fetchFundingRateHistory': false,
49
+ 'fetchFundingRates': false,
50
+ 'fetchIndexOHLCV': false,
51
+ 'fetchLeverage': false,
52
+ 'fetchLeverageTiers': false,
53
+ 'fetchMarkets': true,
54
+ 'fetchMarkOHLCV': false,
55
+ 'fetchMyTrades': true,
56
+ 'fetchOHLCV': true,
57
+ 'fetchOpenOrders': true,
58
+ 'fetchOrder': true,
59
+ 'fetchOrderBook': true,
60
+ 'fetchOrders': true,
61
+ 'fetchOrderTrades': true,
62
+ 'fetchPosition': false,
63
+ 'fetchPositions': false,
64
+ 'fetchPositionsRisk': false,
65
+ 'fetchPremiumIndexOHLCV': false,
66
+ 'fetchTicker': true,
67
+ 'fetchTickers': true,
68
+ 'fetchTime': true,
69
+ 'fetchTrades': true,
70
+ 'fetchTradingFee': false,
71
+ 'fetchTradingFees': false,
72
+ 'fetchTransactions': true,
73
+ 'fetchWithdrawals': true,
74
+ 'reduceMargin': false,
75
+ 'setLeverage': false,
76
+ 'setMarginMode': false,
77
+ 'setPositionMode': false,
78
+ 'transfer': true,
79
+ 'withdraw': true,
80
+ },
81
+ 'timeframes': {
82
+ '1m': 'ONE_MIN',
83
+ '5m': 'FIVE_MIN',
84
+ '15m': 'FIFTEEN_MIN',
85
+ '30m': 'HALF_HOU',
86
+ '1h': 'ONE_HOU',
87
+ '1d': 'ONE_DAY',
88
+ '1w': 'ONE_WEE',
89
+ '1M': 'ONE_MON',
90
+ },
91
+ 'urls': {
92
+ 'logo': 'https://user-images.githubusercontent.com/1294454/92337550-2b085500-f0b3-11ea-98e7-5794fb07dd3b.jpg',
93
+ 'api': {
94
+ 'public': 'https://api.novadax.com',
95
+ 'private': 'https://api.novadax.com',
96
+ },
97
+ 'www': 'https://www.novadax.com.br',
98
+ 'doc': [
99
+ 'https://doc.novadax.com/pt-BR/',
100
+ ],
101
+ 'fees': 'https://www.novadax.com.br/fees-and-limits',
102
+ 'referral': 'https://www.novadax.com.br/?s=ccxt',
103
+ },
104
+ 'api': {
105
+ 'public': {
106
+ 'get': {
107
+ 'common/symbol': 1.2,
108
+ 'common/symbols': 1.2,
109
+ 'common/timestamp': 1.2,
110
+ 'market/tickers': 1.2,
111
+ 'market/ticker': 1.2,
112
+ 'market/depth': 1.2,
113
+ 'market/trades': 1.2,
114
+ 'market/kline/history': 1.2,
115
+ },
116
+ },
117
+ 'private': {
118
+ 'get': {
119
+ 'orders/get': 3,
120
+ 'orders/list': 3,
121
+ 'orders/fill': 3,
122
+ 'orders/fills': 3,
123
+ 'account/getBalance': 3,
124
+ 'account/subs': 3,
125
+ 'account/subs/balance': 3,
126
+ 'account/subs/transfer/record': 3,
127
+ 'wallet/query/deposit-withdraw': 3,
128
+ },
129
+ 'post': {
130
+ 'orders/create': 3,
131
+ 'orders/cancel': 3,
132
+ 'account/withdraw/coin': 3,
133
+ 'account/subs/transfer': 3,
134
+ },
135
+ },
136
+ },
137
+ 'fees': {
138
+ 'trading': {
139
+ 'tierBased': false,
140
+ 'percentage': true,
141
+ 'taker': this.parseNumber ('0.005'),
142
+ 'maker': this.parseNumber ('0.0025'),
143
+ },
144
+ },
145
+ 'requiredCredentials': {
146
+ 'apiKey': true,
147
+ 'secret': true,
148
+ },
149
+ 'exceptions': {
150
+ 'exact': {
151
+ 'A99999': ExchangeError, // 500 Failed Internal error
152
+ // 'A10000': ExchangeError, // 200 Success Successful request
153
+ 'A10001': BadRequest, // 400 Params error Parameter is invalid
154
+ 'A10002': ExchangeError, // 404 Api not found API used is irrelevant
155
+ 'A10003': AuthenticationError, // 403 Authentication failed Authentication is failed
156
+ 'A10004': RateLimitExceeded, // 429 Too many requests Too many requests are made
157
+ 'A10005': PermissionDenied, // 403 Kyc required Need to complete KYC firstly
158
+ 'A10006': AccountSuspended, // 403 Customer canceled Account is canceled
159
+ 'A10007': AccountNotEnabled, // 400 Account not exist Sub account does not exist
160
+ 'A10011': BadSymbol, // 400 Symbol not exist Trading symbol does not exist
161
+ 'A10012': BadSymbol, // 400 Symbol not trading Trading symbol is temporarily not available
162
+ 'A10013': OnMaintenance, // 503 Symbol maintain Trading symbol is in maintain
163
+ 'A30001': OrderNotFound, // 400 Order not found Queried order is not found
164
+ 'A30002': InvalidOrder, // 400 Order amount is too small Order amount is too small
165
+ 'A30003': InvalidOrder, // 400 Order amount is invalid Order amount is invalid
166
+ 'A30004': InvalidOrder, // 400 Order value is too small Order value is too small
167
+ 'A30005': InvalidOrder, // 400 Order value is invalid Order value is invalid
168
+ 'A30006': InvalidOrder, // 400 Order price is invalid Order price is invalid
169
+ 'A30007': InsufficientFunds, // 400 Insufficient balance The balance is insufficient
170
+ 'A30008': InvalidOrder, // 400 Order was closed The order has been executed
171
+ 'A30009': InvalidOrder, // 400 Order canceled The order has been cancelled
172
+ 'A30010': CancelPending, // 400 Order cancelling The order is being cancelled
173
+ 'A30011': InvalidOrder, // 400 Order price too high The order price is too high
174
+ 'A30012': InvalidOrder, // 400 Order price too low The order price is too low
175
+ 'A40004': InsufficientFunds, // {"code":"A40004","data":[],"message":"sub account balance Insufficient"}
176
+ },
177
+ 'broad': {
178
+ },
179
+ },
180
+ 'options': {
181
+ 'fetchOHLCV': {
182
+ 'volume': 'amount', // 'amount' for base volume or 'vol' for quote volume
183
+ },
184
+ 'transfer': {
185
+ 'fillResponseFromRequest': true,
186
+ },
187
+ },
188
+ });
189
+ }
190
+
191
+ async fetchTime (params = {}) {
192
+ const response = await this.publicGetCommonTimestamp (params);
193
+ //
194
+ // {
195
+ // "code":"A10000",
196
+ // "data":1599090512080,
197
+ // "message":"Success"
198
+ // }
199
+ //
200
+ return this.safeInteger (response, 'data');
201
+ }
202
+
203
+ async fetchMarkets (params = {}) {
204
+ const response = await this.publicGetCommonSymbols (params);
205
+ //
206
+ // {
207
+ // "code":"A10000",
208
+ // "data":[
209
+ // {
210
+ // "amountPrecision":8,
211
+ // "baseCurrency":"BTC",
212
+ // "minOrderAmount":"0.001",
213
+ // "minOrderValue":"25",
214
+ // "pricePrecision":2,
215
+ // "quoteCurrency":"BRL",
216
+ // "status":"ONLINE",
217
+ // "symbol":"BTC_BRL",
218
+ // "valuePrecision":2
219
+ // },
220
+ // ],
221
+ // "message":"Success"
222
+ // }
223
+ //
224
+ const result = [];
225
+ const data = this.safeValue (response, 'data', []);
226
+ for (let i = 0; i < data.length; i++) {
227
+ const market = data[i];
228
+ const baseId = this.safeString (market, 'baseCurrency');
229
+ const quoteId = this.safeString (market, 'quoteCurrency');
230
+ const id = this.safeString (market, 'symbol');
231
+ const base = this.safeCurrencyCode (baseId);
232
+ const quote = this.safeCurrencyCode (quoteId);
233
+ const status = this.safeString (market, 'status');
234
+ result.push ({
235
+ 'id': id,
236
+ 'symbol': base + '/' + quote,
237
+ 'base': base,
238
+ 'quote': quote,
239
+ 'settle': undefined,
240
+ 'baseId': baseId,
241
+ 'quoteId': quoteId,
242
+ 'settleId': undefined,
243
+ 'type': 'spot',
244
+ 'spot': true,
245
+ 'margin': false,
246
+ 'swap': false,
247
+ 'future': false,
248
+ 'option': false,
249
+ 'active': (status === 'ONLINE'),
250
+ 'contract': false,
251
+ 'linear': undefined,
252
+ 'inverse': undefined,
253
+ 'contractSize': undefined,
254
+ 'expiry': undefined,
255
+ 'expiryDatetime': undefined,
256
+ 'strike': undefined,
257
+ 'optionType': undefined,
258
+ 'precision': {
259
+ 'amount': this.safeInteger (market, 'amountPrecision'),
260
+ 'price': this.safeInteger (market, 'pricePrecision'),
261
+ 'cost': this.safeInteger (market, 'valuePrecision'),
262
+ },
263
+ 'limits': {
264
+ 'leverage': {
265
+ 'min': undefined,
266
+ 'max': undefined,
267
+ },
268
+ 'amount': {
269
+ 'min': this.safeNumber (market, 'minOrderAmount'),
270
+ 'max': undefined,
271
+ },
272
+ 'price': {
273
+ 'min': undefined,
274
+ 'max': undefined,
275
+ },
276
+ 'cost': {
277
+ 'min': this.safeNumber (market, 'minOrderValue'),
278
+ 'max': undefined,
279
+ },
280
+ },
281
+ 'info': market,
282
+ });
283
+ }
284
+ return result;
285
+ }
286
+
287
+ parseTicker (ticker, market = undefined) {
288
+ //
289
+ // fetchTicker, fetchTickers
290
+ //
291
+ // {
292
+ // "ask":"61946.1",
293
+ // "baseVolume24h":"164.41930186",
294
+ // "bid":"61815",
295
+ // "high24h":"64930.72",
296
+ // "lastPrice":"61928.41",
297
+ // "low24h":"61156.32",
298
+ // "open24h":"64512.46",
299
+ // "quoteVolume24h":"10308157.95",
300
+ // "symbol":"BTC_BRL",
301
+ // "timestamp":1599091115090
302
+ // }
303
+ //
304
+ const timestamp = this.safeInteger (ticker, 'timestamp');
305
+ const marketId = this.safeString (ticker, 'symbol');
306
+ const symbol = this.safeSymbol (marketId, market, '_');
307
+ const open = this.safeNumber (ticker, 'open24h');
308
+ const last = this.safeNumber (ticker, 'lastPrice');
309
+ const baseVolume = this.safeNumber (ticker, 'baseVolume24h');
310
+ const quoteVolume = this.safeNumber (ticker, 'quoteVolume24h');
311
+ const vwap = this.vwap (baseVolume, quoteVolume);
312
+ return this.safeTicker ({
313
+ 'symbol': symbol,
314
+ 'timestamp': timestamp,
315
+ 'datetime': this.iso8601 (timestamp),
316
+ 'high': this.safeNumber (ticker, 'high24h'),
317
+ 'low': this.safeNumber (ticker, 'low24h'),
318
+ 'bid': this.safeNumber (ticker, 'bid'),
319
+ 'bidVolume': undefined,
320
+ 'ask': this.safeNumber (ticker, 'ask'),
321
+ 'askVolume': undefined,
322
+ 'vwap': vwap,
323
+ 'open': open,
324
+ 'close': last,
325
+ 'last': last,
326
+ 'previousClose': undefined,
327
+ 'change': undefined,
328
+ 'percentage': undefined,
329
+ 'average': undefined,
330
+ 'baseVolume': baseVolume,
331
+ 'quoteVolume': quoteVolume,
332
+ 'info': ticker,
333
+ }, market);
334
+ }
335
+
336
+ async fetchTicker (symbol, params = {}) {
337
+ await this.loadMarkets ();
338
+ const market = this.market (symbol);
339
+ const request = {
340
+ 'symbol': market['id'],
341
+ };
342
+ const response = await this.publicGetMarketTicker (this.extend (request, params));
343
+ //
344
+ // {
345
+ // "code":"A10000",
346
+ // "data":{
347
+ // "ask":"61946.1",
348
+ // "baseVolume24h":"164.41930186",
349
+ // "bid":"61815",
350
+ // "high24h":"64930.72",
351
+ // "lastPrice":"61928.41",
352
+ // "low24h":"61156.32",
353
+ // "open24h":"64512.46",
354
+ // "quoteVolume24h":"10308157.95",
355
+ // "symbol":"BTC_BRL",
356
+ // "timestamp":1599091115090
357
+ // },
358
+ // "message":"Success"
359
+ // }
360
+ //
361
+ const data = this.safeValue (response, 'data', {});
362
+ return this.parseTicker (data, market);
363
+ }
364
+
365
+ async fetchTickers (symbols = undefined, params = {}) {
366
+ await this.loadMarkets ();
367
+ const response = await this.publicGetMarketTickers (params);
368
+ //
369
+ // {
370
+ // "code":"A10000",
371
+ // "data":[
372
+ // {
373
+ // "ask":"61879.36",
374
+ // "baseVolume24h":"164.40955092",
375
+ // "bid":"61815",
376
+ // "high24h":"64930.72",
377
+ // "lastPrice":"61820.04",
378
+ // "low24h":"61156.32",
379
+ // "open24h":"64624.19",
380
+ // "quoteVolume24h":"10307493.92",
381
+ // "symbol":"BTC_BRL",
382
+ // "timestamp":1599091291083
383
+ // },
384
+ // ],
385
+ // "message":"Success"
386
+ // }
387
+ //
388
+ const data = this.safeValue (response, 'data', []);
389
+ const result = {};
390
+ for (let i = 0; i < data.length; i++) {
391
+ const ticker = this.parseTicker (data[i]);
392
+ const symbol = ticker['symbol'];
393
+ result[symbol] = ticker;
394
+ }
395
+ return this.filterByArray (result, 'symbol', symbols);
396
+ }
397
+
398
+ async fetchOrderBook (symbol, limit = undefined, params = {}) {
399
+ await this.loadMarkets ();
400
+ const request = {
401
+ 'symbol': this.marketId (symbol),
402
+ };
403
+ if (limit !== undefined) {
404
+ request['limit'] = limit; // default 10, max 20
405
+ }
406
+ const response = await this.publicGetMarketDepth (this.extend (request, params));
407
+ //
408
+ // {
409
+ // "code":"A10000",
410
+ // "data":{
411
+ // "asks":[
412
+ // ["0.037159","0.3741"],
413
+ // ["0.037215","0.2706"],
414
+ // ["0.037222","1.8459"],
415
+ // ],
416
+ // "bids":[
417
+ // ["0.037053","0.3857"],
418
+ // ["0.036969","0.8101"],
419
+ // ["0.036953","1.5226"],
420
+ // ],
421
+ // "timestamp":1599280414448
422
+ // },
423
+ // "message":"Success"
424
+ // }
425
+ //
426
+ const data = this.safeValue (response, 'data', {});
427
+ const timestamp = this.safeInteger (data, 'timestamp');
428
+ return this.parseOrderBook (data, symbol, timestamp, 'bids', 'asks');
429
+ }
430
+
431
+ parseTrade (trade, market = undefined) {
432
+ //
433
+ // public fetchTrades
434
+ //
435
+ // {
436
+ // "amount":"0.0632",
437
+ // "price":"0.037288",
438
+ // "side":"BUY",
439
+ // "timestamp":1599279694576
440
+ // }
441
+ //
442
+ // private fetchOrderTrades
443
+ //
444
+ // {
445
+ // "id": "608717046691139584",
446
+ // "orderId": "608716957545402368",
447
+ // "symbol": "BTC_BRL",
448
+ // "side": "BUY",
449
+ // "amount": "0.0988",
450
+ // "price": "45514.76",
451
+ // "fee": "0.0000988 BTC",
452
+ // "feeAmount": "0.0000988",
453
+ // "feeCurrency": "BTC",
454
+ // "role": "MAKER",
455
+ // "timestamp": 1565171053345
456
+ // }
457
+ //
458
+ // private fetchMyTrades (same endpoint as fetchOrderTrades)
459
+ //
460
+ // {
461
+ // "id": "608717046691139584",
462
+ // "orderId": "608716957545402368",
463
+ // "symbol": "BTC_BRL",
464
+ // "side": "BUY",
465
+ // "amount": "0.0988",
466
+ // "price": "45514.76",
467
+ // "fee": "0.0000988 BTC",
468
+ // "feeAmount": "0.0000988",
469
+ // "feeCurrency": "BTC",
470
+ // "role": "MAKER",
471
+ // "timestamp": 1565171053345
472
+ // }
473
+ //
474
+ const id = this.safeString (trade, 'id');
475
+ const orderId = this.safeString (trade, 'orderId');
476
+ const timestamp = this.safeInteger (trade, 'timestamp');
477
+ const side = this.safeStringLower (trade, 'side');
478
+ const priceString = this.safeString (trade, 'price');
479
+ const amountString = this.safeString (trade, 'amount');
480
+ const marketId = this.safeString (trade, 'symbol');
481
+ const symbol = this.safeSymbol (marketId, market, '_');
482
+ const takerOrMaker = this.safeStringLower (trade, 'role');
483
+ const feeString = this.safeString (trade, 'fee');
484
+ let fee = undefined;
485
+ if (feeString !== undefined) {
486
+ const feeCurrencyId = this.safeString (trade, 'feeCurrency');
487
+ const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId);
488
+ fee = {
489
+ 'cost': this.safeString (trade, 'feeAmount'),
490
+ 'currency': feeCurrencyCode,
491
+ };
492
+ }
493
+ return this.safeTrade ({
494
+ 'id': id,
495
+ 'order': orderId,
496
+ 'timestamp': timestamp,
497
+ 'datetime': this.iso8601 (timestamp),
498
+ 'symbol': symbol,
499
+ 'type': undefined,
500
+ 'side': side,
501
+ 'price': priceString,
502
+ 'amount': amountString,
503
+ 'cost': undefined,
504
+ 'takerOrMaker': takerOrMaker,
505
+ 'fee': fee,
506
+ 'info': trade,
507
+ }, market);
508
+ }
509
+
510
+ async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
511
+ await this.loadMarkets ();
512
+ const market = this.market (symbol);
513
+ const request = {
514
+ 'symbol': market['id'],
515
+ };
516
+ if (limit !== undefined) {
517
+ request['limit'] = limit; // default 100
518
+ }
519
+ const response = await this.publicGetMarketTrades (this.extend (request, params));
520
+ //
521
+ // {
522
+ // "code":"A10000",
523
+ // "data":[
524
+ // {"amount":"0.0632","price":"0.037288","side":"BUY","timestamp":1599279694576},
525
+ // {"amount":"0.0052","price":"0.03715","side":"SELL","timestamp":1599276606852},
526
+ // {"amount":"0.0058","price":"0.037188","side":"SELL","timestamp":1599275187812},
527
+ // ],
528
+ // "message":"Success"
529
+ // }
530
+ //
531
+ const data = this.safeValue (response, 'data', []);
532
+ return this.parseTrades (data, market, since, limit);
533
+ }
534
+
535
+ async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
536
+ await this.loadMarkets ();
537
+ const market = this.market (symbol);
538
+ const request = {
539
+ 'symbol': market['id'],
540
+ 'unit': this.timeframes[timeframe],
541
+ };
542
+ const duration = this.parseTimeframe (timeframe);
543
+ const now = this.seconds ();
544
+ if (limit === undefined) {
545
+ limit = 3000; // max
546
+ }
547
+ if (since === undefined) {
548
+ request['from'] = now - limit * duration;
549
+ request['to'] = now;
550
+ } else {
551
+ const startFrom = parseInt (since / 1000);
552
+ request['from'] = startFrom;
553
+ request['to'] = this.sum (startFrom, limit * duration);
554
+ }
555
+ const response = await this.publicGetMarketKlineHistory (this.extend (request, params));
556
+ //
557
+ // {
558
+ // "code": "A10000",
559
+ // "data": [
560
+ // {
561
+ // "amount": 8.25709100,
562
+ // "closePrice": 62553.20,
563
+ // "count": 29,
564
+ // "highPrice": 62592.87,
565
+ // "lowPrice": 62553.20,
566
+ // "openPrice": 62554.23,
567
+ // "score": 1602501480,
568
+ // "symbol": "BTC_BRL",
569
+ // "vol": 516784.2504067500
570
+ // }
571
+ // ],
572
+ // "message": "Success"
573
+ // }
574
+ //
575
+ const data = this.safeValue (response, 'data', []);
576
+ return this.parseOHLCVs (data, market, timeframe, since, limit);
577
+ }
578
+
579
+ parseOHLCV (ohlcv, market = undefined) {
580
+ //
581
+ // {
582
+ // "amount": 8.25709100,
583
+ // "closePrice": 62553.20,
584
+ // "count": 29,
585
+ // "highPrice": 62592.87,
586
+ // "lowPrice": 62553.20,
587
+ // "openPrice": 62554.23,
588
+ // "score": 1602501480,
589
+ // "symbol": "BTC_BRL",
590
+ // "vol": 516784.2504067500
591
+ // }
592
+ //
593
+ const options = this.safeValue (this.options, 'fetchOHLCV', {});
594
+ const volumeField = this.safeString (options, 'volume', 'amount'); // or vol
595
+ return [
596
+ this.safeTimestamp (ohlcv, 'score'),
597
+ this.safeNumber (ohlcv, 'openPrice'),
598
+ this.safeNumber (ohlcv, 'highPrice'),
599
+ this.safeNumber (ohlcv, 'lowPrice'),
600
+ this.safeNumber (ohlcv, 'closePrice'),
601
+ this.safeNumber (ohlcv, volumeField),
602
+ ];
603
+ }
604
+
605
+ parseBalance (response) {
606
+ const data = this.safeValue (response, 'data', []);
607
+ const result = {
608
+ 'info': response,
609
+ 'timestamp': undefined,
610
+ 'datetime': undefined,
611
+ };
612
+ for (let i = 0; i < data.length; i++) {
613
+ const balance = data[i];
614
+ const currencyId = this.safeString (balance, 'currency');
615
+ const code = this.safeCurrencyCode (currencyId);
616
+ const account = this.account ();
617
+ account['total'] = this.safeString (balance, 'balance');
618
+ account['free'] = this.safeString (balance, 'available');
619
+ account['used'] = this.safeString (balance, 'hold');
620
+ result[code] = account;
621
+ }
622
+ return this.safeBalance (result);
623
+ }
624
+
625
+ async fetchBalance (params = {}) {
626
+ await this.loadMarkets ();
627
+ const response = await this.privateGetAccountGetBalance (params);
628
+ //
629
+ // {
630
+ // "code": "A10000",
631
+ // "data": [
632
+ // {
633
+ // "available": "1.23",
634
+ // "balance": "0.23",
635
+ // "currency": "BTC",
636
+ // "hold": "1"
637
+ // }
638
+ // ],
639
+ // "message": "Success"
640
+ // }
641
+ //
642
+ return this.parseBalance (response);
643
+ }
644
+
645
+ async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
646
+ await this.loadMarkets ();
647
+ const market = this.market (symbol);
648
+ let uppercaseType = type.toUpperCase ();
649
+ const uppercaseSide = side.toUpperCase ();
650
+ const request = {
651
+ 'symbol': market['id'],
652
+ 'side': uppercaseSide, // or SELL
653
+ // 'amount': this.amountToPrecision (symbol, amount),
654
+ // "price": "1234.5678", // required for LIMIT and STOP orders
655
+ // 'operator': '' // for stop orders, can be found in order introduction
656
+ // 'stopPrice': this.priceToPrecision (symbol, stopPrice),
657
+ // 'accountId': '...', // subaccount id, optional
658
+ };
659
+ const stopPrice = this.safeNumber (params, 'stopPrice');
660
+ if (stopPrice === undefined) {
661
+ if ((uppercaseType === 'STOP_LIMIT') || (uppercaseType === 'STOP_MARKET')) {
662
+ throw new ArgumentsRequired (this.id + ' createOrder() requires a stopPrice parameter for ' + uppercaseType + ' orders');
663
+ }
664
+ } else {
665
+ if (uppercaseType === 'LIMIT') {
666
+ uppercaseType = 'STOP_LIMIT';
667
+ } else if (uppercaseType === 'MARKET') {
668
+ uppercaseType = 'STOP_MARKET';
669
+ }
670
+ const defaultOperator = (uppercaseSide === 'BUY') ? 'LTE' : 'GTE';
671
+ request['operator'] = this.safeString (params, 'operator', defaultOperator);
672
+ request['stopPrice'] = this.priceToPrecision (symbol, stopPrice);
673
+ params = this.omit (params, 'stopPrice');
674
+ }
675
+ if ((uppercaseType === 'LIMIT') || (uppercaseType === 'STOP_LIMIT')) {
676
+ request['price'] = this.priceToPrecision (symbol, price);
677
+ request['amount'] = this.amountToPrecision (symbol, amount);
678
+ } else if ((uppercaseType === 'MARKET') || (uppercaseType === 'STOP_MARKET')) {
679
+ if (uppercaseSide === 'SELL') {
680
+ request['amount'] = this.amountToPrecision (symbol, amount);
681
+ } else if (uppercaseSide === 'BUY') {
682
+ let value = this.safeNumber (params, 'value');
683
+ const createMarketBuyOrderRequiresPrice = this.safeValue (this.options, 'createMarketBuyOrderRequiresPrice', true);
684
+ if (createMarketBuyOrderRequiresPrice) {
685
+ if (price !== undefined) {
686
+ if (value === undefined) {
687
+ value = amount * price;
688
+ }
689
+ } else if (value === undefined) {
690
+ 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, or, alternatively, add .options['createMarketBuyOrderRequiresPrice'] = false and supply the total cost value in the 'amount' argument or in the 'value' extra parameter (the exchange-specific behaviour)");
691
+ }
692
+ } else {
693
+ value = (value === undefined) ? amount : value;
694
+ }
695
+ const precision = market['precision']['price'];
696
+ request['value'] = this.decimalToPrecision (value, TRUNCATE, precision, this.precisionMode);
697
+ }
698
+ }
699
+ request['type'] = uppercaseType;
700
+ const response = await this.privatePostOrdersCreate (this.extend (request, params));
701
+ //
702
+ // {
703
+ // "code": "A10000",
704
+ // "data": {
705
+ // "amount": "0.001",
706
+ // "averagePrice": null,
707
+ // "filledAmount": "0",
708
+ // "filledFee": "0",
709
+ // "filledValue": "0",
710
+ // "id": "870613508008464384",
711
+ // "operator": "GTE",
712
+ // "price": "210000",
713
+ // "side": "BUY",
714
+ // "status": "SUBMITTED",
715
+ // "stopPrice": "211000",
716
+ // "symbol": "BTC_BRL",
717
+ // "timestamp": 1627612035528,
718
+ // "type": "STOP_LIMIT",
719
+ // "value": "210"
720
+ // },
721
+ // "message": "Success"
722
+ // }
723
+ //
724
+ const data = this.safeValue (response, 'data', {});
725
+ return this.parseOrder (data, market);
726
+ }
727
+
728
+ async cancelOrder (id, symbol = undefined, params = {}) {
729
+ await this.loadMarkets ();
730
+ const request = {
731
+ 'id': id,
732
+ };
733
+ const response = await this.privatePostOrdersCancel (this.extend (request, params));
734
+ //
735
+ // {
736
+ // "code": "A10000",
737
+ // "data": {
738
+ // "result": true
739
+ // },
740
+ // "message": "Success"
741
+ // }
742
+ //
743
+ const data = this.safeValue (response, 'data', {});
744
+ return this.parseOrder (data);
745
+ }
746
+
747
+ async fetchOrder (id, symbol = undefined, params = {}) {
748
+ await this.loadMarkets ();
749
+ const request = {
750
+ 'id': id,
751
+ };
752
+ const response = await this.privateGetOrdersGet (this.extend (request, params));
753
+ //
754
+ // {
755
+ // "code": "A10000",
756
+ // "data": {
757
+ // "id": "608695623247466496",
758
+ // "symbol": "BTC_BRL",
759
+ // "type": "MARKET",
760
+ // "side": "SELL",
761
+ // "price": null,
762
+ // "averagePrice": "0",
763
+ // "amount": "0.123",
764
+ // "filledAmount": "0",
765
+ // "value": null,
766
+ // "filledValue": "0",
767
+ // "filledFee": "0",
768
+ // "status": "REJECTED",
769
+ // "timestamp": 1565165945588
770
+ // },
771
+ // "message": "Success"
772
+ // }
773
+ //
774
+ const data = this.safeValue (response, 'data', {});
775
+ return this.parseOrder (data);
776
+ }
777
+
778
+ async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
779
+ await this.loadMarkets ();
780
+ const request = {
781
+ // 'symbol': market['id'],
782
+ // 'status': 'SUBMITTED,PROCESSING', // SUBMITTED, PROCESSING, PARTIAL_FILLED, CANCELING, FILLED, CANCELED, REJECTED
783
+ // 'fromId': '...', // order id to begin with
784
+ // 'toId': '...', // order id to end up with
785
+ // 'fromTimestamp': since,
786
+ // 'toTimestamp': this.milliseconds (),
787
+ // 'limit': limit, // default 100, max 100
788
+ };
789
+ let market = undefined;
790
+ if (symbol !== undefined) {
791
+ market = this.market (symbol);
792
+ request['symbol'] = market['id'];
793
+ }
794
+ if (limit !== undefined) {
795
+ request['limit'] = limit; // default 100, max 100
796
+ }
797
+ if (since !== undefined) {
798
+ request['fromTimestamp'] = since;
799
+ }
800
+ const response = await this.privateGetOrdersList (this.extend (request, params));
801
+ //
802
+ // {
803
+ // "code": "A10000",
804
+ // "data": [
805
+ // {
806
+ // "id": "608695678650028032",
807
+ // "symbol": "BTC_BRL",
808
+ // "type": "MARKET",
809
+ // "side": "SELL",
810
+ // "price": null,
811
+ // "averagePrice": "0",
812
+ // "amount": "0.123",
813
+ // "filledAmount": "0",
814
+ // "value": null,
815
+ // "filledValue": "0",
816
+ // "filledFee": "0",
817
+ // "status": "REJECTED",
818
+ // "timestamp": 1565165958796
819
+ // },
820
+ // ],
821
+ // "message": "Success"
822
+ // }
823
+ //
824
+ const data = this.safeValue (response, 'data', []);
825
+ return this.parseOrders (data, market, since, limit);
826
+ }
827
+
828
+ async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
829
+ const request = {
830
+ 'status': 'SUBMITTED,PROCESSING,PARTIAL_FILLED,CANCELING',
831
+ };
832
+ return await this.fetchOrders (symbol, since, limit, this.extend (request, params));
833
+ }
834
+
835
+ async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
836
+ const request = {
837
+ 'status': 'FILLED,CANCELED,REJECTED',
838
+ };
839
+ return await this.fetchOrders (symbol, since, limit, this.extend (request, params));
840
+ }
841
+
842
+ async fetchOrderTrades (id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
843
+ await this.loadMarkets ();
844
+ const request = {
845
+ 'id': id,
846
+ };
847
+ const response = await this.privateGetOrdersFill (this.extend (request, params));
848
+ let market = undefined;
849
+ if (symbol !== undefined) {
850
+ market = this.market (symbol);
851
+ }
852
+ const data = this.safeValue (response, 'data', []);
853
+ //
854
+ // {
855
+ // "code": "A10000",
856
+ // "data": [
857
+ // {
858
+ // "id": "608717046691139584",
859
+ // "orderId": "608716957545402368",
860
+ // "symbol": "BTC_BRL",
861
+ // "side": "BUY",
862
+ // "amount": "0.0988",
863
+ // "price": "45514.76",
864
+ // "fee": "0.0000988 BTC",
865
+ // "feeAmount": "0.0000988",
866
+ // "feeCurrency": "BTC",
867
+ // "role": "MAKER",
868
+ // "timestamp": 1565171053345
869
+ // },
870
+ // ],
871
+ // "message": "Success"
872
+ // }
873
+ //
874
+ return this.parseTrades (data, market, since, limit);
875
+ }
876
+
877
+ parseOrderStatus (status) {
878
+ const statuses = {
879
+ 'SUBMITTED': 'open',
880
+ 'PROCESSING': 'open',
881
+ 'PARTIAL_FILLED': 'open',
882
+ 'CANCELING': 'open',
883
+ 'FILLED': 'closed',
884
+ 'CANCELED': 'canceled',
885
+ 'REJECTED': 'rejected',
886
+ };
887
+ return this.safeString (statuses, status, status);
888
+ }
889
+
890
+ parseOrder (order, market = undefined) {
891
+ //
892
+ // createOrder, fetchOrders, fetchOrder
893
+ //
894
+ // {
895
+ // "amount": "0.001",
896
+ // "averagePrice": null,
897
+ // "filledAmount": "0",
898
+ // "filledFee": "0",
899
+ // "filledValue": "0",
900
+ // "id": "870613508008464384",
901
+ // "operator": "GTE",
902
+ // "price": "210000",
903
+ // "side": "BUY",
904
+ // "status": "SUBMITTED",
905
+ // "stopPrice": "211000",
906
+ // "symbol": "BTC_BRL",
907
+ // "timestamp": 1627612035528,
908
+ // "type": "STOP_LIMIT",
909
+ // "value": "210"
910
+ // }
911
+ //
912
+ // cancelOrder
913
+ //
914
+ // {
915
+ // "result": true
916
+ // }
917
+ //
918
+ const id = this.safeString (order, 'id');
919
+ const amount = this.safeString (order, 'amount');
920
+ const price = this.safeString (order, 'price');
921
+ const cost = this.safeString2 (order, 'filledValue', 'value');
922
+ const type = this.safeStringLower (order, 'type');
923
+ const side = this.safeStringLower (order, 'side');
924
+ const status = this.parseOrderStatus (this.safeString (order, 'status'));
925
+ const timestamp = this.safeInteger (order, 'timestamp');
926
+ const average = this.safeString (order, 'averagePrice');
927
+ const filled = this.safeString (order, 'filledAmount');
928
+ let fee = undefined;
929
+ const feeCost = this.safeNumber (order, 'filledFee');
930
+ if (feeCost !== undefined) {
931
+ fee = {
932
+ 'cost': feeCost,
933
+ 'currency': undefined,
934
+ };
935
+ }
936
+ const marketId = this.safeString (order, 'symbol');
937
+ const symbol = this.safeSymbol (marketId, market, '_');
938
+ const stopPrice = this.safeNumber (order, 'stopPrice');
939
+ return this.safeOrder ({
940
+ 'id': id,
941
+ 'clientOrderId': undefined,
942
+ 'info': order,
943
+ 'timestamp': timestamp,
944
+ 'datetime': this.iso8601 (timestamp),
945
+ 'lastTradeTimestamp': undefined,
946
+ 'symbol': symbol,
947
+ 'type': type,
948
+ 'timeInForce': undefined,
949
+ 'postOnly': undefined,
950
+ 'side': side,
951
+ 'price': price,
952
+ 'stopPrice': stopPrice,
953
+ 'amount': amount,
954
+ 'cost': cost,
955
+ 'average': average,
956
+ 'filled': filled,
957
+ 'remaining': undefined,
958
+ 'status': status,
959
+ 'fee': fee,
960
+ 'trades': undefined,
961
+ }, market);
962
+ }
963
+
964
+ async transfer (code, amount, fromAccount, toAccount, params = {}) {
965
+ await this.loadMarkets ();
966
+ const currency = this.currency (code);
967
+ if (fromAccount !== 'main' && toAccount !== 'main') {
968
+ throw new ExchangeError (this.id + ' transfer() supports transfers between main account and subaccounts only');
969
+ }
970
+ // master-transfer-in = from master account to subaccount
971
+ // master-transfer-out = from subaccount to master account
972
+ const type = (fromAccount === 'main') ? 'master-transfer-in' : 'master-transfer-out';
973
+ const request = {
974
+ 'transferAmount': this.currencyToPrecision (code, amount),
975
+ 'currency': currency['id'],
976
+ 'subId': (type === 'master-transfer-in') ? toAccount : fromAccount,
977
+ 'transferType': type,
978
+ };
979
+ const response = await this.privatePostAccountSubsTransfer (this.extend (request, params));
980
+ //
981
+ // {
982
+ // "code":"A10000",
983
+ // "message":"Success",
984
+ // "data":40
985
+ // }
986
+ //
987
+ const transfer = this.parseTransfer (response, currency);
988
+ const transferOptions = this.safeValue (this.options, 'transfer', {});
989
+ const fillResponseFromRequest = this.safeValue (transferOptions, 'fillResponseFromRequest', true);
990
+ if (fillResponseFromRequest) {
991
+ transfer['fromAccount'] = fromAccount;
992
+ transfer['toAccount'] = toAccount;
993
+ transfer['amount'] = amount;
994
+ }
995
+ return transfer;
996
+ }
997
+
998
+ parseTransfer (transfer, currency = undefined) {
999
+ //
1000
+ // {
1001
+ // "code":"A10000",
1002
+ // "message":"Success",
1003
+ // "data":40
1004
+ // }
1005
+ //
1006
+ const id = this.safeString (transfer, 'data');
1007
+ const status = this.safeString (transfer, 'message');
1008
+ return {
1009
+ 'info': transfer,
1010
+ 'id': id,
1011
+ 'amount': undefined,
1012
+ 'code': this.safeCurrencyCode (undefined, currency),
1013
+ 'fromAccount': undefined,
1014
+ 'toAccount': undefined,
1015
+ 'timestamp': undefined,
1016
+ 'datetime': undefined,
1017
+ 'status': status,
1018
+ };
1019
+ }
1020
+
1021
+ parseTransferStatus (status) {
1022
+ const statuses = {
1023
+ 'SUCCESS': 'pending',
1024
+ };
1025
+ return this.safeString (statuses, status, 'failed');
1026
+ }
1027
+
1028
+ async withdraw (code, amount, address, tag = undefined, params = {}) {
1029
+ [ tag, params ] = this.handleWithdrawTagAndParams (tag, params);
1030
+ await this.loadMarkets ();
1031
+ const currency = this.currency (code);
1032
+ const request = {
1033
+ 'code': currency['id'],
1034
+ 'amount': this.currencyToPrecision (code, amount),
1035
+ 'wallet': address,
1036
+ };
1037
+ if (tag !== undefined) {
1038
+ request['tag'] = tag;
1039
+ }
1040
+ const response = await this.privatePostAccountWithdrawCoin (this.extend (request, params));
1041
+ //
1042
+ // {
1043
+ // "code":"A10000",
1044
+ // "data": "DR123",
1045
+ // "message":"Success"
1046
+ // }
1047
+ //
1048
+ return this.parseTransaction (response, currency);
1049
+ }
1050
+
1051
+ async fetchAccounts (params = {}) {
1052
+ const response = await this.privateGetAccountSubs (params);
1053
+ //
1054
+ // {
1055
+ // "code": "A10000",
1056
+ // "data": [
1057
+ // {
1058
+ // "subId": "CA648856083527372800",
1059
+ // "state": "Normal",
1060
+ // "subAccount": "003",
1061
+ // "subIdentify": "003"
1062
+ // }
1063
+ // ],
1064
+ // "message": "Success"
1065
+ // }
1066
+ //
1067
+ const data = this.safeValue (response, 'data', []);
1068
+ const result = [];
1069
+ for (let i = 0; i < data.length; i++) {
1070
+ const account = data[i];
1071
+ const accountId = this.safeString (account, 'subId');
1072
+ const type = this.safeString (account, 'subAccount');
1073
+ result.push ({
1074
+ 'id': accountId,
1075
+ 'type': type,
1076
+ 'currency': undefined,
1077
+ 'info': account,
1078
+ });
1079
+ }
1080
+ return result;
1081
+ }
1082
+
1083
+ async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) {
1084
+ const request = {
1085
+ 'type': 'coin_in',
1086
+ };
1087
+ return await this.fetchTransactions (code, since, limit, this.extend (request, params));
1088
+ }
1089
+
1090
+ async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) {
1091
+ const request = {
1092
+ 'type': 'coin_out',
1093
+ };
1094
+ return await this.fetchTransactions (code, since, limit, this.extend (request, params));
1095
+ }
1096
+
1097
+ async fetchTransactions (code = undefined, since = undefined, limit = undefined, params = {}) {
1098
+ await this.loadMarkets ();
1099
+ const request = {
1100
+ // 'currency': currency['id'],
1101
+ // 'type': 'coin_in', // 'coin_out'
1102
+ // 'direct': 'asc', // 'desc'
1103
+ // 'size': limit, // default 100
1104
+ // 'start': id, // offset id
1105
+ };
1106
+ let currency = undefined;
1107
+ if (code !== undefined) {
1108
+ currency = this.currency (code);
1109
+ request['currency'] = currency['id'];
1110
+ }
1111
+ if (limit !== undefined) {
1112
+ request['size'] = limit;
1113
+ }
1114
+ const response = await this.privateGetWalletQueryDepositWithdraw (this.extend (request, params));
1115
+ //
1116
+ // {
1117
+ // "code": "A10000",
1118
+ // "data": [
1119
+ // {
1120
+ // "id": "DR562339304588709888",
1121
+ // "type": "COIN_IN",
1122
+ // "currency": "XLM",
1123
+ // "chain": "XLM",
1124
+ // "address": "GCUTK7KHPJC3ZQJ3OMWWFHAK2OXIBRD4LNZQRCCOVE7A2XOPP2K5PU5Q",
1125
+ // "addressTag": "1000009",
1126
+ // "amount": 1.0,
1127
+ // "state": "SUCCESS",
1128
+ // "txHash": "39210645748822f8d4ce673c7559aa6622e6e9cdd7073bc0fcae14b1edfda5f4",
1129
+ // "createdAt": 1554113737000,
1130
+ // "updatedAt": 1601371273000
1131
+ // }
1132
+ // ],
1133
+ // "message": "Success"
1134
+ // }
1135
+ //
1136
+ const data = this.safeValue (response, 'data', []);
1137
+ return this.parseTransactions (data, currency, since, limit);
1138
+ }
1139
+
1140
+ parseTransactionStatus (status) {
1141
+ // Pending the record is wait broadcast to chain
1142
+ // x/M confirming the comfirming state of tx, the M is total confirmings needed
1143
+ // SUCCESS the record is success full
1144
+ // FAIL the record failed
1145
+ const parts = status.split (' ');
1146
+ status = this.safeString (parts, 1, status);
1147
+ const statuses = {
1148
+ 'Pending': 'pending',
1149
+ 'confirming': 'pending',
1150
+ 'SUCCESS': 'ok',
1151
+ 'FAIL': 'failed',
1152
+ };
1153
+ return this.safeString (statuses, status, status);
1154
+ }
1155
+
1156
+ parseTransaction (transaction, currency = undefined) {
1157
+ //
1158
+ // withdraw
1159
+ //
1160
+ // {
1161
+ // "code":"A10000",
1162
+ // "data": "DR123",
1163
+ // "message":"Success"
1164
+ // }
1165
+ //
1166
+ // fetchTransactions
1167
+ //
1168
+ // {
1169
+ // "id": "DR562339304588709888",
1170
+ // "type": "COIN_IN",
1171
+ // "currency": "XLM",
1172
+ // "chain": "XLM",
1173
+ // "address": "GCUTK7KHPJC3ZQJ3OMWWFHAK2OXIBRD4LNZQRCCOVE7A2XOPP2K5PU5Q",
1174
+ // "addressTag": "1000009",
1175
+ // "amount": 1.0,
1176
+ // "state": "SUCCESS",
1177
+ // "txHash": "39210645748822f8d4ce673c7559aa6622e6e9cdd7073bc0fcae14b1edfda5f4",
1178
+ // "createdAt": 1554113737000,
1179
+ // "updatedAt": 1601371273000
1180
+ // }
1181
+ //
1182
+ const id = this.safeString2 (transaction, 'id', 'data');
1183
+ let type = this.safeString (transaction, 'type');
1184
+ if (type === 'COIN_IN') {
1185
+ type = 'deposit';
1186
+ } else if (type === 'COIN_OUT') {
1187
+ type = 'withdraw';
1188
+ }
1189
+ const amount = this.safeNumber (transaction, 'amount');
1190
+ const address = this.safeString (transaction, 'address');
1191
+ const tag = this.safeString (transaction, 'addressTag');
1192
+ const txid = this.safeString (transaction, 'txHash');
1193
+ const timestamp = this.safeInteger (transaction, 'createdAt');
1194
+ const updated = this.safeInteger (transaction, 'updatedAt');
1195
+ const currencyId = this.safeString (transaction, 'currency');
1196
+ const code = this.safeCurrencyCode (currencyId, currency);
1197
+ const status = this.parseTransactionStatus (this.safeString (transaction, 'state'));
1198
+ const network = this.safeString (transaction, 'chain');
1199
+ return {
1200
+ 'info': transaction,
1201
+ 'id': id,
1202
+ 'currency': code,
1203
+ 'amount': amount,
1204
+ 'network': network,
1205
+ 'address': address,
1206
+ 'addressTo': address,
1207
+ 'addressFrom': undefined,
1208
+ 'tag': tag,
1209
+ 'tagTo': tag,
1210
+ 'tagFrom': undefined,
1211
+ 'status': status,
1212
+ 'type': type,
1213
+ 'updated': updated,
1214
+ 'txid': txid,
1215
+ 'timestamp': timestamp,
1216
+ 'datetime': this.iso8601 (timestamp),
1217
+ 'fee': undefined,
1218
+ };
1219
+ }
1220
+
1221
+ async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
1222
+ await this.loadMarkets ();
1223
+ const request = {
1224
+ // 'orderId': id, // Order ID, string
1225
+ // 'symbol': market['id'], // The trading symbol, like BTC_BRL, string
1226
+ // 'fromId': fromId, // Search fill id to begin with, string
1227
+ // 'toId': toId, // Search fill id to end up with, string
1228
+ // 'fromTimestamp': since, // Search order fill time to begin with, in milliseconds, string
1229
+ // 'toTimestamp': this.milliseconds (), // Search order fill time to end up with, in milliseconds, string
1230
+ // 'limit': limit, // The number of fills to return, default 100, max 100, string
1231
+ // 'accountId': subaccountId, // Sub account ID, if not informed, the fills will be return under master account, string
1232
+ };
1233
+ let market = undefined;
1234
+ if (symbol !== undefined) {
1235
+ market = this.market (symbol);
1236
+ request['symbol'] = market['id'];
1237
+ }
1238
+ if (limit !== undefined) {
1239
+ request['limit'] = limit;
1240
+ }
1241
+ if (since !== undefined) {
1242
+ request['fromTimestamp'] = since;
1243
+ }
1244
+ const response = await this.privateGetOrdersFills (this.extend (request, params));
1245
+ //
1246
+ // {
1247
+ // "code": "A10000",
1248
+ // "data": [
1249
+ // {
1250
+ // "id": "608717046691139584",
1251
+ // "orderId": "608716957545402368",
1252
+ // "symbol": "BTC_BRL",
1253
+ // "side": "BUY",
1254
+ // "amount": "0.0988",
1255
+ // "price": "45514.76",
1256
+ // "fee": "0.0000988 BTC",
1257
+ // "feeAmount": "0.0000988",
1258
+ // "feeCurrency": "BTC",
1259
+ // "role": "MAKER",
1260
+ // "timestamp": 1565171053345
1261
+ // },
1262
+ // ],
1263
+ // "message": "Success"
1264
+ // }
1265
+ //
1266
+ const data = this.safeValue (response, 'data', []);
1267
+ return this.parseTrades (data, market, since, limit);
1268
+ }
1269
+
1270
+ sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
1271
+ const request = '/' + this.version + '/' + this.implodeParams (path, params);
1272
+ let url = this.urls['api'][api] + request;
1273
+ const query = this.omit (params, this.extractParams (path));
1274
+ if (api === 'public') {
1275
+ if (Object.keys (query).length) {
1276
+ url += '?' + this.urlencode (query);
1277
+ }
1278
+ } else if (api === 'private') {
1279
+ this.checkRequiredCredentials ();
1280
+ const timestamp = this.milliseconds ().toString ();
1281
+ headers = {
1282
+ 'X-Nova-Access-Key': this.apiKey,
1283
+ 'X-Nova-Timestamp': timestamp,
1284
+ };
1285
+ let queryString = undefined;
1286
+ if (method === 'POST') {
1287
+ body = this.json (query);
1288
+ queryString = this.hash (body, 'md5');
1289
+ headers['Content-Type'] = 'application/json';
1290
+ } else {
1291
+ if (Object.keys (query).length) {
1292
+ url += '?' + this.urlencode (query);
1293
+ }
1294
+ queryString = this.urlencode (this.keysort (query));
1295
+ }
1296
+ const auth = method + "\n" + request + "\n" + queryString + "\n" + timestamp; // eslint-disable-line quotes
1297
+ headers['X-Nova-Signature'] = this.hmac (this.encode (auth), this.encode (this.secret));
1298
+ }
1299
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
1300
+ }
1301
+
1302
+ handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
1303
+ if (response === undefined) {
1304
+ return;
1305
+ }
1306
+ //
1307
+ // {"code":"A10003","data":[],"message":"Authentication failed, Invalid accessKey."}
1308
+ //
1309
+ const errorCode = this.safeString (response, 'code');
1310
+ if (errorCode !== 'A10000') {
1311
+ const message = this.safeString (response, 'message');
1312
+ const feedback = this.id + ' ' + body;
1313
+ this.throwExactlyMatchedException (this.exceptions['exact'], errorCode, feedback);
1314
+ this.throwBroadlyMatchedException (this.exceptions['broad'], message, feedback);
1315
+ throw new ExchangeError (feedback); // unknown message
1316
+ }
1317
+ }
1318
+ };