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/tidebit.js ADDED
@@ -0,0 +1,632 @@
1
+ 'use strict';
2
+
3
+ // ---------------------------------------------------------------------------
4
+
5
+ const Exchange = require ('./base/Exchange');
6
+ const { ExchangeError, InsufficientFunds, OrderNotFound, ArgumentsRequired } = require ('./base/errors');
7
+
8
+ // ---------------------------------------------------------------------------
9
+
10
+ module.exports = class tidebit extends Exchange {
11
+ describe () {
12
+ return this.deepExtend (super.describe (), {
13
+ 'id': 'tidebit',
14
+ 'name': 'TideBit',
15
+ 'countries': [ 'HK' ],
16
+ 'rateLimit': 1000,
17
+ 'version': 'v2',
18
+ 'has': {
19
+ 'CORS': undefined,
20
+ 'spot': true,
21
+ 'margin': false,
22
+ 'swap': false,
23
+ 'future': false,
24
+ 'option': false,
25
+ 'addMargin': false,
26
+ 'cancelOrder': true,
27
+ 'createOrder': true,
28
+ 'createReduceOnlyOrder': false,
29
+ 'fetchBalance': true,
30
+ 'fetchBorrowRate': false,
31
+ 'fetchBorrowRateHistories': false,
32
+ 'fetchBorrowRateHistory': false,
33
+ 'fetchBorrowRates': false,
34
+ 'fetchBorrowRatesPerSymbol': false,
35
+ 'fetchDepositAddress': true,
36
+ 'fetchFundingHistory': false,
37
+ 'fetchFundingRate': false,
38
+ 'fetchFundingRateHistory': false,
39
+ 'fetchFundingRates': false,
40
+ 'fetchIndexOHLCV': false,
41
+ 'fetchLeverage': false,
42
+ 'fetchLeverageTiers': false,
43
+ 'fetchMarkets': true,
44
+ 'fetchMarkOHLCV': false,
45
+ 'fetchOHLCV': true,
46
+ 'fetchOrderBook': true,
47
+ 'fetchPosition': false,
48
+ 'fetchPositions': false,
49
+ 'fetchPositionsRisk': false,
50
+ 'fetchPremiumIndexOHLCV': false,
51
+ 'fetchTicker': true,
52
+ 'fetchTickers': true,
53
+ 'fetchTrades': true,
54
+ 'fetchTradingFee': false,
55
+ 'fetchTradingFees': false,
56
+ 'reduceMargin': false,
57
+ 'setLeverage': false,
58
+ 'setMarginMode': false,
59
+ 'setPositionMode': false,
60
+ 'withdraw': true,
61
+ },
62
+ 'timeframes': {
63
+ '1m': '1',
64
+ '5m': '5',
65
+ '15m': '15',
66
+ '30m': '30',
67
+ '1h': '60',
68
+ '2h': '120',
69
+ '4h': '240',
70
+ '12h': '720',
71
+ '1d': '1440',
72
+ '3d': '4320',
73
+ '1w': '10080',
74
+ },
75
+ 'urls': {
76
+ 'logo': 'https://user-images.githubusercontent.com/51840849/87460811-1e690280-c616-11ea-8652-69f187305add.jpg',
77
+ 'api': 'https://www.tidebit.com',
78
+ 'www': 'https://www.tidebit.com',
79
+ 'doc': [
80
+ 'https://www.tidebit.com/documents/api/guide',
81
+ 'https://www.tidebit.com/swagger/#/default',
82
+ ],
83
+ 'referral': 'http://bit.ly/2IX0LrM',
84
+ },
85
+ 'api': {
86
+ 'public': {
87
+ 'get': [
88
+ 'markets',
89
+ 'tickers',
90
+ 'tickers/{market}',
91
+ 'timestamp',
92
+ 'trades',
93
+ 'trades/{market}',
94
+ 'order_book',
95
+ 'order',
96
+ 'k_with_pending_trades',
97
+ 'k',
98
+ 'depth',
99
+ ],
100
+ 'post': [],
101
+ },
102
+ 'private': {
103
+ 'get': [
104
+ 'addresses/{address}',
105
+ 'deposits/history',
106
+ 'deposits/get_deposit',
107
+ 'deposits/deposit_address',
108
+ 'historys/orders',
109
+ 'historys/vouchers',
110
+ 'historys/accounts',
111
+ 'historys/snapshots',
112
+ 'linkage/get_status',
113
+ 'members/me',
114
+ 'order',
115
+ 'orders',
116
+ 'partners/orders/{id}/trades',
117
+ 'referral_commissions/get_undeposited',
118
+ 'referral_commissions/get_graph_data',
119
+ 'trades/my',
120
+ 'withdraws/bind_account_list',
121
+ 'withdraws/get_withdraw_account',
122
+ 'withdraws/fetch_bind_info',
123
+ ],
124
+ 'post': [
125
+ 'deposits/deposit_cash',
126
+ 'favorite_markets/update',
127
+ 'order/delete',
128
+ 'orders',
129
+ 'orders/multi',
130
+ 'orders/clear',
131
+ 'referral_commissions/deposit',
132
+ 'withdraws/apply',
133
+ 'withdraws/bind_bank',
134
+ 'withdraws/bind_address',
135
+ ],
136
+ },
137
+ },
138
+ 'fees': {
139
+ 'trading': {
140
+ 'tierBased': false,
141
+ 'percentage': true,
142
+ 'maker': this.parseNumber ('0.003'),
143
+ 'taker': this.parseNumber ('0.003'),
144
+ },
145
+ 'funding': {
146
+ 'tierBased': false,
147
+ 'percentage': true,
148
+ 'withdraw': {}, // There is only 1% fee on withdrawals to your bank account.
149
+ },
150
+ },
151
+ 'exceptions': {
152
+ '2002': InsufficientFunds,
153
+ '2003': OrderNotFound,
154
+ },
155
+ });
156
+ }
157
+
158
+ async fetchDepositAddress (code, params = {}) {
159
+ await this.loadMarkets ();
160
+ const currency = this.currency (code);
161
+ const request = {
162
+ 'currency': currency['id'],
163
+ };
164
+ const response = await this.privateGetDepositAddress (this.extend (request, params));
165
+ if ('success' in response) {
166
+ if (response['success']) {
167
+ const address = this.safeString (response, 'address');
168
+ const tag = this.safeString (response, 'addressTag');
169
+ return {
170
+ 'currency': code,
171
+ 'address': this.checkAddress (address),
172
+ 'tag': tag,
173
+ 'info': response,
174
+ };
175
+ }
176
+ }
177
+ }
178
+
179
+ async fetchMarkets (params = {}) {
180
+ const response = await this.publicGetMarkets (params);
181
+ const result = [];
182
+ for (let i = 0; i < response.length; i++) {
183
+ const market = response[i];
184
+ const id = this.safeString (market, 'id');
185
+ const symbol = this.safeString (market, 'name');
186
+ const [ baseId, quoteId ] = symbol.split ('/');
187
+ result.push ({
188
+ 'id': id,
189
+ 'symbol': symbol,
190
+ 'base': this.safeCurrencyCode (baseId),
191
+ 'quote': this.safeCurrencyCode (quoteId),
192
+ 'settle': undefined,
193
+ 'baseId': baseId,
194
+ 'quoteId': quoteId,
195
+ 'settleId': undefined,
196
+ 'type': 'spot',
197
+ 'spot': true,
198
+ 'margin': false,
199
+ 'swap': false,
200
+ 'future': false,
201
+ 'option': false,
202
+ 'active': undefined,
203
+ 'contract': false,
204
+ 'linear': undefined,
205
+ 'inverse': undefined,
206
+ 'contractSize': undefined,
207
+ 'expiry': undefined,
208
+ 'expiryDatetime': undefined,
209
+ 'strike': undefined,
210
+ 'optionType': undefined,
211
+ 'precision': this.precision,
212
+ 'limits': this.extend ({
213
+ 'leverage': {
214
+ 'min': undefined,
215
+ 'max': undefined,
216
+ },
217
+ }, this.limits),
218
+ 'info': market,
219
+ });
220
+ }
221
+ return result;
222
+ }
223
+
224
+ parseBalance (response) {
225
+ const balances = this.safeValue (response, 'accounts');
226
+ const result = { 'info': balances };
227
+ for (let i = 0; i < balances.length; i++) {
228
+ const balance = balances[i];
229
+ const currencyId = this.safeString (balance, 'currency');
230
+ const code = this.safeCurrencyCode (currencyId);
231
+ const account = this.account ();
232
+ account['free'] = this.safeString (balance, 'balance');
233
+ account['used'] = this.safeString (balance, 'locked');
234
+ result[code] = account;
235
+ }
236
+ return this.safeBalance (result);
237
+ }
238
+
239
+ async fetchBalance (params = {}) {
240
+ await this.loadMarkets ();
241
+ const response = await this.privateGetMembersMe (params);
242
+ return this.parseBalance (response);
243
+ }
244
+
245
+ async fetchOrderBook (symbol, limit = undefined, params = {}) {
246
+ await this.loadMarkets ();
247
+ const market = this.market (symbol);
248
+ const request = {
249
+ 'market': market['id'],
250
+ };
251
+ if (limit !== undefined) {
252
+ request['limit'] = limit; // default = 300
253
+ }
254
+ request['market'] = market['id'];
255
+ const response = await this.publicGetDepth (this.extend (request, params));
256
+ const timestamp = this.safeTimestamp (response, 'timestamp');
257
+ return this.parseOrderBook (response, symbol, timestamp);
258
+ }
259
+
260
+ parseTicker (ticker, market = undefined) {
261
+ //
262
+ // {
263
+ // "at":1398410899,
264
+ // "ticker": {
265
+ // "buy": "3000.0",
266
+ // "sell":"3100.0",
267
+ // "low":"3000.0",
268
+ // "high":"3000.0",
269
+ // "last":"3000.0",
270
+ // "vol":"0.11"
271
+ // }
272
+ // }
273
+ //
274
+ const timestamp = this.safeTimestamp (ticker, 'at');
275
+ ticker = this.safeValue (ticker, 'ticker', {});
276
+ market = this.safeMarket (undefined, market);
277
+ const last = this.safeString (ticker, 'last');
278
+ return this.safeTicker ({
279
+ 'symbol': market['symbol'],
280
+ 'timestamp': timestamp,
281
+ 'datetime': this.iso8601 (timestamp),
282
+ 'high': this.safeString (ticker, 'high'),
283
+ 'low': this.safeString (ticker, 'low'),
284
+ 'bid': this.safeString (ticker, 'buy'),
285
+ 'ask': this.safeString (ticker, 'sell'),
286
+ 'bidVolume': undefined,
287
+ 'askVolume': undefined,
288
+ 'vwap': undefined,
289
+ 'open': undefined,
290
+ 'close': last,
291
+ 'last': last,
292
+ 'change': undefined,
293
+ 'percentage': undefined,
294
+ 'previousClose': undefined,
295
+ 'average': undefined,
296
+ 'baseVolume': this.safeString (ticker, 'vol'),
297
+ 'quoteVolume': undefined,
298
+ 'info': ticker,
299
+ }, market, false);
300
+ }
301
+
302
+ async fetchTickers (symbols = undefined, params = {}) {
303
+ await this.loadMarkets ();
304
+ const tickers = await this.publicGetTickers (params);
305
+ const ids = Object.keys (tickers);
306
+ const result = {};
307
+ for (let i = 0; i < ids.length; i++) {
308
+ const id = ids[i];
309
+ const market = this.safeMarket (id);
310
+ const symbol = market['symbol'];
311
+ const ticker = tickers[id];
312
+ result[symbol] = this.parseTicker (ticker, market);
313
+ }
314
+ return this.filterByArray (result, 'symbol', symbols);
315
+ }
316
+
317
+ async fetchTicker (symbol, params = {}) {
318
+ await this.loadMarkets ();
319
+ const market = this.market (symbol);
320
+ const request = {
321
+ 'market': market['id'],
322
+ };
323
+ const response = await this.publicGetTickersMarket (this.extend (request, params));
324
+ //
325
+ // {
326
+ // "at":1398410899,
327
+ // "ticker": {
328
+ // "buy": "3000.0",
329
+ // "sell":"3100.0",
330
+ // "low":"3000.0",
331
+ // "high":"3000.0",
332
+ // "last":"3000.0",
333
+ // "vol":"0.11"
334
+ // }
335
+ // }
336
+ //
337
+ return this.parseTicker (response, market);
338
+ }
339
+
340
+ parseTrade (trade, market = undefined) {
341
+ const timestamp = this.parse8601 (this.safeString (trade, 'created_at'));
342
+ const id = this.safeString (trade, 'id');
343
+ const price = this.safeString (trade, 'price');
344
+ const amount = this.safeString (trade, 'volume');
345
+ market = this.safeMarket (undefined, market);
346
+ return this.safeTrade ({
347
+ 'id': id,
348
+ 'info': trade,
349
+ 'timestamp': timestamp,
350
+ 'datetime': this.iso8601 (timestamp),
351
+ 'symbol': market['symbol'],
352
+ 'type': undefined,
353
+ 'side': undefined,
354
+ 'order': undefined,
355
+ 'takerOrMaker': undefined,
356
+ 'price': price,
357
+ 'amount': amount,
358
+ 'cost': undefined,
359
+ 'fee': undefined,
360
+ }, market);
361
+ }
362
+
363
+ async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
364
+ await this.loadMarkets ();
365
+ const market = this.market (symbol);
366
+ const request = {
367
+ 'market': market['id'],
368
+ };
369
+ const response = await this.publicGetTrades (this.extend (request, params));
370
+ return this.parseTrades (response, market, since, limit);
371
+ }
372
+
373
+ parseOHLCV (ohlcv, market = undefined) {
374
+ //
375
+ // [
376
+ // 1498530360,
377
+ // 2700.0,
378
+ // 2700.0,
379
+ // 2700.0,
380
+ // 2700.0,
381
+ // 0.01
382
+ // ]
383
+ //
384
+ return [
385
+ this.safeTimestamp (ohlcv, 0),
386
+ this.safeNumber (ohlcv, 1),
387
+ this.safeNumber (ohlcv, 2),
388
+ this.safeNumber (ohlcv, 3),
389
+ this.safeNumber (ohlcv, 4),
390
+ this.safeNumber (ohlcv, 5),
391
+ ];
392
+ }
393
+
394
+ async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
395
+ await this.loadMarkets ();
396
+ const market = this.market (symbol);
397
+ if (limit === undefined) {
398
+ limit = 30; // default is 30
399
+ }
400
+ const request = {
401
+ 'market': market['id'],
402
+ 'period': this.timeframes[timeframe],
403
+ 'limit': limit,
404
+ };
405
+ if (since !== undefined) {
406
+ request['timestamp'] = parseInt (since / 1000);
407
+ } else {
408
+ request['timestamp'] = 1800000;
409
+ }
410
+ const response = await this.publicGetK (this.extend (request, params));
411
+ //
412
+ // [
413
+ // [1498530360,2700.0,2700.0,2700.0,2700.0,0.01],
414
+ // [1498530420,2700.0,2700.0,2700.0,2700.0,0],
415
+ // [1498530480,2700.0,2700.0,2700.0,2700.0,0],
416
+ // ]
417
+ //
418
+ if (response === 'null') {
419
+ return [];
420
+ }
421
+ return this.parseOHLCVs (response, market, timeframe, since, limit);
422
+ }
423
+
424
+ parseOrderStatus (status) {
425
+ const statuses = {
426
+ 'done': 'closed',
427
+ 'wait': 'open',
428
+ 'cancel': 'canceled',
429
+ };
430
+ return this.safeString (statuses, status, status);
431
+ }
432
+
433
+ parseOrder (order, market = undefined) {
434
+ //
435
+ // {
436
+ // "id": 7, // 唯一的 Order ID
437
+ // "side": "sell", // Buy/Sell 代表买单/卖单
438
+ // "price": "3100.0", // 出价
439
+ // "avg_price": "3101.2", // 平均成交价
440
+ // "state": "wait", // 订单的当前状态 [wait,done,cancel]
441
+ // // wait 表明订单正在市场上挂单
442
+ // // 是一个active order
443
+ // // 此时订单可能部分成交或者尚未成交
444
+ // // done 代表订单已经完全成交
445
+ // // cancel 代表订单已经被撤销
446
+ // "market": "btccny", // 订单参与的交易市场
447
+ // "created_at": "2014-04-18T02:02:33Z", // 下单时间 ISO8601格式
448
+ // "volume": "100.0", // 购买/卖出数量
449
+ // "remaining_volume": "89.8", // 还未成交的数量 remaining_volume 总是小于等于 volume
450
+ // // 在订单完全成交时变成 0
451
+ // "executed_volume": "10.2", // 已成交的数量
452
+ // // volume = remaining_volume + executed_volume
453
+ // "trades_count": 1, // 订单的成交数 整数值
454
+ // // 未成交的订单为 0 有一笔成交的订单为 1
455
+ // // 通过该字段可以判断订单是否处于部分成交状态
456
+ // "trades": [ // 订单的详细成交记录 参见Trade
457
+ // // 注意: 只有某些返回详细订单数据的 API 才会包含 Trade 数据
458
+ // {
459
+ // "id": 2,
460
+ // "price": "3100.0",
461
+ // "volume": "10.2",
462
+ // "market": "btccny",
463
+ // "created_at": "2014-04-18T02:04:49Z",
464
+ // "side": "sell"
465
+ // }
466
+ // ]
467
+ // }
468
+ //
469
+ const marketId = this.safeString (order, 'market');
470
+ const symbol = this.safeSymbol (marketId, market);
471
+ const timestamp = this.parse8601 (this.safeString (order, 'created_at'));
472
+ const status = this.parseOrderStatus (this.safeString (order, 'state'));
473
+ const id = this.safeString (order, 'id');
474
+ const type = this.safeString (order, 'ord_type');
475
+ const side = this.safeString (order, 'side');
476
+ const price = this.safeString (order, 'price');
477
+ const amount = this.safeString (order, 'volume');
478
+ const filled = this.safeString (order, 'executed_volume');
479
+ const remaining = this.safeString (order, 'remaining_volume');
480
+ const average = this.safeString (order, 'avg_price');
481
+ return this.safeOrder ({
482
+ 'id': id,
483
+ 'clientOrderId': undefined,
484
+ 'timestamp': timestamp,
485
+ 'datetime': this.iso8601 (timestamp),
486
+ 'lastTradeTimestamp': undefined,
487
+ 'status': status,
488
+ 'symbol': symbol,
489
+ 'type': type,
490
+ 'timeInForce': undefined,
491
+ 'postOnly': undefined,
492
+ 'side': side,
493
+ 'price': price,
494
+ 'stopPrice': undefined,
495
+ 'amount': amount,
496
+ 'filled': filled,
497
+ 'remaining': remaining,
498
+ 'cost': undefined,
499
+ 'trades': undefined,
500
+ 'fee': undefined,
501
+ 'info': order,
502
+ 'average': average,
503
+ }, market);
504
+ }
505
+
506
+ async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
507
+ await this.loadMarkets ();
508
+ const request = {
509
+ 'market': this.marketId (symbol),
510
+ 'side': side,
511
+ 'volume': amount.toString (),
512
+ 'ord_type': type,
513
+ };
514
+ if (type === 'limit') {
515
+ request['price'] = price.toString ();
516
+ }
517
+ const response = await this.privatePostOrders (this.extend (request, params));
518
+ return this.parseOrder (response);
519
+ }
520
+
521
+ async cancelOrder (id, symbol = undefined, params = {}) {
522
+ await this.loadMarkets ();
523
+ const request = {
524
+ 'id': id,
525
+ };
526
+ const result = await this.privatePostOrderDelete (this.extend (request, params));
527
+ const order = this.parseOrder (result);
528
+ const status = this.safeString (order, 'status');
529
+ if (status === 'closed' || status === 'canceled') {
530
+ throw new OrderNotFound (this.id + ' ' + this.json (order));
531
+ }
532
+ return order;
533
+ }
534
+
535
+ async withdraw (code, amount, address, tag = undefined, params = {}) {
536
+ [ tag, params ] = this.handleWithdrawTagAndParams (tag, params);
537
+ this.checkAddress (address);
538
+ await this.loadMarkets ();
539
+ const currency = this.currency (code);
540
+ const id = this.safeString (params, 'id');
541
+ if (id === undefined) {
542
+ throw new ArgumentsRequired (this.id + ' withdraw() requires an extra `id` param (withdraw account id according to withdraws/bind_account_list endpoint');
543
+ }
544
+ const request = {
545
+ 'id': id,
546
+ 'currency_type': 'coin', // or 'cash'
547
+ 'currency': currency['id'],
548
+ 'body': amount,
549
+ // 'address': address, // they don't allow withdrawing to direct addresses?
550
+ };
551
+ if (tag !== undefined) {
552
+ request['memo'] = tag;
553
+ }
554
+ const result = await this.privatePostWithdrawsApply (this.extend (request, params));
555
+ return this.parseTransaction (result, currency);
556
+ }
557
+
558
+ parseTransaction (transaction, currency = undefined) {
559
+ currency = this.safeCurrency (undefined, currency);
560
+ return {
561
+ 'id': undefined,
562
+ 'txid': undefined,
563
+ 'timestamp': undefined,
564
+ 'datetime': undefined,
565
+ 'network': undefined,
566
+ 'addressFrom': undefined,
567
+ 'address': undefined,
568
+ 'addressTo': undefined,
569
+ 'amount': undefined,
570
+ 'type': undefined,
571
+ 'currency': currency['code'],
572
+ 'status': undefined,
573
+ 'updated': undefined,
574
+ 'tagFrom': undefined,
575
+ 'tag': undefined,
576
+ 'tagTo': undefined,
577
+ 'comment': undefined,
578
+ 'fee': undefined,
579
+ 'info': transaction,
580
+ };
581
+ }
582
+
583
+ nonce () {
584
+ return this.milliseconds ();
585
+ }
586
+
587
+ encodeParams (params) {
588
+ return this.urlencode (this.keysort (params));
589
+ }
590
+
591
+ sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
592
+ const request = '/' + 'api/' + this.version + '/' + this.implodeParams (path, params) + '.json';
593
+ const query = this.omit (params, this.extractParams (path));
594
+ let url = this.urls['api'] + request;
595
+ if (api === 'public') {
596
+ if (Object.keys (query).length) {
597
+ url += '?' + this.urlencode (query);
598
+ }
599
+ } else {
600
+ this.checkRequiredCredentials ();
601
+ const nonce = this.nonce ().toString ();
602
+ const sortedByKey = this.keysort (this.extend ({
603
+ 'access_key': this.apiKey,
604
+ 'tonce': nonce,
605
+ }, params));
606
+ const query = this.urlencode (sortedByKey);
607
+ const payload = method + '|' + request + '|' + query;
608
+ const signature = this.hmac (this.encode (payload), this.encode (this.secret));
609
+ const suffix = query + '&signature=' + signature;
610
+ if (method === 'GET') {
611
+ url += '?' + suffix;
612
+ } else {
613
+ body = suffix;
614
+ headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
615
+ }
616
+ }
617
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
618
+ }
619
+
620
+ handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
621
+ if ((code === 400) || (response === undefined)) {
622
+ const feedback = this.id + ' ' + body;
623
+ if (response === undefined) {
624
+ throw new ExchangeError (feedback);
625
+ }
626
+ const error = this.safeValue (response, 'error', {});
627
+ const errorCode = this.safeString (error, 'code');
628
+ this.throwExactlyMatchedException (this.exceptions, errorCode, feedback);
629
+ // fallback to default error handler
630
+ }
631
+ }
632
+ };