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/bitvavo.js ADDED
@@ -0,0 +1,1579 @@
1
+ 'use strict';
2
+
3
+ // ----------------------------------------------------------------------------
4
+
5
+ const Exchange = require ('./base/Exchange');
6
+ const { ExchangeError, BadSymbol, AuthenticationError, InsufficientFunds, InvalidOrder, ArgumentsRequired, OrderNotFound, InvalidAddress, BadRequest, RateLimitExceeded, PermissionDenied, ExchangeNotAvailable, AccountSuspended, OnMaintenance } = require ('./base/errors');
7
+ const { SIGNIFICANT_DIGITS, DECIMAL_PLACES, TRUNCATE, ROUND } = require ('./base/functions/number');
8
+
9
+ // ----------------------------------------------------------------------------
10
+
11
+ module.exports = class bitvavo extends Exchange {
12
+ describe () {
13
+ return this.deepExtend (super.describe (), {
14
+ 'id': 'bitvavo',
15
+ 'name': 'Bitvavo',
16
+ 'countries': [ 'NL' ], // Netherlands
17
+ 'rateLimit': 60, // 1000 requests per minute
18
+ 'version': 'v2',
19
+ 'certified': true,
20
+ 'pro': true,
21
+ 'has': {
22
+ 'CORS': undefined,
23
+ 'spot': true,
24
+ 'margin': false,
25
+ 'swap': false,
26
+ 'future': false,
27
+ 'option': false,
28
+ 'addMargin': false,
29
+ 'cancelAllOrders': true,
30
+ 'cancelOrder': true,
31
+ 'createOrder': true,
32
+ 'createReduceOnlyOrder': false,
33
+ 'createStopLimitOrder': true,
34
+ 'createStopMarketOrder': true,
35
+ 'createStopOrder': true,
36
+ 'editOrder': true,
37
+ 'fetchBalance': true,
38
+ 'fetchBorrowRate': false,
39
+ 'fetchBorrowRateHistories': false,
40
+ 'fetchBorrowRateHistory': false,
41
+ 'fetchBorrowRates': false,
42
+ 'fetchBorrowRatesPerSymbol': false,
43
+ 'fetchCurrencies': true,
44
+ 'fetchDepositAddress': true,
45
+ 'fetchDeposits': true,
46
+ 'fetchFundingHistory': false,
47
+ 'fetchFundingRate': false,
48
+ 'fetchFundingRateHistory': false,
49
+ 'fetchFundingRates': false,
50
+ 'fetchIndexOHLCV': false,
51
+ 'fetchLeverage': false,
52
+ 'fetchLeverageTiers': false,
53
+ 'fetchMarkets': true,
54
+ 'fetchMarkOHLCV': false,
55
+ 'fetchMyTrades': true,
56
+ 'fetchOHLCV': true,
57
+ 'fetchOpenOrders': true,
58
+ 'fetchOrder': true,
59
+ 'fetchOrderBook': true,
60
+ 'fetchOrders': true,
61
+ 'fetchPosition': false,
62
+ 'fetchPositions': false,
63
+ 'fetchPositionsRisk': false,
64
+ 'fetchPremiumIndexOHLCV': false,
65
+ 'fetchTicker': true,
66
+ 'fetchTickers': true,
67
+ 'fetchTime': true,
68
+ 'fetchTrades': true,
69
+ 'fetchTradingFee': false,
70
+ 'fetchTradingFees': true,
71
+ 'fetchTransfer': false,
72
+ 'fetchTransfers': false,
73
+ 'fetchWithdrawals': true,
74
+ 'reduceMargin': false,
75
+ 'setLeverage': false,
76
+ 'setMarginMode': false,
77
+ 'setPositionMode': false,
78
+ 'transfer': false,
79
+ 'withdraw': true,
80
+ },
81
+ 'timeframes': {
82
+ '1m': '1m',
83
+ '5m': '5m',
84
+ '15m': '15m',
85
+ '30m': '30m',
86
+ '1h': '1h',
87
+ '2h': '2h',
88
+ '4h': '4h',
89
+ '6h': '6h',
90
+ '8h': '8h',
91
+ '12h': '12h',
92
+ '1d': '1d',
93
+ },
94
+ 'urls': {
95
+ 'logo': 'https://user-images.githubusercontent.com/1294454/83165440-2f1cf200-a116-11ea-9046-a255d09fb2ed.jpg',
96
+ 'api': {
97
+ 'public': 'https://api.bitvavo.com',
98
+ 'private': 'https://api.bitvavo.com',
99
+ },
100
+ 'www': 'https://bitvavo.com/',
101
+ 'doc': 'https://docs.bitvavo.com/',
102
+ 'fees': 'https://bitvavo.com/en/fees',
103
+ 'referral': 'https://bitvavo.com/?a=24F34952F7',
104
+ },
105
+ 'api': {
106
+ 'public': {
107
+ 'get': {
108
+ 'time': 1,
109
+ 'markets': 1,
110
+ 'assets': 1,
111
+ '{market}/book': 1,
112
+ '{market}/trades': 5,
113
+ '{market}/candles': 1,
114
+ 'ticker/price': 1,
115
+ 'ticker/book': 1,
116
+ 'ticker/24h': { 'cost': 1, 'noMarket': 25 },
117
+ },
118
+ },
119
+ 'private': {
120
+ 'get': {
121
+ 'account': 1,
122
+ 'order': 1,
123
+ 'orders': 5,
124
+ 'ordersOpen': { 'cost': 1, 'noMarket': 25 },
125
+ 'trades': 5,
126
+ 'balance': 5,
127
+ 'deposit': 1,
128
+ 'depositHistory': 5,
129
+ 'withdrawalHistory': 5,
130
+ },
131
+ 'post': {
132
+ 'order': 1,
133
+ 'withdrawal': 1,
134
+ },
135
+ 'put': {
136
+ 'order': 1,
137
+ },
138
+ 'delete': {
139
+ 'order': 1,
140
+ 'orders': 1,
141
+ },
142
+ },
143
+ },
144
+ 'fees': {
145
+ 'trading': {
146
+ 'tierBased': true,
147
+ 'percentage': true,
148
+ 'taker': this.parseNumber ('0.0025'),
149
+ 'maker': this.parseNumber ('0.002'),
150
+ 'tiers': {
151
+ 'taker': [
152
+ [ this.parseNumber ('0'), this.parseNumber ('0.0025') ],
153
+ [ this.parseNumber ('100000'), this.parseNumber ('0.0020') ],
154
+ [ this.parseNumber ('250000'), this.parseNumber ('0.0016') ],
155
+ [ this.parseNumber ('500000'), this.parseNumber ('0.0012') ],
156
+ [ this.parseNumber ('1000000'), this.parseNumber ('0.0010') ],
157
+ [ this.parseNumber ('2500000'), this.parseNumber ('0.0008') ],
158
+ [ this.parseNumber ('5000000'), this.parseNumber ('0.0006') ],
159
+ [ this.parseNumber ('10000000'), this.parseNumber ('0.0005') ],
160
+ [ this.parseNumber ('25000000'), this.parseNumber ('0.0004') ],
161
+ ],
162
+ 'maker': [
163
+ [ this.parseNumber ('0'), this.parseNumber ('0.0015') ],
164
+ [ this.parseNumber ('100000'), this.parseNumber ('0.0010') ],
165
+ [ this.parseNumber ('250000'), this.parseNumber ('0.0008') ],
166
+ [ this.parseNumber ('500000'), this.parseNumber ('0.0006') ],
167
+ [ this.parseNumber ('1000000'), this.parseNumber ('0.0005') ],
168
+ [ this.parseNumber ('2500000'), this.parseNumber ('0.0004') ],
169
+ [ this.parseNumber ('5000000'), this.parseNumber ('0.0004') ],
170
+ [ this.parseNumber ('10000000'), this.parseNumber ('0.0003') ],
171
+ [ this.parseNumber ('25000000'), this.parseNumber ('0.0003') ],
172
+ ],
173
+ },
174
+ },
175
+ },
176
+ 'requiredCredentials': {
177
+ 'apiKey': true,
178
+ 'secret': true,
179
+ },
180
+ 'exceptions': {
181
+ 'exact': {
182
+ '101': ExchangeError, // Unknown error. Operation may or may not have succeeded.
183
+ '102': BadRequest, // Invalid JSON.
184
+ '103': RateLimitExceeded, // You have been rate limited. Please observe the Bitvavo-Ratelimit-AllowAt header to see when you can send requests again. Failure to respect this limit will result in an IP ban. The default value is 1000 weighted requests per minute. Please contact support if you wish to increase this limit.
185
+ '104': RateLimitExceeded, // You have been rate limited by the number of new orders. The default value is 100 new orders per second or 100.000 new orders per day. Please update existing orders instead of cancelling and creating orders. Please contact support if you wish to increase this limit.
186
+ '105': PermissionDenied, // Your IP or API key has been banned for not respecting the rate limit. The ban expires at ${expiryInMs}.
187
+ '107': ExchangeNotAvailable, // The matching engine is overloaded. Please wait 500ms and resubmit your order.
188
+ '108': ExchangeNotAvailable, // The matching engine could not process your order in time. Please consider increasing the access window or resubmit your order.
189
+ '109': ExchangeNotAvailable, // The matching engine did not respond in time. Operation may or may not have succeeded.
190
+ '110': BadRequest, // Invalid endpoint. Please check url and HTTP method.
191
+ '200': BadRequest, // ${param} url parameter is not supported. Please note that parameters are case-sensitive and use body parameters for PUT and POST requests.
192
+ '201': BadRequest, // ${param} body parameter is not supported. Please note that parameters are case-sensitive and use url parameters for GET and DELETE requests.
193
+ '202': BadRequest, // ${param} order parameter is not supported. Please note that certain parameters are only allowed for market or limit orders.
194
+ '203': BadSymbol, // {"errorCode":203,"error":"symbol parameter is required."}
195
+ '204': BadRequest, // ${param} parameter is not supported.
196
+ '205': BadRequest, // ${param} parameter is invalid.
197
+ '206': BadRequest, // Use either ${paramA} or ${paramB}. The usage of both parameters at the same time is not supported.
198
+ '210': InvalidOrder, // Amount exceeds the maximum allowed amount (1000000000).
199
+ '211': InvalidOrder, // Price exceeds the maximum allowed amount (100000000000).
200
+ '212': InvalidOrder, // Amount is below the minimum allowed amount for this asset.
201
+ '213': InvalidOrder, // Price is below the minimum allowed amount (0.000000000000001).
202
+ '214': InvalidOrder, // Price is too detailed
203
+ '215': InvalidOrder, // Price is too detailed. A maximum of 15 digits behind the decimal point are allowed.
204
+ '216': InsufficientFunds, // {"errorCode":216,"error":"You do not have sufficient balance to complete this operation."}
205
+ '217': InvalidOrder, // {"errorCode":217,"error":"Minimum order size in quote currency is 5 EUR or 0.001 BTC."}
206
+ '230': ExchangeError, // The order is rejected by the matching engine.
207
+ '231': ExchangeError, // The order is rejected by the matching engine. TimeInForce must be GTC when markets are paused.
208
+ '232': BadRequest, // You must change at least one of amount, amountRemaining, price, timeInForce, selfTradePrevention or postOnly.
209
+ '233': InvalidOrder, // {"errorCode":233,"error":"Order must be active (status new or partiallyFilled) to allow updating/cancelling."}
210
+ '234': InvalidOrder, // Market orders cannot be updated.
211
+ '235': ExchangeError, // You can only have 100 open orders on each book.
212
+ '236': BadRequest, // You can only update amount or amountRemaining, not both.
213
+ '240': OrderNotFound, // {"errorCode":240,"error":"No order found. Please be aware that simultaneously updating the same order may return this error."}
214
+ '300': AuthenticationError, // Authentication is required for this endpoint.
215
+ '301': AuthenticationError, // {"errorCode":301,"error":"API Key must be of length 64."}
216
+ '302': AuthenticationError, // Timestamp is invalid. This must be a timestamp in ms. See Bitvavo-Access-Timestamp header or timestamp parameter for websocket.
217
+ '303': AuthenticationError, // Window must be between 100 and 60000 ms.
218
+ '304': AuthenticationError, // Request was not received within acceptable window (default 30s, or custom with Bitvavo-Access-Window header) of Bitvavo-Access-Timestamp header (or timestamp parameter for websocket).
219
+ // '304': AuthenticationError, // Authentication is required for this endpoint.
220
+ '305': AuthenticationError, // {"errorCode":305,"error":"No active API key found."}
221
+ '306': AuthenticationError, // No active API key found. Please ensure that you have confirmed the API key by e-mail.
222
+ '307': PermissionDenied, // This key does not allow access from this IP.
223
+ '308': AuthenticationError, // {"errorCode":308,"error":"The signature length is invalid (HMAC-SHA256 should return a 64 length hexadecimal string)."}
224
+ '309': AuthenticationError, // {"errorCode":309,"error":"The signature is invalid."}
225
+ '310': PermissionDenied, // This key does not allow trading actions.
226
+ '311': PermissionDenied, // This key does not allow showing account information.
227
+ '312': PermissionDenied, // This key does not allow withdrawal of funds.
228
+ '315': BadRequest, // Websocket connections may not be used in a browser. Please use REST requests for this.
229
+ '317': AccountSuspended, // This account is locked. Please contact support.
230
+ '400': ExchangeError, // Unknown error. Please contact support with a copy of your request.
231
+ '401': ExchangeError, // Deposits for this asset are not available at this time.
232
+ '402': PermissionDenied, // You need to verify your identitiy before you can deposit and withdraw digital assets.
233
+ '403': PermissionDenied, // You need to verify your phone number before you can deposit and withdraw digital assets.
234
+ '404': OnMaintenance, // Could not complete this operation, because our node cannot be reached. Possibly under maintenance.
235
+ '405': ExchangeError, // You cannot withdraw digital assets during a cooldown period. This is the result of newly added bank accounts.
236
+ '406': BadRequest, // {"errorCode":406,"error":"Your withdrawal is too small."}
237
+ '407': ExchangeError, // Internal transfer is not possible.
238
+ '408': InsufficientFunds, // {"errorCode":408,"error":"You do not have sufficient balance to complete this operation."}
239
+ '409': InvalidAddress, // {"errorCode":409,"error":"This is not a verified bank account."}
240
+ '410': ExchangeError, // Withdrawals for this asset are not available at this time.
241
+ '411': BadRequest, // You can not transfer assets to yourself.
242
+ '412': InvalidAddress, // {"errorCode":412,"error":"eth_address_invalid."}
243
+ '413': InvalidAddress, // This address violates the whitelist.
244
+ '414': ExchangeError, // You cannot withdraw assets within 2 minutes of logging in.
245
+ },
246
+ 'broad': {
247
+ 'start parameter is invalid': BadRequest, // {"errorCode":205,"error":"start parameter is invalid."}
248
+ 'symbol parameter is invalid': BadSymbol, // {"errorCode":205,"error":"symbol parameter is invalid."}
249
+ 'amount parameter is invalid': InvalidOrder, // {"errorCode":205,"error":"amount parameter is invalid."}
250
+ 'orderId parameter is invalid': InvalidOrder, // {"errorCode":205,"error":"orderId parameter is invalid."}
251
+ },
252
+ },
253
+ 'options': {
254
+ 'BITVAVO-ACCESS-WINDOW': 10000, // default 10 sec
255
+ 'fetchCurrencies': {
256
+ 'expires': 1000, // 1 second
257
+ },
258
+ },
259
+ 'precisionMode': SIGNIFICANT_DIGITS,
260
+ 'commonCurrencies': {
261
+ 'MIOTA': 'IOTA', // https://github.com/ccxt/ccxt/issues/7487
262
+ },
263
+ });
264
+ }
265
+
266
+ currencyToPrecision (code, fee) {
267
+ return this.decimalToPrecision (fee, 0, this.currencies[code]['precision']);
268
+ }
269
+
270
+ amountToPrecision (symbol, amount) {
271
+ // https://docs.bitfinex.com/docs/introduction#amount-precision
272
+ // The amount field allows up to 8 decimals.
273
+ // Anything exceeding this will be rounded to the 8th decimal.
274
+ return this.decimalToPrecision (amount, TRUNCATE, this.markets[symbol]['precision']['amount'], DECIMAL_PLACES);
275
+ }
276
+
277
+ priceToPrecision (symbol, price) {
278
+ price = this.decimalToPrecision (price, ROUND, this.markets[symbol]['precision']['price'], this.precisionMode);
279
+ // https://docs.bitfinex.com/docs/introduction#price-precision
280
+ // The precision level of all trading prices is based on significant figures.
281
+ // All pairs on Bitfinex use up to 5 significant digits and up to 8 decimals (e.g. 1.2345, 123.45, 1234.5, 0.00012345).
282
+ // Prices submit with a precision larger than 5 will be cut by the API.
283
+ return this.decimalToPrecision (price, TRUNCATE, 8, DECIMAL_PLACES);
284
+ }
285
+
286
+ async fetchTime (params = {}) {
287
+ const response = await this.publicGetTime (params);
288
+ //
289
+ // { "time": 1590379519148 }
290
+ //
291
+ return this.safeInteger (response, 'time');
292
+ }
293
+
294
+ async fetchMarkets (params = {}) {
295
+ const response = await this.publicGetMarkets (params);
296
+ const currencies = await this.fetchCurrenciesFromCache (params);
297
+ const currenciesById = this.indexBy (currencies, 'symbol');
298
+ //
299
+ // [
300
+ // {
301
+ // "market":"ADA-BTC",
302
+ // "status":"trading", // "trading" "halted" "auction"
303
+ // "base":"ADA",
304
+ // "quote":"BTC",
305
+ // "pricePrecision":5,
306
+ // "minOrderInBaseAsset":"100",
307
+ // "minOrderInQuoteAsset":"0.001",
308
+ // "orderTypes": [ "market", "limit" ]
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, 'market');
316
+ const baseId = this.safeString (market, 'base');
317
+ const quoteId = this.safeString (market, 'quote');
318
+ const base = this.safeCurrencyCode (baseId);
319
+ const quote = this.safeCurrencyCode (quoteId);
320
+ const status = this.safeString (market, 'status');
321
+ const baseCurrency = this.safeValue (currenciesById, baseId);
322
+ let amountPrecision = undefined;
323
+ if (baseCurrency !== undefined) {
324
+ amountPrecision = this.safeInteger (baseCurrency, 'decimals', 8);
325
+ }
326
+ result.push ({
327
+ 'id': id,
328
+ 'symbol': base + '/' + quote,
329
+ 'base': base,
330
+ 'quote': quote,
331
+ 'settle': undefined,
332
+ 'baseId': baseId,
333
+ 'quoteId': quoteId,
334
+ 'settleId': undefined,
335
+ 'type': 'spot',
336
+ 'spot': true,
337
+ 'margin': false,
338
+ 'swap': false,
339
+ 'future': false,
340
+ 'option': false,
341
+ 'active': (status === 'trading'),
342
+ 'contract': false,
343
+ 'linear': undefined,
344
+ 'inverse': undefined,
345
+ 'contractSize': undefined,
346
+ 'expiry': undefined,
347
+ 'expiryDatetime': undefined,
348
+ 'strike': undefined,
349
+ 'optionType': undefined,
350
+ 'precision': {
351
+ 'amount': amountPrecision,
352
+ 'price': this.safeInteger (market, 'pricePrecision'),
353
+ },
354
+ 'limits': {
355
+ 'leverage': {
356
+ 'min': undefined,
357
+ 'max': undefined,
358
+ },
359
+ 'amount': {
360
+ 'min': this.safeNumber (market, 'minOrderInBaseAsset'),
361
+ 'max': undefined,
362
+ },
363
+ 'price': {
364
+ 'min': undefined,
365
+ 'max': undefined,
366
+ },
367
+ 'cost': {
368
+ 'min': this.safeNumber (market, 'minOrderInQuoteAsset'),
369
+ 'max': undefined,
370
+ },
371
+ },
372
+ 'info': market,
373
+ });
374
+ }
375
+ return result;
376
+ }
377
+
378
+ async fetchCurrenciesFromCache (params = {}) {
379
+ // this method is now redundant
380
+ // currencies are now fetched before markets
381
+ const options = this.safeValue (this.options, 'fetchCurrencies', {});
382
+ const timestamp = this.safeInteger (options, 'timestamp');
383
+ const expires = this.safeInteger (options, 'expires', 1000);
384
+ const now = this.milliseconds ();
385
+ if ((timestamp === undefined) || ((now - timestamp) > expires)) {
386
+ const response = await this.publicGetAssets (params);
387
+ this.options['fetchCurrencies'] = this.extend (options, {
388
+ 'response': response,
389
+ 'timestamp': now,
390
+ });
391
+ }
392
+ return this.safeValue (this.options['fetchCurrencies'], 'response');
393
+ }
394
+
395
+ async fetchCurrencies (params = {}) {
396
+ const response = await this.fetchCurrenciesFromCache (params);
397
+ //
398
+ // [
399
+ // {
400
+ // "symbol":"ADA",
401
+ // "name":"Cardano",
402
+ // "decimals":6,
403
+ // "depositFee":"0",
404
+ // "depositConfirmations":15,
405
+ // "depositStatus":"OK", // "OK", "MAINTENANCE", "DELISTED"
406
+ // "withdrawalFee":"0.2",
407
+ // "withdrawalMinAmount":"0.2",
408
+ // "withdrawalStatus":"OK", // "OK", "MAINTENANCE", "DELISTED"
409
+ // "networks": [ "Mainnet" ], // "ETH", "NEO", "ONT", "SEPA", "VET"
410
+ // "message":"",
411
+ // },
412
+ // ]
413
+ //
414
+ const result = {};
415
+ for (let i = 0; i < response.length; i++) {
416
+ const currency = response[i];
417
+ const id = this.safeString (currency, 'symbol');
418
+ const code = this.safeCurrencyCode (id);
419
+ const depositStatus = this.safeValue (currency, 'depositStatus');
420
+ const deposit = (depositStatus === 'OK');
421
+ const withdrawalStatus = this.safeValue (currency, 'withdrawalStatus');
422
+ const withdrawal = (withdrawalStatus === 'OK');
423
+ const active = deposit && withdrawal;
424
+ const name = this.safeString (currency, 'name');
425
+ const precision = this.safeInteger (currency, 'decimals', 8);
426
+ result[code] = {
427
+ 'id': id,
428
+ 'info': currency,
429
+ 'code': code,
430
+ 'name': name,
431
+ 'active': active,
432
+ 'deposit': deposit,
433
+ 'withdraw': withdrawal,
434
+ 'fee': this.safeNumber (currency, 'withdrawalFee'),
435
+ 'precision': precision,
436
+ 'limits': {
437
+ 'amount': {
438
+ 'min': undefined,
439
+ 'max': undefined,
440
+ },
441
+ 'withdraw': {
442
+ 'min': this.safeNumber (currency, 'withdrawalMinAmount'),
443
+ 'max': undefined,
444
+ },
445
+ },
446
+ };
447
+ }
448
+ return result;
449
+ }
450
+
451
+ async fetchTicker (symbol, params = {}) {
452
+ await this.loadMarkets ();
453
+ const market = this.market (symbol);
454
+ const request = {
455
+ 'market': market['id'],
456
+ };
457
+ const response = await this.publicGetTicker24h (this.extend (request, params));
458
+ //
459
+ // {
460
+ // "market":"ETH-BTC",
461
+ // "open":"0.022578",
462
+ // "high":"0.023019",
463
+ // "low":"0.022573",
464
+ // "last":"0.023019",
465
+ // "volume":"25.16366324",
466
+ // "volumeQuote":"0.57333305",
467
+ // "bid":"0.023039",
468
+ // "bidSize":"0.53500578",
469
+ // "ask":"0.023041",
470
+ // "askSize":"0.47859202",
471
+ // "timestamp":1590381666900
472
+ // }
473
+ //
474
+ return this.parseTicker (response, market);
475
+ }
476
+
477
+ parseTicker (ticker, market = undefined) {
478
+ //
479
+ // fetchTicker
480
+ //
481
+ // {
482
+ // "market":"ETH-BTC",
483
+ // "open":"0.022578",
484
+ // "high":"0.023019",
485
+ // "low":"0.022573",
486
+ // "last":"0.023019",
487
+ // "volume":"25.16366324",
488
+ // "volumeQuote":"0.57333305",
489
+ // "bid":"0.023039",
490
+ // "bidSize":"0.53500578",
491
+ // "ask":"0.023041",
492
+ // "askSize":"0.47859202",
493
+ // "timestamp":1590381666900
494
+ // }
495
+ //
496
+ const marketId = this.safeString (ticker, 'market');
497
+ const symbol = this.safeSymbol (marketId, market, '-');
498
+ const timestamp = this.safeInteger (ticker, 'timestamp');
499
+ const last = this.safeString (ticker, 'last');
500
+ const baseVolume = this.safeString (ticker, 'volume');
501
+ const quoteVolume = this.safeString (ticker, 'volumeQuote');
502
+ const open = this.safeString (ticker, 'open');
503
+ return this.safeTicker ({
504
+ 'symbol': symbol,
505
+ 'timestamp': timestamp,
506
+ 'datetime': this.iso8601 (timestamp),
507
+ 'high': this.safeString (ticker, 'high'),
508
+ 'low': this.safeString (ticker, 'low'),
509
+ 'bid': this.safeString (ticker, 'bid'),
510
+ 'bidVolume': this.safeString (ticker, 'bidSize'),
511
+ 'ask': this.safeString (ticker, 'ask'),
512
+ 'askVolume': this.safeString (ticker, 'askSize'),
513
+ 'vwap': undefined,
514
+ 'open': open,
515
+ 'close': last,
516
+ 'last': last,
517
+ 'previousClose': undefined, // previous day close
518
+ 'change': undefined,
519
+ 'percentage': undefined,
520
+ 'average': undefined,
521
+ 'baseVolume': baseVolume,
522
+ 'quoteVolume': quoteVolume,
523
+ 'info': ticker,
524
+ }, market, false);
525
+ }
526
+
527
+ async fetchTickers (symbols = undefined, params = {}) {
528
+ await this.loadMarkets ();
529
+ const response = await this.publicGetTicker24h (params);
530
+ //
531
+ // [
532
+ // {
533
+ // "market":"ADA-BTC",
534
+ // "open":"0.0000059595",
535
+ // "high":"0.0000059765",
536
+ // "low":"0.0000059595",
537
+ // "last":"0.0000059765",
538
+ // "volume":"2923.172",
539
+ // "volumeQuote":"0.01743483",
540
+ // "bid":"0.0000059515",
541
+ // "bidSize":"1117.630919",
542
+ // "ask":"0.0000059585",
543
+ // "askSize":"809.999739",
544
+ // "timestamp":1590382266324
545
+ // }
546
+ // ]
547
+ //
548
+ return this.parseTickers (response, symbols);
549
+ }
550
+
551
+ async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
552
+ await this.loadMarkets ();
553
+ const market = this.market (symbol);
554
+ const request = {
555
+ 'market': market['id'],
556
+ // 'limit': 500, // default 500, max 1000
557
+ // 'start': since,
558
+ // 'end': this.milliseconds (),
559
+ // 'tradeIdFrom': '57b1159b-6bf5-4cde-9e2c-6bd6a5678baf',
560
+ // 'tradeIdTo': '57b1159b-6bf5-4cde-9e2c-6bd6a5678baf',
561
+ };
562
+ if (limit !== undefined) {
563
+ request['limit'] = limit;
564
+ }
565
+ if (since !== undefined) {
566
+ request['start'] = since;
567
+ }
568
+ const response = await this.publicGetMarketTrades (this.extend (request, params));
569
+ //
570
+ // [
571
+ // {
572
+ // "id":"94154c98-6e8b-4e33-92a8-74e33fc05650",
573
+ // "timestamp":1590382761859,
574
+ // "amount":"0.06026079",
575
+ // "price":"8095.3",
576
+ // "side":"buy"
577
+ // }
578
+ // ]
579
+ //
580
+ return this.parseTrades (response, market, since, limit);
581
+ }
582
+
583
+ parseTrade (trade, market = undefined) {
584
+ //
585
+ // fetchTrades (public)
586
+ //
587
+ // {
588
+ // "id":"94154c98-6e8b-4e33-92a8-74e33fc05650",
589
+ // "timestamp":1590382761859,
590
+ // "amount":"0.06026079",
591
+ // "price":"8095.3",
592
+ // "side":"buy"
593
+ // }
594
+ //
595
+ // createOrder, fetchOpenOrders, fetchOrders, editOrder (private)
596
+ //
597
+ // {
598
+ // "id":"b0c86aa5-6ed3-4a2d-ba3a-be9a964220f4",
599
+ // "timestamp":1590505649245,
600
+ // "amount":"0.249825",
601
+ // "price":"183.49",
602
+ // "taker":true,
603
+ // "fee":"0.12038925",
604
+ // "feeCurrency":"EUR",
605
+ // "settled":true
606
+ // }
607
+ //
608
+ // fetchMyTrades (private)
609
+ //
610
+ // {
611
+ // "id":"b0c86aa5-6ed3-4a2d-ba3a-be9a964220f4",
612
+ // "orderId":"af76d6ce-9f7c-4006-b715-bb5d430652d0",
613
+ // "timestamp":1590505649245,
614
+ // "market":"ETH-EUR",
615
+ // "side":"sell",
616
+ // "amount":"0.249825",
617
+ // "price":"183.49",
618
+ // "taker":true,
619
+ // "fee":"0.12038925",
620
+ // "feeCurrency":"EUR",
621
+ // "settled":true
622
+ // }
623
+ //
624
+ // watchMyTrades (private)
625
+ //
626
+ // {
627
+ // event: 'fill',
628
+ // timestamp: 1590964470132,
629
+ // market: 'ETH-EUR',
630
+ // orderId: '85d082e1-eda4-4209-9580-248281a29a9a',
631
+ // fillId: '861d2da5-aa93-475c-8d9a-dce431bd4211',
632
+ // side: 'sell',
633
+ // amount: '0.1',
634
+ // price: '211.46',
635
+ // taker: true,
636
+ // fee: '0.056',
637
+ // feeCurrency: 'EUR'
638
+ // }
639
+ //
640
+ const priceString = this.safeString (trade, 'price');
641
+ const amountString = this.safeString (trade, 'amount');
642
+ const timestamp = this.safeInteger (trade, 'timestamp');
643
+ const side = this.safeString (trade, 'side');
644
+ const id = this.safeString2 (trade, 'id', 'fillId');
645
+ const marketId = this.safeString (trade, 'market');
646
+ const symbol = this.safeSymbol (marketId, market, '-');
647
+ const taker = this.safeValue (trade, 'taker');
648
+ let takerOrMaker = undefined;
649
+ if (taker !== undefined) {
650
+ takerOrMaker = taker ? 'taker' : 'maker';
651
+ }
652
+ const feeCostString = this.safeString (trade, 'fee');
653
+ let fee = undefined;
654
+ if (feeCostString !== undefined) {
655
+ const feeCurrencyId = this.safeString (trade, 'feeCurrency');
656
+ const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId);
657
+ fee = {
658
+ 'cost': feeCostString,
659
+ 'currency': feeCurrencyCode,
660
+ };
661
+ }
662
+ const orderId = this.safeString (trade, 'orderId');
663
+ return this.safeTrade ({
664
+ 'info': trade,
665
+ 'id': id,
666
+ 'symbol': symbol,
667
+ 'timestamp': timestamp,
668
+ 'datetime': this.iso8601 (timestamp),
669
+ 'order': orderId,
670
+ 'type': undefined,
671
+ 'side': side,
672
+ 'takerOrMaker': takerOrMaker,
673
+ 'price': priceString,
674
+ 'amount': amountString,
675
+ 'cost': undefined,
676
+ 'fee': fee,
677
+ }, market);
678
+ }
679
+
680
+ async fetchTradingFees (params = {}) {
681
+ await this.loadMarkets ();
682
+ const response = await this.privateGetAccount (params);
683
+ //
684
+ // {
685
+ // "fees": {
686
+ // "taker": "0.0025",
687
+ // "maker": "0.0015",
688
+ // "volume": "10000.00"
689
+ // }
690
+ // }
691
+ //
692
+ const fees = this.safeValue (response, 'fees');
693
+ const maker = this.safeNumber (fees, 'maker');
694
+ const taker = this.safeNumber (fees, 'taker');
695
+ const result = {};
696
+ for (let i = 0; i < this.symbols.length; i++) {
697
+ const symbol = this.symbols[i];
698
+ result[symbol] = {
699
+ 'info': response,
700
+ 'symbol': symbol,
701
+ 'maker': maker,
702
+ 'taker': taker,
703
+ 'percentage': true,
704
+ 'tierBased': true,
705
+ };
706
+ }
707
+ return result;
708
+ }
709
+
710
+ async fetchOrderBook (symbol, limit = undefined, params = {}) {
711
+ await this.loadMarkets ();
712
+ const request = {
713
+ 'market': this.marketId (symbol),
714
+ };
715
+ if (limit !== undefined) {
716
+ request['depth'] = limit;
717
+ }
718
+ const response = await this.publicGetMarketBook (this.extend (request, params));
719
+ //
720
+ // {
721
+ // "market":"BTC-EUR",
722
+ // "nonce":35883831,
723
+ // "bids":[
724
+ // ["8097.4","0.6229099"],
725
+ // ["8097.2","0.64151283"],
726
+ // ["8097.1","0.24966294"],
727
+ // ],
728
+ // "asks":[
729
+ // ["8097.5","1.36916911"],
730
+ // ["8098.8","0.33462248"],
731
+ // ["8099.3","1.12908646"],
732
+ // ]
733
+ // }
734
+ //
735
+ const orderbook = this.parseOrderBook (response, symbol);
736
+ orderbook['nonce'] = this.safeInteger (response, 'nonce');
737
+ return orderbook;
738
+ }
739
+
740
+ parseOHLCV (ohlcv, market = undefined) {
741
+ //
742
+ // [
743
+ // 1590383700000,
744
+ // "8088.5",
745
+ // "8088.5",
746
+ // "8088.5",
747
+ // "8088.5",
748
+ // "0.04788623"
749
+ // ]
750
+ //
751
+ return [
752
+ this.safeInteger (ohlcv, 0),
753
+ this.safeNumber (ohlcv, 1),
754
+ this.safeNumber (ohlcv, 2),
755
+ this.safeNumber (ohlcv, 3),
756
+ this.safeNumber (ohlcv, 4),
757
+ this.safeNumber (ohlcv, 5),
758
+ ];
759
+ }
760
+
761
+ async fetchOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
762
+ await this.loadMarkets ();
763
+ const market = this.market (symbol);
764
+ const request = {
765
+ 'market': market['id'],
766
+ 'interval': this.timeframes[timeframe],
767
+ // 'limit': 1440, // default 1440, max 1440
768
+ // 'start': since,
769
+ // 'end': this.milliseconds (),
770
+ };
771
+ if (since !== undefined) {
772
+ // https://github.com/ccxt/ccxt/issues/9227
773
+ const duration = this.parseTimeframe (timeframe);
774
+ request['start'] = since;
775
+ if (limit === undefined) {
776
+ limit = 1440;
777
+ }
778
+ request['end'] = this.sum (since, limit * duration * 1000);
779
+ }
780
+ if (limit !== undefined) {
781
+ request['limit'] = limit; // default 1440, max 1440
782
+ }
783
+ const response = await this.publicGetMarketCandles (this.extend (request, params));
784
+ //
785
+ // [
786
+ // [1590383700000,"8088.5","8088.5","8088.5","8088.5","0.04788623"],
787
+ // [1590383580000,"8091.3","8091.5","8091.3","8091.5","0.04931221"],
788
+ // [1590383520000,"8090.3","8092.7","8090.3","8092.5","0.04001286"],
789
+ // ]
790
+ //
791
+ return this.parseOHLCVs (response, market, timeframe, since, limit);
792
+ }
793
+
794
+ parseBalance (response) {
795
+ const result = {
796
+ 'info': response,
797
+ 'timestamp': undefined,
798
+ 'datetime': undefined,
799
+ };
800
+ for (let i = 0; i < response.length; i++) {
801
+ const balance = response[i];
802
+ const currencyId = this.safeString (balance, 'symbol');
803
+ const code = this.safeCurrencyCode (currencyId);
804
+ const account = this.account ();
805
+ account['free'] = this.safeString (balance, 'available');
806
+ account['used'] = this.safeString (balance, 'inOrder');
807
+ result[code] = account;
808
+ }
809
+ return this.safeBalance (result);
810
+ }
811
+
812
+ async fetchBalance (params = {}) {
813
+ await this.loadMarkets ();
814
+ const response = await this.privateGetBalance (params);
815
+ //
816
+ // [
817
+ // {
818
+ // "symbol": "BTC",
819
+ // "available": "1.57593193",
820
+ // "inOrder": "0.74832374"
821
+ // }
822
+ // ]
823
+ //
824
+ return this.parseBalance (response);
825
+ }
826
+
827
+ async fetchDepositAddress (code, params = {}) {
828
+ await this.loadMarkets ();
829
+ const currency = this.currency (code);
830
+ const request = {
831
+ 'symbol': currency['id'],
832
+ };
833
+ const response = await this.privateGetDeposit (this.extend (request, params));
834
+ //
835
+ // {
836
+ // "address": "0x449889e3234514c45d57f7c5a571feba0c7ad567",
837
+ // "paymentId": "10002653"
838
+ // }
839
+ //
840
+ const address = this.safeString (response, 'address');
841
+ const tag = this.safeString (response, 'paymentId');
842
+ this.checkAddress (address);
843
+ return {
844
+ 'currency': code,
845
+ 'address': address,
846
+ 'tag': tag,
847
+ 'network': undefined,
848
+ 'info': response,
849
+ };
850
+ }
851
+
852
+ async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
853
+ await this.loadMarkets ();
854
+ const market = this.market (symbol);
855
+ const request = {
856
+ 'market': market['id'],
857
+ 'side': side,
858
+ 'orderType': type, // 'market', 'limit', 'stopLoss', 'stopLossLimit', 'takeProfit', 'takeProfitLimit'
859
+ // 'amount': this.amountToPrecision (symbol, amount),
860
+ // 'price': this.priceToPrecision (symbol, price),
861
+ // 'amountQuote': this.costToPrecision (symbol, cost),
862
+ // 'timeInForce': 'GTC', // 'GTC', 'IOC', 'FOK'
863
+ // 'selfTradePrevention': 'decrementAndCancel', // 'decrementAndCancel', 'cancelOldest', 'cancelNewest', 'cancelBoth'
864
+ // 'postOnly': false,
865
+ // 'disableMarketProtection': false, // don't cancel if the next fill price is 10% worse than the best fill price
866
+ // 'responseRequired': true, // false is faster
867
+ };
868
+ const isStopLimit = (type === 'stopLossLimit') || (type === 'takeProfitLimit');
869
+ const isStopMarket = (type === 'stopLoss') || (type === 'takeProfit');
870
+ if (type === 'market') {
871
+ let cost = undefined;
872
+ if (price !== undefined) {
873
+ cost = amount * price;
874
+ } else {
875
+ cost = this.safeNumber2 (params, 'cost', 'amountQuote');
876
+ }
877
+ if (cost !== undefined) {
878
+ const precision = market['precision']['price'];
879
+ request['amountQuote'] = this.decimalToPrecision (cost, TRUNCATE, precision, this.precisionMode);
880
+ } else {
881
+ request['amount'] = this.amountToPrecision (symbol, amount);
882
+ }
883
+ params = this.omit (params, [ 'cost', 'amountQuote' ]);
884
+ } else if (type === 'limit') {
885
+ request['price'] = this.priceToPrecision (symbol, price);
886
+ request['amount'] = this.amountToPrecision (symbol, amount);
887
+ } else if (isStopMarket || isStopLimit) {
888
+ let stopPrice = this.safeNumber2 (params, 'stopPrice', 'triggerAmount');
889
+ if (stopPrice === undefined) {
890
+ if (isStopLimit) {
891
+ throw new ArgumentsRequired (this.id + ' createOrder() requires a stopPrice parameter for a ' + type + ' order');
892
+ } else if (isStopMarket) {
893
+ if (price === undefined) {
894
+ throw new ArgumentsRequired (this.id + ' createOrder() requires a price argument or a stopPrice parameter for a ' + type + ' order');
895
+ } else {
896
+ stopPrice = price;
897
+ }
898
+ }
899
+ }
900
+ if (isStopLimit) {
901
+ request['price'] = this.priceToPrecision (symbol, price);
902
+ }
903
+ params = this.omit (params, [ 'stopPrice', 'triggerAmount' ]);
904
+ request['triggerAmount'] = this.priceToPrecision (symbol, stopPrice);
905
+ request['triggerType'] = 'price';
906
+ request['amount'] = this.amountToPrecision (symbol, amount);
907
+ }
908
+ const response = await this.privatePostOrder (this.extend (request, params));
909
+ //
910
+ // {
911
+ // "orderId":"af76d6ce-9f7c-4006-b715-bb5d430652d0",
912
+ // "market":"ETH-EUR",
913
+ // "created":1590505649241,
914
+ // "updated":1590505649241,
915
+ // "status":"filled",
916
+ // "side":"sell",
917
+ // "orderType":"market",
918
+ // "amount":"0.249825",
919
+ // "amountRemaining":"0",
920
+ // "onHold":"0",
921
+ // "onHoldCurrency":"ETH",
922
+ // "filledAmount":"0.249825",
923
+ // "filledAmountQuote":"45.84038925",
924
+ // "feePaid":"0.12038925",
925
+ // "feeCurrency":"EUR",
926
+ // "fills":[
927
+ // {
928
+ // "id":"b0c86aa5-6ed3-4a2d-ba3a-be9a964220f4",
929
+ // "timestamp":1590505649245,
930
+ // "amount":"0.249825",
931
+ // "price":"183.49",
932
+ // "taker":true,
933
+ // "fee":"0.12038925",
934
+ // "feeCurrency":"EUR",
935
+ // "settled":true
936
+ // }
937
+ // ],
938
+ // "selfTradePrevention":"decrementAndCancel",
939
+ // "visible":false,
940
+ // "disableMarketProtection":false
941
+ // }
942
+ //
943
+ return this.parseOrder (response, market);
944
+ }
945
+
946
+ async editOrder (id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
947
+ await this.loadMarkets ();
948
+ const market = this.market (symbol);
949
+ let request = {};
950
+ const amountRemaining = this.safeNumber (params, 'amountRemaining');
951
+ params = this.omit (params, 'amountRemaining');
952
+ if (price !== undefined) {
953
+ request['price'] = this.priceToPrecision (symbol, price);
954
+ }
955
+ if (amount !== undefined) {
956
+ request['amount'] = this.amountToPrecision (symbol, amount);
957
+ }
958
+ if (amountRemaining !== undefined) {
959
+ request['amountRemaining'] = this.amountToPrecision (symbol, amountRemaining);
960
+ }
961
+ request = this.extend (request, params);
962
+ if (Object.keys (request).length) {
963
+ request['orderId'] = id;
964
+ request['market'] = market['id'];
965
+ const response = await this.privatePutOrder (this.extend (request, params));
966
+ return this.parseOrder (response, market);
967
+ } else {
968
+ throw new ArgumentsRequired (this.id + ' editOrder() requires an amount argument, or a price argument, or non-empty params');
969
+ }
970
+ }
971
+
972
+ async cancelOrder (id, symbol = undefined, params = {}) {
973
+ if (symbol === undefined) {
974
+ throw new ArgumentsRequired (this.id + ' cancelOrder() requires a symbol argument');
975
+ }
976
+ await this.loadMarkets ();
977
+ const market = this.market (symbol);
978
+ const request = {
979
+ 'orderId': id,
980
+ 'market': market['id'],
981
+ };
982
+ const response = await this.privateDeleteOrder (this.extend (request, params));
983
+ //
984
+ // {
985
+ // "orderId": "2e7ce7fc-44e2-4d80-a4a7-d079c4750b61"
986
+ // }
987
+ //
988
+ return this.parseOrder (response, market);
989
+ }
990
+
991
+ async cancelAllOrders (symbol = undefined, params = {}) {
992
+ await this.loadMarkets ();
993
+ const request = {};
994
+ let market = undefined;
995
+ if (symbol !== undefined) {
996
+ market = this.market (symbol);
997
+ request['market'] = market['id'];
998
+ }
999
+ const response = await this.privateDeleteOrders (this.extend (request, params));
1000
+ //
1001
+ // [
1002
+ // {
1003
+ // "orderId": "1be6d0df-d5dc-4b53-a250-3376f3b393e6"
1004
+ // }
1005
+ // ]
1006
+ //
1007
+ return this.parseOrders (response, market);
1008
+ }
1009
+
1010
+ async fetchOrder (id, symbol = undefined, params = {}) {
1011
+ if (symbol === undefined) {
1012
+ throw new ArgumentsRequired (this.id + ' fetchOrder() requires a symbol argument');
1013
+ }
1014
+ await this.loadMarkets ();
1015
+ const market = this.market (symbol);
1016
+ const request = {
1017
+ 'orderId': id,
1018
+ 'market': market['id'],
1019
+ };
1020
+ const response = await this.privateGetOrder (this.extend (request, params));
1021
+ //
1022
+ // {
1023
+ // "orderId":"af76d6ce-9f7c-4006-b715-bb5d430652d0",
1024
+ // "market":"ETH-EUR",
1025
+ // "created":1590505649241,
1026
+ // "updated":1590505649241,
1027
+ // "status":"filled",
1028
+ // "side":"sell",
1029
+ // "orderType":"market",
1030
+ // "amount":"0.249825",
1031
+ // "amountRemaining":"0",
1032
+ // "onHold":"0",
1033
+ // "onHoldCurrency":"ETH",
1034
+ // "filledAmount":"0.249825",
1035
+ // "filledAmountQuote":"45.84038925",
1036
+ // "feePaid":"0.12038925",
1037
+ // "feeCurrency":"EUR",
1038
+ // "fills":[
1039
+ // {
1040
+ // "id":"b0c86aa5-6ed3-4a2d-ba3a-be9a964220f4",
1041
+ // "timestamp":1590505649245,
1042
+ // "amount":"0.249825",
1043
+ // "price":"183.49",
1044
+ // "taker":true,
1045
+ // "fee":"0.12038925",
1046
+ // "feeCurrency":"EUR",
1047
+ // "settled":true
1048
+ // }
1049
+ // ],
1050
+ // "selfTradePrevention":"decrementAndCancel",
1051
+ // "visible":false,
1052
+ // "disableMarketProtection":false
1053
+ // }
1054
+ //
1055
+ return this.parseOrder (response, market);
1056
+ }
1057
+
1058
+ async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
1059
+ if (symbol === undefined) {
1060
+ throw new ArgumentsRequired (this.id + ' fetchOrders() requires a symbol argument');
1061
+ }
1062
+ await this.loadMarkets ();
1063
+ const market = this.market (symbol);
1064
+ const request = {
1065
+ 'market': market['id'],
1066
+ // 'limit': 500,
1067
+ // 'start': since,
1068
+ // 'end': this.milliseconds (),
1069
+ // 'orderIdFrom': 'af76d6ce-9f7c-4006-b715-bb5d430652d0',
1070
+ // 'orderIdTo': 'af76d6ce-9f7c-4006-b715-bb5d430652d0',
1071
+ };
1072
+ if (since !== undefined) {
1073
+ request['start'] = since;
1074
+ }
1075
+ if (limit !== undefined) {
1076
+ request['limit'] = limit; // default 500, max 1000
1077
+ }
1078
+ const response = await this.privateGetOrders (this.extend (request, params));
1079
+ //
1080
+ // [
1081
+ // {
1082
+ // "orderId":"af76d6ce-9f7c-4006-b715-bb5d430652d0",
1083
+ // "market":"ETH-EUR",
1084
+ // "created":1590505649241,
1085
+ // "updated":1590505649241,
1086
+ // "status":"filled",
1087
+ // "side":"sell",
1088
+ // "orderType":"market",
1089
+ // "amount":"0.249825",
1090
+ // "amountRemaining":"0",
1091
+ // "onHold":"0",
1092
+ // "onHoldCurrency":"ETH",
1093
+ // "filledAmount":"0.249825",
1094
+ // "filledAmountQuote":"45.84038925",
1095
+ // "feePaid":"0.12038925",
1096
+ // "feeCurrency":"EUR",
1097
+ // "fills":[
1098
+ // {
1099
+ // "id":"b0c86aa5-6ed3-4a2d-ba3a-be9a964220f4",
1100
+ // "timestamp":1590505649245,
1101
+ // "amount":"0.249825",
1102
+ // "price":"183.49",
1103
+ // "taker":true,
1104
+ // "fee":"0.12038925",
1105
+ // "feeCurrency":"EUR",
1106
+ // "settled":true
1107
+ // }
1108
+ // ],
1109
+ // "selfTradePrevention":"decrementAndCancel",
1110
+ // "visible":false,
1111
+ // "disableMarketProtection":false
1112
+ // }
1113
+ // ]
1114
+ //
1115
+ return this.parseOrders (response, market, since, limit);
1116
+ }
1117
+
1118
+ async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
1119
+ await this.loadMarkets ();
1120
+ const request = {
1121
+ // 'market': market['id'], // rate limit 25 without a market, 1 with market specified
1122
+ };
1123
+ let market = undefined;
1124
+ if (symbol !== undefined) {
1125
+ market = this.market (symbol);
1126
+ request['market'] = market['id'];
1127
+ }
1128
+ const response = await this.privateGetOrdersOpen (this.extend (request, params));
1129
+ //
1130
+ // [
1131
+ // {
1132
+ // "orderId":"af76d6ce-9f7c-4006-b715-bb5d430652d0",
1133
+ // "market":"ETH-EUR",
1134
+ // "created":1590505649241,
1135
+ // "updated":1590505649241,
1136
+ // "status":"filled",
1137
+ // "side":"sell",
1138
+ // "orderType":"market",
1139
+ // "amount":"0.249825",
1140
+ // "amountRemaining":"0",
1141
+ // "onHold":"0",
1142
+ // "onHoldCurrency":"ETH",
1143
+ // "filledAmount":"0.249825",
1144
+ // "filledAmountQuote":"45.84038925",
1145
+ // "feePaid":"0.12038925",
1146
+ // "feeCurrency":"EUR",
1147
+ // "fills":[
1148
+ // {
1149
+ // "id":"b0c86aa5-6ed3-4a2d-ba3a-be9a964220f4",
1150
+ // "timestamp":1590505649245,
1151
+ // "amount":"0.249825",
1152
+ // "price":"183.49",
1153
+ // "taker":true,
1154
+ // "fee":"0.12038925",
1155
+ // "feeCurrency":"EUR",
1156
+ // "settled":true
1157
+ // }
1158
+ // ],
1159
+ // "selfTradePrevention":"decrementAndCancel",
1160
+ // "visible":false,
1161
+ // "disableMarketProtection":false
1162
+ // }
1163
+ // ]
1164
+ //
1165
+ return this.parseOrders (response, market, since, limit);
1166
+ }
1167
+
1168
+ parseOrderStatus (status) {
1169
+ const statuses = {
1170
+ 'new': 'open',
1171
+ 'canceled': 'canceled',
1172
+ 'canceledAuction': 'canceled',
1173
+ 'canceledSelfTradePrevention': 'canceled',
1174
+ 'canceledIOC': 'canceled',
1175
+ 'canceledFOK': 'canceled',
1176
+ 'canceledMarketProtection': 'canceled',
1177
+ 'canceledPostOnly': 'canceled',
1178
+ 'filled': 'closed',
1179
+ 'partiallyFilled': 'open',
1180
+ 'expired': 'canceled',
1181
+ 'rejected': 'canceled',
1182
+ 'awaitingTrigger': 'open', // https://github.com/ccxt/ccxt/issues/8489
1183
+ };
1184
+ return this.safeString (statuses, status, status);
1185
+ }
1186
+
1187
+ parseOrder (order, market = undefined) {
1188
+ //
1189
+ // cancelOrder, cancelAllOrders
1190
+ //
1191
+ // {
1192
+ // "orderId": "2e7ce7fc-44e2-4d80-a4a7-d079c4750b61"
1193
+ // }
1194
+ //
1195
+ // createOrder, fetchOrder, fetchOpenOrders, fetchOrders, editOrder
1196
+ //
1197
+ // {
1198
+ // "orderId":"af76d6ce-9f7c-4006-b715-bb5d430652d0",
1199
+ // "market":"ETH-EUR",
1200
+ // "created":1590505649241,
1201
+ // "updated":1590505649241,
1202
+ // "status":"filled",
1203
+ // "side":"sell",
1204
+ // "orderType":"market",
1205
+ // "amount":"0.249825",
1206
+ // "amountRemaining":"0",
1207
+ // "price": "183.49", // limit orders only
1208
+ // "onHold":"0",
1209
+ // "onHoldCurrency":"ETH",
1210
+ // "filledAmount":"0.249825",
1211
+ // "filledAmountQuote":"45.84038925",
1212
+ // "feePaid":"0.12038925",
1213
+ // "feeCurrency":"EUR",
1214
+ // "fills":[
1215
+ // {
1216
+ // "id":"b0c86aa5-6ed3-4a2d-ba3a-be9a964220f4",
1217
+ // "timestamp":1590505649245,
1218
+ // "amount":"0.249825",
1219
+ // "price":"183.49",
1220
+ // "taker":true,
1221
+ // "fee":"0.12038925",
1222
+ // "feeCurrency":"EUR",
1223
+ // "settled":true
1224
+ // }
1225
+ // ],
1226
+ // "selfTradePrevention":"decrementAndCancel",
1227
+ // "visible":false,
1228
+ // "disableMarketProtection":false
1229
+ // "timeInForce": "GTC",
1230
+ // "postOnly": true,
1231
+ // }
1232
+ //
1233
+ const id = this.safeString (order, 'orderId');
1234
+ const timestamp = this.safeInteger (order, 'created');
1235
+ const marketId = this.safeString (order, 'market');
1236
+ market = this.safeMarket (marketId, market, '-');
1237
+ const symbol = market['symbol'];
1238
+ const status = this.parseOrderStatus (this.safeString (order, 'status'));
1239
+ const side = this.safeString (order, 'side');
1240
+ const type = this.safeString (order, 'orderType');
1241
+ const price = this.safeString (order, 'price');
1242
+ const amount = this.safeString (order, 'amount');
1243
+ const remaining = this.safeString (order, 'amountRemaining');
1244
+ const filled = this.safeString (order, 'filledAmount');
1245
+ const cost = this.safeString (order, 'filledAmountQuote');
1246
+ let fee = undefined;
1247
+ const feeCost = this.safeNumber (order, 'feePaid');
1248
+ if (feeCost !== undefined) {
1249
+ const feeCurrencyId = this.safeString (order, 'feeCurrency');
1250
+ const feeCurrencyCode = this.safeCurrencyCode (feeCurrencyId);
1251
+ fee = {
1252
+ 'cost': feeCost,
1253
+ 'currency': feeCurrencyCode,
1254
+ };
1255
+ }
1256
+ const rawTrades = this.safeValue (order, 'fills', []);
1257
+ const timeInForce = this.safeString (order, 'timeInForce');
1258
+ const postOnly = this.safeValue (order, 'postOnly');
1259
+ // https://github.com/ccxt/ccxt/issues/8489
1260
+ const stopPrice = this.safeNumber (order, 'triggerPrice');
1261
+ return this.safeOrder ({
1262
+ 'info': order,
1263
+ 'id': id,
1264
+ 'clientOrderId': undefined,
1265
+ 'timestamp': timestamp,
1266
+ 'datetime': this.iso8601 (timestamp),
1267
+ 'lastTradeTimestamp': undefined,
1268
+ 'symbol': symbol,
1269
+ 'type': type,
1270
+ 'timeInForce': timeInForce,
1271
+ 'postOnly': postOnly,
1272
+ 'side': side,
1273
+ 'price': price,
1274
+ 'stopPrice': stopPrice,
1275
+ 'amount': amount,
1276
+ 'cost': cost,
1277
+ 'average': undefined,
1278
+ 'filled': filled,
1279
+ 'remaining': remaining,
1280
+ 'status': status,
1281
+ 'fee': fee,
1282
+ 'trades': rawTrades,
1283
+ }, market);
1284
+ }
1285
+
1286
+ async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
1287
+ if (symbol === undefined) {
1288
+ throw new ArgumentsRequired (this.id + ' fetchMyTrades() requires a symbol argument');
1289
+ }
1290
+ await this.loadMarkets ();
1291
+ const market = this.market (symbol);
1292
+ const request = {
1293
+ 'market': market['id'],
1294
+ // 'limit': 500,
1295
+ // 'start': since,
1296
+ // 'end': this.milliseconds (),
1297
+ // 'tradeIdFrom': 'af76d6ce-9f7c-4006-b715-bb5d430652d0',
1298
+ // 'tradeIdTo': 'af76d6ce-9f7c-4006-b715-bb5d430652d0',
1299
+ };
1300
+ if (since !== undefined) {
1301
+ request['start'] = since;
1302
+ }
1303
+ if (limit !== undefined) {
1304
+ request['limit'] = limit; // default 500, max 1000
1305
+ }
1306
+ const response = await this.privateGetTrades (this.extend (request, params));
1307
+ //
1308
+ // [
1309
+ // {
1310
+ // "id":"b0c86aa5-6ed3-4a2d-ba3a-be9a964220f4",
1311
+ // "orderId":"af76d6ce-9f7c-4006-b715-bb5d430652d0",
1312
+ // "timestamp":1590505649245,
1313
+ // "market":"ETH-EUR",
1314
+ // "side":"sell",
1315
+ // "amount":"0.249825",
1316
+ // "price":"183.49",
1317
+ // "taker":true,
1318
+ // "fee":"0.12038925",
1319
+ // "feeCurrency":"EUR",
1320
+ // "settled":true
1321
+ // }
1322
+ // ]
1323
+ //
1324
+ return this.parseTrades (response, market, since, limit);
1325
+ }
1326
+
1327
+ async withdraw (code, amount, address, tag = undefined, params = {}) {
1328
+ [ tag, params ] = this.handleWithdrawTagAndParams (tag, params);
1329
+ this.checkAddress (address);
1330
+ await this.loadMarkets ();
1331
+ const currency = this.currency (code);
1332
+ const request = {
1333
+ 'symbol': currency['id'],
1334
+ 'amount': this.currencyToPrecision (code, amount),
1335
+ 'address': address, // address or IBAN
1336
+ // 'internal': false, // transfer to another Bitvavo user address, no fees
1337
+ // 'addWithdrawalFee': false, // true = add the fee on top, otherwise the fee is subtracted from the amount
1338
+ };
1339
+ if (tag !== undefined) {
1340
+ request['paymentId'] = tag;
1341
+ }
1342
+ const response = await this.privatePostWithdrawal (this.extend (request, params));
1343
+ //
1344
+ // {
1345
+ // "success": true,
1346
+ // "symbol": "BTC",
1347
+ // "amount": "1.5"
1348
+ // }
1349
+ //
1350
+ return this.parseTransaction (response, currency);
1351
+ }
1352
+
1353
+ async fetchWithdrawals (code = undefined, since = undefined, limit = undefined, params = {}) {
1354
+ await this.loadMarkets ();
1355
+ const request = {
1356
+ // 'symbol': currency['id'],
1357
+ // 'limit': 500, // default 500, max 1000
1358
+ // 'start': since,
1359
+ // 'end': this.milliseconds (),
1360
+ };
1361
+ let currency = undefined;
1362
+ if (code !== undefined) {
1363
+ currency = this.currency (code);
1364
+ request['symbol'] = currency['id'];
1365
+ }
1366
+ if (since !== undefined) {
1367
+ request['start'] = since;
1368
+ }
1369
+ if (limit !== undefined) {
1370
+ request['limit'] = limit; // default 500, max 1000
1371
+ }
1372
+ const response = await this.privateGetWithdrawalHistory (this.extend (request, params));
1373
+ //
1374
+ // [
1375
+ // {
1376
+ // "timestamp":1590531212000,
1377
+ // "symbol":"ETH",
1378
+ // "amount":"0.091",
1379
+ // "fee":"0.009",
1380
+ // "status":"awaiting_bitvavo_inspection",
1381
+ // "address":"0xe42b309f1eE9F0cbf7f54CcF3bc2159eBfA6735b",
1382
+ // "paymentId": "10002653",
1383
+ // "txId": "927b3ea50c5bb52c6854152d305dfa1e27fc01d10464cf10825d96d69d235eb3",
1384
+ // }
1385
+ // ]
1386
+ //
1387
+ return this.parseTransactions (response, currency, since, limit, { 'type': 'withdrawal' });
1388
+ }
1389
+
1390
+ async fetchDeposits (code = undefined, since = undefined, limit = undefined, params = {}) {
1391
+ await this.loadMarkets ();
1392
+ const request = {
1393
+ // 'symbol': currency['id'],
1394
+ // 'limit': 500, // default 500, max 1000
1395
+ // 'start': since,
1396
+ // 'end': this.milliseconds (),
1397
+ };
1398
+ let currency = undefined;
1399
+ if (code !== undefined) {
1400
+ currency = this.currency (code);
1401
+ request['symbol'] = currency['id'];
1402
+ }
1403
+ if (since !== undefined) {
1404
+ request['start'] = since;
1405
+ }
1406
+ if (limit !== undefined) {
1407
+ request['limit'] = limit; // default 500, max 1000
1408
+ }
1409
+ const response = await this.privateGetDepositHistory (this.extend (request, params));
1410
+ //
1411
+ // [
1412
+ // {
1413
+ // "timestamp":1590492401000,
1414
+ // "symbol":"ETH",
1415
+ // "amount":"0.249825",
1416
+ // "fee":"0",
1417
+ // "status":"completed",
1418
+ // "txId":"0x5167b473fd37811f9ef22364c3d54726a859ef9d98934b3a1e11d7baa8d2c2e2"
1419
+ // }
1420
+ // ]
1421
+ //
1422
+ return this.parseTransactions (response, currency, since, limit, { 'type': 'deposit' });
1423
+ }
1424
+
1425
+ parseTransactionStatus (status) {
1426
+ const statuses = {
1427
+ 'awaiting_processing': 'pending',
1428
+ 'awaiting_email_confirmation': 'pending',
1429
+ 'awaiting_bitvavo_inspection': 'pending',
1430
+ 'approved': 'pending',
1431
+ 'sending': 'pending',
1432
+ 'in_mempool': 'pending',
1433
+ 'processed': 'pending',
1434
+ 'completed': 'ok',
1435
+ 'canceled': 'canceled',
1436
+ };
1437
+ return this.safeString (statuses, status, status);
1438
+ }
1439
+
1440
+ parseTransaction (transaction, currency = undefined) {
1441
+ //
1442
+ // withdraw
1443
+ //
1444
+ // {
1445
+ // "success": true,
1446
+ // "symbol": "BTC",
1447
+ // "amount": "1.5"
1448
+ // }
1449
+ //
1450
+ // fetchWithdrawals
1451
+ //
1452
+ // {
1453
+ // "timestamp": 1542967486256,
1454
+ // "symbol": "BTC",
1455
+ // "amount": "0.99994",
1456
+ // "address": "BitcoinAddress",
1457
+ // "paymentId": "10002653",
1458
+ // "txId": "927b3ea50c5bb52c6854152d305dfa1e27fc01d10464cf10825d96d69d235eb3",
1459
+ // "fee": "0.00006",
1460
+ // "status": "awaiting_processing"
1461
+ // }
1462
+ //
1463
+ // fetchDeposits
1464
+ //
1465
+ // {
1466
+ // "timestamp":1590492401000,
1467
+ // "symbol":"ETH",
1468
+ // "amount":"0.249825",
1469
+ // "fee":"0",
1470
+ // "status":"completed",
1471
+ // "txId":"0x5167b473fd37811f9ef22364c3d54726a859ef9d98934b3a1e11d7baa8d2c2e2"
1472
+ // }
1473
+ //
1474
+ const id = undefined;
1475
+ const timestamp = this.safeInteger (transaction, 'timestamp');
1476
+ const currencyId = this.safeString (transaction, 'symbol');
1477
+ const code = this.safeCurrencyCode (currencyId, currency);
1478
+ const status = this.parseTransactionStatus (this.safeString (transaction, 'status'));
1479
+ const amount = this.safeNumber (transaction, 'amount');
1480
+ const address = this.safeString (transaction, 'address');
1481
+ const txid = this.safeString (transaction, 'txId');
1482
+ let fee = undefined;
1483
+ const feeCost = this.safeNumber (transaction, 'fee');
1484
+ if (feeCost !== undefined) {
1485
+ fee = {
1486
+ 'cost': feeCost,
1487
+ 'currency': code,
1488
+ };
1489
+ }
1490
+ let type = undefined;
1491
+ if (('success' in transaction) || ('address' in transaction)) {
1492
+ type = 'withdrawal';
1493
+ } else {
1494
+ type = 'deposit';
1495
+ }
1496
+ const tag = this.safeString (transaction, 'paymentId');
1497
+ return {
1498
+ 'info': transaction,
1499
+ 'id': id,
1500
+ 'txid': txid,
1501
+ 'timestamp': timestamp,
1502
+ 'datetime': this.iso8601 (timestamp),
1503
+ 'addressFrom': undefined,
1504
+ 'address': address,
1505
+ 'addressTo': address,
1506
+ 'tagFrom': undefined,
1507
+ 'tag': tag,
1508
+ 'tagTo': tag,
1509
+ 'type': type,
1510
+ 'amount': amount,
1511
+ 'currency': code,
1512
+ 'status': status,
1513
+ 'updated': undefined,
1514
+ 'fee': fee,
1515
+ };
1516
+ }
1517
+
1518
+ sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
1519
+ const query = this.omit (params, this.extractParams (path));
1520
+ let url = '/' + this.version + '/' + this.implodeParams (path, params);
1521
+ const getOrDelete = (method === 'GET') || (method === 'DELETE');
1522
+ if (getOrDelete) {
1523
+ if (Object.keys (query).length) {
1524
+ url += '?' + this.urlencode (query);
1525
+ }
1526
+ }
1527
+ if (api === 'private') {
1528
+ this.checkRequiredCredentials ();
1529
+ let payload = '';
1530
+ if (!getOrDelete) {
1531
+ if (Object.keys (query).length) {
1532
+ body = this.json (query);
1533
+ payload = body;
1534
+ }
1535
+ }
1536
+ const timestamp = this.milliseconds ().toString ();
1537
+ const auth = timestamp + method + url + payload;
1538
+ const signature = this.hmac (this.encode (auth), this.encode (this.secret));
1539
+ const accessWindow = this.safeString (this.options, 'BITVAVO-ACCESS-WINDOW', '10000');
1540
+ headers = {
1541
+ 'BITVAVO-ACCESS-KEY': this.apiKey,
1542
+ 'BITVAVO-ACCESS-SIGNATURE': signature,
1543
+ 'BITVAVO-ACCESS-TIMESTAMP': timestamp,
1544
+ 'BITVAVO-ACCESS-WINDOW': accessWindow,
1545
+ };
1546
+ if (!getOrDelete) {
1547
+ headers['Content-Type'] = 'application/json';
1548
+ }
1549
+ }
1550
+ url = this.urls['api'][api] + url;
1551
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
1552
+ }
1553
+
1554
+ handleErrors (httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
1555
+ if (response === undefined) {
1556
+ return; // fallback to default error handler
1557
+ }
1558
+ //
1559
+ // {"errorCode":308,"error":"The signature length is invalid (HMAC-SHA256 should return a 64 length hexadecimal string)."}
1560
+ // {"errorCode":203,"error":"symbol parameter is required."}
1561
+ // {"errorCode":205,"error":"symbol parameter is invalid."}
1562
+ //
1563
+ const errorCode = this.safeString (response, 'errorCode');
1564
+ const error = this.safeString (response, 'error');
1565
+ if (errorCode !== undefined) {
1566
+ const feedback = this.id + ' ' + body;
1567
+ this.throwBroadlyMatchedException (this.exceptions['broad'], error, feedback);
1568
+ this.throwExactlyMatchedException (this.exceptions['exact'], errorCode, feedback);
1569
+ throw new ExchangeError (feedback); // unknown message
1570
+ }
1571
+ }
1572
+
1573
+ calculateRateLimiterCost (api, method, path, params, config = {}, context = {}) {
1574
+ if (('noMarket' in config) && !('market' in params)) {
1575
+ return config['noMarket'];
1576
+ }
1577
+ return this.safeValue (config, 'cost', 1);
1578
+ }
1579
+ };