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/crex24.js ADDED
@@ -0,0 +1,1636 @@
1
+ 'use strict';
2
+
3
+ // ---------------------------------------------------------------------------
4
+
5
+ const Exchange = require ('./base/Exchange');
6
+ const { ExchangeError, BadRequest, InvalidNonce, RequestTimeout, ExchangeNotAvailable, InsufficientFunds, OrderNotFound, InvalidOrder, DDoSProtection, AuthenticationError, BadSymbol, AccountSuspended, ArgumentsRequired } = require ('./base/errors');
7
+ const { TICK_SIZE } = require ('./base/functions/number');
8
+
9
+ // ---------------------------------------------------------------------------
10
+
11
+ module.exports = class crex24 extends Exchange {
12
+ describe () {
13
+ return this.deepExtend (super.describe (), {
14
+ 'id': 'crex24',
15
+ 'name': 'CREX24',
16
+ 'countries': [ 'EE' ], // Estonia
17
+ 'rateLimit': 500,
18
+ 'version': 'v2',
19
+ // new metainfo interface
20
+ 'has': {
21
+ 'CORS': undefined,
22
+ 'spot': true,
23
+ 'margin': false,
24
+ 'swap': false,
25
+ 'future': false,
26
+ 'option': false,
27
+ 'addMargin': false,
28
+ 'cancelAllOrders': true,
29
+ 'cancelOrder': true,
30
+ 'cancelOrders': true,
31
+ 'createOrder': true,
32
+ 'createReduceOnlyOrder': false,
33
+ 'createStopLimitOrder': true,
34
+ 'createStopMarketOrder': true,
35
+ 'createStopOrder': true,
36
+ 'editOrder': true,
37
+ 'fetchBalance': true,
38
+ 'fetchBidsAsks': true,
39
+ 'fetchBorrowRate': false,
40
+ 'fetchBorrowRateHistories': false,
41
+ 'fetchBorrowRateHistory': false,
42
+ 'fetchBorrowRates': false,
43
+ 'fetchBorrowRatesPerSymbol': false,
44
+ 'fetchClosedOrders': true,
45
+ 'fetchCurrencies': true,
46
+ 'fetchDepositAddress': true,
47
+ 'fetchDeposits': true,
48
+ 'fetchFundingFees': true,
49
+ 'fetchFundingHistory': false,
50
+ 'fetchFundingRate': false,
51
+ 'fetchFundingRateHistory': false,
52
+ 'fetchFundingRates': false,
53
+ 'fetchIndexOHLCV': false,
54
+ 'fetchLeverage': false,
55
+ 'fetchLeverageTiers': false,
56
+ 'fetchMarkets': true,
57
+ 'fetchMarkOHLCV': false,
58
+ 'fetchMyTrades': true,
59
+ 'fetchOHLCV': true,
60
+ 'fetchOpenOrders': true,
61
+ 'fetchOrder': true,
62
+ 'fetchOrderBook': true,
63
+ 'fetchOrders': true,
64
+ 'fetchOrderTrades': true,
65
+ 'fetchPosition': false,
66
+ 'fetchPositions': false,
67
+ 'fetchPositionsRisk': false,
68
+ 'fetchPremiumIndexOHLCV': false,
69
+ 'fetchTicker': true,
70
+ 'fetchTickers': true,
71
+ 'fetchTrades': true,
72
+ 'fetchTradingFee': false,
73
+ 'fetchTradingFees': true,
74
+ 'fetchTransactions': true,
75
+ 'fetchWithdrawals': true,
76
+ 'reduceMargin': false,
77
+ 'setLeverage': false,
78
+ 'setMarginMode': false,
79
+ 'setPositionMode': false,
80
+ 'withdraw': true,
81
+ },
82
+ 'timeframes': {
83
+ '1m': '1m',
84
+ '3m': '3m',
85
+ '5m': '5m',
86
+ '15m': '15m',
87
+ '30m': '30m',
88
+ '1h': '1h',
89
+ '4h': '4h',
90
+ '1d': '1d',
91
+ '1w': '1w',
92
+ '1M': '1mo',
93
+ },
94
+ 'urls': {
95
+ 'logo': 'https://user-images.githubusercontent.com/1294454/47813922-6f12cc00-dd5d-11e8-97c6-70f957712d47.jpg',
96
+ 'api': 'https://api.crex24.com',
97
+ 'www': 'https://crex24.com',
98
+ 'referral': 'https://crex24.com/?refid=slxsjsjtil8xexl9hksr',
99
+ 'doc': 'https://docs.crex24.com/trade-api/v2',
100
+ 'fees': 'https://crex24.com/fees',
101
+ },
102
+ 'api': {
103
+ 'public': {
104
+ 'get': [
105
+ 'currencies',
106
+ 'instruments',
107
+ 'tickers',
108
+ 'recentTrades',
109
+ 'orderBook',
110
+ 'ohlcv',
111
+ 'tradingFeeSchedules',
112
+ 'withdrawalFees',
113
+ 'currencyTransport',
114
+ 'currenciesWithdrawalFees',
115
+ ],
116
+ },
117
+ 'trading': {
118
+ 'get': [
119
+ 'orderStatus',
120
+ 'orderTrades',
121
+ 'activeOrders',
122
+ 'orderHistory',
123
+ 'tradeHistory',
124
+ 'tradingFee',
125
+ 'tradeFee', // The support of this method has been dropped on February 18, 2020. Please, use tradingFee method instead. https://docs.crex24.com/trade-api/v2/#trade-fee-and-rebate-discontinued
126
+ ],
127
+ 'post': [
128
+ 'placeOrder',
129
+ 'modifyOrder',
130
+ 'cancelOrdersById',
131
+ 'cancelOrdersByInstrument',
132
+ 'cancelAllOrders',
133
+ ],
134
+ },
135
+ 'account': {
136
+ 'get': [
137
+ 'balance',
138
+ 'depositAddress',
139
+ 'moneyTransfers',
140
+ 'moneyTransferStatus',
141
+ 'previewWithdrawal',
142
+ ],
143
+ 'post': [
144
+ 'withdraw',
145
+ ],
146
+ },
147
+ },
148
+ 'precisionMode': TICK_SIZE,
149
+ 'fees': {
150
+ 'trading': {
151
+ 'tierBased': true,
152
+ 'percentage': true,
153
+ 'taker': 0.001,
154
+ 'maker': -0.0001,
155
+ },
156
+ // should be deleted, these are outdated and inaccurate
157
+ 'funding': {
158
+ 'tierBased': false,
159
+ 'percentage': false,
160
+ 'withdraw': {},
161
+ 'deposit': {},
162
+ },
163
+ },
164
+ 'commonCurrencies': {
165
+ 'ACM': 'Actinium',
166
+ 'BCC': 'BCH',
167
+ 'BIT': 'BitMoney',
168
+ 'BULL': 'BuySell',
169
+ 'CLC': 'CaluraCoin',
170
+ 'CREDIT': 'TerraCredit',
171
+ 'DMS': 'Documentchain', // conflict with Dragon Mainland Shards
172
+ 'EGG': 'NestEGG Coin',
173
+ 'EPS': 'Epanus', // conflict with EPS Ellipsis https://github.com/ccxt/ccxt/issues/8909
174
+ 'FUND': 'FUNDChains',
175
+ 'GHOST': 'GHOSTPRISM',
176
+ 'GM': 'GM Holding',
177
+ 'GMT': 'GMT Token',
178
+ 'GTC': 'GastroCoin', // conflict with Gitcoin and Game.com
179
+ 'IQ': 'IQ.Cash',
180
+ 'ONE': 'One Hundred Coin',
181
+ 'PUT': 'PutinCoin',
182
+ 'SBTC': 'SBTCT', // SiamBitcoin
183
+ 'SPH': 'SapphireCoin',
184
+ 'SUPER': 'SuperCoin',
185
+ 'UNI': 'Universe',
186
+ 'YOYO': 'YOYOW',
187
+ },
188
+ // exchange-specific options
189
+ 'options': {
190
+ 'networks': {
191
+ 'ETH': 'ERC20',
192
+ 'TRX': 'TRC20',
193
+ 'BSC': 'BEP20',
194
+ },
195
+ 'fetchOrdersMethod': 'tradingGetOrderHistory', // or 'tradingGetActiveOrders'
196
+ 'fetchClosedOrdersMethod': 'tradingGetOrderHistory', // or 'tradingGetActiveOrders'
197
+ 'fetchTickersMethod': 'publicGetTicker24hr',
198
+ 'defaultTimeInForce': 'GTC', // 'GTC' = Good To Cancel (default), 'IOC' = Immediate Or Cancel
199
+ 'hasAlreadyAuthenticatedSuccessfully': false,
200
+ 'warnOnFetchOpenOrdersWithoutSymbol': true,
201
+ 'parseOrderToPrecision': false, // force amounts and costs in parseOrder to precision
202
+ 'newOrderRespType': 'RESULT', // 'ACK' for order id, 'RESULT' for full order or 'FULL' for order with fills
203
+ 'fetchTradingFees': {
204
+ 'method': 'fetchPrivateTradingFees', // or 'fetchPublicTradingFees'
205
+ },
206
+ },
207
+ 'exceptions': {
208
+ 'exact': {
209
+ "Parameter 'filter' contains invalid value.": BadRequest, // eslint-disable-quotes
210
+ "Mandatory parameter 'instrument' is missing.": BadRequest, // eslint-disable-quotes
211
+ "The value of parameter 'till' must be greater than or equal to the value of parameter 'from'.": BadRequest, // eslint-disable-quotes
212
+ 'Failed to verify request signature.': AuthenticationError, // eslint-disable-quotes
213
+ "Nonce error. Make sure that the value passed in the 'X-CREX24-API-NONCE' header is greater in each consecutive request than in the previous one for the corresponding API-Key provided in 'X-CREX24-API-KEY' header.": InvalidNonce,
214
+ 'Market orders are not supported by the instrument currently.': InvalidOrder,
215
+ "Parameter 'instrument' contains invalid value.": BadSymbol,
216
+ "Trading has been disabled for the account until the verification is passed. To initiate the verification process, please log into your account at crex24.com and proceed to 'My account' -> 'Verification'.": AccountSuspended, // {"errorDescription":"Trading has been disabled for the account until the verification is passed. To initiate the verification process, please log into your account at crex24.com and proceed to 'My account' -> 'Verification'."}
217
+ },
218
+ 'broad': {
219
+ 'try again later': ExchangeNotAvailable, // {"errorDescription":"Failed to process the request. Please, try again later."}
220
+ 'API Key': AuthenticationError, // "API Key '9edc48de-d5b0-4248-8e7e-f59ffcd1c7f1' doesn't exist."
221
+ 'Insufficient funds': InsufficientFunds, // "Insufficient funds: new order requires 10 ETH which is more than the available balance."
222
+ 'has been delisted.': BadSymbol, // {"errorDescription":"Instrument '$PAC-BTC' has been delisted."}
223
+ 'is currently suspended.': BadSymbol, // {"errorDescription":"Trading in BITG-BTC is currently suspended."}
224
+ 'Mandatory parameter': BadRequest, // {"errorDescription":"Mandatory parameter 'feeCurrency' is missing."}
225
+ 'can not trade': AccountSuspended, // {"errorDescription":"User 123456 can not trade"}
226
+ },
227
+ },
228
+ });
229
+ }
230
+
231
+ nonce () {
232
+ return this.milliseconds ();
233
+ }
234
+
235
+ async fetchMarkets (params = {}) {
236
+ const response = await this.publicGetInstruments (params);
237
+ //
238
+ // [ {
239
+ // "symbol": "$PAC-BTC",
240
+ // "baseCurrency": "$PAC",
241
+ // "quoteCurrency": "BTC",
242
+ // "feeCurrency": "BTC",
243
+ // "feeSchedule": "OriginalSchedule",
244
+ // "tickSize": 0.00000001,
245
+ // "minPrice": 0.00000001,
246
+ // "maxPrice": 10000000000.0,
247
+ // "volumeIncrement": 0.00000001,
248
+ // "minVolume": 1.0,
249
+ // "maxVolume": 1000000000.0,
250
+ // "minQuoteVolume": 0.000000000000001,
251
+ // "maxQuoteVolume": 100000000000.0,
252
+ // "supportedOrderTypes": [
253
+ // "limit"
254
+ // ],
255
+ // "state": "delisted"
256
+ // },
257
+ // {
258
+ // "symbol": "1INCH-USDT",
259
+ // "baseCurrency": "1INCH",
260
+ // "quoteCurrency": "USDT",
261
+ // "feeCurrency": "USDT",
262
+ // "feeSchedule": "FeeSchedule10",
263
+ // "tickSize": 0.0001,
264
+ // "minPrice": 0.0001,
265
+ // "maxPrice": 10000000000.0,
266
+ // "volumeIncrement": 0.00000001,
267
+ // "minVolume": 0.01,
268
+ // "maxVolume": 1000000000.0,
269
+ // "minQuoteVolume": 0.000000000000001,
270
+ // "maxQuoteVolume": 100000000000.0,
271
+ // "supportedOrderTypes": [
272
+ // "limit"
273
+ // ],
274
+ // "state": "active"
275
+ // }, ]
276
+ //
277
+ const response2 = await this.publicGetTradingFeeSchedules (params);
278
+ //
279
+ // [
280
+ // {
281
+ // "name": "FeeSchedule05",
282
+ // "feeRates": [
283
+ // {
284
+ // "volumeThreshold": 0.0,
285
+ // "maker": 0.0005,
286
+ // "taker": 0.0005
287
+ // },
288
+ // {
289
+ // "volumeThreshold": 5.0,
290
+ // "maker": 0.0004,
291
+ // "taker": 0.0004
292
+ // },
293
+ // {
294
+ // "volumeThreshold": 15.0,
295
+ // "maker": 0.0003,
296
+ // "taker": 0.0003
297
+ // },
298
+ // {
299
+ // "volumeThreshold": 30.0,
300
+ // "maker": 0.0002,
301
+ // "taker": 0.0002
302
+ // },
303
+ // {
304
+ // "volumeThreshold": 50.0,
305
+ // "maker": 0.0001,
306
+ // "taker": 0.0001
307
+ // }
308
+ // ]
309
+ // },
310
+ // ]
311
+ //
312
+ const result = [];
313
+ for (let i = 0; i < response.length; i++) {
314
+ const market = response[i];
315
+ const id = this.safeString (market, 'symbol');
316
+ const baseId = this.safeString (market, 'baseCurrency');
317
+ const quoteId = this.safeString (market, 'quoteCurrency');
318
+ const base = this.safeCurrencyCode (baseId);
319
+ const quote = this.safeCurrencyCode (quoteId);
320
+ let maker = undefined;
321
+ let taker = undefined;
322
+ const feeSchedule = this.safeString (market, 'feeSchedule');
323
+ for (let j = 0; j < response2.length; j++) {
324
+ const feeScheduleName = this.safeString (response2[j], 'name');
325
+ if (feeScheduleName === feeSchedule) {
326
+ const feeRates = this.safeValue (response2[j], 'feeRates', []);
327
+ for (let k = 0; k < feeRates.length; k++) {
328
+ const volumeThreshold = this.safeNumber (feeRates[k], 'volumeThreshold');
329
+ if (volumeThreshold === 0) {
330
+ maker = this.safeNumber (feeRates[k], 'maker');
331
+ taker = this.safeNumber (feeRates[k], 'taker');
332
+ break;
333
+ }
334
+ }
335
+ break;
336
+ }
337
+ }
338
+ const state = this.safeString (market, 'state');
339
+ result.push ({
340
+ 'id': id,
341
+ 'symbol': base + '/' + quote,
342
+ 'base': base,
343
+ 'quote': quote,
344
+ 'settle': undefined,
345
+ 'baseId': baseId,
346
+ 'quoteId': quoteId,
347
+ 'settleId': undefined,
348
+ 'type': 'spot',
349
+ 'spot': true,
350
+ 'margin': false,
351
+ 'swap': false,
352
+ 'future': false,
353
+ 'option': false,
354
+ 'active': (state === 'active'),
355
+ 'contract': false,
356
+ 'linear': undefined,
357
+ 'inverse': undefined,
358
+ 'taker': taker,
359
+ 'maker': maker,
360
+ 'contractSize': undefined,
361
+ 'expiry': undefined,
362
+ 'expiryDatetime': undefined,
363
+ 'strike': undefined,
364
+ 'optionType': undefined,
365
+ 'precision': {
366
+ 'amount': this.safeNumber (market, 'volumeIncrement'),
367
+ 'price': this.safeNumber (market, 'tickSize'),
368
+ },
369
+ 'limits': {
370
+ 'leverage': {
371
+ 'min': undefined,
372
+ 'max': undefined,
373
+ },
374
+ 'amount': {
375
+ 'min': this.safeNumber (market, 'minVolume'),
376
+ 'max': this.safeNumber (market, 'maxVolume'),
377
+ },
378
+ 'price': {
379
+ 'min': this.safeNumber (market, 'minPrice'),
380
+ 'max': this.safeNumber (market, 'maxPrice'),
381
+ },
382
+ 'cost': {
383
+ 'min': this.safeNumber (market, 'minQuoteVolume'),
384
+ 'max': this.safeNumber (market, 'maxQuoteVolume'),
385
+ },
386
+ },
387
+ 'info': market,
388
+ });
389
+ }
390
+ return result;
391
+ }
392
+
393
+ async fetchCurrencies (params = {}) {
394
+ const response = await this.publicGetCurrencies (params);
395
+ //
396
+ // [ { symbol: "$PAC",
397
+ // name: "PACCoin",
398
+ // isFiat: false,
399
+ // depositsAllowed: true,
400
+ // depositConfirmationCount: 8,
401
+ // minDeposit: 0,
402
+ // withdrawalsAllowed: true,
403
+ // withdrawalPrecision: 8,
404
+ // minWithdrawal: 4,
405
+ // maxWithdrawal: 1000000000,
406
+ // flatWithdrawalFee: 2,
407
+ // isDelisted: false },
408
+ // { symbol: "ZZC",
409
+ // name: "Zozo",
410
+ // isFiat: false,
411
+ // depositsAllowed: false,
412
+ // depositConfirmationCount: 8,
413
+ // minDeposit: 0,
414
+ // withdrawalsAllowed: false,
415
+ // withdrawalPrecision: 8,
416
+ // minWithdrawal: 0.2,
417
+ // maxWithdrawal: 1000000000,
418
+ // flatWithdrawalFee: 0.1,
419
+ // isDelisted: false } ]
420
+ //
421
+ const result = {};
422
+ for (let i = 0; i < response.length; i++) {
423
+ const currency = response[i];
424
+ const id = this.safeString (currency, 'symbol');
425
+ const code = this.safeCurrencyCode (id);
426
+ const withdrawalPrecision = this.safeInteger (currency, 'withdrawalPrecision');
427
+ const precision = Math.pow (10, -withdrawalPrecision);
428
+ const address = this.safeValue (currency, 'BaseAddress');
429
+ const deposit = this.safeValue (currency, 'depositsAllowed');
430
+ const withdraw = this.safeValue (currency, 'withdrawalsAllowed');
431
+ const delisted = this.safeValue (currency, 'isDelisted');
432
+ const active = deposit && withdraw && !delisted;
433
+ const fiat = this.safeValue (currency, 'isFiat');
434
+ const type = fiat ? 'fiat' : 'crypto';
435
+ result[code] = {
436
+ 'id': id,
437
+ 'code': code,
438
+ 'address': address,
439
+ 'info': currency,
440
+ 'type': type,
441
+ 'name': this.safeString (currency, 'name'),
442
+ 'active': active,
443
+ 'deposit': deposit,
444
+ 'withdraw': withdraw,
445
+ 'fee': this.safeNumber (currency, 'flatWithdrawalFee'), // todo: redesign
446
+ 'precision': precision,
447
+ 'limits': {
448
+ 'amount': {
449
+ 'min': Math.pow (10, -precision),
450
+ 'max': Math.pow (10, precision),
451
+ },
452
+ 'deposit': {
453
+ 'min': this.safeNumber (currency, 'minDeposit'),
454
+ 'max': undefined,
455
+ },
456
+ 'withdraw': {
457
+ 'min': this.safeNumber (currency, 'minWithdrawal'),
458
+ 'max': this.safeNumber (currency, 'maxWithdrawal'),
459
+ },
460
+ },
461
+ };
462
+ }
463
+ return result;
464
+ }
465
+
466
+ async fetchFundingFees (codes = undefined, params = {}) {
467
+ await this.loadMarkets ();
468
+ const response = await this.publicGetCurrenciesWithdrawalFees (params);
469
+ //
470
+ // [
471
+ // {
472
+ // currency: '1INCH',
473
+ // fees: [
474
+ // { feeCurrency: 'BTC', amount: 0.00032 },
475
+ // { feeCurrency: 'ETH', amount: 0.0054 },
476
+ // { feeCurrency: 'DOGE', amount: 63.06669 },
477
+ // { feeCurrency: 'LTC', amount: 0.0912 },
478
+ // { feeCurrency: 'BCH', amount: 0.02364 },
479
+ // { feeCurrency: 'USDT', amount: 12.717 },
480
+ // { feeCurrency: 'USDC', amount: 12.7367 },
481
+ // { feeCurrency: 'TRX', amount: 205.99108 },
482
+ // { feeCurrency: 'EOS', amount: 3.30141 }
483
+ // ]
484
+ // }
485
+ // ]
486
+ //
487
+ const withdrawFees = {};
488
+ for (let i = 0; i < response.length; i++) {
489
+ const entry = response[i];
490
+ const currencyId = this.safeString (entry, 'currency');
491
+ const code = this.safeCurrencyCode (currencyId);
492
+ const networkList = this.safeValue (entry, 'fees');
493
+ withdrawFees[code] = {};
494
+ for (let j = 0; j < networkList.length; j++) {
495
+ const networkEntry = networkList[j];
496
+ const networkId = this.safeString (networkEntry, 'feeCurrency');
497
+ const networkCode = this.safeCurrencyCode (networkId);
498
+ const fee = this.safeNumber (networkEntry, 'amount');
499
+ withdrawFees[code][networkCode] = fee;
500
+ }
501
+ }
502
+ return {
503
+ 'withdraw': withdrawFees,
504
+ 'deposit': {},
505
+ 'info': response,
506
+ };
507
+ }
508
+
509
+ parseBalance (response) {
510
+ const result = { 'info': response };
511
+ for (let i = 0; i < response.length; i++) {
512
+ const balance = response[i];
513
+ const currencyId = this.safeString (balance, 'currency');
514
+ const code = this.safeCurrencyCode (currencyId);
515
+ const account = this.account ();
516
+ account['free'] = this.safeString (balance, 'available');
517
+ account['used'] = this.safeString (balance, 'reserved');
518
+ result[code] = account;
519
+ }
520
+ return this.safeBalance (result);
521
+ }
522
+
523
+ async fetchBalance (params = {}) {
524
+ await this.loadMarkets ();
525
+ const request = {
526
+ // 'currency': 'ETH', // comma-separated list of currency ids
527
+ // 'nonZeroOnly': 'false', // true by default
528
+ };
529
+ const response = await this.accountGetBalance (this.extend (request, params));
530
+ //
531
+ // [
532
+ // {
533
+ // "currency": "ETH",
534
+ // "available": 0.0,
535
+ // "reserved": 0.0
536
+ // }
537
+ // ]
538
+ //
539
+ return this.parseBalance (response);
540
+ }
541
+
542
+ async fetchOrderBook (symbol, limit = undefined, params = {}) {
543
+ await this.loadMarkets ();
544
+ const market = this.market (symbol);
545
+ const request = {
546
+ 'instrument': market['id'],
547
+ };
548
+ if (limit !== undefined) {
549
+ request['limit'] = limit; // default = maximum = 100
550
+ }
551
+ const response = await this.publicGetOrderBook (this.extend (request, params));
552
+ //
553
+ // { buyLevels: [ { price: 0.03099, volume: 0.00610063 },
554
+ // { price: 0.03097, volume: 1.33455158 },
555
+ // { price: 0.03096, volume: 0.0830889 },
556
+ // { price: 0.03095, volume: 0.0820356 },
557
+ // { price: 0.03093, volume: 0.5499419 },
558
+ // { price: 0.03092, volume: 0.23317494 },
559
+ // { price: 0.03091, volume: 0.62105322 },
560
+ // { price: 0.00620041, volume: 0.003 } ],
561
+ // sellLevels: [ { price: 0.03117, volume: 5.47492315 },
562
+ // { price: 0.03118, volume: 1.97744139 },
563
+ // { price: 0.03119, volume: 0.012 },
564
+ // { price: 0.03121, volume: 0.741242 },
565
+ // { price: 0.03122, volume: 0.96178089 },
566
+ // { price: 0.03123, volume: 0.152326 },
567
+ // { price: 0.03124, volume: 2.63462933 },
568
+ // { price: 0.069, volume: 0.004 } ] }
569
+ //
570
+ return this.parseOrderBook (response, symbol, undefined, 'buyLevels', 'sellLevels', 'price', 'volume');
571
+ }
572
+
573
+ parseTicker (ticker, market = undefined) {
574
+ //
575
+ // { instrument: "ZZC-USD",
576
+ // last: 0.065,
577
+ // percentChange: 0,
578
+ // low: 0.065,
579
+ // high: 0.065,
580
+ // baseVolume: 0,
581
+ // quoteVolume: 0,
582
+ // volumeInBtc: 0,
583
+ // volumeInUsd: 0,
584
+ // ask: 0.5,
585
+ // bid: 0.0007,
586
+ // timestamp: "2018-10-31T09:21:25Z" } ]
587
+ //
588
+ const timestamp = this.parse8601 (this.safeString (ticker, 'timestamp'));
589
+ const marketId = this.safeString (ticker, 'instrument');
590
+ const symbol = this.safeSymbol (marketId, market, '-');
591
+ const last = this.safeString (ticker, 'last');
592
+ return this.safeTicker ({
593
+ 'symbol': symbol,
594
+ 'timestamp': timestamp,
595
+ 'datetime': this.iso8601 (timestamp),
596
+ 'high': this.safeString (ticker, 'high'),
597
+ 'low': this.safeString (ticker, 'low'),
598
+ 'bid': this.safeString (ticker, 'bid'),
599
+ 'bidVolume': undefined,
600
+ 'ask': this.safeString (ticker, 'ask'),
601
+ 'askVolume': undefined,
602
+ 'vwap': undefined,
603
+ 'open': undefined,
604
+ 'close': last,
605
+ 'last': last,
606
+ 'previousClose': undefined, // previous day close
607
+ 'change': undefined,
608
+ 'percentage': this.safeString (ticker, 'percentChange'),
609
+ 'average': undefined,
610
+ 'baseVolume': this.safeString (ticker, 'baseVolume'),
611
+ 'quoteVolume': this.safeString (ticker, 'quoteVolume'),
612
+ 'info': ticker,
613
+ }, market, false);
614
+ }
615
+
616
+ async fetchTicker (symbol, params = {}) {
617
+ await this.loadMarkets ();
618
+ const market = this.market (symbol);
619
+ const request = {
620
+ 'instrument': market['id'],
621
+ };
622
+ const response = await this.publicGetTickers (this.extend (request, params));
623
+ //
624
+ // [ { instrument: "$PAC-BTC",
625
+ // last: 3.3e-7,
626
+ // percentChange: 3.125,
627
+ // low: 2.7e-7,
628
+ // high: 3.3e-7,
629
+ // baseVolume: 191700.79823187,
630
+ // quoteVolume: 0.0587930939346704,
631
+ // volumeInBtc: 0.0587930939346704,
632
+ // volumeInUsd: 376.2006339435353,
633
+ // ask: 3.3e-7,
634
+ // bid: 3.1e-7,
635
+ // timestamp: "2018-10-31T09:21:25Z" } ]
636
+ //
637
+ const numTickers = response.length;
638
+ if (numTickers < 1) {
639
+ throw new ExchangeError (this.id + ' fetchTicker() could not load quotes for symbol ' + symbol);
640
+ }
641
+ return this.parseTicker (response[0], market);
642
+ }
643
+
644
+ async fetchTickers (symbols = undefined, params = {}) {
645
+ await this.loadMarkets ();
646
+ const request = {};
647
+ if (symbols !== undefined) {
648
+ const ids = this.marketIds (symbols);
649
+ request['instrument'] = ids.join (',');
650
+ }
651
+ const response = await this.publicGetTickers (this.extend (request, params));
652
+ //
653
+ // [ { instrument: "$PAC-BTC",
654
+ // last: 3.3e-7,
655
+ // percentChange: 3.125,
656
+ // low: 2.7e-7,
657
+ // high: 3.3e-7,
658
+ // baseVolume: 191700.79823187,
659
+ // quoteVolume: 0.0587930939346704,
660
+ // volumeInBtc: 0.0587930939346704,
661
+ // volumeInUsd: 376.2006339435353,
662
+ // ask: 3.3e-7,
663
+ // bid: 3.1e-7,
664
+ // timestamp: "2018-10-31T09:21:25Z" },
665
+ // { instrument: "ZZC-USD",
666
+ // last: 0.065,
667
+ // percentChange: 0,
668
+ // low: 0.065,
669
+ // high: 0.065,
670
+ // baseVolume: 0,
671
+ // quoteVolume: 0,
672
+ // volumeInBtc: 0,
673
+ // volumeInUsd: 0,
674
+ // ask: 0.5,
675
+ // bid: 0.0007,
676
+ // timestamp: "2018-10-31T09:21:25Z" } ]
677
+ //
678
+ return this.parseTickers (response, symbols);
679
+ }
680
+
681
+ parseTrade (trade, market = undefined) {
682
+ //
683
+ // public fetchTrades
684
+ //
685
+ // { price: 0.03105,
686
+ // volume: 0.11,
687
+ // side: "sell",
688
+ // timestamp: "2018-10-31T04:19:35Z" } ]
689
+ //
690
+ // private fetchMyTrades
691
+ //
692
+ // {
693
+ // "id": 3005866,
694
+ // "orderId": 468533093,
695
+ // "timestamp": "2018-06-02T16:26:27Z",
696
+ // "instrument": "BCH-ETH",
697
+ // "side": "buy",
698
+ // "price": 1.78882,
699
+ // "volume": 0.027,
700
+ // "fee": 0.0000483,
701
+ // "feeCurrency": "ETH"
702
+ // }
703
+ //
704
+ const timestamp = this.parse8601 (this.safeString (trade, 'timestamp'));
705
+ const priceString = this.safeString (trade, 'price');
706
+ const amountString = this.safeString (trade, 'volume');
707
+ const id = this.safeString (trade, 'id');
708
+ const side = this.safeString (trade, 'side');
709
+ const orderId = this.safeString (trade, 'orderId');
710
+ const marketId = this.safeString (trade, 'instrument');
711
+ const symbol = this.safeSymbol (marketId, market, '-');
712
+ let fee = undefined;
713
+ const feeCurrencyId = this.safeString (trade, 'feeCurrency');
714
+ const feeCode = this.safeCurrencyCode (feeCurrencyId);
715
+ const feeCostString = this.safeString (trade, 'fee');
716
+ if (feeCostString !== undefined) {
717
+ fee = {
718
+ 'cost': feeCostString,
719
+ 'currency': feeCode,
720
+ };
721
+ }
722
+ const takerOrMaker = undefined;
723
+ return this.safeTrade ({
724
+ 'info': trade,
725
+ 'timestamp': timestamp,
726
+ 'datetime': this.iso8601 (timestamp),
727
+ 'symbol': symbol,
728
+ 'id': id,
729
+ 'order': orderId,
730
+ 'type': undefined,
731
+ 'takerOrMaker': takerOrMaker,
732
+ 'side': side,
733
+ 'price': priceString,
734
+ 'cost': undefined,
735
+ 'amount': amountString,
736
+ 'fee': fee,
737
+ }, market);
738
+ }
739
+
740
+ async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
741
+ await this.loadMarkets ();
742
+ const market = this.market (symbol);
743
+ const request = {
744
+ 'instrument': market['id'],
745
+ };
746
+ if (limit !== undefined) {
747
+ request['limit'] = limit; // min 1, max 1000, default 100
748
+ }
749
+ const response = await this.publicGetRecentTrades (this.extend (request, params));
750
+ //
751
+ // [ { price: 0.03117,
752
+ // volume: 0.02597403,
753
+ // side: "buy",
754
+ // timestamp: "2018-10-31T09:37:46Z" },
755
+ // { price: 0.03105,
756
+ // volume: 0.11,
757
+ // side: "sell",
758
+ // timestamp: "2018-10-31T04:19:35Z" } ]
759
+ //
760
+ return this.parseTrades (response, market, since, limit);
761
+ }
762
+
763
+ async fetchTradingFees (params = {}) {
764
+ let method = this.safeString (params, 'method');
765
+ params = this.omit (params, 'method');
766
+ if (method === undefined) {
767
+ const options = this.safeValue (this.options, 'fetchTradingFees', {});
768
+ method = this.safeString (options, 'method', 'fetchPrivateTradingFees');
769
+ }
770
+ return await this[method] (params);
771
+ }
772
+
773
+ async fetchPublicTradingFees (params = {}) {
774
+ await this.loadMarkets ();
775
+ const response = await this.publicGetTradingFeeSchedules (params);
776
+ //
777
+ // [
778
+ // {
779
+ // name: 'FeeSchedule05',
780
+ // feeRates: [
781
+ // { volumeThreshold: 0, maker: 0.0005, taker: 0.0005 },
782
+ // { volumeThreshold: 5, maker: 0.0004, taker: 0.0004 },
783
+ // { volumeThreshold: 15, maker: 0.0003, taker: 0.0003 },
784
+ // { volumeThreshold: 30, maker: 0.0002, taker: 0.0002 },
785
+ // { volumeThreshold: 50, maker: 0.0001, taker: 0.0001 }
786
+ // ]
787
+ // },
788
+ // {
789
+ // name: 'OriginalSchedule',
790
+ // feeRates: [
791
+ // { volumeThreshold: 0, maker: -0.0001, taker: 0.001 },
792
+ // { volumeThreshold: 5, maker: -0.0002, taker: 0.0009 },
793
+ // { volumeThreshold: 15, maker: -0.0003, taker: 0.0008 },
794
+ // { volumeThreshold: 30, maker: -0.0004, taker: 0.0007 },
795
+ // { volumeThreshold: 50, maker: -0.0005, taker: 0.0006 }
796
+ // ]
797
+ // }
798
+ // ]
799
+ //
800
+ const feeSchedulesByName = this.indexBy (response, 'name');
801
+ const originalSchedule = this.safeValue (feeSchedulesByName, 'OriginalSchedule', {});
802
+ const feeRates = this.safeValue (originalSchedule, 'feeRates', []);
803
+ const firstFee = this.safeValue (feeRates, 0, {});
804
+ const maker = this.safeNumber (firstFee, 'maker');
805
+ const taker = this.safeNumber (firstFee, 'taker');
806
+ const result = {};
807
+ for (let i = 0; i < this.symbols.length; i++) {
808
+ const symbol = this.symbols[i];
809
+ result[symbol] = {
810
+ 'info': response,
811
+ 'symbol': symbol,
812
+ 'maker': maker,
813
+ 'taker': taker,
814
+ 'percentage': true,
815
+ 'tierBased': true,
816
+ };
817
+ }
818
+ return result;
819
+ }
820
+
821
+ async fetchPrivateTradingFees (params = {}) {
822
+ await this.loadMarkets ();
823
+ const response = await this.tradingGetTradingFee (params);
824
+ //
825
+ // {
826
+ // feeRates: [
827
+ // { schedule: 'FeeSchedule05', maker: 0.0005, taker: 0.0005 },
828
+ // { schedule: 'FeeSchedule08', maker: 0.0008, taker: 0.0008 },
829
+ // { schedule: 'FeeSchedule10', maker: 0.001, taker: 0.001 },
830
+ // { schedule: 'FeeSchedule15', maker: 0.0015, taker: 0.0015 },
831
+ // { schedule: 'FeeSchedule20', maker: 0.002, taker: 0.002 },
832
+ // { schedule: 'FeeSchedule30', maker: 0.003, taker: 0.003 },
833
+ // { schedule: 'FeeSchedule40', maker: 0.004, taker: 0.004 },
834
+ // { schedule: 'FeeSchedule50', maker: 0.005, taker: 0.005 },
835
+ // { schedule: 'OriginalSchedule', maker: -0.0001, taker: 0.001 }
836
+ // ],
837
+ // tradingVolume: 0,
838
+ // lastUpdate: '2022-03-16T04:55:02Z'
839
+ // }
840
+ //
841
+ const feeRates = this.safeValue (response, 'feeRates', []);
842
+ const feeRatesBySchedule = this.indexBy (feeRates, 'schedule');
843
+ const originalSchedule = this.safeValue (feeRatesBySchedule, 'OriginalSchedule', {});
844
+ const maker = this.safeNumber (originalSchedule, 'maker');
845
+ const taker = this.safeNumber (originalSchedule, 'taker');
846
+ const result = {};
847
+ for (let i = 0; i < this.symbols.length; i++) {
848
+ const symbol = this.symbols[i];
849
+ result[symbol] = {
850
+ 'info': response,
851
+ 'symbol': symbol,
852
+ 'maker': maker,
853
+ 'taker': taker,
854
+ 'percentage': true,
855
+ 'tierBased': true,
856
+ };
857
+ }
858
+ return result;
859
+ }
860
+
861
+ parseOHLCV (ohlcv, market = undefined) {
862
+ //
863
+ // {
864
+ // timestamp: '2019-09-21T10:36:00Z',
865
+ // open: 0.02152,
866
+ // high: 0.02156,
867
+ // low: 0.02152,
868
+ // close: 0.02156,
869
+ // volume: 0.01741259
870
+ // }
871
+ //
872
+ return [
873
+ this.parse8601 (this.safeString (ohlcv, 'timestamp')),
874
+ this.safeNumber (ohlcv, 'open'),
875
+ this.safeNumber (ohlcv, 'high'),
876
+ this.safeNumber (ohlcv, 'low'),
877
+ this.safeNumber (ohlcv, 'close'),
878
+ this.safeNumber (ohlcv, 'volume'),
879
+ ];
880
+ }
881
+
882
+ async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
883
+ await this.loadMarkets ();
884
+ const market = this.market (symbol);
885
+ const request = {
886
+ 'granularity': this.timeframes[timeframe],
887
+ 'instrument': market['id'],
888
+ };
889
+ if (limit !== undefined) {
890
+ request['limit'] = limit; // Accepted values: 1 - 1000. If the parameter is not specified, the number of results is limited to 100
891
+ }
892
+ const response = await this.publicGetOhlcv (this.extend (request, params));
893
+ //
894
+ // [
895
+ // {
896
+ // "timestamp": "2020-06-06T17:36:00Z",
897
+ // "open": 0.025,
898
+ // "high": 0.025,
899
+ // "low": 0.02499,
900
+ // "close": 0.02499,
901
+ // "volume": 0.00643127
902
+ // }
903
+ // ]
904
+ //
905
+ return this.parseOHLCVs (response, market, timeframe, since, limit);
906
+ }
907
+
908
+ parseOrderStatus (status) {
909
+ const statuses = {
910
+ 'submitting': 'open', // A newly created limit order has a status "submitting" until it has been processed.
911
+ // This status changes during the lifetime of an order and can have different values depending on the value of the parameter Time In Force.
912
+ 'unfilledActive': 'open', // order is active, no trades have been made
913
+ 'partiallyFilledActive': 'open', // part of the order has been filled, the other part is active
914
+ 'filled': 'closed', // order has been filled entirely
915
+ 'partiallyFilledCancelled': 'canceled', // part of the order has been filled, the other part has been cancelled either by the trader or by the system (see the value of cancellationReason of an Order for more details on the reason of cancellation)
916
+ 'unfilledCancelled': 'canceled', // order has been cancelled, no trades have taken place (see the value of cancellationReason of an Order for more details on the reason of cancellation)
917
+ };
918
+ return (status in statuses) ? statuses[status] : status;
919
+ }
920
+
921
+ parseOrder (order, market = undefined) {
922
+ //
923
+ // createOrder
924
+ //
925
+ // {
926
+ // "id": 469594855,
927
+ // "timestamp": "2018-06-08T16:59:44Z",
928
+ // "instrument": "BTS-BTC",
929
+ // "side": "buy",
930
+ // "type": "limit",
931
+ // "status": "submitting",
932
+ // "cancellationReason": null,
933
+ // "timeInForce": "GTC",
934
+ // "volume": 4.0,
935
+ // "price": 0.000025,
936
+ // "stopPrice": null,
937
+ // "remainingVolume": 4.0,
938
+ // "lastUpdate": null,
939
+ // "parentOrderId": null,
940
+ // "childOrderId": null
941
+ // }
942
+ //
943
+ // cancelOrder, cancelOrders, cancelAllOrders
944
+ //
945
+ // 465448358
946
+ //
947
+ const status = this.parseOrderStatus (this.safeString (order, 'status'));
948
+ const marketId = this.safeString (order, 'instrument');
949
+ const symbol = this.safeSymbol (marketId, market, '-');
950
+ const timestamp = this.parse8601 (this.safeString (order, 'timestamp'));
951
+ const price = this.safeString (order, 'price');
952
+ const amount = this.safeString (order, 'volume');
953
+ const remaining = this.safeString (order, 'remainingVolume');
954
+ const lastTradeTimestamp = this.parse8601 (this.safeString (order, 'lastUpdate'));
955
+ const id = this.safeString (order, 'id', order); // if order was integer
956
+ const type = this.safeString (order, 'type');
957
+ const side = this.safeString (order, 'side');
958
+ const timeInForce = this.safeString (order, 'timeInForce');
959
+ const stopPrice = this.safeNumber (order, 'stopPrice');
960
+ return this.safeOrder ({
961
+ 'info': order,
962
+ 'id': id,
963
+ 'clientOrderId': undefined,
964
+ 'timestamp': timestamp,
965
+ 'datetime': this.iso8601 (timestamp),
966
+ 'lastTradeTimestamp': lastTradeTimestamp,
967
+ 'symbol': symbol,
968
+ 'type': type,
969
+ 'timeInForce': timeInForce,
970
+ 'side': side,
971
+ 'price': price,
972
+ 'stopPrice': stopPrice,
973
+ 'amount': amount,
974
+ 'cost': undefined,
975
+ 'average': undefined,
976
+ 'filled': undefined,
977
+ 'remaining': remaining,
978
+ 'status': status,
979
+ 'fee': undefined,
980
+ 'trades': undefined,
981
+ }, market);
982
+ }
983
+
984
+ async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
985
+ await this.loadMarkets ();
986
+ const market = this.market (symbol);
987
+ const request = {
988
+ 'instrument': market['id'],
989
+ 'volume': this.amountToPrecision (symbol, amount),
990
+ // The value must comply with the list of order types supported by the instrument (see the value of parameter supportedOrderTypes of the Instrument)
991
+ // If the parameter is not specified, the default value "limit" is used
992
+ // More about order types in the corresponding section of documentation
993
+ 'type': type, // 'limit', 'market', 'stopLimit', in fact as of 2018-10-31, only 'limit' orders are supported for all markets
994
+ 'side': side, // 'buy' or 'sell'
995
+ // "GTC" - Good-Til-Cancelled
996
+ // "IOC" - Immediate-Or-Cancel (currently not supported by the exchange API, reserved for future use)
997
+ // "FOK" - Fill-Or-Kill (currently not supported by the exchange API, reserved for future use)
998
+ // 'timeInForce': 'GTC', // IOC', 'FOK'
999
+ // 'strictValidation': false, // false - prices will be rounded to meet the requirement, true - execution of the method will be aborted and an error message will be returned
1000
+ };
1001
+ let priceIsRequired = false;
1002
+ let stopPriceIsRequired = false;
1003
+ if (type === 'limit') {
1004
+ priceIsRequired = true;
1005
+ } else if (type === 'stopLimit') {
1006
+ priceIsRequired = true;
1007
+ stopPriceIsRequired = true;
1008
+ }
1009
+ if (priceIsRequired) {
1010
+ if (price === undefined) {
1011
+ throw new InvalidOrder (this.id + ' createOrder() requires a price argument for a ' + type + ' order');
1012
+ }
1013
+ request['price'] = this.priceToPrecision (symbol, price);
1014
+ }
1015
+ if (stopPriceIsRequired) {
1016
+ const stopPrice = this.safeNumber (params, 'stopPrice');
1017
+ if (stopPrice === undefined) {
1018
+ throw new InvalidOrder (this.id + ' createOrder() requires a stopPrice extra param for a ' + type + ' order');
1019
+ } else {
1020
+ request['stopPrice'] = this.priceToPrecision (symbol, stopPrice);
1021
+ }
1022
+ params = this.omit (params, 'stopPrice');
1023
+ }
1024
+ const response = await this.tradingPostPlaceOrder (this.extend (request, params));
1025
+ //
1026
+ // {
1027
+ // "id": 469594855,
1028
+ // "timestamp": "2018-06-08T16:59:44Z",
1029
+ // "instrument": "BTS-BTC",
1030
+ // "side": "buy",
1031
+ // "type": "limit",
1032
+ // "status": "submitting",
1033
+ // "cancellationReason": null,
1034
+ // "timeInForce": "GTC",
1035
+ // "volume": 4.0,
1036
+ // "price": 0.000025,
1037
+ // "stopPrice": null,
1038
+ // "remainingVolume": 4.0,
1039
+ // "lastUpdate": null,
1040
+ // "parentOrderId": null,
1041
+ // "childOrderId": null
1042
+ // }
1043
+ //
1044
+ return this.parseOrder (response, market);
1045
+ }
1046
+
1047
+ async fetchOrder (id, symbol = undefined, params = {}) {
1048
+ await this.loadMarkets ();
1049
+ const request = {
1050
+ 'id': id,
1051
+ };
1052
+ const response = await this.tradingGetOrderStatus (this.extend (request, params));
1053
+ //
1054
+ // [
1055
+ // {
1056
+ // "id": 466747915,
1057
+ // "timestamp": "2018-05-26T06:43:49Z",
1058
+ // "instrument": "UNI-BTC",
1059
+ // "side": "sell",
1060
+ // "type": "limit",
1061
+ // "status": "partiallyFilledActive",
1062
+ // "cancellationReason": null,
1063
+ // "timeInForce": "GTC",
1064
+ // "volume": 5700.0,
1065
+ // "price": 0.000005,
1066
+ // "stopPrice": null,
1067
+ // "remainingVolume": 1.948051948052,
1068
+ // "lastUpdate": null,
1069
+ // "parentOrderId": null,
1070
+ // "childOrderId": null
1071
+ // }
1072
+ // ]
1073
+ //
1074
+ const numOrders = response.length;
1075
+ if (numOrders < 1) {
1076
+ throw new OrderNotFound (this.id + ' fetchOrder() could not fetch order id ' + id);
1077
+ }
1078
+ return this.parseOrder (response[0]);
1079
+ }
1080
+
1081
+ async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
1082
+ await this.loadMarkets ();
1083
+ const request = {};
1084
+ if (since !== undefined) {
1085
+ request['from'] = this.ymdhms (since, 'T');
1086
+ }
1087
+ if (limit !== undefined) {
1088
+ request['limit'] = limit;
1089
+ }
1090
+ if (symbol !== undefined) {
1091
+ const market = this.market (symbol);
1092
+ request['instrument'] = market['id'];
1093
+ }
1094
+ const method = this.safeString (this.options, 'fetchOrdersMethod', 'tradingGetOrderHistory');
1095
+ const response = await this[method] (this.extend (request, params));
1096
+ //
1097
+ // [
1098
+ // {
1099
+ // "id": 468535711,
1100
+ // "timestamp": "2018-06-02T16:42:40Z",
1101
+ // "instrument": "BTC-EUR",
1102
+ // "side": "sell",
1103
+ // "type": "limit",
1104
+ // "status": "submitting",
1105
+ // "cancellationReason": null,
1106
+ // "timeInForce": "GTC",
1107
+ // "volume": 0.00770733,
1108
+ // "price": 6724.9,
1109
+ // "stopPrice": null,
1110
+ // "remainingVolume": 0.00770733,
1111
+ // "lastUpdate": "2018-06-02T16:42:40Z",
1112
+ // "parentOrderId": null,
1113
+ // "childOrderId": null
1114
+ // }
1115
+ // ]
1116
+ //
1117
+ return this.parseOrders (response);
1118
+ }
1119
+
1120
+ async fetchOrdersByIds (ids = undefined, since = undefined, limit = undefined, params = {}) {
1121
+ await this.loadMarkets ();
1122
+ const request = {
1123
+ 'id': ids.join (','),
1124
+ };
1125
+ const response = await this.tradingGetOrderStatus (this.extend (request, params));
1126
+ //
1127
+ // [
1128
+ // {
1129
+ // "id": 466747915,
1130
+ // "timestamp": "2018-05-26T06:43:49Z",
1131
+ // "instrument": "UNI-BTC",
1132
+ // "side": "sell",
1133
+ // "type": "limit",
1134
+ // "status": "partiallyFilledActive",
1135
+ // "cancellationReason": null,
1136
+ // "timeInForce": "GTC",
1137
+ // "volume": 5700.0,
1138
+ // "price": 0.000005,
1139
+ // "stopPrice": null,
1140
+ // "remainingVolume": 1.948051948052,
1141
+ // "lastUpdate": null,
1142
+ // "parentOrderId": null,
1143
+ // "childOrderId": null
1144
+ // }
1145
+ // ]
1146
+ //
1147
+ return this.parseOrders (response, undefined, since, limit);
1148
+ }
1149
+
1150
+ async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
1151
+ await this.loadMarkets ();
1152
+ let market = undefined;
1153
+ const request = {};
1154
+ if (symbol !== undefined) {
1155
+ market = this.market (symbol);
1156
+ request['instrument'] = market['id'];
1157
+ }
1158
+ const response = await this.tradingGetActiveOrders (this.extend (request, params));
1159
+ //
1160
+ // [
1161
+ // {
1162
+ // "id": 466747915,
1163
+ // "timestamp": "2018-05-26T06:43:49Z",
1164
+ // "instrument": "UNI-BTC",
1165
+ // "side": "sell",
1166
+ // "type": "limit",
1167
+ // "status": "partiallyFilledActive",
1168
+ // "cancellationReason": null,
1169
+ // "timeInForce": "GTC",
1170
+ // "volume": 5700.0,
1171
+ // "price": 0.000005,
1172
+ // "stopPrice": null,
1173
+ // "remainingVolume": 1.948051948052,
1174
+ // "lastUpdate": null,
1175
+ // "parentOrderId": null,
1176
+ // "childOrderId": null
1177
+ // },
1178
+ // {
1179
+ // "id": 466748077,
1180
+ // "timestamp": "2018-05-26T06:45:29Z",
1181
+ // "instrument": "PRJ-BTC",
1182
+ // "side": "sell",
1183
+ // "type": "limit",
1184
+ // "status": "partiallyFilledActive",
1185
+ // "cancellationReason": null,
1186
+ // "timeInForce": "GTC",
1187
+ // "volume": 10000.0,
1188
+ // "price": 0.0000007,
1189
+ // "stopPrice": null,
1190
+ // "remainingVolume": 9975.0,
1191
+ // "lastUpdate": null,
1192
+ // "parentOrderId": null,
1193
+ // "childOrderId": null
1194
+ // },
1195
+ // ...
1196
+ // ]
1197
+ //
1198
+ return this.parseOrders (response, market, since, limit);
1199
+ }
1200
+
1201
+ async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
1202
+ await this.loadMarkets ();
1203
+ let market = undefined;
1204
+ const request = {};
1205
+ if (symbol !== undefined) {
1206
+ market = this.market (symbol);
1207
+ request['instrument'] = market['id'];
1208
+ }
1209
+ if (since !== undefined) {
1210
+ request['from'] = this.ymdhms (since, 'T');
1211
+ }
1212
+ if (limit !== undefined) {
1213
+ request['limit'] = limit; // min 1, max 1000, default 100
1214
+ }
1215
+ const method = this.safeString (this.options, 'fetchClosedOrdersMethod', 'tradingGetOrderHistory');
1216
+ const response = await this[method] (this.extend (request, params));
1217
+ // [
1218
+ // {
1219
+ // "id": 468535711,
1220
+ // "timestamp": "2018-06-02T16:42:40Z",
1221
+ // "instrument": "BTC-EUR",
1222
+ // "side": "sell",
1223
+ // "type": "limit",
1224
+ // "status": "submitting",
1225
+ // "cancellationReason": null,
1226
+ // "timeInForce": "GTC",
1227
+ // "volume": 0.00770733,
1228
+ // "price": 6724.9,
1229
+ // "stopPrice": null,
1230
+ // "remainingVolume": 0.00770733,
1231
+ // "lastUpdate": null,
1232
+ // "parentOrderId": null,
1233
+ // "childOrderId": null
1234
+ // },
1235
+ // {
1236
+ // "id": 468535707,
1237
+ // "timestamp": "2018-06-02T16:42:37Z",
1238
+ // "instrument": "BTG-BTC",
1239
+ // "side": "buy",
1240
+ // "type": "limit",
1241
+ // "status": "unfilledActive",
1242
+ // "cancellationReason": null,
1243
+ // "timeInForce": "GTC",
1244
+ // "volume": 0.0173737,
1245
+ // "price": 0.00589027,
1246
+ // "stopPrice": null,
1247
+ // "remainingVolume": 0.0173737,
1248
+ // "lastUpdate": null,
1249
+ // "parentOrderId": null,
1250
+ // "childOrderId": null
1251
+ // },
1252
+ // ...
1253
+ // ]
1254
+ //
1255
+ return this.parseOrders (response, market, since, limit);
1256
+ }
1257
+
1258
+ async cancelOrder (id, symbol = undefined, params = {}) {
1259
+ const response = await this.cancelOrders ([ id ], symbol, params);
1260
+ return this.safeValue (response, 0);
1261
+ }
1262
+
1263
+ async cancelOrders (ids, symbol = undefined, params = {}) {
1264
+ if (!Array.isArray (ids)) {
1265
+ throw new ArgumentsRequired (this.id + ' cancelOrders() ids argument should be an array');
1266
+ }
1267
+ await this.loadMarkets ();
1268
+ const request = {
1269
+ 'ids': [],
1270
+ };
1271
+ for (let i = 0; i < ids.length; i++) {
1272
+ const id = parseInt (ids[i]);
1273
+ request['ids'].push (id);
1274
+ }
1275
+ const response = await this.tradingPostCancelOrdersById (this.extend (request, params));
1276
+ //
1277
+ // [
1278
+ // 465448358,
1279
+ // 468364313
1280
+ // ]
1281
+ //
1282
+ return this.parseOrders (response);
1283
+ }
1284
+
1285
+ async cancelAllOrders (symbol = undefined, params = {}) { // TODO: atm, this doesnt accept an array as symbol argument, because of unification (however, exchange allows multiple symbols)
1286
+ let response = undefined;
1287
+ let market = undefined;
1288
+ if (symbol === undefined) {
1289
+ response = await this.tradingPostCancelAllOrders (params);
1290
+ //
1291
+ // [
1292
+ // 465448358,
1293
+ // 468364313
1294
+ // ]
1295
+ //
1296
+ } else {
1297
+ await this.loadMarkets ();
1298
+ market = this.market (symbol);
1299
+ const request = {
1300
+ 'instruments': [ market['id'] ],
1301
+ };
1302
+ response = await this.tradingPostCancelOrdersByInstrument (this.extend (request, params));
1303
+ //
1304
+ // [
1305
+ // 465441234,
1306
+ // 468364321
1307
+ // ]
1308
+ //
1309
+ }
1310
+ return this.parseOrders (response, market, undefined, undefined, params);
1311
+ }
1312
+
1313
+ async fetchOrderTrades (id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
1314
+ await this.loadMarkets ();
1315
+ const request = {
1316
+ 'id': id,
1317
+ };
1318
+ const response = await this.tradingGetOrderTrades (this.extend (request, params));
1319
+ //
1320
+ // [
1321
+ // {
1322
+ // "id": 3005866,
1323
+ // "orderId": 468533093,
1324
+ // "timestamp": "2018-06-02T16:26:27Z",
1325
+ // "instrument": "BCH-ETH",
1326
+ // "side": "buy",
1327
+ // "price": 1.78882,
1328
+ // "volume": 0.027,
1329
+ // "fee": 0.0000483,
1330
+ // "feeCurrency": "ETH"
1331
+ // },
1332
+ // {
1333
+ // "id": 3005812,
1334
+ // "orderId": 468515771,
1335
+ // "timestamp": "2018-06-02T16:16:05Z",
1336
+ // "instrument": "ETC-BTC",
1337
+ // "side": "sell",
1338
+ // "price": 0.00210958,
1339
+ // "volume": 0.05994006,
1340
+ // "fee": -0.000000063224,
1341
+ // "feeCurrency": "BTC"
1342
+ // },
1343
+ // ...
1344
+ // ]
1345
+ //
1346
+ return this.parseTrades (response, undefined, since, limit);
1347
+ }
1348
+
1349
+ async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
1350
+ await this.loadMarkets ();
1351
+ let market = undefined;
1352
+ const request = {};
1353
+ if (symbol !== undefined) {
1354
+ market = this.market (symbol);
1355
+ request['instrument'] = market['id'];
1356
+ }
1357
+ if (since !== undefined) {
1358
+ request['from'] = this.ymdhms (since, 'T');
1359
+ }
1360
+ if (limit !== undefined) {
1361
+ request['limit'] = limit; // min 1, max 1000, default 100
1362
+ }
1363
+ const response = await this.tradingGetTradeHistory (this.extend (request, params));
1364
+ //
1365
+ // [
1366
+ // {
1367
+ // "id": 3005866,
1368
+ // "orderId": 468533093,
1369
+ // "timestamp": "2018-06-02T16:26:27Z",
1370
+ // "instrument": "BCH-ETH",
1371
+ // "side": "buy",
1372
+ // "price": 1.78882,
1373
+ // "volume": 0.027,
1374
+ // "fee": 0.0000483,
1375
+ // "feeCurrency": "ETH"
1376
+ // },
1377
+ // {
1378
+ // "id": 3005812,
1379
+ // "orderId": 468515771,
1380
+ // "timestamp": "2018-06-02T16:16:05Z",
1381
+ // "instrument": "ETC-BTC",
1382
+ // "side": "sell",
1383
+ // "price": 0.00210958,
1384
+ // "volume": 0.05994006,
1385
+ // "fee": -0.000000063224,
1386
+ // "feeCurrency": "BTC"
1387
+ // },
1388
+ // ...
1389
+ // ]
1390
+ //
1391
+ return this.parseTrades (response, market, since, limit);
1392
+ }
1393
+
1394
+ async fetchTransactions (code = undefined, since = undefined, limit = undefined, params = {}) {
1395
+ await this.loadMarkets ();
1396
+ let currency = undefined;
1397
+ const request = {};
1398
+ if (code !== undefined) {
1399
+ currency = this.currency (code);
1400
+ request['currency'] = currency['id'];
1401
+ }
1402
+ if (since !== undefined) {
1403
+ request['from'] = this.ymdhms (since, 'T');
1404
+ }
1405
+ const response = await this.accountGetMoneyTransfers (this.extend (request, params));
1406
+ //
1407
+ // [
1408
+ // {
1409
+ // "id": 756446,
1410
+ // "type": "deposit",
1411
+ // "currency": "ETH",
1412
+ // "address": "0x451d5a1b7519aa75164f440df78c74aac96023fe",
1413
+ // "paymentId": null,
1414
+ // "amount": 0.142,
1415
+ // "fee": null,
1416
+ // "txId": "0x2b49098749840a9482c4894be94f94864b498a1306b6874687a5640cc9871918",
1417
+ // "createdAt": "2018-06-02T19:30:28Z",
1418
+ // "processedAt": "2018-06-02T21:10:41Z",
1419
+ // "confirmationsRequired": 12,
1420
+ // "confirmationCount": 12,
1421
+ // "status": "success",
1422
+ // "errorDescription": null
1423
+ // },
1424
+ // {
1425
+ // "id": 754618,
1426
+ // "type": "deposit",
1427
+ // "currency": "BTC",
1428
+ // "address": "1IgNfmERVcier4IhfGEfutkLfu4AcmeiUC",
1429
+ // "paymentId": null,
1430
+ // "amount": 0.09,
1431
+ // "fee": null,
1432
+ // "txId": "6876541687a9187e987c9187654f7198b9718af974641687b19a87987f91874f",
1433
+ // "createdAt": "2018-06-02T16:19:44Z",
1434
+ // "processedAt": "2018-06-02T16:20:50Z",
1435
+ // "confirmationsRequired": 1,
1436
+ // "confirmationCount": 1,
1437
+ // "status": "success",
1438
+ // "errorDescription": null
1439
+ // },
1440
+ // ...
1441
+ // ]
1442
+ //
1443
+ return this.parseTransactions (response, currency, since, limit);
1444
+ }
1445
+
1446
+ async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) {
1447
+ const request = {
1448
+ 'type': 'deposit',
1449
+ };
1450
+ return this.fetchTransactions (code, since, limit, this.extend (request, params));
1451
+ }
1452
+
1453
+ async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) {
1454
+ const request = {
1455
+ 'type': 'withdrawal',
1456
+ };
1457
+ return this.fetchTransactions (code, since, limit, this.extend (request, params));
1458
+ }
1459
+
1460
+ parseTransactionStatus (status) {
1461
+ const statuses = {
1462
+ 'pending': 'pending', // transfer is in progress
1463
+ 'success': 'ok', // completed successfully
1464
+ 'failed': 'failed', // aborted at some point (money will be credited back to the account of origin)
1465
+ };
1466
+ return this.safeString (statuses, status, status);
1467
+ }
1468
+
1469
+ parseTransaction (transaction, currency = undefined) {
1470
+ //
1471
+ // {
1472
+ // "id": 756446,
1473
+ // "type": "deposit",
1474
+ // "currency": "ETH",
1475
+ // "address": "0x451d5a1b7519aa75164f440df78c74aac96023fe",
1476
+ // "paymentId": null,
1477
+ // "amount": 0.142,
1478
+ // "fee": null,
1479
+ // "txId": "0x2b49098749840a9482c4894be94f94864b498a1306b6874687a5640cc9871918",
1480
+ // "createdAt": "2018-06-02T19:30:28Z",
1481
+ // "processedAt": "2018-06-02T21:10:41Z",
1482
+ // "confirmationsRequired": 12,
1483
+ // "confirmationCount": 12,
1484
+ // "status": "success",
1485
+ // "errorDescription": null,
1486
+ // }
1487
+ //
1488
+ const id = this.safeString (transaction, 'id');
1489
+ const address = this.safeString (transaction, 'address');
1490
+ const tag = this.safeString (transaction, 'paymentId');
1491
+ const txid = this.safeValue (transaction, 'txId');
1492
+ const currencyId = this.safeString (transaction, 'currency');
1493
+ const code = this.safeCurrencyCode (currencyId, currency);
1494
+ const type = this.safeString (transaction, 'type');
1495
+ const timestamp = this.parse8601 (this.safeString (transaction, 'createdAt'));
1496
+ const updated = this.parse8601 (this.safeString (transaction, 'processedAt'));
1497
+ const status = this.parseTransactionStatus (this.safeString (transaction, 'status'));
1498
+ const amount = this.safeNumber (transaction, 'amount');
1499
+ const feeCost = this.safeNumber (transaction, 'fee');
1500
+ const fee = {
1501
+ 'cost': feeCost,
1502
+ 'currency': code,
1503
+ };
1504
+ return {
1505
+ 'info': transaction,
1506
+ 'id': id,
1507
+ 'txid': txid,
1508
+ 'timestamp': timestamp,
1509
+ 'datetime': this.iso8601 (timestamp),
1510
+ 'network': undefined,
1511
+ 'address': address,
1512
+ 'addressTo': undefined,
1513
+ 'addressFrom': undefined,
1514
+ 'tag': tag,
1515
+ 'tagTo': undefined,
1516
+ 'tagFrom': undefined,
1517
+ 'type': type,
1518
+ 'amount': amount,
1519
+ 'currency': code,
1520
+ 'status': status,
1521
+ 'updated': updated,
1522
+ 'fee': fee,
1523
+ };
1524
+ }
1525
+
1526
+ async fetchDepositAddress (code, params = {}) {
1527
+ await this.loadMarkets ();
1528
+ const currency = this.currency (code);
1529
+ const request = {
1530
+ 'currency': currency['id'],
1531
+ };
1532
+ const response = await this.accountGetDepositAddress (this.extend (request, params));
1533
+ //
1534
+ // {
1535
+ // "currency": "BTS",
1536
+ // "address": "crex24",
1537
+ // "paymentId": "0fg4da4186741579"
1538
+ // }
1539
+ //
1540
+ const address = this.safeString (response, 'address');
1541
+ const tag = this.safeString (response, 'paymentId');
1542
+ return {
1543
+ 'currency': code,
1544
+ 'address': this.checkAddress (address),
1545
+ 'tag': tag,
1546
+ 'network': undefined,
1547
+ 'info': response,
1548
+ };
1549
+ }
1550
+
1551
+ async withdraw (code, amount, address, tag = undefined, params = {}) {
1552
+ [ tag, params ] = this.handleWithdrawTagAndParams (tag, params);
1553
+ this.checkAddress (address);
1554
+ await this.loadMarkets ();
1555
+ const currency = this.currency (code);
1556
+ const request = {
1557
+ 'currency': currency['id'],
1558
+ 'address': address,
1559
+ 'amount': parseFloat (this.currencyToPrecision (code, amount)),
1560
+ // sets whether the specified amount includes fee, can have either of the two values
1561
+ // true - balance will be decreased by amount, whereas [amount - fee] will be transferred to the specified address
1562
+ // false - amount will be deposited to the specified address, whereas the balance will be decreased by [amount + fee]
1563
+ // 'includeFee': false, // the default value is false
1564
+ 'feeCurrency': currency['id'], // https://github.com/ccxt/ccxt/issues/7544
1565
+ };
1566
+ if (tag !== undefined) {
1567
+ request['paymentId'] = tag;
1568
+ }
1569
+ const networks = this.safeValue (this.options, 'networks', {});
1570
+ let network = this.safeStringUpper (params, 'network'); // this line allows the user to specify either ERC20 or ETH
1571
+ network = this.safeString (networks, network, network); // handle ERC20>ETH alias
1572
+ if (network !== undefined) {
1573
+ request['transport'] = network;
1574
+ params = this.omit (params, 'network');
1575
+ }
1576
+ const response = await this.accountPostWithdraw (this.extend (request, params));
1577
+ return this.parseTransaction (response);
1578
+ }
1579
+
1580
+ sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
1581
+ let request = '/' + this.version + '/' + api + '/' + this.implodeParams (path, params);
1582
+ const query = this.omit (params, this.extractParams (path));
1583
+ if (method === 'GET') {
1584
+ if (Object.keys (query).length) {
1585
+ request += '?' + this.urlencode (query);
1586
+ }
1587
+ }
1588
+ const url = this.urls['api'] + request;
1589
+ if ((api === 'trading') || (api === 'account')) {
1590
+ this.checkRequiredCredentials ();
1591
+ const nonce = this.nonce ().toString ();
1592
+ const secret = this.base64ToBinary (this.secret);
1593
+ let auth = request + nonce;
1594
+ headers = {
1595
+ 'X-CREX24-API-KEY': this.apiKey,
1596
+ 'X-CREX24-API-NONCE': nonce,
1597
+ };
1598
+ if (method === 'POST') {
1599
+ headers['Content-Type'] = 'application/json';
1600
+ body = this.json (params);
1601
+ auth += body;
1602
+ }
1603
+ headers['X-CREX24-API-SIGN'] = this.hmac (this.encode (auth), secret, 'sha512', 'base64');
1604
+ }
1605
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
1606
+ }
1607
+
1608
+ handleErrors (code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
1609
+ if (!this.isJsonEncodedObject (body)) {
1610
+ return; // fallback to default error handler
1611
+ }
1612
+ if ((code >= 200) && (code < 300)) {
1613
+ return; // no error
1614
+ }
1615
+ const message = this.safeString (response, 'errorDescription');
1616
+ const feedback = this.id + ' ' + body;
1617
+ this.throwExactlyMatchedException (this.exceptions['exact'], message, feedback);
1618
+ this.throwBroadlyMatchedException (this.exceptions['broad'], message, feedback);
1619
+ if (code === 400) {
1620
+ throw new BadRequest (feedback);
1621
+ } else if (code === 401) {
1622
+ throw new AuthenticationError (feedback);
1623
+ } else if (code === 403) {
1624
+ throw new AuthenticationError (feedback);
1625
+ } else if (code === 429) {
1626
+ throw new DDoSProtection (feedback);
1627
+ } else if (code === 500) {
1628
+ throw new ExchangeError (feedback);
1629
+ } else if (code === 503) {
1630
+ throw new ExchangeNotAvailable (feedback);
1631
+ } else if (code === 504) {
1632
+ throw new RequestTimeout (feedback);
1633
+ }
1634
+ throw new ExchangeError (feedback); // unknown message
1635
+ }
1636
+ };