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/bitbank.js ADDED
@@ -0,0 +1,842 @@
1
+ 'use strict';
2
+
3
+ // ---------------------------------------------------------------------------
4
+
5
+ const Exchange = require ('./base/Exchange');
6
+ const { ExchangeError, AuthenticationError, InvalidNonce, InsufficientFunds, InvalidOrder, OrderNotFound, PermissionDenied, ArgumentsRequired } = require ('./base/errors');
7
+
8
+ // ---------------------------------------------------------------------------
9
+
10
+ module.exports = class bitbank extends Exchange {
11
+ describe () {
12
+ return this.deepExtend (super.describe (), {
13
+ 'id': 'bitbank',
14
+ 'name': 'bitbank',
15
+ 'countries': [ 'JP' ],
16
+ 'version': 'v1',
17
+ 'has': {
18
+ 'CORS': undefined,
19
+ 'spot': true,
20
+ 'margin': false,
21
+ 'swap': false,
22
+ 'future': false,
23
+ 'option': false,
24
+ 'addMargin': false,
25
+ 'cancelOrder': true,
26
+ 'createOrder': true,
27
+ 'createReduceOnlyOrder': false,
28
+ 'fetchBalance': true,
29
+ 'fetchBorrowRate': false,
30
+ 'fetchBorrowRateHistories': false,
31
+ 'fetchBorrowRateHistory': false,
32
+ 'fetchBorrowRates': false,
33
+ 'fetchBorrowRatesPerSymbol': false,
34
+ 'fetchDepositAddress': true,
35
+ 'fetchFundingHistory': false,
36
+ 'fetchFundingRate': false,
37
+ 'fetchFundingRateHistory': false,
38
+ 'fetchFundingRates': false,
39
+ 'fetchIndexOHLCV': false,
40
+ 'fetchLeverage': false,
41
+ 'fetchLeverageTiers': false,
42
+ 'fetchMarkOHLCV': false,
43
+ 'fetchMyTrades': true,
44
+ 'fetchOHLCV': true,
45
+ 'fetchOpenOrders': true,
46
+ 'fetchOrder': true,
47
+ 'fetchOrderBook': true,
48
+ 'fetchPosition': false,
49
+ 'fetchPositions': false,
50
+ 'fetchPositionsRisk': false,
51
+ 'fetchPremiumIndexOHLCV': false,
52
+ 'fetchTicker': true,
53
+ 'fetchTrades': true,
54
+ 'fetchTradingFee': false,
55
+ 'fetchTradingFees': true,
56
+ 'fetchTransfer': false,
57
+ 'fetchTransfers': false,
58
+ 'reduceMargin': false,
59
+ 'setLeverage': false,
60
+ 'setMarginMode': false,
61
+ 'setPositionMode': false,
62
+ 'transfer': false,
63
+ 'withdraw': true,
64
+ },
65
+ 'timeframes': {
66
+ '1m': '1min',
67
+ '5m': '5min',
68
+ '15m': '15min',
69
+ '30m': '30min',
70
+ '1h': '1hour',
71
+ '4h': '4hour',
72
+ '8h': '8hour',
73
+ '12h': '12hour',
74
+ '1d': '1day',
75
+ '1w': '1week',
76
+ },
77
+ 'hostname': 'bitbank.cc',
78
+ 'urls': {
79
+ 'logo': 'https://user-images.githubusercontent.com/1294454/37808081-b87f2d9c-2e59-11e8-894d-c1900b7584fe.jpg',
80
+ 'api': {
81
+ 'public': 'https://public.{hostname}',
82
+ 'private': 'https://api.{hostname}',
83
+ 'markets': 'https://api.{hostname}',
84
+ },
85
+ 'www': 'https://bitbank.cc/',
86
+ 'doc': 'https://docs.bitbank.cc/',
87
+ 'fees': 'https://bitbank.cc/docs/fees/',
88
+ },
89
+ 'api': {
90
+ 'public': {
91
+ 'get': [
92
+ '{pair}/ticker',
93
+ '{pair}/depth',
94
+ '{pair}/transactions',
95
+ '{pair}/transactions/{yyyymmdd}',
96
+ '{pair}/candlestick/{candletype}/{yyyymmdd}',
97
+ ],
98
+ },
99
+ 'private': {
100
+ 'get': [
101
+ 'user/assets',
102
+ 'user/spot/order',
103
+ 'user/spot/active_orders',
104
+ 'user/spot/trade_history',
105
+ 'user/withdrawal_account',
106
+ ],
107
+ 'post': [
108
+ 'user/spot/order',
109
+ 'user/spot/cancel_order',
110
+ 'user/spot/cancel_orders',
111
+ 'user/spot/orders_info',
112
+ 'user/request_withdrawal',
113
+ ],
114
+ },
115
+ 'markets': {
116
+ 'get': [
117
+ 'spot/pairs',
118
+ ],
119
+ },
120
+ },
121
+ 'exceptions': {
122
+ '20001': AuthenticationError,
123
+ '20002': AuthenticationError,
124
+ '20003': AuthenticationError,
125
+ '20005': AuthenticationError,
126
+ '20004': InvalidNonce,
127
+ '40020': InvalidOrder,
128
+ '40021': InvalidOrder,
129
+ '40025': ExchangeError,
130
+ '40013': OrderNotFound,
131
+ '40014': OrderNotFound,
132
+ '50008': PermissionDenied,
133
+ '50009': OrderNotFound,
134
+ '50010': OrderNotFound,
135
+ '60001': InsufficientFunds,
136
+ '60005': InvalidOrder,
137
+ },
138
+ });
139
+ }
140
+
141
+ async fetchMarkets (params = {}) {
142
+ const response = await this.marketsGetSpotPairs (params);
143
+ //
144
+ // {
145
+ // "success": 1,
146
+ // "data": {
147
+ // "pairs": [
148
+ // {
149
+ // "name": "btc_jpy",
150
+ // "base_asset": "btc",
151
+ // "quote_asset": "jpy",
152
+ // "maker_fee_rate_base": "0",
153
+ // "taker_fee_rate_base": "0",
154
+ // "maker_fee_rate_quote": "-0.0002",
155
+ // "taker_fee_rate_quote": "0.0012",
156
+ // "unit_amount": "0.0001",
157
+ // "limit_max_amount": "1000",
158
+ // "market_max_amount": "10",
159
+ // "market_allowance_rate": "0.2",
160
+ // "price_digits": 0,
161
+ // "amount_digits": 4,
162
+ // "is_enabled": true,
163
+ // "stop_order": false,
164
+ // "stop_order_and_cancel": false
165
+ // }
166
+ // ]
167
+ // }
168
+ // }
169
+ //
170
+ const data = this.safeValue (response, 'data');
171
+ const pairs = this.safeValue (data, 'pairs', []);
172
+ const result = [];
173
+ for (let i = 0; i < pairs.length; i++) {
174
+ const entry = pairs[i];
175
+ const id = this.safeString (entry, 'name');
176
+ const baseId = this.safeString (entry, 'base_asset');
177
+ const quoteId = this.safeString (entry, 'quote_asset');
178
+ const base = this.safeCurrencyCode (baseId);
179
+ const quote = this.safeCurrencyCode (quoteId);
180
+ result.push ({
181
+ 'id': id,
182
+ 'symbol': base + '/' + quote,
183
+ 'base': base,
184
+ 'quote': quote,
185
+ 'settle': undefined,
186
+ 'baseId': baseId,
187
+ 'quoteId': quoteId,
188
+ 'settleId': undefined,
189
+ 'type': 'spot',
190
+ 'spot': true,
191
+ 'margin': false,
192
+ 'swap': false,
193
+ 'future': false,
194
+ 'option': false,
195
+ 'active': this.safeValue (entry, 'is_enabled'),
196
+ 'contract': false,
197
+ 'linear': undefined,
198
+ 'inverse': undefined,
199
+ 'taker': this.safeNumber (entry, 'taker_fee_rate_quote'),
200
+ 'maker': this.safeNumber (entry, 'maker_fee_rate_quote'),
201
+ 'contractSize': undefined,
202
+ 'expiry': undefined,
203
+ 'expiryDatetime': undefined,
204
+ 'strike': undefined,
205
+ 'optionType': undefined,
206
+ 'precision': {
207
+ 'amount': this.safeInteger (entry, 'amount_digits'),
208
+ 'price': this.safeInteger (entry, 'price_digits'),
209
+ },
210
+ 'limits': {
211
+ 'leverage': {
212
+ 'min': undefined,
213
+ 'max': undefined,
214
+ },
215
+ 'amount': {
216
+ 'min': this.safeNumber (entry, 'unit_amount'),
217
+ 'max': this.safeNumber (entry, 'limit_max_amount'),
218
+ },
219
+ 'price': {
220
+ 'min': undefined,
221
+ 'max': undefined,
222
+ },
223
+ 'cost': {
224
+ 'min': undefined,
225
+ 'max': undefined,
226
+ },
227
+ },
228
+ 'info': entry,
229
+ });
230
+ }
231
+ return result;
232
+ }
233
+
234
+ parseTicker (ticker, market = undefined) {
235
+ const symbol = this.safeSymbol (undefined, market);
236
+ const timestamp = this.safeInteger (ticker, 'timestamp');
237
+ const last = this.safeString (ticker, 'last');
238
+ return this.safeTicker ({
239
+ 'symbol': symbol,
240
+ 'timestamp': timestamp,
241
+ 'datetime': this.iso8601 (timestamp),
242
+ 'high': this.safeString (ticker, 'high'),
243
+ 'low': this.safeString (ticker, 'low'),
244
+ 'bid': this.safeString (ticker, 'buy'),
245
+ 'bidVolume': undefined,
246
+ 'ask': this.safeString (ticker, 'sell'),
247
+ 'askVolume': undefined,
248
+ 'vwap': undefined,
249
+ 'open': undefined,
250
+ 'close': last,
251
+ 'last': last,
252
+ 'previousClose': undefined,
253
+ 'change': undefined,
254
+ 'percentage': undefined,
255
+ 'average': undefined,
256
+ 'baseVolume': this.safeString (ticker, 'vol'),
257
+ 'quoteVolume': undefined,
258
+ 'info': ticker,
259
+ }, market, false);
260
+ }
261
+
262
+ async fetchTicker (symbol, params = {}) {
263
+ await this.loadMarkets ();
264
+ const market = this.market (symbol);
265
+ const request = {
266
+ 'pair': market['id'],
267
+ };
268
+ const response = await this.publicGetPairTicker (this.extend (request, params));
269
+ const data = this.safeValue (response, 'data', {});
270
+ return this.parseTicker (data, market);
271
+ }
272
+
273
+ async fetchOrderBook (symbol, limit = undefined, params = {}) {
274
+ await this.loadMarkets ();
275
+ const request = {
276
+ 'pair': this.marketId (symbol),
277
+ };
278
+ const response = await this.publicGetPairDepth (this.extend (request, params));
279
+ const orderbook = this.safeValue (response, 'data', {});
280
+ const timestamp = this.safeInteger (orderbook, 'timestamp');
281
+ return this.parseOrderBook (orderbook, symbol, timestamp);
282
+ }
283
+
284
+ parseTrade (trade, market = undefined) {
285
+ const timestamp = this.safeInteger (trade, 'executed_at');
286
+ market = this.safeMarket (undefined, market);
287
+ const priceString = this.safeString (trade, 'price');
288
+ const amountString = this.safeString (trade, 'amount');
289
+ const id = this.safeString2 (trade, 'transaction_id', 'trade_id');
290
+ const takerOrMaker = this.safeString (trade, 'maker_taker');
291
+ let fee = undefined;
292
+ const feeCostString = this.safeString (trade, 'fee_amount_quote');
293
+ if (feeCostString !== undefined) {
294
+ fee = {
295
+ 'currency': market['quote'],
296
+ 'cost': feeCostString,
297
+ };
298
+ }
299
+ const orderId = this.safeString (trade, 'order_id');
300
+ const type = this.safeString (trade, 'type');
301
+ const side = this.safeString (trade, 'side');
302
+ return this.safeTrade ({
303
+ 'timestamp': timestamp,
304
+ 'datetime': this.iso8601 (timestamp),
305
+ 'symbol': market['symbol'],
306
+ 'id': id,
307
+ 'order': orderId,
308
+ 'type': type,
309
+ 'side': side,
310
+ 'takerOrMaker': takerOrMaker,
311
+ 'price': priceString,
312
+ 'amount': amountString,
313
+ 'cost': undefined,
314
+ 'fee': fee,
315
+ 'info': trade,
316
+ }, market);
317
+ }
318
+
319
+ async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
320
+ await this.loadMarkets ();
321
+ const market = this.market (symbol);
322
+ const request = {
323
+ 'pair': market['id'],
324
+ };
325
+ const response = await this.publicGetPairTransactions (this.extend (request, params));
326
+ const data = this.safeValue (response, 'data', {});
327
+ const trades = this.safeValue (data, 'transactions', []);
328
+ return this.parseTrades (trades, market, since, limit);
329
+ }
330
+
331
+ async fetchTradingFees (params = {}) {
332
+ await this.loadMarkets ();
333
+ const response = await this.marketsGetSpotPairs (params);
334
+ //
335
+ // {
336
+ // success: '1',
337
+ // data: {
338
+ // pairs: [
339
+ // {
340
+ // name: 'btc_jpy',
341
+ // base_asset: 'btc',
342
+ // quote_asset: 'jpy',
343
+ // maker_fee_rate_base: '0',
344
+ // taker_fee_rate_base: '0',
345
+ // maker_fee_rate_quote: '-0.0002',
346
+ // taker_fee_rate_quote: '0.0012',
347
+ // unit_amount: '0.0001',
348
+ // limit_max_amount: '1000',
349
+ // market_max_amount: '10',
350
+ // market_allowance_rate: '0.2',
351
+ // price_digits: '0',
352
+ // amount_digits: '4',
353
+ // is_enabled: true,
354
+ // stop_order: false,
355
+ // stop_order_and_cancel: false
356
+ // },
357
+ // ...
358
+ // ]
359
+ // }
360
+ // }
361
+ //
362
+ const data = this.safeValue (response, 'data', {});
363
+ const pairs = this.safeValue (data, 'pairs', []);
364
+ const result = {};
365
+ for (let i = 0; i < pairs.length; i++) {
366
+ const pair = pairs[i];
367
+ const marketId = this.safeString (pair, 'name');
368
+ const market = this.safeMarket (marketId);
369
+ const symbol = market['symbol'];
370
+ result[symbol] = {
371
+ 'info': pair,
372
+ 'symbol': symbol,
373
+ 'maker': this.safeNumber (pair, 'maker_fee_rate_quote'),
374
+ 'taker': this.safeNumber (pair, 'taker_fee_rate_quote'),
375
+ 'percentage': true,
376
+ 'tierBased': false,
377
+ };
378
+ }
379
+ return result;
380
+ }
381
+
382
+ parseOHLCV (ohlcv, market = undefined) {
383
+ //
384
+ // [
385
+ // "0.02501786",
386
+ // "0.02501786",
387
+ // "0.02501786",
388
+ // "0.02501786",
389
+ // "0.0000",
390
+ // 1591488000000
391
+ // ]
392
+ //
393
+ return [
394
+ this.safeInteger (ohlcv, 5),
395
+ this.safeNumber (ohlcv, 0),
396
+ this.safeNumber (ohlcv, 1),
397
+ this.safeNumber (ohlcv, 2),
398
+ this.safeNumber (ohlcv, 3),
399
+ this.safeNumber (ohlcv, 4),
400
+ ];
401
+ }
402
+
403
+ async fetchOHLCV (symbol, timeframe = '5m', since = undefined, limit = undefined, params = {}) {
404
+ if (since === undefined) {
405
+ throw new ArgumentsRequired (this.id + ' fetchOHLCV() requires a since argument');
406
+ }
407
+ await this.loadMarkets ();
408
+ const market = this.market (symbol);
409
+ const request = {
410
+ 'pair': market['id'],
411
+ 'candletype': this.timeframes[timeframe],
412
+ 'yyyymmdd': this.yyyymmdd (since, ''),
413
+ };
414
+ const response = await this.publicGetPairCandlestickCandletypeYyyymmdd (this.extend (request, params));
415
+ //
416
+ // {
417
+ // "success":1,
418
+ // "data":{
419
+ // "candlestick":[
420
+ // {
421
+ // "type":"5min",
422
+ // "ohlcv":[
423
+ // ["0.02501786","0.02501786","0.02501786","0.02501786","0.0000",1591488000000],
424
+ // ["0.02501747","0.02501953","0.02501747","0.02501953","0.3017",1591488300000],
425
+ // ["0.02501762","0.02501762","0.02500392","0.02500392","0.1500",1591488600000],
426
+ // ]
427
+ // }
428
+ // ],
429
+ // "timestamp":1591508668190
430
+ // }
431
+ // }
432
+ //
433
+ const data = this.safeValue (response, 'data', {});
434
+ const candlestick = this.safeValue (data, 'candlestick', []);
435
+ const first = this.safeValue (candlestick, 0, {});
436
+ const ohlcv = this.safeValue (first, 'ohlcv', []);
437
+ return this.parseOHLCVs (ohlcv, market, timeframe, since, limit);
438
+ }
439
+
440
+ parseBalance (response) {
441
+ const result = {
442
+ 'info': response,
443
+ 'timestamp': undefined,
444
+ 'datetime': undefined,
445
+ };
446
+ const data = this.safeValue (response, 'data', {});
447
+ const assets = this.safeValue (data, 'assets', []);
448
+ for (let i = 0; i < assets.length; i++) {
449
+ const balance = assets[i];
450
+ const currencyId = this.safeString (balance, 'asset');
451
+ const code = this.safeCurrencyCode (currencyId);
452
+ const account = this.account ();
453
+ account['free'] = this.safeString (balance, 'free_amount');
454
+ account['used'] = this.safeString (balance, 'locked_amount');
455
+ account['total'] = this.safeString (balance, 'onhand_amount');
456
+ result[code] = account;
457
+ }
458
+ return this.safeBalance (result);
459
+ }
460
+
461
+ async fetchBalance (params = {}) {
462
+ await this.loadMarkets ();
463
+ const response = await this.privateGetUserAssets (params);
464
+ //
465
+ // {
466
+ // "success": "1",
467
+ // "data": {
468
+ // "assets": [
469
+ // {
470
+ // "asset": "jpy",
471
+ // "amount_precision": "4",
472
+ // "onhand_amount": "0.0000",
473
+ // "locked_amount": "0.0000",
474
+ // "free_amount": "0.0000",
475
+ // "stop_deposit": false,
476
+ // "stop_withdrawal": false,
477
+ // "withdrawal_fee": {
478
+ // "threshold": "30000.0000",
479
+ // "under": "550.0000",
480
+ // "over": "770.0000"
481
+ // }
482
+ // },
483
+ // {
484
+ // "asset": "btc",
485
+ // "amount_precision": "8",
486
+ // "onhand_amount": "0.00000000",
487
+ // "locked_amount": "0.00000000",
488
+ // "free_amount": "0.00000000",
489
+ // "stop_deposit": false,
490
+ // "stop_withdrawal": false,
491
+ // "withdrawal_fee": "0.00060000"
492
+ // },
493
+ // ]
494
+ // }
495
+ // }
496
+ //
497
+ return this.parseBalance (response);
498
+ }
499
+
500
+ parseOrderStatus (status) {
501
+ const statuses = {
502
+ 'UNFILLED': 'open',
503
+ 'PARTIALLY_FILLED': 'open',
504
+ 'FULLY_FILLED': 'closed',
505
+ 'CANCELED_UNFILLED': 'canceled',
506
+ 'CANCELED_PARTIALLY_FILLED': 'canceled',
507
+ };
508
+ return this.safeString (statuses, status, status);
509
+ }
510
+
511
+ parseOrder (order, market = undefined) {
512
+ const id = this.safeString (order, 'order_id');
513
+ const marketId = this.safeString (order, 'pair');
514
+ market = this.safeMarket (marketId, market);
515
+ const timestamp = this.safeInteger (order, 'ordered_at');
516
+ const price = this.safeString (order, 'price');
517
+ const amount = this.safeString (order, 'start_amount');
518
+ const filled = this.safeString (order, 'executed_amount');
519
+ const remaining = this.safeString (order, 'remaining_amount');
520
+ const average = this.safeString (order, 'average_price');
521
+ const status = this.parseOrderStatus (this.safeString (order, 'status'));
522
+ const type = this.safeStringLower (order, 'type');
523
+ const side = this.safeStringLower (order, 'side');
524
+ return this.safeOrder ({
525
+ 'id': id,
526
+ 'clientOrderId': undefined,
527
+ 'datetime': this.iso8601 (timestamp),
528
+ 'timestamp': timestamp,
529
+ 'lastTradeTimestamp': undefined,
530
+ 'status': status,
531
+ 'symbol': market['symbol'],
532
+ 'type': type,
533
+ 'timeInForce': undefined,
534
+ 'postOnly': undefined,
535
+ 'side': side,
536
+ 'price': price,
537
+ 'stopPrice': undefined,
538
+ 'cost': undefined,
539
+ 'average': average,
540
+ 'amount': amount,
541
+ 'filled': filled,
542
+ 'remaining': remaining,
543
+ 'trades': undefined,
544
+ 'fee': undefined,
545
+ 'info': order,
546
+ }, market);
547
+ }
548
+
549
+ async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
550
+ await this.loadMarkets ();
551
+ const market = this.market (symbol);
552
+ const request = {
553
+ 'pair': market['id'],
554
+ 'amount': this.amountToPrecision (symbol, amount),
555
+ 'side': side,
556
+ 'type': type,
557
+ };
558
+ if (type === 'limit') {
559
+ request['price'] = this.priceToPrecision (symbol, price);
560
+ }
561
+ const response = await this.privatePostUserSpotOrder (this.extend (request, params));
562
+ const data = this.safeValue (response, 'data');
563
+ return this.parseOrder (data, market);
564
+ }
565
+
566
+ async cancelOrder (id, symbol = undefined, params = {}) {
567
+ await this.loadMarkets ();
568
+ const market = this.market (symbol);
569
+ const request = {
570
+ 'order_id': id,
571
+ 'pair': market['id'],
572
+ };
573
+ const response = await this.privatePostUserSpotCancelOrder (this.extend (request, params));
574
+ const data = this.safeValue (response, 'data');
575
+ return data;
576
+ }
577
+
578
+ async fetchOrder (id, symbol = undefined, params = {}) {
579
+ await this.loadMarkets ();
580
+ const market = this.market (symbol);
581
+ const request = {
582
+ 'order_id': id,
583
+ 'pair': market['id'],
584
+ };
585
+ const response = await this.privateGetUserSpotOrder (this.extend (request, params));
586
+ const data = this.safeValue (response, 'data');
587
+ return this.parseOrder (data, market);
588
+ }
589
+
590
+ async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
591
+ await this.loadMarkets ();
592
+ const market = this.market (symbol);
593
+ const request = {
594
+ 'pair': market['id'],
595
+ };
596
+ if (limit !== undefined) {
597
+ request['count'] = limit;
598
+ }
599
+ if (since !== undefined) {
600
+ request['since'] = parseInt (since / 1000);
601
+ }
602
+ const response = await this.privateGetUserSpotActiveOrders (this.extend (request, params));
603
+ const data = this.safeValue (response, 'data', {});
604
+ const orders = this.safeValue (data, 'orders', []);
605
+ return this.parseOrders (orders, market, since, limit);
606
+ }
607
+
608
+ async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
609
+ await this.loadMarkets ();
610
+ const request = {};
611
+ let market = undefined;
612
+ if (symbol !== undefined) {
613
+ request['pair'] = market['id'];
614
+ market = this.market (symbol);
615
+ }
616
+ if (limit !== undefined) {
617
+ request['count'] = limit;
618
+ }
619
+ if (since !== undefined) {
620
+ request['since'] = parseInt (since / 1000);
621
+ }
622
+ const response = await this.privateGetUserSpotTradeHistory (this.extend (request, params));
623
+ const data = this.safeValue (response, 'data', {});
624
+ const trades = this.safeValue (data, 'trades', []);
625
+ return this.parseTrades (trades, market, since, limit);
626
+ }
627
+
628
+ async fetchDepositAddress (code, params = {}) {
629
+ await this.loadMarkets ();
630
+ const currency = this.currency (code);
631
+ const request = {
632
+ 'asset': currency['id'],
633
+ };
634
+ const response = await this.privateGetUserWithdrawalAccount (this.extend (request, params));
635
+ const data = this.safeValue (response, 'data', {});
636
+ // Not sure about this if there could be more than one account...
637
+ const accounts = this.safeValue (data, 'accounts', []);
638
+ const firstAccount = this.safeValue (accounts, 0, {});
639
+ const address = this.safeString (firstAccount, 'address');
640
+ return {
641
+ 'currency': currency,
642
+ 'address': address,
643
+ 'tag': undefined,
644
+ 'network': undefined,
645
+ 'info': response,
646
+ };
647
+ }
648
+
649
+ async withdraw (code, amount, address, tag = undefined, params = {}) {
650
+ [ tag, params ] = this.handleWithdrawTagAndParams (tag, params);
651
+ if (!('uuid' in params)) {
652
+ throw new ExchangeError (this.id + ' uuid is required for withdrawal');
653
+ }
654
+ await this.loadMarkets ();
655
+ const currency = this.currency (code);
656
+ const request = {
657
+ 'asset': currency['id'],
658
+ 'amount': amount,
659
+ };
660
+ const response = await this.privatePostUserRequestWithdrawal (this.extend (request, params));
661
+ //
662
+ // {
663
+ // "success": 1,
664
+ // "data": {
665
+ // "uuid": "string",
666
+ // "asset": "btc",
667
+ // "amount": 0,
668
+ // "account_uuid": "string",
669
+ // "fee": 0,
670
+ // "status": "DONE",
671
+ // "label": "string",
672
+ // "txid": "string",
673
+ // "address": "string",
674
+ // "requested_at": 0
675
+ // }
676
+ // }
677
+ //
678
+ const data = this.safeValue (response, 'data', {});
679
+ return this.parseTransaction (data, currency);
680
+ }
681
+
682
+ parseTransaction (transaction, currency = undefined) {
683
+ //
684
+ // withdraw
685
+ //
686
+ // {
687
+ // "uuid": "string",
688
+ // "asset": "btc",
689
+ // "amount": 0,
690
+ // "account_uuid": "string",
691
+ // "fee": 0,
692
+ // "status": "DONE",
693
+ // "label": "string",
694
+ // "txid": "string",
695
+ // "address": "string",
696
+ // "requested_at": 0
697
+ // }
698
+ //
699
+ const txid = this.safeString (transaction, 'txid');
700
+ currency = this.safeCurrency (undefined, currency);
701
+ return {
702
+ 'id': txid,
703
+ 'txid': txid,
704
+ 'timestamp': undefined,
705
+ 'datetime': undefined,
706
+ 'network': undefined,
707
+ 'addressFrom': undefined,
708
+ 'address': undefined,
709
+ 'addressTo': undefined,
710
+ 'amount': undefined,
711
+ 'type': undefined,
712
+ 'currency': currency['code'],
713
+ 'status': undefined,
714
+ 'updated': undefined,
715
+ 'tagFrom': undefined,
716
+ 'tag': undefined,
717
+ 'tagTo': undefined,
718
+ 'comment': undefined,
719
+ 'fee': undefined,
720
+ 'info': transaction,
721
+ };
722
+ }
723
+
724
+ nonce () {
725
+ return this.milliseconds ();
726
+ }
727
+
728
+ sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
729
+ let query = this.omit (params, this.extractParams (path));
730
+ let url = this.implodeHostname (this.urls['api'][api]) + '/';
731
+ if ((api === 'public') || (api === 'markets')) {
732
+ url += this.implodeParams (path, params);
733
+ if (Object.keys (query).length) {
734
+ url += '?' + this.urlencode (query);
735
+ }
736
+ } else {
737
+ this.checkRequiredCredentials ();
738
+ const nonce = this.nonce ().toString ();
739
+ let auth = nonce;
740
+ url += this.version + '/' + this.implodeParams (path, params);
741
+ if (method === 'POST') {
742
+ body = this.json (query);
743
+ auth += body;
744
+ } else {
745
+ auth += '/' + this.version + '/' + path;
746
+ if (Object.keys (query).length) {
747
+ query = this.urlencode (query);
748
+ url += '?' + query;
749
+ auth += '?' + query;
750
+ }
751
+ }
752
+ headers = {
753
+ 'Content-Type': 'application/json',
754
+ 'ACCESS-KEY': this.apiKey,
755
+ 'ACCESS-NONCE': nonce,
756
+ 'ACCESS-SIGNATURE': this.hmac (this.encode (auth), this.encode (this.secret)),
757
+ };
758
+ }
759
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
760
+ }
761
+
762
+ handleErrors (httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
763
+ if (response === undefined) {
764
+ return;
765
+ }
766
+ const success = this.safeInteger (response, 'success');
767
+ const data = this.safeValue (response, 'data');
768
+ if (!success || !data) {
769
+ const errorMessages = {
770
+ '10000': 'URL does not exist',
771
+ '10001': 'A system error occurred. Please contact support',
772
+ '10002': 'Invalid JSON format. Please check the contents of transmission',
773
+ '10003': 'A system error occurred. Please contact support',
774
+ '10005': 'A timeout error occurred. Please wait for a while and try again',
775
+ '20001': 'API authentication failed',
776
+ '20002': 'Illegal API key',
777
+ '20003': 'API key does not exist',
778
+ '20004': 'API Nonce does not exist',
779
+ '20005': 'API signature does not exist',
780
+ '20011': 'Two-step verification failed',
781
+ '20014': 'SMS authentication failed',
782
+ '30001': 'Please specify the order quantity',
783
+ '30006': 'Please specify the order ID',
784
+ '30007': 'Please specify the order ID array',
785
+ '30009': 'Please specify the stock',
786
+ '30012': 'Please specify the order price',
787
+ '30013': 'Trade Please specify either',
788
+ '30015': 'Please specify the order type',
789
+ '30016': 'Please specify asset name',
790
+ '30019': 'Please specify uuid',
791
+ '30039': 'Please specify the amount to be withdrawn',
792
+ '40001': 'The order quantity is invalid',
793
+ '40006': 'Count value is invalid',
794
+ '40007': 'End time is invalid',
795
+ '40008': 'end_id Value is invalid',
796
+ '40009': 'The from_id value is invalid',
797
+ '40013': 'The order ID is invalid',
798
+ '40014': 'The order ID array is invalid',
799
+ '40015': 'Too many specified orders',
800
+ '40017': 'Incorrect issue name',
801
+ '40020': 'The order price is invalid',
802
+ '40021': 'The trading classification is invalid',
803
+ '40022': 'Start date is invalid',
804
+ '40024': 'The order type is invalid',
805
+ '40025': 'Incorrect asset name',
806
+ '40028': 'uuid is invalid',
807
+ '40048': 'The amount of withdrawal is illegal',
808
+ '50003': 'Currently, this account is in a state where you can not perform the operation you specified. Please contact support',
809
+ '50004': 'Currently, this account is temporarily registered. Please try again after registering your account',
810
+ '50005': 'Currently, this account is locked. Please contact support',
811
+ '50006': 'Currently, this account is locked. Please contact support',
812
+ '50008': 'User identification has not been completed',
813
+ '50009': 'Your order does not exist',
814
+ '50010': 'Can not cancel specified order',
815
+ '50011': 'API not found',
816
+ '60001': 'The number of possessions is insufficient',
817
+ '60002': 'It exceeds the quantity upper limit of the tender buying order',
818
+ '60003': 'The specified quantity exceeds the limit',
819
+ '60004': 'The specified quantity is below the threshold',
820
+ '60005': 'The specified price is above the limit',
821
+ '60006': 'The specified price is below the lower limit',
822
+ '70001': 'A system error occurred. Please contact support',
823
+ '70002': 'A system error occurred. Please contact support',
824
+ '70003': 'A system error occurred. Please contact support',
825
+ '70004': 'We are unable to accept orders as the transaction is currently suspended',
826
+ '70005': 'Order can not be accepted because purchase order is currently suspended',
827
+ '70006': 'We can not accept orders because we are currently unsubscribed ',
828
+ '70009': 'We are currently temporarily restricting orders to be carried out. Please use the limit order.',
829
+ '70010': 'We are temporarily raising the minimum order quantity as the system load is now rising.',
830
+ };
831
+ const errorClasses = this.exceptions;
832
+ const code = this.safeString (data, 'code');
833
+ const message = this.safeString (errorMessages, code, 'Error');
834
+ const ErrorClass = this.safeValue (errorClasses, code);
835
+ if (ErrorClass !== undefined) {
836
+ throw new ErrorClass (message);
837
+ } else {
838
+ throw new ExchangeError (this.id + ' ' + this.json (response));
839
+ }
840
+ }
841
+ }
842
+ };