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/bigone.js ADDED
@@ -0,0 +1,1366 @@
1
+ 'use strict';
2
+
3
+ // ---------------------------------------------------------------------------
4
+
5
+ const Exchange = require ('./base/Exchange');
6
+ const { ExchangeError, ArgumentsRequired, AuthenticationError, InsufficientFunds, PermissionDenied, BadRequest, BadSymbol, RateLimitExceeded, InvalidOrder } = require ('./base/errors');
7
+
8
+ // ---------------------------------------------------------------------------
9
+
10
+ module.exports = class bigone extends Exchange {
11
+ describe () {
12
+ return this.deepExtend (super.describe (), {
13
+ 'id': 'bigone',
14
+ 'name': 'BigONE',
15
+ 'countries': [ 'CN' ],
16
+ 'version': 'v3',
17
+ 'rateLimit': 1200, // 500 request per 10 minutes
18
+ 'has': {
19
+ 'CORS': undefined,
20
+ 'spot': true,
21
+ 'margin': undefined, // has but unimplemented
22
+ 'swap': undefined, // has but unimplemented
23
+ 'future': undefined, // has but unimplemented
24
+ 'option': undefined,
25
+ 'cancelAllOrders': true,
26
+ 'cancelOrder': true,
27
+ 'createOrder': true,
28
+ 'createStopLimitOrder': true,
29
+ 'createStopMarketOrder': true,
30
+ 'createStopOrder': true,
31
+ 'fetchBalance': true,
32
+ 'fetchClosedOrders': true,
33
+ 'fetchDepositAddress': true,
34
+ 'fetchDeposits': true,
35
+ 'fetchMarkets': true,
36
+ 'fetchMyTrades': true,
37
+ 'fetchOHLCV': true,
38
+ 'fetchOpenOrders': true,
39
+ 'fetchOrder': true,
40
+ 'fetchOrderBook': true,
41
+ 'fetchOrders': true,
42
+ 'fetchTicker': true,
43
+ 'fetchTickers': true,
44
+ 'fetchTime': true,
45
+ 'fetchTrades': true,
46
+ 'fetchTradingFee': false,
47
+ 'fetchTradingFees': false,
48
+ 'fetchWithdrawals': true,
49
+ 'transfer': true,
50
+ 'withdraw': true,
51
+ },
52
+ 'timeframes': {
53
+ '1m': 'min1',
54
+ '5m': 'min5',
55
+ '15m': 'min15',
56
+ '30m': 'min30',
57
+ '1h': 'hour1',
58
+ '3h': 'hour3',
59
+ '4h': 'hour4',
60
+ '6h': 'hour6',
61
+ '12h': 'hour12',
62
+ '1d': 'day1',
63
+ '1w': 'week1',
64
+ '1M': 'month1',
65
+ },
66
+ 'hostname': 'big.one', // or 'bigone.com'
67
+ 'urls': {
68
+ 'logo': 'https://user-images.githubusercontent.com/1294454/69354403-1d532180-0c91-11ea-88ed-44c06cefdf87.jpg',
69
+ 'api': {
70
+ 'public': 'https://{hostname}/api/v3',
71
+ 'private': 'https://{hostname}/api/v3/viewer',
72
+ },
73
+ 'www': 'https://big.one',
74
+ 'doc': 'https://open.big.one/docs/api.html',
75
+ 'fees': 'https://bigone.zendesk.com/hc/en-us/articles/115001933374-BigONE-Fee-Policy',
76
+ 'referral': 'https://b1.run/users/new?code=D3LLBVFT',
77
+ },
78
+ 'api': {
79
+ 'public': {
80
+ 'get': [
81
+ 'ping',
82
+ 'asset_pairs',
83
+ 'asset_pairs/{asset_pair_name}/depth',
84
+ 'asset_pairs/{asset_pair_name}/trades',
85
+ 'asset_pairs/{asset_pair_name}/ticker',
86
+ 'asset_pairs/{asset_pair_name}/candles',
87
+ 'asset_pairs/tickers',
88
+ ],
89
+ },
90
+ 'private': {
91
+ 'get': [
92
+ 'accounts',
93
+ 'fund/accounts',
94
+ 'assets/{asset_symbol}/address',
95
+ 'orders',
96
+ 'orders/{id}',
97
+ 'orders/multi',
98
+ 'trades',
99
+ 'withdrawals',
100
+ 'deposits',
101
+ ],
102
+ 'post': [
103
+ 'orders',
104
+ 'orders/{id}/cancel',
105
+ 'orders/cancel',
106
+ 'withdrawals',
107
+ 'transfer',
108
+ ],
109
+ },
110
+ },
111
+ 'fees': {
112
+ 'trading': {
113
+ 'maker': this.parseNumber ('0.001'),
114
+ 'taker': this.parseNumber ('0.001'),
115
+ },
116
+ 'funding': {
117
+ 'withdraw': {},
118
+ },
119
+ },
120
+ 'options': {
121
+ 'accountsByType': {
122
+ 'spot': 'SPOT',
123
+ 'funding': 'FUND',
124
+ 'future': 'CONTRACT',
125
+ 'swap': 'CONTRACT',
126
+ },
127
+ 'transfer': {
128
+ 'fillResponseFromRequest': true,
129
+ },
130
+ },
131
+ 'exceptions': {
132
+ 'exact': {
133
+ '10001': BadRequest, // syntax error
134
+ '10005': ExchangeError, // internal error
135
+ "Amount's scale must greater than AssetPair's base scale": InvalidOrder,
136
+ "Price mulit with amount should larger than AssetPair's min_quote_value": InvalidOrder,
137
+ '10007': BadRequest, // parameter error, {"code":10007,"message":"Amount's scale must greater than AssetPair's base scale"}
138
+ '10011': ExchangeError, // system error
139
+ '10013': BadSymbol, // {"code":10013,"message":"Resource not found"}
140
+ '10014': InsufficientFunds, // {"code":10014,"message":"Insufficient funds"}
141
+ '10403': PermissionDenied, // permission denied
142
+ '10429': RateLimitExceeded, // too many requests
143
+ '40004': AuthenticationError, // {"code":40004,"message":"invalid jwt"}
144
+ '40103': AuthenticationError, // invalid otp code
145
+ '40104': AuthenticationError, // invalid asset pin code
146
+ '40301': PermissionDenied, // {"code":40301,"message":"Permission denied withdrawal create"}
147
+ '40302': ExchangeError, // already requested
148
+ '40601': ExchangeError, // resource is locked
149
+ '40602': ExchangeError, // resource is depleted
150
+ '40603': InsufficientFunds, // insufficient resource
151
+ '40605': InvalidOrder, // {"code":40605,"message":"Price less than the minimum order price"}
152
+ '40120': InvalidOrder, // Order is in trading
153
+ '40121': InvalidOrder, // Order is already cancelled or filled
154
+ '60100': BadSymbol, // {"code":60100,"message":"Asset pair is suspended"}
155
+ },
156
+ 'broad': {
157
+ },
158
+ },
159
+ 'commonCurrencies': {
160
+ 'CRE': 'Cybereits',
161
+ 'FXT': 'FXTTOKEN',
162
+ 'FREE': 'FreeRossDAO',
163
+ 'MBN': 'Mobilian Coin',
164
+ 'ONE': 'BigONE Token',
165
+ },
166
+ });
167
+ }
168
+
169
+ async fetchMarkets (params = {}) {
170
+ const response = await this.publicGetAssetPairs (params);
171
+ //
172
+ // {
173
+ // "code":0,
174
+ // "data":[
175
+ // {
176
+ // "id":"01e48809-b42f-4a38-96b1-c4c547365db1",
177
+ // "name":"PCX-BTC",
178
+ // "quote_scale":7,
179
+ // "quote_asset":{
180
+ // "id":"0df9c3c3-255a-46d7-ab82-dedae169fba9",
181
+ // "symbol":"BTC",
182
+ // "name":"Bitcoin",
183
+ // },
184
+ // "base_asset":{
185
+ // "id":"405484f7-4b03-4378-a9c1-2bd718ecab51",
186
+ // "symbol":"PCX",
187
+ // "name":"ChainX",
188
+ // },
189
+ // "base_scale":3,
190
+ // "min_quote_value":"0.0001",
191
+ // "max_quote_value":"35"
192
+ // },
193
+ // ]
194
+ // }
195
+ //
196
+ const markets = this.safeValue (response, 'data', []);
197
+ const result = [];
198
+ for (let i = 0; i < markets.length; i++) {
199
+ const market = markets[i];
200
+ const id = this.safeString (market, 'name');
201
+ const uuid = this.safeString (market, 'id');
202
+ const baseAsset = this.safeValue (market, 'base_asset', {});
203
+ const quoteAsset = this.safeValue (market, 'quote_asset', {});
204
+ const baseId = this.safeString (baseAsset, 'symbol');
205
+ const quoteId = this.safeString (quoteAsset, 'symbol');
206
+ const base = this.safeCurrencyCode (baseId);
207
+ const quote = this.safeCurrencyCode (quoteId);
208
+ const entry = {
209
+ 'id': id,
210
+ 'uuid': uuid,
211
+ 'symbol': base + '/' + quote,
212
+ 'base': base,
213
+ 'quote': quote,
214
+ 'settle': undefined,
215
+ 'baseId': baseId,
216
+ 'quoteId': quoteId,
217
+ 'settleId': undefined,
218
+ 'type': 'spot',
219
+ 'spot': true,
220
+ 'margin': false,
221
+ 'swap': false,
222
+ 'future': false,
223
+ 'option': false,
224
+ 'active': true,
225
+ 'contract': false,
226
+ 'linear': undefined,
227
+ 'inverse': undefined,
228
+ 'contractSize': undefined,
229
+ 'expiry': undefined,
230
+ 'expiryDatetime': undefined,
231
+ 'strike': undefined,
232
+ 'optionType': undefined,
233
+ 'precision': {
234
+ 'amount': this.safeInteger (market, 'base_scale'),
235
+ 'price': this.safeInteger (market, 'quote_scale'),
236
+ },
237
+ 'limits': {
238
+ 'leverage': {
239
+ 'min': undefined,
240
+ 'max': undefined,
241
+ },
242
+ 'amount': {
243
+ 'min': undefined,
244
+ 'max': undefined,
245
+ },
246
+ 'price': {
247
+ 'min': undefined,
248
+ 'max': undefined,
249
+ },
250
+ 'cost': {
251
+ 'min': this.safeNumber (market, 'min_quote_value'),
252
+ 'max': this.safeNumber (market, 'max_quote_value'),
253
+ },
254
+ },
255
+ 'info': market,
256
+ };
257
+ result.push (entry);
258
+ }
259
+ return result;
260
+ }
261
+
262
+ async loadMarkets (reload = false, params = {}) {
263
+ const markets = await super.loadMarkets (reload, params);
264
+ let marketsByUuid = this.safeValue (this.options, 'marketsByUuid');
265
+ if ((marketsByUuid === undefined) || reload) {
266
+ marketsByUuid = {};
267
+ for (let i = 0; i < this.symbols.length; i++) {
268
+ const symbol = this.symbols[i];
269
+ const market = this.markets[symbol];
270
+ const uuid = this.safeString (market, 'uuid');
271
+ marketsByUuid[uuid] = market;
272
+ }
273
+ this.options['marketsByUuid'] = marketsByUuid;
274
+ }
275
+ return markets;
276
+ }
277
+
278
+ parseTicker (ticker, market = undefined) {
279
+ //
280
+ // {
281
+ // "asset_pair_name":"ETH-BTC",
282
+ // "bid":{"price":"0.021593","order_count":1,"quantity":"0.20936"},
283
+ // "ask":{"price":"0.021613","order_count":1,"quantity":"2.87064"},
284
+ // "open":"0.021795",
285
+ // "high":"0.021795",
286
+ // "low":"0.021471",
287
+ // "close":"0.021613",
288
+ // "volume":"117078.90431",
289
+ // "daily_change":"-0.000182"
290
+ // }
291
+ //
292
+ const marketId = this.safeString (ticker, 'asset_pair_name');
293
+ const symbol = this.safeSymbol (marketId, market, '-');
294
+ const timestamp = undefined;
295
+ const close = this.safeString (ticker, 'close');
296
+ const bid = this.safeValue (ticker, 'bid', {});
297
+ const ask = this.safeValue (ticker, 'ask', {});
298
+ return this.safeTicker ({
299
+ 'symbol': symbol,
300
+ 'timestamp': timestamp,
301
+ 'datetime': this.iso8601 (timestamp),
302
+ 'high': this.safeString (ticker, 'high'),
303
+ 'low': this.safeString (ticker, 'low'),
304
+ 'bid': this.safeString (bid, 'price'),
305
+ 'bidVolume': this.safeString (bid, 'quantity'),
306
+ 'ask': this.safeString (ask, 'price'),
307
+ 'askVolume': this.safeString (ask, 'quantity'),
308
+ 'vwap': undefined,
309
+ 'open': this.safeString (ticker, 'open'),
310
+ 'close': close,
311
+ 'last': close,
312
+ 'previousClose': undefined,
313
+ 'change': this.safeString (ticker, 'daily_change'),
314
+ 'percentage': undefined,
315
+ 'average': undefined,
316
+ 'baseVolume': this.safeString (ticker, 'volume'),
317
+ 'quoteVolume': undefined,
318
+ 'info': ticker,
319
+ }, market, false);
320
+ }
321
+
322
+ async fetchTicker (symbol, params = {}) {
323
+ await this.loadMarkets ();
324
+ const market = this.market (symbol);
325
+ const request = {
326
+ 'asset_pair_name': market['id'],
327
+ };
328
+ const response = await this.publicGetAssetPairsAssetPairNameTicker (this.extend (request, params));
329
+ //
330
+ // {
331
+ // "code":0,
332
+ // "data":{
333
+ // "asset_pair_name":"ETH-BTC",
334
+ // "bid":{"price":"0.021593","order_count":1,"quantity":"0.20936"},
335
+ // "ask":{"price":"0.021613","order_count":1,"quantity":"2.87064"},
336
+ // "open":"0.021795",
337
+ // "high":"0.021795",
338
+ // "low":"0.021471",
339
+ // "close":"0.021613",
340
+ // "volume":"117078.90431",
341
+ // "daily_change":"-0.000182"
342
+ // }
343
+ // }
344
+ //
345
+ const ticker = this.safeValue (response, 'data', {});
346
+ return this.parseTicker (ticker, market);
347
+ }
348
+
349
+ async fetchTickers (symbols = undefined, params = {}) {
350
+ await this.loadMarkets ();
351
+ const request = {};
352
+ if (symbols !== undefined) {
353
+ const ids = this.marketIds (symbols);
354
+ request['pair_names'] = ids.join (',');
355
+ }
356
+ const response = await this.publicGetAssetPairsTickers (this.extend (request, params));
357
+ //
358
+ // {
359
+ // "code":0,
360
+ // "data":[
361
+ // {
362
+ // "asset_pair_name":"PCX-BTC",
363
+ // "bid":{"price":"0.000234","order_count":1,"quantity":"0.518"},
364
+ // "ask":{"price":"0.0002348","order_count":1,"quantity":"2.348"},
365
+ // "open":"0.0002343",
366
+ // "high":"0.0002348",
367
+ // "low":"0.0002162",
368
+ // "close":"0.0002348",
369
+ // "volume":"12887.016",
370
+ // "daily_change":"0.0000005"
371
+ // },
372
+ // {
373
+ // "asset_pair_name":"GXC-USDT",
374
+ // "bid":{"price":"0.5054","order_count":1,"quantity":"40.53"},
375
+ // "ask":{"price":"0.5055","order_count":1,"quantity":"38.53"},
376
+ // "open":"0.5262",
377
+ // "high":"0.5323",
378
+ // "low":"0.5055",
379
+ // "close":"0.5055",
380
+ // "volume":"603963.05",
381
+ // "daily_change":"-0.0207"
382
+ // }
383
+ // ]
384
+ // }
385
+ //
386
+ const tickers = this.safeValue (response, 'data', []);
387
+ const result = {};
388
+ for (let i = 0; i < tickers.length; i++) {
389
+ const ticker = this.parseTicker (tickers[i]);
390
+ const symbol = ticker['symbol'];
391
+ result[symbol] = ticker;
392
+ }
393
+ return this.filterByArray (result, 'symbol', symbols);
394
+ }
395
+
396
+ async fetchTime (params = {}) {
397
+ const response = await this.publicGetPing (params);
398
+ //
399
+ // {
400
+ // "data": {
401
+ // "timestamp": 1527665262168391000
402
+ // }
403
+ // }
404
+ //
405
+ const data = this.safeValue (response, 'data', {});
406
+ const timestamp = this.safeInteger (data, 'timestamp');
407
+ return parseInt (timestamp / 1000000);
408
+ }
409
+
410
+ async fetchOrderBook (symbol, limit = undefined, params = {}) {
411
+ await this.loadMarkets ();
412
+ const market = this.market (symbol);
413
+ const request = {
414
+ 'asset_pair_name': market['id'],
415
+ };
416
+ if (limit !== undefined) {
417
+ request['limit'] = limit; // default 50, max 200
418
+ }
419
+ const response = await this.publicGetAssetPairsAssetPairNameDepth (this.extend (request, params));
420
+ //
421
+ // {
422
+ // "code":0,
423
+ // "data": {
424
+ // "asset_pair_name": "EOS-BTC",
425
+ // "bids": [
426
+ // { "price": "42", "order_count": 4, "quantity": "23.33363711" }
427
+ // ],
428
+ // "asks": [
429
+ // { "price": "45", "order_count": 2, "quantity": "4193.3283464" }
430
+ // ]
431
+ // }
432
+ // }
433
+ //
434
+ const orderbook = this.safeValue (response, 'data', {});
435
+ return this.parseOrderBook (orderbook, symbol, undefined, 'bids', 'asks', 'price', 'quantity');
436
+ }
437
+
438
+ parseTrade (trade, market = undefined) {
439
+ //
440
+ // fetchTrades (public)
441
+ //
442
+ // {
443
+ // "id": 38199941,
444
+ // "price": "3378.67",
445
+ // "amount": "0.019812",
446
+ // "taker_side": "ASK",
447
+ // "created_at": "2019-01-29T06:05:56Z"
448
+ // }
449
+ //
450
+ // fetchMyTrades (private)
451
+ //
452
+ // {
453
+ // "id": 10854280,
454
+ // "asset_pair_name": "XIN-USDT",
455
+ // "price": "70",
456
+ // "amount": "1",
457
+ // "taker_side": "ASK",
458
+ // "maker_order_id": 58284908,
459
+ // "taker_order_id": 58284909,
460
+ // "maker_fee": "0.0008",
461
+ // "taker_fee": "0.07",
462
+ // "side": "SELF_TRADING",
463
+ // "inserted_at": "2019-04-16T12:00:01Z"
464
+ // },
465
+ //
466
+ // {
467
+ // "id": 10854263,
468
+ // "asset_pair_name": "XIN-USDT",
469
+ // "price": "75.7",
470
+ // "amount": "12.743149",
471
+ // "taker_side": "BID",
472
+ // "maker_order_id": null,
473
+ // "taker_order_id": 58284888,
474
+ // "maker_fee": null,
475
+ // "taker_fee": "0.0025486298",
476
+ // "side": "BID",
477
+ // "inserted_at": "2019-04-15T06:20:57Z"
478
+ // }
479
+ //
480
+ const timestamp = this.parse8601 (this.safeString2 (trade, 'created_at', 'inserted_at'));
481
+ const priceString = this.safeString (trade, 'price');
482
+ const amountString = this.safeString (trade, 'amount');
483
+ const marketId = this.safeString (trade, 'asset_pair_name');
484
+ market = this.safeMarket (marketId, market, '-');
485
+ let side = this.safeString (trade, 'side');
486
+ const takerSide = this.safeString (trade, 'taker_side');
487
+ let takerOrMaker = undefined;
488
+ if ((takerSide !== undefined) && (side !== undefined) && (side !== 'SELF_TRADING')) {
489
+ takerOrMaker = (takerSide === side) ? 'taker' : 'maker';
490
+ }
491
+ if (side === undefined) {
492
+ // taker side is not related to buy/sell side
493
+ // the following code is probably a mistake
494
+ side = (takerSide === 'ASK') ? 'sell' : 'buy';
495
+ } else {
496
+ if (side === 'BID') {
497
+ side = 'buy';
498
+ } else if (side === 'ASK') {
499
+ side = 'sell';
500
+ }
501
+ }
502
+ const makerOrderId = this.safeString (trade, 'maker_order_id');
503
+ const takerOrderId = this.safeString (trade, 'taker_order_id');
504
+ let orderId = undefined;
505
+ if (makerOrderId !== undefined) {
506
+ if (takerOrderId !== undefined) {
507
+ orderId = [ makerOrderId, takerOrderId ];
508
+ } else {
509
+ orderId = makerOrderId;
510
+ }
511
+ } else if (takerOrderId !== undefined) {
512
+ orderId = takerOrderId;
513
+ }
514
+ const id = this.safeString (trade, 'id');
515
+ const result = {
516
+ 'id': id,
517
+ 'timestamp': timestamp,
518
+ 'datetime': this.iso8601 (timestamp),
519
+ 'symbol': market['symbol'],
520
+ 'order': orderId,
521
+ 'type': 'limit',
522
+ 'side': side,
523
+ 'takerOrMaker': takerOrMaker,
524
+ 'price': priceString,
525
+ 'amount': amountString,
526
+ 'cost': undefined,
527
+ 'info': trade,
528
+ };
529
+ let makerCurrencyCode = undefined;
530
+ let takerCurrencyCode = undefined;
531
+ if (takerOrMaker !== undefined) {
532
+ if (side === 'buy') {
533
+ if (takerOrMaker === 'maker') {
534
+ makerCurrencyCode = market['base'];
535
+ takerCurrencyCode = market['quote'];
536
+ } else {
537
+ makerCurrencyCode = market['quote'];
538
+ takerCurrencyCode = market['base'];
539
+ }
540
+ } else {
541
+ if (takerOrMaker === 'maker') {
542
+ makerCurrencyCode = market['quote'];
543
+ takerCurrencyCode = market['base'];
544
+ } else {
545
+ makerCurrencyCode = market['base'];
546
+ takerCurrencyCode = market['quote'];
547
+ }
548
+ }
549
+ } else if (side === 'SELF_TRADING') {
550
+ if (takerSide === 'BID') {
551
+ makerCurrencyCode = market['quote'];
552
+ takerCurrencyCode = market['base'];
553
+ } else if (takerSide === 'ASK') {
554
+ makerCurrencyCode = market['base'];
555
+ takerCurrencyCode = market['quote'];
556
+ }
557
+ }
558
+ const makerFeeCost = this.safeString (trade, 'maker_fee');
559
+ const takerFeeCost = this.safeString (trade, 'taker_fee');
560
+ if (makerFeeCost !== undefined) {
561
+ if (takerFeeCost !== undefined) {
562
+ result['fees'] = [
563
+ { 'cost': makerFeeCost, 'currency': makerCurrencyCode },
564
+ { 'cost': takerFeeCost, 'currency': takerCurrencyCode },
565
+ ];
566
+ } else {
567
+ result['fee'] = { 'cost': makerFeeCost, 'currency': makerCurrencyCode };
568
+ }
569
+ } else if (takerFeeCost !== undefined) {
570
+ result['fee'] = { 'cost': takerFeeCost, 'currency': takerCurrencyCode };
571
+ } else {
572
+ result['fee'] = undefined;
573
+ }
574
+ return this.safeTrade (result, market);
575
+ }
576
+
577
+ async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
578
+ await this.loadMarkets ();
579
+ const market = this.market (symbol);
580
+ const request = {
581
+ 'asset_pair_name': market['id'],
582
+ };
583
+ const response = await this.publicGetAssetPairsAssetPairNameTrades (this.extend (request, params));
584
+ //
585
+ // {
586
+ // "code": 0,
587
+ // "data": [
588
+ // {
589
+ // "id": 38199941,
590
+ // "price": "3378.67",
591
+ // "amount": "0.019812",
592
+ // "taker_side": "ASK",
593
+ // "created_at": "2019-01-29T06:05:56Z"
594
+ // },
595
+ // {
596
+ // "id": 38199934,
597
+ // "price": "3376.14",
598
+ // "amount": "0.019384",
599
+ // "taker_side": "ASK",
600
+ // "created_at": "2019-01-29T06:05:40Z"
601
+ // }
602
+ // ]
603
+ // }
604
+ //
605
+ const trades = this.safeValue (response, 'data', []);
606
+ return this.parseTrades (trades, market, since, limit);
607
+ }
608
+
609
+ parseOHLCV (ohlcv, market = undefined) {
610
+ //
611
+ // {
612
+ // close: '0.021562',
613
+ // high: '0.021563',
614
+ // low: '0.02156',
615
+ // open: '0.021563',
616
+ // time: '2019-11-21T07:54:00Z',
617
+ // volume: '59.84376'
618
+ // }
619
+ //
620
+ return [
621
+ this.parse8601 (this.safeString (ohlcv, 'time')),
622
+ this.safeNumber (ohlcv, 'open'),
623
+ this.safeNumber (ohlcv, 'high'),
624
+ this.safeNumber (ohlcv, 'low'),
625
+ this.safeNumber (ohlcv, 'close'),
626
+ this.safeNumber (ohlcv, 'volume'),
627
+ ];
628
+ }
629
+
630
+ async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
631
+ await this.loadMarkets ();
632
+ const market = this.market (symbol);
633
+ if (limit === undefined) {
634
+ limit = 100; // default 100, max 500
635
+ }
636
+ const request = {
637
+ 'asset_pair_name': market['id'],
638
+ 'period': this.timeframes[timeframe],
639
+ 'limit': limit,
640
+ };
641
+ if (since !== undefined) {
642
+ // const start = parseInt (since / 1000);
643
+ const duration = this.parseTimeframe (timeframe);
644
+ const end = this.sum (since, limit * duration * 1000);
645
+ request['time'] = this.iso8601 (end);
646
+ }
647
+ const response = await this.publicGetAssetPairsAssetPairNameCandles (this.extend (request, params));
648
+ //
649
+ // {
650
+ // code: 0,
651
+ // data: [
652
+ // {
653
+ // close: '0.021656',
654
+ // high: '0.021658',
655
+ // low: '0.021652',
656
+ // open: '0.021652',
657
+ // time: '2019-11-21T09:30:00Z',
658
+ // volume: '53.08664'
659
+ // },
660
+ // {
661
+ // close: '0.021652',
662
+ // high: '0.021656',
663
+ // low: '0.021652',
664
+ // open: '0.021656',
665
+ // time: '2019-11-21T09:29:00Z',
666
+ // volume: '88.39861'
667
+ // },
668
+ // ]
669
+ // }
670
+ //
671
+ const data = this.safeValue (response, 'data', []);
672
+ return this.parseOHLCVs (data, market, timeframe, since, limit);
673
+ }
674
+
675
+ parseBalance (response) {
676
+ const result = {
677
+ 'info': response,
678
+ 'timestamp': undefined,
679
+ 'datetime': undefined,
680
+ };
681
+ const balances = this.safeValue (response, 'data', []);
682
+ for (let i = 0; i < balances.length; i++) {
683
+ const balance = balances[i];
684
+ const symbol = this.safeString (balance, 'asset_symbol');
685
+ const code = this.safeCurrencyCode (symbol);
686
+ const account = this.account ();
687
+ account['total'] = this.safeString (balance, 'balance');
688
+ account['used'] = this.safeString (balance, 'locked_balance');
689
+ result[code] = account;
690
+ }
691
+ return this.safeBalance (result);
692
+ }
693
+
694
+ async fetchBalance (params = {}) {
695
+ await this.loadMarkets ();
696
+ const type = this.safeString (params, 'type', '');
697
+ params = this.omit (params, 'type');
698
+ const method = 'privateGet' + this.capitalize (type) + 'Accounts';
699
+ const response = await this[method] (params);
700
+ //
701
+ // {
702
+ // "code":0,
703
+ // "data":[
704
+ // {"asset_symbol":"NKC","balance":"0","locked_balance":"0"},
705
+ // {"asset_symbol":"UBTC","balance":"0","locked_balance":"0"},
706
+ // {"asset_symbol":"READ","balance":"0","locked_balance":"0"},
707
+ // ],
708
+ // }
709
+ //
710
+ return this.parseBalance (response);
711
+ }
712
+
713
+ parseOrder (order, market = undefined) {
714
+ //
715
+ // {
716
+ // "id": 10,
717
+ // "asset_pair_name": "EOS-BTC",
718
+ // "price": "10.00",
719
+ // "amount": "10.00",
720
+ // "filled_amount": "9.0",
721
+ // "avg_deal_price": "12.0",
722
+ // "side": "ASK",
723
+ // "state": "FILLED",
724
+ // "created_at":"2019-01-29T06:05:56Z",
725
+ // "updated_at":"2019-01-29T06:05:56Z",
726
+ // }
727
+ //
728
+ const id = this.safeString (order, 'id');
729
+ const marketId = this.safeString (order, 'asset_pair_name');
730
+ const symbol = this.safeSymbol (marketId, market, '-');
731
+ const timestamp = this.parse8601 (this.safeString (order, 'created_at'));
732
+ const price = this.safeString (order, 'price');
733
+ const amount = this.safeString (order, 'amount');
734
+ const average = this.safeString (order, 'avg_deal_price');
735
+ const filled = this.safeString (order, 'filled_amount');
736
+ const status = this.parseOrderStatus (this.safeString (order, 'state'));
737
+ let side = this.safeString (order, 'side');
738
+ if (side === 'BID') {
739
+ side = 'buy';
740
+ } else {
741
+ side = 'sell';
742
+ }
743
+ const lastTradeTimestamp = this.parse8601 (this.safeString (order, 'updated_at'));
744
+ return this.safeOrder ({
745
+ 'info': order,
746
+ 'id': id,
747
+ 'clientOrderId': undefined,
748
+ 'timestamp': timestamp,
749
+ 'datetime': this.iso8601 (timestamp),
750
+ 'lastTradeTimestamp': lastTradeTimestamp,
751
+ 'symbol': symbol,
752
+ 'type': undefined,
753
+ 'timeInForce': undefined,
754
+ 'postOnly': undefined,
755
+ 'side': side,
756
+ 'price': price,
757
+ 'stopPrice': undefined,
758
+ 'amount': amount,
759
+ 'cost': undefined,
760
+ 'average': average,
761
+ 'filled': filled,
762
+ 'remaining': undefined,
763
+ 'status': status,
764
+ 'fee': undefined,
765
+ 'trades': undefined,
766
+ }, market);
767
+ }
768
+
769
+ async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
770
+ await this.loadMarkets ();
771
+ const market = this.market (symbol);
772
+ side = (side === 'buy') ? 'BID' : 'ASK';
773
+ const uppercaseType = type.toUpperCase ();
774
+ const request = {
775
+ 'asset_pair_name': market['id'], // asset pair name BTC-USDT, required
776
+ 'side': side, // order side one of "ASK"/"BID", required
777
+ 'amount': this.amountToPrecision (symbol, amount), // order amount, string, required
778
+ // 'price': this.priceToPrecision (symbol, price), // order price, string, required
779
+ 'type': uppercaseType,
780
+ // 'operator': 'GTE', // stop orders only, GTE greater than and equal, LTE less than and equal
781
+ // 'immediate_or_cancel': false, // limit orders only, must be false when post_only is true
782
+ // 'post_only': false, // limit orders only, must be false when immediate_or_cancel is true
783
+ };
784
+ if (uppercaseType === 'LIMIT') {
785
+ request['price'] = this.priceToPrecision (symbol, price);
786
+ } else {
787
+ const isStopLimit = (uppercaseType === 'STOP_LIMIT');
788
+ const isStopMarket = (uppercaseType === 'STOP_MARKET');
789
+ if (isStopLimit || isStopMarket) {
790
+ const stopPrice = this.safeNumber2 (params, 'stop_price', 'stopPrice');
791
+ if (stopPrice === undefined) {
792
+ throw new ArgumentsRequired (this.id + ' createOrder() requires a stop_price parameter');
793
+ }
794
+ request['stop_price'] = this.priceToPrecision (symbol, stopPrice);
795
+ params = this.omit (params, [ 'stop_price', 'stopPrice' ]);
796
+ }
797
+ if (isStopLimit) {
798
+ request['price'] = this.priceToPrecision (symbol, price);
799
+ }
800
+ }
801
+ const response = await this.privatePostOrders (this.extend (request, params));
802
+ //
803
+ // {
804
+ // "id": 10,
805
+ // "asset_pair_name": "EOS-BTC",
806
+ // "price": "10.00",
807
+ // "amount": "10.00",
808
+ // "filled_amount": "9.0",
809
+ // "avg_deal_price": "12.0",
810
+ // "side": "ASK",
811
+ // "state": "FILLED",
812
+ // "created_at":"2019-01-29T06:05:56Z",
813
+ // "updated_at":"2019-01-29T06:05:56Z"
814
+ // }
815
+ //
816
+ const order = this.safeValue (response, 'data');
817
+ return this.parseOrder (order, market);
818
+ }
819
+
820
+ async cancelOrder (id, symbol = undefined, params = {}) {
821
+ await this.loadMarkets ();
822
+ const request = { 'id': id };
823
+ const response = await this.privatePostOrdersIdCancel (this.extend (request, params));
824
+ // {
825
+ // "id": 10,
826
+ // "asset_pair_name": "EOS-BTC",
827
+ // "price": "10.00",
828
+ // "amount": "10.00",
829
+ // "filled_amount": "9.0",
830
+ // "avg_deal_price": "12.0",
831
+ // "side": "ASK",
832
+ // "state": "CANCELLED",
833
+ // "created_at":"2019-01-29T06:05:56Z",
834
+ // "updated_at":"2019-01-29T06:05:56Z"
835
+ // }
836
+ const order = this.safeValue (response, 'data');
837
+ return this.parseOrder (order);
838
+ }
839
+
840
+ async cancelAllOrders (symbol = undefined, params = {}) {
841
+ await this.loadMarkets ();
842
+ const market = this.market (symbol);
843
+ const request = {
844
+ 'asset_pair_name': market['id'],
845
+ };
846
+ const response = await this.privatePostOrdersCancel (this.extend (request, params));
847
+ //
848
+ // {
849
+ // "code":0,
850
+ // "data": {
851
+ // "cancelled":[
852
+ // 58272370,
853
+ // 58272377
854
+ // ],
855
+ // "failed": []
856
+ // }
857
+ // }
858
+ //
859
+ return response;
860
+ }
861
+
862
+ async fetchOrder (id, symbol = undefined, params = {}) {
863
+ await this.loadMarkets ();
864
+ const request = { 'id': id };
865
+ const response = await this.privateGetOrdersId (this.extend (request, params));
866
+ const order = this.safeValue (response, 'data', {});
867
+ return this.parseOrder (order);
868
+ }
869
+
870
+ async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
871
+ if (symbol === undefined) {
872
+ throw new ArgumentsRequired (this.id + ' fetchOrders() requires a symbol argument');
873
+ }
874
+ await this.loadMarkets ();
875
+ const market = this.market (symbol);
876
+ const request = {
877
+ 'asset_pair_name': market['id'],
878
+ // 'page_token': 'dxzef', // request page after this page token
879
+ // 'side': 'ASK', // 'ASK' or 'BID', optional
880
+ // 'state': 'FILLED', // 'CANCELLED', 'FILLED', 'PENDING'
881
+ // 'limit' 20, // default 20, max 200
882
+ };
883
+ if (limit !== undefined) {
884
+ request['limit'] = limit; // default 20, max 200
885
+ }
886
+ const response = await this.privateGetOrders (this.extend (request, params));
887
+ //
888
+ // {
889
+ // "code":0,
890
+ // "data": [
891
+ // {
892
+ // "id": 10,
893
+ // "asset_pair_name": "ETH-BTC",
894
+ // "price": "10.00",
895
+ // "amount": "10.00",
896
+ // "filled_amount": "9.0",
897
+ // "avg_deal_price": "12.0",
898
+ // "side": "ASK",
899
+ // "state": "FILLED",
900
+ // "created_at":"2019-01-29T06:05:56Z",
901
+ // "updated_at":"2019-01-29T06:05:56Z",
902
+ // },
903
+ // ],
904
+ // "page_token":"dxzef",
905
+ // }
906
+ //
907
+ const orders = this.safeValue (response, 'data', []);
908
+ return this.parseOrders (orders, market, since, limit);
909
+ }
910
+
911
+ async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
912
+ await this.loadMarkets ();
913
+ if (symbol === undefined) {
914
+ throw new ArgumentsRequired (this.id + ' fetchMyTrades() requires a symbol argument');
915
+ }
916
+ const market = this.market (symbol);
917
+ const request = {
918
+ 'asset_pair_name': market['id'],
919
+ // 'page_token': 'dxzef', // request page after this page token
920
+ };
921
+ if (limit !== undefined) {
922
+ request['limit'] = limit; // default 20, max 200
923
+ }
924
+ const response = await this.privateGetTrades (this.extend (request, params));
925
+ //
926
+ // {
927
+ // "code": 0,
928
+ // "data": [
929
+ // {
930
+ // "id": 10854280,
931
+ // "asset_pair_name": "XIN-USDT",
932
+ // "price": "70",
933
+ // "amount": "1",
934
+ // "taker_side": "ASK",
935
+ // "maker_order_id": 58284908,
936
+ // "taker_order_id": 58284909,
937
+ // "maker_fee": "0.0008",
938
+ // "taker_fee": "0.07",
939
+ // "side": "SELF_TRADING",
940
+ // "inserted_at": "2019-04-16T12:00:01Z"
941
+ // },
942
+ // {
943
+ // "id": 10854263,
944
+ // "asset_pair_name": "XIN-USDT",
945
+ // "price": "75.7",
946
+ // "amount": "12.743149",
947
+ // "taker_side": "BID",
948
+ // "maker_order_id": null,
949
+ // "taker_order_id": 58284888,
950
+ // "maker_fee": null,
951
+ // "taker_fee": "0.0025486298",
952
+ // "side": "BID",
953
+ // "inserted_at": "2019-04-15T06:20:57Z"
954
+ // }
955
+ // ],
956
+ // "page_token":"dxfv"
957
+ // }
958
+ //
959
+ const trades = this.safeValue (response, 'data', []);
960
+ return this.parseTrades (trades, market, since, limit);
961
+ }
962
+
963
+ parseOrderStatus (status) {
964
+ const statuses = {
965
+ 'PENDING': 'open',
966
+ 'FILLED': 'closed',
967
+ 'CANCELLED': 'canceled',
968
+ };
969
+ return this.safeString (statuses, status);
970
+ }
971
+
972
+ async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
973
+ const request = {
974
+ 'state': 'PENDING',
975
+ };
976
+ return await this.fetchOrders (symbol, since, limit, this.extend (request, params));
977
+ }
978
+
979
+ async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
980
+ const request = {
981
+ 'state': 'FILLED',
982
+ };
983
+ return await this.fetchOrders (symbol, since, limit, this.extend (request, params));
984
+ }
985
+
986
+ nonce () {
987
+ return this.microseconds () * 1000;
988
+ }
989
+
990
+ sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
991
+ const query = this.omit (params, this.extractParams (path));
992
+ const baseUrl = this.implodeHostname (this.urls['api'][api]);
993
+ let url = baseUrl + '/' + this.implodeParams (path, params);
994
+ if (api === 'public') {
995
+ if (Object.keys (query).length) {
996
+ url += '?' + this.urlencode (query);
997
+ }
998
+ } else {
999
+ this.checkRequiredCredentials ();
1000
+ const nonce = this.nonce ().toString ();
1001
+ const request = {
1002
+ 'type': 'OpenAPIV2',
1003
+ 'sub': this.apiKey,
1004
+ 'nonce': nonce,
1005
+ // 'recv_window': '30', // default 30
1006
+ };
1007
+ const jwt = this.jwt (request, this.encode (this.secret));
1008
+ headers = {
1009
+ 'Authorization': 'Bearer ' + jwt,
1010
+ };
1011
+ if (method === 'GET') {
1012
+ if (Object.keys (query).length) {
1013
+ url += '?' + this.urlencode (query);
1014
+ }
1015
+ } else if (method === 'POST') {
1016
+ headers['Content-Type'] = 'application/json';
1017
+ body = this.json (query);
1018
+ }
1019
+ }
1020
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
1021
+ }
1022
+
1023
+ async fetchDepositAddress (code, params = {}) {
1024
+ await this.loadMarkets ();
1025
+ const currency = this.currency (code);
1026
+ const request = {
1027
+ 'asset_symbol': currency['id'],
1028
+ };
1029
+ const response = await this.privateGetAssetsAssetSymbolAddress (this.extend (request, params));
1030
+ //
1031
+ // the actual response format is not the same as the documented one
1032
+ // the data key contains an array in the actual response
1033
+ //
1034
+ // {
1035
+ // "code":0,
1036
+ // "message":"",
1037
+ // "data":[
1038
+ // {
1039
+ // "id":5521878,
1040
+ // "chain":"Bitcoin",
1041
+ // "value":"1GbmyKoikhpiQVZ1C9sbF17mTyvBjeobVe",
1042
+ // "memo":""
1043
+ // }
1044
+ // ]
1045
+ // }
1046
+ //
1047
+ const data = this.safeValue (response, 'data', []);
1048
+ const dataLength = data.length;
1049
+ if (dataLength < 1) {
1050
+ throw new ExchangeError (this.id + ' fetchDepositAddress() returned empty address response');
1051
+ }
1052
+ const firstElement = data[0];
1053
+ const address = this.safeString (firstElement, 'value');
1054
+ const tag = this.safeString (firstElement, 'memo');
1055
+ this.checkAddress (address);
1056
+ return {
1057
+ 'currency': code,
1058
+ 'address': address,
1059
+ 'tag': tag,
1060
+ 'network': undefined,
1061
+ 'info': response,
1062
+ };
1063
+ }
1064
+
1065
+ parseTransactionStatus (status) {
1066
+ const statuses = {
1067
+ // what are other statuses here?
1068
+ 'WITHHOLD': 'ok', // deposits
1069
+ 'UNCONFIRMED': 'pending',
1070
+ 'CONFIRMED': 'ok', // withdrawals
1071
+ 'COMPLETED': 'ok',
1072
+ 'PENDING': 'pending',
1073
+ };
1074
+ return this.safeString (statuses, status, status);
1075
+ }
1076
+
1077
+ parseTransaction (transaction, currency = undefined) {
1078
+ //
1079
+ // fetchDeposits
1080
+ //
1081
+ // {
1082
+ // "amount": "25.0",
1083
+ // "asset_symbol": "BTS"
1084
+ // "confirms": 100,
1085
+ // "id": 5,
1086
+ // "inserted_at": "2018-02-16T11:39:58.000Z",
1087
+ // "is_internal": false,
1088
+ // "kind": "default",
1089
+ // "memo": "",
1090
+ // "state": "WITHHOLD",
1091
+ // "txid": "72e03037d144dae3d32b68b5045462b1049a0755",
1092
+ // "updated_at": "2018-11-09T10:20:09.000Z",
1093
+ // }
1094
+ //
1095
+ // fetchWithdrawals
1096
+ //
1097
+ // {
1098
+ // "amount": "5",
1099
+ // "asset_symbol": "ETH",
1100
+ // "completed_at": "2018-03-15T16:13:45.610463Z",
1101
+ // "customer_id": "10",
1102
+ // "id": 10,
1103
+ // "inserted_at": "2018-03-15T16:13:45.610463Z",
1104
+ // "is_internal": true,
1105
+ // "note": "2018-03-15T16:13:45.610463Z",
1106
+ // "state": "CONFIRMED",
1107
+ // "target_address": "0x4643bb6b393ac20a6175c713175734a72517c63d6f7"
1108
+ // "txid": "0x4643bb6b393ac20a6175c713175734a72517c63d6f73a3ca90a15356f2e967da0",
1109
+ // }
1110
+ //
1111
+ // withdraw
1112
+ //
1113
+ // {
1114
+ // "id":1077391,
1115
+ // "customer_id":1082679,
1116
+ // "amount":"21.9000000000000000",
1117
+ // "txid":"",
1118
+ // "is_internal":false,
1119
+ // "kind":"on_chain",
1120
+ // "state":"PENDING",
1121
+ // "inserted_at":"2020-06-03T00:50:57+00:00",
1122
+ // "updated_at":"2020-06-03T00:50:57+00:00",
1123
+ // "memo":"",
1124
+ // "target_address":"rDYtYT3dBeuw376rvHqoZBKW3UmvguoBAf",
1125
+ // "fee":"0.1000000000000000",
1126
+ // "asset_symbol":"XRP"
1127
+ // }
1128
+ //
1129
+ const currencyId = this.safeString (transaction, 'asset_symbol');
1130
+ const code = this.safeCurrencyCode (currencyId);
1131
+ const id = this.safeInteger (transaction, 'id');
1132
+ const amount = this.safeNumber (transaction, 'amount');
1133
+ const status = this.parseTransactionStatus (this.safeString (transaction, 'state'));
1134
+ const timestamp = this.parse8601 (this.safeString (transaction, 'inserted_at'));
1135
+ const updated = this.parse8601 (this.safeString2 (transaction, 'updated_at', 'completed_at'));
1136
+ const txid = this.safeString (transaction, 'txid');
1137
+ const address = this.safeString (transaction, 'target_address');
1138
+ const tag = this.safeString (transaction, 'memo');
1139
+ const type = ('customer_id' in transaction) ? 'deposit' : 'withdrawal';
1140
+ return {
1141
+ 'info': transaction,
1142
+ 'id': id,
1143
+ 'txid': txid,
1144
+ 'timestamp': timestamp,
1145
+ 'datetime': this.iso8601 (timestamp),
1146
+ 'network': undefined,
1147
+ 'addressFrom': undefined,
1148
+ 'address': undefined,
1149
+ 'addressTo': address,
1150
+ 'tagFrom': undefined,
1151
+ 'tag': tag,
1152
+ 'tagTo': undefined,
1153
+ 'type': type,
1154
+ 'amount': amount,
1155
+ 'currency': code,
1156
+ 'status': status,
1157
+ 'updated': updated,
1158
+ 'fee': undefined,
1159
+ };
1160
+ }
1161
+
1162
+ async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) {
1163
+ await this.loadMarkets ();
1164
+ const request = {
1165
+ // 'page_token': 'dxzef', // request page after this page token
1166
+ // 'limit': 50, // optional, default 50
1167
+ // 'kind': 'string', // optional - air_drop, big_holder_dividend, default, eosc_to_eos, internal, equally_airdrop, referral_mining, one_holder_dividend, single_customer, snapshotted_airdrop, trade_mining
1168
+ // 'asset_symbol': 'BTC', // optional
1169
+ };
1170
+ let currency = undefined;
1171
+ if (code !== undefined) {
1172
+ currency = this.currency (code);
1173
+ request['asset_symbol'] = currency['id'];
1174
+ }
1175
+ if (limit !== undefined) {
1176
+ request['limit'] = limit; // default 50
1177
+ }
1178
+ const response = await this.privateGetDeposits (this.extend (request, params));
1179
+ //
1180
+ // {
1181
+ // "code": 0,
1182
+ // "page_token": "NQ==",
1183
+ // "data": [
1184
+ // {
1185
+ // "id": 5,
1186
+ // "amount": "25.0",
1187
+ // "confirms": 100,
1188
+ // "txid": "72e03037d144dae3d32b68b5045462b1049a0755",
1189
+ // "is_internal": false,
1190
+ // "inserted_at": "2018-02-16T11:39:58.000Z",
1191
+ // "updated_at": "2018-11-09T10:20:09.000Z",
1192
+ // "kind": "default",
1193
+ // "memo": "",
1194
+ // "state": "WITHHOLD",
1195
+ // "asset_symbol": "BTS"
1196
+ // }
1197
+ // ]
1198
+ // }
1199
+ //
1200
+ const deposits = this.safeValue (response, 'data', []);
1201
+ return this.parseTransactions (deposits, code, since, limit);
1202
+ }
1203
+
1204
+ async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) {
1205
+ await this.loadMarkets ();
1206
+ const request = {
1207
+ // 'page_token': 'dxzef', // request page after this page token
1208
+ // 'limit': 50, // optional, default 50
1209
+ // 'kind': 'string', // optional - air_drop, big_holder_dividend, default, eosc_to_eos, internal, equally_airdrop, referral_mining, one_holder_dividend, single_customer, snapshotted_airdrop, trade_mining
1210
+ // 'asset_symbol': 'BTC', // optional
1211
+ };
1212
+ let currency = undefined;
1213
+ if (code !== undefined) {
1214
+ currency = this.currency (code);
1215
+ request['asset_symbol'] = currency['id'];
1216
+ }
1217
+ if (limit !== undefined) {
1218
+ request['limit'] = limit; // default 50
1219
+ }
1220
+ const response = await this.privateGetWithdrawals (this.extend (request, params));
1221
+ //
1222
+ // {
1223
+ // "code": 0,
1224
+ // "data": [
1225
+ // {
1226
+ // "id": 10,
1227
+ // "customer_id": "10",
1228
+ // "asset_symbol": "ETH",
1229
+ // "amount": "5",
1230
+ // "state": "CONFIRMED",
1231
+ // "note": "2018-03-15T16:13:45.610463Z",
1232
+ // "txid": "0x4643bb6b393ac20a6175c713175734a72517c63d6f73a3ca90a15356f2e967da0",
1233
+ // "completed_at": "2018-03-15T16:13:45.610463Z",
1234
+ // "inserted_at": "2018-03-15T16:13:45.610463Z",
1235
+ // "is_internal": true,
1236
+ // "target_address": "0x4643bb6b393ac20a6175c713175734a72517c63d6f7"
1237
+ // }
1238
+ // ],
1239
+ // "page_token":"dxvf"
1240
+ // }
1241
+ //
1242
+ const withdrawals = this.safeValue (response, 'data', []);
1243
+ return this.parseTransactions (withdrawals, code, since, limit);
1244
+ }
1245
+
1246
+ async transfer (code, amount, fromAccount, toAccount, params = {}) {
1247
+ await this.loadMarkets ();
1248
+ const currency = this.currency (code);
1249
+ const accountsByType = this.safeValue (this.options, 'accountsByType', {});
1250
+ const fromId = this.safeString (accountsByType, fromAccount, fromAccount);
1251
+ const toId = this.safeString (accountsByType, toAccount, toAccount);
1252
+ const guid = this.safeString (params, 'guid', this.uuid ());
1253
+ const request = {
1254
+ 'symbol': currency['id'],
1255
+ 'amount': this.currencyToPrecision (code, amount),
1256
+ 'from': fromId,
1257
+ 'to': toId,
1258
+ 'guid': guid,
1259
+ // 'type': type, // NORMAL, MASTER_TO_SUB, SUB_TO_MASTER, SUB_INTERNAL, default is NORMAL
1260
+ // 'sub_acccunt': '', // when type is NORMAL, it should be empty, and when type is others it is required
1261
+ };
1262
+ const response = await this.privatePostTransfer (this.extend (request, params));
1263
+ //
1264
+ // {
1265
+ // "code": 0,
1266
+ // "data": null
1267
+ // }
1268
+ //
1269
+ const transfer = this.parseTransfer (response, currency);
1270
+ const transferOptions = this.safeValue (this.options, 'transfer', {});
1271
+ const fillResponseFromRequest = this.safeValue (transferOptions, 'fillResponseFromRequest', true);
1272
+ if (fillResponseFromRequest) {
1273
+ transfer['fromAccount'] = fromAccount;
1274
+ transfer['toAccount'] = toAccount;
1275
+ transfer['amount'] = amount;
1276
+ transfer['id'] = guid;
1277
+ }
1278
+ return transfer;
1279
+ }
1280
+
1281
+ parseTransfer (transfer, currency = undefined) {
1282
+ //
1283
+ // {
1284
+ // "code": 0,
1285
+ // "data": null
1286
+ // }
1287
+ //
1288
+ const code = this.safeNumber (transfer, 'code');
1289
+ return {
1290
+ 'info': transfer,
1291
+ 'id': undefined,
1292
+ 'timestamp': undefined,
1293
+ 'datetime': undefined,
1294
+ 'currency': code,
1295
+ 'amount': undefined,
1296
+ 'fromAccount': undefined,
1297
+ 'toAccount': undefined,
1298
+ 'status': this.parseTransferStatus (code),
1299
+ };
1300
+ }
1301
+
1302
+ parseTransferStatus (status) {
1303
+ const statuses = {
1304
+ '0': 'ok',
1305
+ };
1306
+ return this.safeString (statuses, status, 'failed');
1307
+ }
1308
+
1309
+ async withdraw (code, amount, address, tag = undefined, params = {}) {
1310
+ [ tag, params ] = this.handleWithdrawTagAndParams (tag, params);
1311
+ await this.loadMarkets ();
1312
+ const currency = this.currency (code);
1313
+ const request = {
1314
+ 'symbol': currency['id'],
1315
+ 'target_address': address,
1316
+ 'amount': this.currencyToPrecision (code, amount),
1317
+ };
1318
+ if (tag !== undefined) {
1319
+ request['memo'] = tag;
1320
+ }
1321
+ // requires write permission on the wallet
1322
+ const response = await this.privatePostWithdrawals (this.extend (request, params));
1323
+ //
1324
+ // {
1325
+ // "code":0,
1326
+ // "message":"",
1327
+ // "data":{
1328
+ // "id":1077391,
1329
+ // "customer_id":1082679,
1330
+ // "amount":"21.9000000000000000",
1331
+ // "txid":"",
1332
+ // "is_internal":false,
1333
+ // "kind":"on_chain",
1334
+ // "state":"PENDING",
1335
+ // "inserted_at":"2020-06-03T00:50:57+00:00",
1336
+ // "updated_at":"2020-06-03T00:50:57+00:00",
1337
+ // "memo":"",
1338
+ // "target_address":"rDYtYT3dBeuw376rvHqoZBKW3UmvguoBAf",
1339
+ // "fee":"0.1000000000000000",
1340
+ // "asset_symbol":"XRP"
1341
+ // }
1342
+ // }
1343
+ //
1344
+ const data = this.safeValue (response, 'data', {});
1345
+ return this.parseTransaction (data, currency);
1346
+ }
1347
+
1348
+ handleErrors (httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
1349
+ if (response === undefined) {
1350
+ return; // fallback to default error handler
1351
+ }
1352
+ //
1353
+ // {"code":10013,"message":"Resource not found"}
1354
+ // {"code":40004,"message":"invalid jwt"}
1355
+ //
1356
+ const code = this.safeString (response, 'code');
1357
+ const message = this.safeString (response, 'message');
1358
+ if (code !== '0') {
1359
+ const feedback = this.id + ' ' + body;
1360
+ this.throwExactlyMatchedException (this.exceptions['exact'], message, feedback);
1361
+ this.throwExactlyMatchedException (this.exceptions['exact'], code, feedback);
1362
+ this.throwBroadlyMatchedException (this.exceptions['broad'], message, feedback);
1363
+ throw new ExchangeError (feedback); // unknown message
1364
+ }
1365
+ }
1366
+ };