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
@@ -0,0 +1,880 @@
1
+ 'use strict';
2
+
3
+ // ---------------------------------------------------------------------------
4
+
5
+ const Exchange = require ('./base/Exchange');
6
+ const { ExchangeError, AuthenticationError, RateLimitExceeded, ArgumentsRequired } = require ('./base/errors');
7
+ const Precise = require ('./base/Precise');
8
+
9
+ // ---------------------------------------------------------------------------
10
+
11
+ module.exports = class coinfalcon extends Exchange {
12
+ describe () {
13
+ return this.deepExtend (super.describe (), {
14
+ 'id': 'coinfalcon',
15
+ 'name': 'CoinFalcon',
16
+ 'countries': [ 'GB' ],
17
+ 'rateLimit': 1000,
18
+ 'version': 'v1',
19
+ 'has': {
20
+ 'CORS': undefined,
21
+ 'spot': true,
22
+ 'margin': false,
23
+ 'swap': false,
24
+ 'future': false,
25
+ 'option': false,
26
+ 'addMargin': false,
27
+ 'cancelOrder': true,
28
+ 'createOrder': true,
29
+ 'createReduceOnlyOrder': false,
30
+ 'fetchBalance': true,
31
+ 'fetchBorrowRate': false,
32
+ 'fetchBorrowRateHistories': false,
33
+ 'fetchBorrowRateHistory': false,
34
+ 'fetchBorrowRates': false,
35
+ 'fetchBorrowRatesPerSymbol': false,
36
+ 'fetchDepositAddress': true,
37
+ 'fetchDepositAddresses': false,
38
+ 'fetchDeposits': true,
39
+ 'fetchFundingHistory': false,
40
+ 'fetchFundingRate': false,
41
+ 'fetchFundingRateHistory': false,
42
+ 'fetchFundingRates': false,
43
+ 'fetchIndexOHLCV': false,
44
+ 'fetchLeverage': false,
45
+ 'fetchLeverageTiers': false,
46
+ 'fetchMarkets': true,
47
+ 'fetchMarkOHLCV': false,
48
+ 'fetchMyTrades': true,
49
+ 'fetchOpenOrders': true,
50
+ 'fetchOrder': true,
51
+ 'fetchOrderBook': true,
52
+ 'fetchPosition': false,
53
+ 'fetchPositions': false,
54
+ 'fetchPositionsRisk': false,
55
+ 'fetchPremiumIndexOHLCV': false,
56
+ 'fetchTicker': true,
57
+ 'fetchTickers': true,
58
+ 'fetchTrades': true,
59
+ 'fetchTradinFee': false,
60
+ 'fetchTradingFees': true,
61
+ 'fetchTransfer': false,
62
+ 'fetchTransfers': false,
63
+ 'fetchWithdrawals': true,
64
+ 'reduceMargin': false,
65
+ 'setLeverage': false,
66
+ 'setMarginMode': false,
67
+ 'setPositionMode': false,
68
+ 'transfer': false,
69
+ 'withdraw': true,
70
+ },
71
+ 'urls': {
72
+ 'logo': 'https://user-images.githubusercontent.com/1294454/41822275-ed982188-77f5-11e8-92bb-496bcd14ca52.jpg',
73
+ 'api': 'https://coinfalcon.com',
74
+ 'www': 'https://coinfalcon.com',
75
+ 'doc': 'https://docs.coinfalcon.com',
76
+ 'fees': 'https://coinfalcon.com/fees',
77
+ 'referral': 'https://coinfalcon.com/?ref=CFJSVGTUPASB',
78
+ },
79
+ 'api': {
80
+ 'public': {
81
+ 'get': [
82
+ 'markets',
83
+ 'markets/{market}',
84
+ 'markets/{market}/orders',
85
+ 'markets/{market}/trades',
86
+ ],
87
+ },
88
+ 'private': {
89
+ 'get': [
90
+ 'user/accounts',
91
+ 'user/orders',
92
+ 'user/orders/{id}',
93
+ 'user/orders/{id}/trades',
94
+ 'user/trades',
95
+ 'user/fees',
96
+ 'account/withdrawals/{id}',
97
+ 'account/withdrawals',
98
+ 'account/deposit/{id}',
99
+ 'account/deposits',
100
+ 'account/deposit_address',
101
+ ],
102
+ 'post': [
103
+ 'user/orders',
104
+ 'account/withdraw',
105
+ ],
106
+ 'delete': [
107
+ 'user/orders/{id}',
108
+ 'account/withdrawals/{id}',
109
+ ],
110
+ },
111
+ },
112
+ 'fees': {
113
+ 'trading': {
114
+ 'tierBased': true,
115
+ 'maker': 0.0,
116
+ 'taker': 0.002, // tiered fee starts at 0.2%
117
+ },
118
+ },
119
+ 'precision': {
120
+ 'amount': 8,
121
+ 'price': 8,
122
+ },
123
+ });
124
+ }
125
+
126
+ async fetchMarkets (params = {}) {
127
+ const response = await this.publicGetMarkets (params);
128
+ //
129
+ // {
130
+ // "data": [
131
+ // {
132
+ // "name": "ETH-BTC",
133
+ // "precision": 6,
134
+ // "min_volume": "0.00000001",
135
+ // "min_price": "0.000001",
136
+ // "volume": "0.015713",
137
+ // "last_price": "0.069322",
138
+ // "highest_bid": "0.063892",
139
+ // "lowest_ask": "0.071437",
140
+ // "change_in_24h": "2.85",
141
+ // "size_precision": 8,
142
+ // "price_precision": 6
143
+ // },
144
+ // ...
145
+ // ]
146
+ // }
147
+ //
148
+ const markets = this.safeValue (response, 'data');
149
+ const result = [];
150
+ for (let i = 0; i < markets.length; i++) {
151
+ const market = markets[i];
152
+ const [ baseId, quoteId ] = market['name'].split ('-');
153
+ const base = this.safeCurrencyCode (baseId);
154
+ const quote = this.safeCurrencyCode (quoteId);
155
+ result.push ({
156
+ 'id': market['name'],
157
+ 'symbol': base + '/' + quote,
158
+ 'base': base,
159
+ 'quote': quote,
160
+ 'settle': undefined,
161
+ 'baseId': baseId,
162
+ 'quoteId': quoteId,
163
+ 'settleId': undefined,
164
+ 'type': 'spot',
165
+ 'spot': true,
166
+ 'margin': false,
167
+ 'swap': false,
168
+ 'future': false,
169
+ 'option': false,
170
+ 'active': true,
171
+ 'contract': false,
172
+ 'linear': undefined,
173
+ 'inverse': undefined,
174
+ 'contractSize': undefined,
175
+ 'expiry': undefined,
176
+ 'expiryDatetime': undefined,
177
+ 'strike': undefined,
178
+ 'optionType': undefined,
179
+ 'precision': {
180
+ 'amount': this.safeInteger (market, 'size_precision'),
181
+ 'price': this.safeInteger (market, 'price_precision'),
182
+ },
183
+ 'limits': {
184
+ 'leverage': {
185
+ 'min': undefined,
186
+ 'max': undefined,
187
+ },
188
+ 'amount': {
189
+ 'min': this.safeNumber (market, 'minPrice'),
190
+ 'max': undefined,
191
+ },
192
+ 'price': {
193
+ 'min': this.safeNumber (market, 'minVolume'),
194
+ 'max': undefined,
195
+ },
196
+ 'cost': {
197
+ 'min': undefined,
198
+ 'max': undefined,
199
+ },
200
+ },
201
+ 'info': market,
202
+ });
203
+ }
204
+ return result;
205
+ }
206
+
207
+ parseTicker (ticker, market = undefined) {
208
+ //
209
+ // {
210
+ // "name":"ETH-BTC",
211
+ // "precision":6,
212
+ // "min_volume":"0.00000001",
213
+ // "min_price":"0.000001",
214
+ // "volume":"0.000452",
215
+ // "last_price":"0.079059",
216
+ // "highest_bid":"0.073472",
217
+ // "lowest_ask":"0.079059",
218
+ // "change_in_24h":"8.9",
219
+ // "size_precision":8,
220
+ // "price_precision":6
221
+ // }
222
+ //
223
+ const marketId = this.safeString (ticker, 'name');
224
+ market = this.safeMarket (marketId, market, '-');
225
+ const timestamp = this.milliseconds ();
226
+ const last = this.safeString (ticker, 'last_price');
227
+ return this.safeTicker ({
228
+ 'symbol': market['symbol'],
229
+ 'timestamp': timestamp,
230
+ 'datetime': this.iso8601 (timestamp),
231
+ 'high': undefined,
232
+ 'low': undefined,
233
+ 'bid': this.safeString (ticker, 'highest_bid'),
234
+ 'bidVolume': undefined,
235
+ 'ask': this.safeString (ticker, 'lowest_ask'),
236
+ 'askVolume': undefined,
237
+ 'vwap': undefined,
238
+ 'open': undefined,
239
+ 'close': last,
240
+ 'last': last,
241
+ 'previousClose': undefined,
242
+ 'change': this.safeString (ticker, 'change_in_24h'),
243
+ 'percentage': undefined,
244
+ 'average': undefined,
245
+ 'baseVolume': undefined,
246
+ 'quoteVolume': this.safeString (ticker, 'volume'),
247
+ 'info': ticker,
248
+ }, market, false);
249
+ }
250
+
251
+ async fetchTicker (symbol, params = {}) {
252
+ await this.loadMarkets ();
253
+ const tickers = await this.fetchTickers ([ symbol ], params);
254
+ return tickers[symbol];
255
+ }
256
+
257
+ async fetchTickers (symbols = undefined, params = {}) {
258
+ await this.loadMarkets ();
259
+ const response = await this.publicGetMarkets (params);
260
+ //
261
+ // {
262
+ // "data":[
263
+ // {
264
+ // "name":"ETH-BTC",
265
+ // "precision":6,
266
+ // "min_volume":"0.00000001",
267
+ // "min_price":"0.000001",
268
+ // "volume":"0.000452",
269
+ // "last_price":"0.079059",
270
+ // "highest_bid":"0.073472",
271
+ // "lowest_ask":"0.079059",
272
+ // "change_in_24h":"8.9",
273
+ // "size_precision":8,
274
+ // "price_precision":6
275
+ // }
276
+ // ]
277
+ // }
278
+ //
279
+ const tickers = this.safeValue (response, 'data');
280
+ const result = {};
281
+ for (let i = 0; i < tickers.length; i++) {
282
+ const ticker = this.parseTicker (tickers[i]);
283
+ const symbol = ticker['symbol'];
284
+ result[symbol] = ticker;
285
+ }
286
+ return this.filterByArray (result, 'symbol', symbols);
287
+ }
288
+
289
+ async fetchOrderBook (symbol, limit = undefined, params = {}) {
290
+ await this.loadMarkets ();
291
+ const request = {
292
+ 'market': this.marketId (symbol),
293
+ 'level': '3',
294
+ };
295
+ const response = await this.publicGetMarketsMarketOrders (this.extend (request, params));
296
+ const data = this.safeValue (response, 'data', {});
297
+ return this.parseOrderBook (data, symbol, undefined, 'bids', 'asks', 'price', 'size');
298
+ }
299
+
300
+ parseTrade (trade, market = undefined) {
301
+ //
302
+ // fetchTrades (public)
303
+ //
304
+ // {
305
+ // "id":"5ec36295-5c8d-4874-8d66-2609d4938557",
306
+ // "price":"4050.06","size":"0.0044",
307
+ // "market_name":"ETH-USDT",
308
+ // "side":"sell",
309
+ // "created_at":"2021-12-07T17:47:36.811000Z"
310
+ // }
311
+ //
312
+ // fetchMyTrades (private)
313
+ //
314
+ // {
315
+ // "id": "0718d520-c796-4061-a16b-915cd13f20c6",
316
+ // "price": "0.00000358",
317
+ // "size": "50.0",
318
+ // "market_name": "DOGE-BTC",
319
+ // "order_id": "ff2616d8-58d4-40fd-87ae-937c73eb6f1c",
320
+ // "side": "buy",
321
+ // "fee': "0.00000036",
322
+ // "fee_currency_code": "btc",
323
+ // "liquidity": "T",
324
+ // "created_at": "2021-12-08T18:26:33.840000Z"
325
+ // }
326
+ //
327
+ const timestamp = this.parse8601 (this.safeString (trade, 'created_at'));
328
+ const priceString = this.safeString (trade, 'price');
329
+ const amountString = this.safeString (trade, 'size');
330
+ const symbol = market['symbol'];
331
+ const tradeId = this.safeString (trade, 'id');
332
+ const side = this.safeString (trade, 'side');
333
+ const orderId = this.safeString (trade, 'order_id');
334
+ let fee = undefined;
335
+ const feeCostString = this.safeString (trade, 'fee');
336
+ if (feeCostString !== undefined) {
337
+ const feeCurrencyCode = this.safeString (trade, 'fee_currency_code');
338
+ fee = {
339
+ 'cost': feeCostString,
340
+ 'currency': this.safeCurrencyCode (feeCurrencyCode),
341
+ };
342
+ }
343
+ return this.safeTrade ({
344
+ 'info': trade,
345
+ 'timestamp': timestamp,
346
+ 'datetime': this.iso8601 (timestamp),
347
+ 'symbol': symbol,
348
+ 'id': tradeId,
349
+ 'order': orderId,
350
+ 'type': undefined,
351
+ 'side': side,
352
+ 'takerOrMaker': undefined,
353
+ 'price': priceString,
354
+ 'amount': amountString,
355
+ 'cost': undefined,
356
+ 'fee': fee,
357
+ }, market);
358
+ }
359
+
360
+ async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
361
+ if (symbol === undefined) {
362
+ throw new ArgumentsRequired (this.id + ' fetchMyTrades() requires a symbol argument');
363
+ }
364
+ await this.loadMarkets ();
365
+ const market = this.market (symbol);
366
+ const request = {
367
+ 'market': market['id'],
368
+ };
369
+ if (since !== undefined) {
370
+ request['start_time'] = this.iso8601 (since);
371
+ }
372
+ if (limit !== undefined) {
373
+ request['limit'] = limit;
374
+ }
375
+ const response = await this.privateGetUserTrades (this.extend (request, params));
376
+ //
377
+ // {
378
+ // "data": [
379
+ // {
380
+ // "id": "0718d520-c796-4061-a16b-915cd13f20c6",
381
+ // "price": "0.00000358",
382
+ // "size": "50.0",
383
+ // "market_name": "DOGE-BTC",
384
+ // "order_id": "ff2616d8-58d4-40fd-87ae-937c73eb6f1c",
385
+ // "side": "buy",
386
+ // "fee': "0.00000036",
387
+ // "fee_currency_code": "btc",
388
+ // "liquidity": "T",
389
+ // "created_at": "2021-12-08T18:26:33.840000Z"
390
+ // },
391
+ // ]
392
+ // }
393
+ //
394
+ const data = this.safeValue (response, 'data', []);
395
+ return this.parseTrades (data, market, since, limit);
396
+ }
397
+
398
+ async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
399
+ await this.loadMarkets ();
400
+ const market = this.market (symbol);
401
+ const request = {
402
+ 'market': market['id'],
403
+ };
404
+ if (since !== undefined) {
405
+ request['since'] = this.iso8601 (since);
406
+ }
407
+ const response = await this.publicGetMarketsMarketTrades (this.extend (request, params));
408
+ //
409
+ // {
410
+ // "data":[
411
+ // {
412
+ // "id":"5ec36295-5c8d-4874-8d66-2609d4938557",
413
+ // "price":"4050.06","size":"0.0044",
414
+ // "market_name":"ETH-USDT",
415
+ // "side":"sell",
416
+ // "created_at":"2021-12-07T17:47:36.811000Z"
417
+ // },
418
+ // ]
419
+ // }
420
+ //
421
+ const data = this.safeValue (response, 'data', []);
422
+ return this.parseTrades (data, market, since, limit);
423
+ }
424
+
425
+ async fetchTradingFees (params = {}) {
426
+ await this.loadMarkets ();
427
+ const response = await this.privateGetUserFees (params);
428
+ //
429
+ // {
430
+ // data: {
431
+ // maker_fee: '0.0',
432
+ // taker_fee: '0.2',
433
+ // btc_volume_30d: '0.0'
434
+ // }
435
+ // }
436
+ //
437
+ const data = this.safeValue (response, 'data', {});
438
+ const makerString = this.safeString (data, 'maker_fee');
439
+ const takerString = this.safeString (data, 'taker_fee');
440
+ const maker = this.parseNumber (Precise.stringDiv (makerString, '100'));
441
+ const taker = this.parseNumber (Precise.stringDiv (takerString, '100'));
442
+ const result = {};
443
+ for (let i = 0; i < this.symbols.length; i++) {
444
+ const symbol = this.symbols[i];
445
+ result[symbol] = {
446
+ 'info': response,
447
+ 'symbol': symbol,
448
+ 'maker': maker,
449
+ 'taker': taker,
450
+ 'percentage': true,
451
+ 'tierBased': true,
452
+ };
453
+ }
454
+ return result;
455
+ }
456
+
457
+ parseBalance (response) {
458
+ const result = { 'info': response };
459
+ const balances = this.safeValue (response, 'data');
460
+ for (let i = 0; i < balances.length; i++) {
461
+ const balance = balances[i];
462
+ const currencyId = this.safeString (balance, 'currency_code');
463
+ const code = this.safeCurrencyCode (currencyId);
464
+ const account = this.account ();
465
+ account['free'] = this.safeString (balance, 'available_balance');
466
+ account['used'] = this.safeString (balance, 'hold_balance');
467
+ account['total'] = this.safeString (balance, 'balance');
468
+ result[code] = account;
469
+ }
470
+ return this.safeBalance (result);
471
+ }
472
+
473
+ async fetchBalance (params = {}) {
474
+ await this.loadMarkets ();
475
+ const response = await this.privateGetUserAccounts (params);
476
+ return this.parseBalance (response);
477
+ }
478
+
479
+ parseDepositAddress (depositAddress, currency = undefined) {
480
+ //
481
+ // {
482
+ // "address":"0x77b5051f97efa9cc52c9ad5b023a53fc15c200d3",
483
+ // "tag":"0"
484
+ // }
485
+ //
486
+ const address = this.safeString (depositAddress, 'address');
487
+ const tag = this.safeString (depositAddress, 'tag');
488
+ this.checkAddress (address);
489
+ return {
490
+ 'currency': this.safeCurrencyCode (undefined, currency),
491
+ 'address': address,
492
+ 'tag': tag,
493
+ 'network': undefined,
494
+ 'info': depositAddress,
495
+ };
496
+ }
497
+
498
+ async fetchDepositAddress (code, params = {}) {
499
+ await this.loadMarkets ();
500
+ const currency = this.safeCurrency (code);
501
+ const request = {
502
+ 'currency': this.safeStringLower (currency, 'id'),
503
+ };
504
+ const response = await this.privateGetAccountDepositAddress (this.extend (request, params));
505
+ //
506
+ // {
507
+ // data: {
508
+ // address: '0x9918987bbe865a1a9301dc736cf6cf3205956694',
509
+ // tag:null
510
+ // }
511
+ // }
512
+ //
513
+ const data = this.safeValue (response, 'data', {});
514
+ return this.parseDepositAddress (data, currency);
515
+ }
516
+
517
+ parseOrderStatus (status) {
518
+ const statuses = {
519
+ 'fulfilled': 'closed',
520
+ 'canceled': 'canceled',
521
+ 'pending': 'open',
522
+ 'open': 'open',
523
+ 'partially_filled': 'open',
524
+ };
525
+ return this.safeString (statuses, status, status);
526
+ }
527
+
528
+ parseOrder (order, market = undefined) {
529
+ //
530
+ // {
531
+ // "id":"8bdd79f4-8414-40a2-90c3-e9f4d6d1eef4"
532
+ // "market":"IOT-BTC"
533
+ // "price":"0.0000003"
534
+ // "size":"4.0"
535
+ // "size_filled":"3.0"
536
+ // "fee":"0.0075"
537
+ // "fee_currency_code":"iot"
538
+ // "funds":"0.0"
539
+ // "status":"canceled"
540
+ // "order_type":"buy"
541
+ // "post_only":false
542
+ // "operation_type":"market_order"
543
+ // "created_at":"2018-01-12T21:14:06.747828Z"
544
+ // }
545
+ //
546
+ const marketId = this.safeString (order, 'market');
547
+ const symbol = this.safeSymbol (marketId, market, '-');
548
+ const timestamp = this.parse8601 (this.safeString (order, 'created_at'));
549
+ const priceString = this.safeString (order, 'price');
550
+ const amountString = this.safeString (order, 'size');
551
+ const filledString = this.safeString (order, 'size_filled');
552
+ const status = this.parseOrderStatus (this.safeString (order, 'status'));
553
+ let type = this.safeString (order, 'operation_type');
554
+ if (type !== undefined) {
555
+ type = type.split ('_');
556
+ type = type[0];
557
+ }
558
+ const side = this.safeString (order, 'order_type');
559
+ const postOnly = this.safeValue (order, 'post_only');
560
+ return this.safeOrder ({
561
+ 'id': this.safeString (order, 'id'),
562
+ 'clientOrderId': undefined,
563
+ 'datetime': this.iso8601 (timestamp),
564
+ 'timestamp': timestamp,
565
+ 'status': status,
566
+ 'symbol': symbol,
567
+ 'type': type,
568
+ 'timeInForce': undefined,
569
+ 'postOnly': postOnly,
570
+ 'side': side,
571
+ 'price': priceString,
572
+ 'stopPrice': undefined,
573
+ 'cost': undefined,
574
+ 'amount': amountString,
575
+ 'filled': filledString,
576
+ 'remaining': undefined,
577
+ 'trades': undefined,
578
+ 'fee': undefined,
579
+ 'info': order,
580
+ 'lastTradeTimestamp': undefined,
581
+ 'average': undefined,
582
+ }, market);
583
+ }
584
+
585
+ async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
586
+ await this.loadMarkets ();
587
+ const market = this.market (symbol);
588
+ // price/size must be string
589
+ const request = {
590
+ 'market': market['id'],
591
+ 'size': this.amountToPrecision (symbol, amount),
592
+ 'order_type': side,
593
+ };
594
+ if (type === 'limit') {
595
+ price = this.priceToPrecision (symbol, price);
596
+ request['price'] = price.toString ();
597
+ }
598
+ request['operation_type'] = type + '_order';
599
+ const response = await this.privatePostUserOrders (this.extend (request, params));
600
+ const data = this.safeValue (response, 'data', {});
601
+ return this.parseOrder (data, market);
602
+ }
603
+
604
+ async cancelOrder (id, symbol = undefined, params = {}) {
605
+ await this.loadMarkets ();
606
+ const request = {
607
+ 'id': id,
608
+ };
609
+ const response = await this.privateDeleteUserOrdersId (this.extend (request, params));
610
+ const market = this.market (symbol);
611
+ const data = this.safeValue (response, 'data', {});
612
+ return this.parseOrder (data, market);
613
+ }
614
+
615
+ async fetchOrder (id, symbol = undefined, params = {}) {
616
+ await this.loadMarkets ();
617
+ const request = {
618
+ 'id': id,
619
+ };
620
+ const response = await this.privateGetUserOrdersId (this.extend (request, params));
621
+ const data = this.safeValue (response, 'data', {});
622
+ return this.parseOrder (data);
623
+ }
624
+
625
+ async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
626
+ await this.loadMarkets ();
627
+ const request = {};
628
+ let market = undefined;
629
+ if (symbol !== undefined) {
630
+ market = this.market (symbol);
631
+ request['market'] = market['id'];
632
+ }
633
+ if (since !== undefined) {
634
+ request['since_time'] = this.iso8601 (since);
635
+ }
636
+ // TODO: test status=all if it works for closed orders too
637
+ const response = await this.privateGetUserOrders (this.extend (request, params));
638
+ const data = this.safeValue (response, 'data', []);
639
+ const orders = this.filterByArray (data, 'status', [ 'pending', 'open', 'partially_filled' ], false);
640
+ return this.parseOrders (orders, market, since, limit);
641
+ }
642
+
643
+ async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) {
644
+ await this.loadMarkets ();
645
+ const request = {
646
+ // currency: 'xrp', // optional: currency code in lowercase
647
+ // status: 'completed', // optional: withdrawal status
648
+ // since_time // datetime in ISO8601 format (2017-11-06T09:53:08.383210Z)
649
+ // end_time // datetime in ISO8601 format (2017-11-06T09:53:08.383210Z)
650
+ // start_time // datetime in ISO8601 format (2017-11-06T09:53:08.383210Z)
651
+ };
652
+ let currency = undefined;
653
+ if (code !== undefined) {
654
+ currency = this.currency (code);
655
+ request['currency'] = this.safeStringLower (currency, 'id');
656
+ }
657
+ if (since !== undefined) {
658
+ request['since_time'] = this.iso8601 (since);
659
+ }
660
+ const response = await this.privateGetAccountDeposits (this.extend (request, params));
661
+ //
662
+ // data: [
663
+ // {
664
+ // id: '6e2f18b5-f80e-xxx-xxx-xxx',
665
+ // amount: '0.1',
666
+ // status: 'completed',
667
+ // currency_code: 'eth',
668
+ // txid: '0xxxx',
669
+ // address: '0xxxx',
670
+ // tag: null,
671
+ // type: 'deposit'
672
+ // },
673
+ // ]
674
+ //
675
+ const transactions = this.safeValue (response, 'data', []);
676
+ transactions.reverse (); // no timestamp but in reversed order
677
+ return this.parseTransactions (transactions, currency, undefined, limit);
678
+ }
679
+
680
+ async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) {
681
+ await this.loadMarkets ();
682
+ const request = {
683
+ // currency: 'xrp', // optional: currency code in lowercase
684
+ // status: 'completed', // optional: withdrawal status
685
+ // since_time // datetime in ISO8601 format (2017-11-06T09:53:08.383210Z)
686
+ // end_time // datetime in ISO8601 format (2017-11-06T09:53:08.383210Z)
687
+ // start_time // datetime in ISO8601 format (2017-11-06T09:53:08.383210Z)
688
+ };
689
+ let currency = undefined;
690
+ if (code !== undefined) {
691
+ currency = this.currency (code);
692
+ request['currency'] = this.safeStringLower (currency, 'id');
693
+ }
694
+ if (since !== undefined) {
695
+ request['since_time'] = this.iso8601 (since);
696
+ }
697
+ const response = await this.privateGetAccountWithdrawals (this.extend (request, params));
698
+ //
699
+ // data: [
700
+ // {
701
+ // id: '25f6f144-3666-xxx-xxx-xxx',
702
+ // amount: '0.01',
703
+ // status: 'completed',
704
+ // fee: '0.0005',
705
+ // currency_code: 'btc',
706
+ // txid: '4xxx',
707
+ // address: 'bc1xxx',
708
+ // tag: null,
709
+ // type: 'withdraw'
710
+ // },
711
+ // ]
712
+ //
713
+ const transactions = this.safeValue (response, 'data', []);
714
+ transactions.reverse (); // no timestamp but in reversed order
715
+ return this.parseTransactions (transactions, currency, undefined, limit);
716
+ }
717
+
718
+ async withdraw (code, amount, address, tag = undefined, params = {}) {
719
+ [ tag, params ] = this.handleWithdrawTagAndParams (tag, params);
720
+ this.checkAddress (address);
721
+ await this.loadMarkets ();
722
+ const currency = this.currency (code);
723
+ const request = {
724
+ 'currency': this.safeStingLower (currency, 'id'),
725
+ 'address': address,
726
+ 'amount': amount,
727
+ // 'tag': 'string', // withdraw tag/memo
728
+ };
729
+ if (tag !== undefined) {
730
+ request['tag'] = tag;
731
+ }
732
+ const response = await this.privatePostAccountWithdraw (this.extend (request, params));
733
+ //
734
+ // data: [
735
+ // {
736
+ // id: '25f6f144-3666-xxx-xxx-xxx',
737
+ // amount: '0.01',
738
+ // status: 'approval_pending',
739
+ // fee: '0.0005',
740
+ // currency_code: 'btc',
741
+ // txid: null,
742
+ // address: 'bc1xxx',
743
+ // tag: null,
744
+ // type: 'withdraw'
745
+ // },
746
+ // ]
747
+ //
748
+ const transaction = this.safeValue (response, 'data', []);
749
+ return this.parseTransaction (transaction, currency);
750
+ }
751
+
752
+ parseTransactionStatus (status) {
753
+ const statuses = {
754
+ 'completed': 'ok',
755
+ 'denied': 'failed',
756
+ 'approval_pending': 'pending',
757
+ };
758
+ return this.safeString (statuses, status, status);
759
+ }
760
+
761
+ parseTransaction (transaction, currency = undefined) {
762
+ //
763
+ // fetchWithdrawals, withdraw
764
+ //
765
+ // {
766
+ // id: '25f6f144-3666-xxx-xxx-xxx',
767
+ // amount: '0.01',
768
+ // status: 'completed',
769
+ // fee: '0.0005',
770
+ // currency_code: 'btc',
771
+ // txid: '4xxx',
772
+ // address: 'bc1xxx',
773
+ // tag: null,
774
+ // type: 'withdraw'
775
+ // },
776
+ //
777
+ // fetchDeposits
778
+ //
779
+ // {
780
+ // id: '6e2f18b5-f80e-xxx-xxx-xxx',
781
+ // amount: '0.1',
782
+ // status: 'completed',
783
+ // currency_code: 'eth',
784
+ // txid: '0xxxx',
785
+ // address: '0xxxx',
786
+ // tag: null,
787
+ // type: 'deposit'
788
+ // },
789
+ //
790
+ const id = this.safeString (transaction, 'id');
791
+ const address = this.safeString (transaction, 'address');
792
+ const tag = this.safeString (transaction, 'tag');
793
+ const txid = this.safeString (transaction, 'txid');
794
+ const currencyId = this.safeString (transaction, 'currency_code');
795
+ const code = this.safeCurrencyCode (currencyId, currency);
796
+ let type = this.safeString (transaction, 'type');
797
+ if (type === 'withdraw') {
798
+ type = 'withdrawal';
799
+ }
800
+ const status = this.parseTransactionStatus (this.safeString (transaction, 'status'));
801
+ const amountString = this.safeString (transaction, 'amount');
802
+ const amount = this.parseNumber (amountString);
803
+ const feeCostString = this.safeString (transaction, 'fee');
804
+ let feeCost = 0;
805
+ if (feeCostString !== undefined) {
806
+ feeCost = this.parseNumber (feeCostString);
807
+ }
808
+ return {
809
+ 'info': transaction,
810
+ 'id': id,
811
+ 'txid': txid,
812
+ 'timestamp': undefined,
813
+ 'datetime': undefined,
814
+ 'network': undefined,
815
+ 'address': address,
816
+ 'addressTo': undefined,
817
+ 'addressFrom': undefined,
818
+ 'tag': tag,
819
+ 'tagTo': undefined,
820
+ 'tagFrom': undefined,
821
+ 'type': type,
822
+ 'amount': amount,
823
+ 'currency': code,
824
+ 'status': status,
825
+ 'updated': undefined,
826
+ 'fee': {
827
+ 'currency': code,
828
+ 'cost': feeCost,
829
+ },
830
+ };
831
+ }
832
+
833
+ nonce () {
834
+ return this.milliseconds ();
835
+ }
836
+
837
+ sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
838
+ let request = '/api/' + this.version + '/' + this.implodeParams (path, params);
839
+ const query = this.omit (params, this.extractParams (path));
840
+ if (api === 'public') {
841
+ if (Object.keys (query).length) {
842
+ request += '?' + this.urlencode (query);
843
+ }
844
+ } else {
845
+ this.checkRequiredCredentials ();
846
+ if (method === 'GET') {
847
+ if (Object.keys (query).length) {
848
+ request += '?' + this.urlencode (query);
849
+ }
850
+ } else {
851
+ body = this.json (query);
852
+ }
853
+ const seconds = this.seconds ().toString ();
854
+ let payload = [ seconds, method, request ].join ('|');
855
+ if (body) {
856
+ payload += '|' + body;
857
+ }
858
+ const signature = this.hmac (this.encode (payload), this.encode (this.secret));
859
+ headers = {
860
+ 'CF-API-KEY': this.apiKey,
861
+ 'CF-API-TIMESTAMP': seconds,
862
+ 'CF-API-SIGNATURE': signature,
863
+ 'Content-Type': 'application/json',
864
+ };
865
+ }
866
+ const url = this.urls['api'] + request;
867
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
868
+ }
869
+
870
+ handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
871
+ if (code < 400) {
872
+ return;
873
+ }
874
+ const ErrorClass = this.safeValue ({
875
+ '401': AuthenticationError,
876
+ '429': RateLimitExceeded,
877
+ }, code, ExchangeError);
878
+ throw new ErrorClass (body);
879
+ }
880
+ };