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/itbit.js ADDED
@@ -0,0 +1,722 @@
1
+ 'use strict';
2
+
3
+ // ---------------------------------------------------------------------------
4
+
5
+ const Exchange = require ('./base/Exchange');
6
+ const { ExchangeError, AuthenticationError, ArgumentsRequired } = require ('./base/errors');
7
+ const Precise = require ('./base/Precise');
8
+
9
+ // ---------------------------------------------------------------------------
10
+
11
+ module.exports = class itbit extends Exchange {
12
+ describe () {
13
+ return this.deepExtend (super.describe (), {
14
+ 'id': 'itbit',
15
+ 'name': 'itBit',
16
+ 'countries': [ 'US' ],
17
+ 'rateLimit': 2000,
18
+ 'version': 'v1',
19
+ 'has': {
20
+ 'CORS': true,
21
+ 'spot': true,
22
+ 'margin': false,
23
+ 'swap': false,
24
+ 'future': false,
25
+ 'option': false,
26
+ 'addMargin': false,
27
+ 'cancelOrder': true,
28
+ 'createMarketOrder': undefined,
29
+ 'createOrder': true,
30
+ 'createReduceOnlyOrder': false,
31
+ 'fetchBalance': true,
32
+ 'fetchBorrowRate': false,
33
+ 'fetchBorrowRateHistories': false,
34
+ 'fetchBorrowRateHistory': false,
35
+ 'fetchBorrowRates': false,
36
+ 'fetchBorrowRatesPerSymbol': false,
37
+ 'fetchClosedOrders': true,
38
+ 'fetchFundingHistory': false,
39
+ 'fetchFundingRate': false,
40
+ 'fetchFundingRateHistory': false,
41
+ 'fetchFundingRates': false,
42
+ 'fetchIndexOHLCV': false,
43
+ 'fetchLeverage': false,
44
+ 'fetchLeverageTiers': false,
45
+ 'fetchMarkOHLCV': false,
46
+ 'fetchMyTrades': true,
47
+ 'fetchOpenOrders': true,
48
+ 'fetchOrder': true,
49
+ 'fetchOrderBook': true,
50
+ 'fetchOrders': true,
51
+ 'fetchPosition': false,
52
+ 'fetchPositions': false,
53
+ 'fetchPositionsRisk': false,
54
+ 'fetchPremiumIndexOHLCV': false,
55
+ 'fetchTicker': true,
56
+ 'fetchTrades': true,
57
+ 'fetchTradingFee': false,
58
+ 'fetchTradingFees': false,
59
+ 'fetchTransactions': true,
60
+ 'reduceMargin': false,
61
+ 'setLeverage': false,
62
+ 'setMarginMode': false,
63
+ 'setPositionMode': false,
64
+ },
65
+ 'urls': {
66
+ 'logo': 'https://user-images.githubusercontent.com/1294454/27822159-66153620-60ad-11e7-89e7-005f6d7f3de0.jpg',
67
+ 'api': 'https://api.itbit.com',
68
+ 'www': 'https://www.itbit.com',
69
+ 'doc': [
70
+ 'https://api.itbit.com/docs',
71
+ 'https://www.itbit.com/api',
72
+ ],
73
+ },
74
+ 'api': {
75
+ 'public': {
76
+ 'get': [
77
+ 'markets/{symbol}/ticker',
78
+ 'markets/{symbol}/order_book',
79
+ 'markets/{symbol}/trades',
80
+ ],
81
+ },
82
+ 'private': {
83
+ 'get': [
84
+ 'wallets',
85
+ 'wallets/{walletId}',
86
+ 'wallets/{walletId}/balances/{currencyCode}',
87
+ 'wallets/{walletId}/funding_history',
88
+ 'wallets/{walletId}/trades',
89
+ 'wallets/{walletId}/orders',
90
+ 'wallets/{walletId}/orders/{id}',
91
+ ],
92
+ 'post': [
93
+ 'wallet_transfers',
94
+ 'wallets',
95
+ 'wallets/{walletId}/cryptocurrency_deposits',
96
+ 'wallets/{walletId}/cryptocurrency_withdrawals',
97
+ 'wallets/{walletId}/orders',
98
+ 'wire_withdrawal',
99
+ ],
100
+ 'delete': [
101
+ 'wallets/{walletId}/orders/{id}',
102
+ ],
103
+ },
104
+ },
105
+ 'markets': {
106
+ 'BTC/USD': { 'id': 'XBTUSD', 'symbol': 'BTC/USD', 'base': 'BTC', 'quote': 'USD', 'baseId': 'XBT', 'quoteId': 'USD', 'type': 'spot', 'spot': true },
107
+ 'BTC/SGD': { 'id': 'XBTSGD', 'symbol': 'BTC/SGD', 'base': 'BTC', 'quote': 'SGD', 'baseId': 'XBT', 'quoteId': 'SGD', 'type': 'spot', 'spot': true },
108
+ 'BTC/EUR': { 'id': 'XBTEUR', 'symbol': 'BTC/EUR', 'base': 'BTC', 'quote': 'EUR', 'baseId': 'XBT', 'quoteId': 'EUR', 'type': 'spot', 'spot': true },
109
+ 'ETH/USD': { 'id': 'ETHUSD', 'symbol': 'ETH/USD', 'base': 'ETH', 'quote': 'USD', 'baseId': 'ETH', 'quoteId': 'USD', 'type': 'spot', 'spot': true },
110
+ 'ETH/EUR': { 'id': 'ETHEUR', 'symbol': 'ETH/EUR', 'base': 'ETH', 'quote': 'EUR', 'baseId': 'ETH', 'quoteId': 'EUR', 'type': 'spot', 'spot': true },
111
+ 'ETH/SGD': { 'id': 'ETHSGD', 'symbol': 'ETH/SGD', 'base': 'ETH', 'quote': 'SGD', 'baseId': 'ETH', 'quoteId': 'SGD', 'type': 'spot', 'spot': true },
112
+ 'PAXGUSD': { 'id': 'PAXGUSD', 'symbol': 'PAXG/USD', 'base': 'PAXG', 'quote': 'USD', 'baseId': 'PAXG', 'quoteId': 'USD', 'type': 'spot', 'spot': true },
113
+ 'BCHUSD': { 'id': 'BCHUSD', 'symbol': 'BCH/USD', 'base': 'BCH', 'quote': 'USD', 'baseId': 'BCH', 'quoteId': 'USD', 'type': 'spot', 'spot': true },
114
+ 'LTCUSD': { 'id': 'LTCUSD', 'symbol': 'LTC/USD', 'base': 'LTC', 'quote': 'USD', 'baseId': 'LTC', 'quoteId': 'USD', 'type': 'spot', 'spot': true },
115
+ },
116
+ 'fees': {
117
+ 'trading': {
118
+ 'maker': -0.03 / 100,
119
+ 'taker': 0.35 / 100,
120
+ },
121
+ },
122
+ 'commonCurrencies': {
123
+ 'XBT': 'BTC',
124
+ },
125
+ });
126
+ }
127
+
128
+ async fetchOrderBook (symbol, limit = undefined, params = {}) {
129
+ await this.loadMarkets ();
130
+ const request = {
131
+ 'symbol': this.marketId (symbol),
132
+ };
133
+ const orderbook = await this.publicGetMarketsSymbolOrderBook (this.extend (request, params));
134
+ return this.parseOrderBook (orderbook, symbol);
135
+ }
136
+
137
+ parseTicker (ticker, market = undefined) {
138
+ //
139
+ // {
140
+ // "pair":"XBTUSD",
141
+ // "bid":"36734.50",
142
+ // "bidAmt":"0.01000000",
143
+ // "ask":"36734.75",
144
+ // "askAmt":"0.30750480",
145
+ // "lastPrice":"36721.75",
146
+ // "lastAmt":"0.00070461",
147
+ // "volume24h":"275.50596346",
148
+ // "volumeToday":"118.19025141",
149
+ // "high24h":"37510.50",
150
+ // "low24h":"35542.75",
151
+ // "highToday":"37510.50",
152
+ // "lowToday":"36176.50",
153
+ // "openToday":"37156.50",
154
+ // "vwapToday":"37008.22463903",
155
+ // "vwap24h":"36580.27146808",
156
+ // "serverTimeUTC":"2022-01-28T14:46:32.4472864Z"
157
+ // }
158
+ //
159
+ const symbol = this.safeSymbol (undefined, market);
160
+ const serverTimeUTC = this.safeString (ticker, 'serverTimeUTC');
161
+ if (!serverTimeUTC) {
162
+ throw new ExchangeError (this.id + ' fetchTicker() returned a bad response: ' + this.json (ticker));
163
+ }
164
+ const timestamp = this.parse8601 (serverTimeUTC);
165
+ const vwap = this.safeString (ticker, 'vwap24h');
166
+ const baseVolume = this.safeString (ticker, 'volume24h');
167
+ const quoteVolume = Precise.stringMul (baseVolume, vwap);
168
+ const last = this.safeString (ticker, 'lastPrice');
169
+ return this.safeTicker ({
170
+ 'symbol': symbol,
171
+ 'timestamp': timestamp,
172
+ 'datetime': this.iso8601 (timestamp),
173
+ 'high': this.safeString (ticker, 'high24h'),
174
+ 'low': this.safeString (ticker, 'low24h'),
175
+ 'bid': this.safeString (ticker, 'bid'),
176
+ 'bidVolume': undefined,
177
+ 'ask': this.safeString (ticker, 'ask'),
178
+ 'askVolume': undefined,
179
+ 'vwap': vwap,
180
+ 'open': this.safeString (ticker, 'openToday'),
181
+ 'close': last,
182
+ 'last': last,
183
+ 'previousClose': undefined,
184
+ 'change': undefined,
185
+ 'percentage': undefined,
186
+ 'average': undefined,
187
+ 'baseVolume': baseVolume,
188
+ 'quoteVolume': quoteVolume,
189
+ 'info': ticker,
190
+ }, market, false);
191
+ }
192
+
193
+ async fetchTicker (symbol, params = {}) {
194
+ await this.loadMarkets ();
195
+ const market = this.market (symbol);
196
+ const request = {
197
+ 'symbol': market['id'],
198
+ };
199
+ const ticker = await this.publicGetMarketsSymbolTicker (this.extend (request, params));
200
+ //
201
+ // {
202
+ // "pair":"XBTUSD",
203
+ // "bid":"36734.50",
204
+ // "bidAmt":"0.01000000",
205
+ // "ask":"36734.75",
206
+ // "askAmt":"0.30750480",
207
+ // "lastPrice":"36721.75",
208
+ // "lastAmt":"0.00070461",
209
+ // "volume24h":"275.50596346",
210
+ // "volumeToday":"118.19025141",
211
+ // "high24h":"37510.50",
212
+ // "low24h":"35542.75",
213
+ // "highToday":"37510.50",
214
+ // "lowToday":"36176.50",
215
+ // "openToday":"37156.50",
216
+ // "vwapToday":"37008.22463903",
217
+ // "vwap24h":"36580.27146808",
218
+ // "serverTimeUTC":"2022-01-28T14:46:32.4472864Z"
219
+ // }
220
+ //
221
+ return this.parseTicker (ticker, market);
222
+ }
223
+
224
+ parseTrade (trade, market = undefined) {
225
+ //
226
+ // fetchTrades (public)
227
+ //
228
+ // {
229
+ // timestamp: "2015-05-22T17:45:34.7570000Z",
230
+ // matchNumber: "5CR1JEUBBM8J",
231
+ // price: "351.45000000",
232
+ // amount: "0.00010000"
233
+ // }
234
+ //
235
+ // fetchMyTrades (private)
236
+ //
237
+ // {
238
+ // "orderId": "248ffda4-83a0-4033-a5bb-8929d523f59f",
239
+ // "timestamp": "2015-05-11T14:48:01.9870000Z",
240
+ // "instrument": "XBTUSD",
241
+ // "direction": "buy", // buy or sell
242
+ // "currency1": "XBT", // base currency
243
+ // "currency1Amount": "0.00010000", // order amount in base currency
244
+ // "currency2": "USD", // quote currency
245
+ // "currency2Amount": "0.0250530000000000", // order cost in quote currency
246
+ // "rate": "250.53000000",
247
+ // "commissionPaid": "0.00000000", // net trade fee paid after using any available rebate balance
248
+ // "commissionCurrency": "USD",
249
+ // "rebatesApplied": "-0.000125265", // negative values represent amount of rebate balance used for trades removing liquidity from order book; positive values represent amount of rebate balance earned from trades adding liquidity to order book
250
+ // "rebateCurrency": "USD",
251
+ // "executionId": "23132"
252
+ // }
253
+ //
254
+ const id = this.safeString2 (trade, 'executionId', 'matchNumber');
255
+ const timestamp = this.parse8601 (this.safeString (trade, 'timestamp'));
256
+ const side = this.safeString (trade, 'direction');
257
+ const orderId = this.safeString (trade, 'orderId');
258
+ let feeCost = this.safeNumber (trade, 'commissionPaid');
259
+ const feeCurrencyId = this.safeString (trade, 'commissionCurrency');
260
+ const feeCurrency = this.safeCurrencyCode (feeCurrencyId);
261
+ let rebatesApplied = this.safeNumber (trade, 'rebatesApplied');
262
+ if (rebatesApplied !== undefined) {
263
+ rebatesApplied = -rebatesApplied;
264
+ }
265
+ const rebateCurrencyId = this.safeString (trade, 'rebateCurrency');
266
+ const rebateCurrency = this.safeCurrencyCode (rebateCurrencyId);
267
+ const priceString = this.safeString2 (trade, 'price', 'rate');
268
+ const amountString = this.safeString2 (trade, 'currency1Amount', 'amount');
269
+ const price = this.parseNumber (priceString);
270
+ const amount = this.parseNumber (amountString);
271
+ const cost = this.parseNumber (Precise.stringMul (priceString, amountString));
272
+ let symbol = undefined;
273
+ const marketId = this.safeString (trade, 'instrument');
274
+ if (marketId !== undefined) {
275
+ if (marketId in this.markets_by_id) {
276
+ market = this.markets_by_id[marketId];
277
+ } else {
278
+ const baseId = this.safeString (trade, 'currency1');
279
+ const quoteId = this.safeString (trade, 'currency2');
280
+ const base = this.safeCurrencyCode (baseId);
281
+ const quote = this.safeCurrencyCode (quoteId);
282
+ symbol = base + '/' + quote;
283
+ }
284
+ }
285
+ if (symbol === undefined) {
286
+ if (market !== undefined) {
287
+ symbol = market['symbol'];
288
+ }
289
+ }
290
+ const result = {
291
+ 'info': trade,
292
+ 'id': id,
293
+ 'timestamp': timestamp,
294
+ 'datetime': this.iso8601 (timestamp),
295
+ 'symbol': symbol,
296
+ 'order': orderId,
297
+ 'type': undefined,
298
+ 'side': side,
299
+ 'takerOrMaker': undefined,
300
+ 'price': price,
301
+ 'amount': amount,
302
+ 'cost': cost,
303
+ 'fee': undefined,
304
+ };
305
+ if (feeCost !== undefined) {
306
+ if (rebatesApplied !== undefined) {
307
+ if (feeCurrency === rebateCurrency) {
308
+ feeCost = this.sum (feeCost, rebatesApplied);
309
+ result['fee'] = {
310
+ 'cost': feeCost,
311
+ 'currency': feeCurrency,
312
+ };
313
+ } else {
314
+ result['fees'] = [
315
+ {
316
+ 'cost': feeCost,
317
+ 'currency': feeCurrency,
318
+ },
319
+ {
320
+ 'cost': rebatesApplied,
321
+ 'currency': rebateCurrency,
322
+ },
323
+ ];
324
+ }
325
+ } else {
326
+ result['fee'] = {
327
+ 'cost': feeCost,
328
+ 'currency': feeCurrency,
329
+ };
330
+ }
331
+ }
332
+ if (!('fee' in result)) {
333
+ if (!('fees' in result)) {
334
+ result['fee'] = undefined;
335
+ }
336
+ }
337
+ return result;
338
+ }
339
+
340
+ async fetchTransactions (code = undefined, since = undefined, limit = undefined, params = {}) {
341
+ await this.loadMarkets ();
342
+ const walletId = this.safeString (params, 'walletId');
343
+ if (walletId === undefined) {
344
+ throw new ArgumentsRequired (this.id + ' fetchMyTrades() requires a walletId parameter');
345
+ }
346
+ const request = {
347
+ 'walletId': walletId,
348
+ };
349
+ if (limit !== undefined) {
350
+ request['perPage'] = limit; // default 50, max 50
351
+ }
352
+ const response = await this.privateGetWalletsWalletIdFundingHistory (this.extend (request, params));
353
+ // { bankName: 'USBC (usd)',
354
+ // withdrawalId: 94740,
355
+ // holdingPeriodCompletionDate: '2018-04-16T07:57:05.9606869',
356
+ // time: '2018-04-16T07:57:05.9600000',
357
+ // currency: 'USD',
358
+ // transactionType: 'Withdrawal',
359
+ // amount: '2186.72000000',
360
+ // walletName: 'Wallet',
361
+ // status: 'completed' },
362
+ //
363
+ // { "time": "2018-01-02T19:52:22.4176503",
364
+ // "amount": "0.50000000",
365
+ // "status": "completed",
366
+ // "txnHash": "1b6fff67ed83cb9e9a38ca4976981fc047322bc088430508fe764a127d3ace95",
367
+ // "currency": "XBT",
368
+ // "walletName": "Wallet",
369
+ // "transactionType": "Deposit",
370
+ // "destinationAddress": "3AAWTH9et4e8o51YKp9qPpmujrNXKwHWNX"}
371
+ const items = response['fundingHistory'];
372
+ const result = [];
373
+ for (let i = 0; i < items.length; i++) {
374
+ const item = items[i];
375
+ const time = this.safeString (item, 'time');
376
+ const timestamp = this.parse8601 (time);
377
+ const currency = this.safeString (item, 'currency');
378
+ const destinationAddress = this.safeString (item, 'destinationAddress');
379
+ const txnHash = this.safeString (item, 'txnHash');
380
+ const transactionType = this.safeStringLower (item, 'transactionType');
381
+ const transactionStatus = this.safeString (item, 'status');
382
+ const status = this.parseTransferStatus (transactionStatus);
383
+ result.push ({
384
+ 'id': this.safeString (item, 'withdrawalId'),
385
+ 'timestamp': timestamp,
386
+ 'datetime': this.iso8601 (timestamp),
387
+ 'currency': this.safeCurrencyCode (currency),
388
+ 'address': destinationAddress,
389
+ 'tag': undefined,
390
+ 'txid': txnHash,
391
+ 'type': transactionType,
392
+ 'status': status,
393
+ 'amount': this.safeNumber (item, 'amount'),
394
+ 'fee': undefined,
395
+ 'info': item,
396
+ });
397
+ }
398
+ return result;
399
+ }
400
+
401
+ parseTransferStatus (status) {
402
+ const options = {
403
+ 'cancelled': 'canceled',
404
+ 'completed': 'ok',
405
+ };
406
+ return this.safeString (options, status, 'pending');
407
+ }
408
+
409
+ async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
410
+ await this.loadMarkets ();
411
+ const walletId = this.safeString (params, 'walletId');
412
+ if (walletId === undefined) {
413
+ throw new ExchangeError (this.id + ' fetchMyTrades() requires a walletId parameter');
414
+ }
415
+ const request = {
416
+ 'walletId': walletId,
417
+ };
418
+ if (since !== undefined) {
419
+ request['rangeStart'] = this.ymdhms (since, 'T');
420
+ }
421
+ if (limit !== undefined) {
422
+ request['perPage'] = limit; // default 50, max 50
423
+ }
424
+ const response = await this.privateGetWalletsWalletIdTrades (this.extend (request, params));
425
+ //
426
+ // {
427
+ // "totalNumberOfRecords": "2",
428
+ // "currentPageNumber": "1",
429
+ // "latestExecutionId": "332", // most recent execution at time of response
430
+ // "recordsPerPage": "50",
431
+ // "tradingHistory": [
432
+ // {
433
+ // "orderId": "248ffda4-83a0-4033-a5bb-8929d523f59f",
434
+ // "timestamp": "2015-05-11T14:48:01.9870000Z",
435
+ // "instrument": "XBTUSD",
436
+ // "direction": "buy", // buy or sell
437
+ // "currency1": "XBT", // base currency
438
+ // "currency1Amount": "0.00010000", // order amount in base currency
439
+ // "currency2": "USD", // quote currency
440
+ // "currency2Amount": "0.0250530000000000", // order cost in quote currency
441
+ // "rate": "250.53000000",
442
+ // "commissionPaid": "0.00000000", // net trade fee paid after using any available rebate balance
443
+ // "commissionCurrency": "USD",
444
+ // "rebatesApplied": "-0.000125265", // negative values represent amount of rebate balance used for trades removing liquidity from order book; positive values represent amount of rebate balance earned from trades adding liquidity to order book
445
+ // "rebateCurrency": "USD",
446
+ // "executionId": "23132"
447
+ // },
448
+ // ],
449
+ // }
450
+ //
451
+ const trades = this.safeValue (response, 'tradingHistory', []);
452
+ let market = undefined;
453
+ if (symbol !== undefined) {
454
+ market = this.market (symbol);
455
+ }
456
+ return this.parseTrades (trades, market, since, limit);
457
+ }
458
+
459
+ async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
460
+ await this.loadMarkets ();
461
+ const market = this.market (symbol);
462
+ const request = {
463
+ 'symbol': market['id'],
464
+ };
465
+ const response = await this.publicGetMarketsSymbolTrades (this.extend (request, params));
466
+ //
467
+ // {
468
+ // count: 3,
469
+ // recentTrades: [
470
+ // {
471
+ // timestamp: "2015-05-22T17:45:34.7570000Z",
472
+ // matchNumber: "5CR1JEUBBM8J",
473
+ // price: "351.45000000",
474
+ // amount: "0.00010000"
475
+ // },
476
+ // ]
477
+ // }
478
+ //
479
+ const trades = this.safeValue (response, 'recentTrades', []);
480
+ return this.parseTrades (trades, market, since, limit);
481
+ }
482
+
483
+ parseBalance (response) {
484
+ const balances = response[0]['balances'];
485
+ const result = { 'info': response };
486
+ for (let i = 0; i < balances.length; i++) {
487
+ const balance = balances[i];
488
+ const currencyId = this.safeString (balance, 'currency');
489
+ const code = this.safeCurrencyCode (currencyId);
490
+ const account = this.account ();
491
+ account['free'] = this.safeString (balance, 'availableBalance');
492
+ account['total'] = this.safeString (balance, 'totalBalance');
493
+ result[code] = account;
494
+ }
495
+ return this.safeBalance (result);
496
+ }
497
+
498
+ async fetchBalance (params = {}) {
499
+ await this.loadMarkets ();
500
+ const response = await this.fetchWallets (params);
501
+ return this.parseBalance (response);
502
+ }
503
+
504
+ async fetchWallets (params = {}) {
505
+ await this.loadMarkets ();
506
+ if (!this.uid) {
507
+ throw new AuthenticationError (this.id + ' fetchWallets() requires uid API credential');
508
+ }
509
+ const request = {
510
+ 'userId': this.uid,
511
+ };
512
+ return await this.privateGetWallets (this.extend (request, params));
513
+ }
514
+
515
+ async fetchWallet (walletId, params = {}) {
516
+ await this.loadMarkets ();
517
+ const request = {
518
+ 'walletId': walletId,
519
+ };
520
+ return await this.privateGetWalletsWalletId (this.extend (request, params));
521
+ }
522
+
523
+ async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
524
+ const request = {
525
+ 'status': 'open',
526
+ };
527
+ return await this.fetchOrders (symbol, since, limit, this.extend (request, params));
528
+ }
529
+
530
+ async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
531
+ const request = {
532
+ 'status': 'filled',
533
+ };
534
+ return await this.fetchOrders (symbol, since, limit, this.extend (request, params));
535
+ }
536
+
537
+ async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
538
+ await this.loadMarkets ();
539
+ let market = undefined;
540
+ if (symbol !== undefined) {
541
+ market = this.market (symbol);
542
+ }
543
+ const walletIdInParams = ('walletId' in params);
544
+ if (!walletIdInParams) {
545
+ throw new ExchangeError (this.id + ' fetchOrders() requires a walletId parameter');
546
+ }
547
+ const walletId = params['walletId'];
548
+ const request = {
549
+ 'walletId': walletId,
550
+ };
551
+ const response = await this.privateGetWalletsWalletIdOrders (this.extend (request, params));
552
+ return this.parseOrders (response, market, since, limit);
553
+ }
554
+
555
+ parseOrderStatus (status) {
556
+ const statuses = {
557
+ 'submitted': 'open', // order pending book entry
558
+ 'open': 'open',
559
+ 'filled': 'closed',
560
+ 'cancelled': 'canceled',
561
+ 'rejected': 'canceled',
562
+ };
563
+ return this.safeString (statuses, status, status);
564
+ }
565
+
566
+ parseOrder (order, market = undefined) {
567
+ //
568
+ // {
569
+ // "id": "13d6af57-8b0b-41e5-af30-becf0bcc574d",
570
+ // "walletId": "7e037345-1288-4c39-12fe-d0f99a475a98",
571
+ // "side": "buy",
572
+ // "instrument": "XBTUSD",
573
+ // "type": "limit",
574
+ // "currency": "XBT",
575
+ // "amount": "2.50000000",
576
+ // "displayAmount": "2.50000000",
577
+ // "price": "650.00000000",
578
+ // "volumeWeightedAveragePrice": "0.00000000",
579
+ // "amountFilled": "0.00000000",
580
+ // "createdTime": "2014-02-11T17:05:15Z",
581
+ // "status": "submitted",
582
+ // "funds": null,
583
+ // "metadata": {},
584
+ // "clientOrderIdentifier": null,
585
+ // "postOnly": "False"
586
+ // }
587
+ //
588
+ const side = this.safeString (order, 'side');
589
+ const type = this.safeString (order, 'type');
590
+ const symbol = this.markets_by_id[order['instrument']]['symbol'];
591
+ const timestamp = this.parse8601 (order['createdTime']);
592
+ const amount = this.safeString (order, 'amount');
593
+ const filled = this.safeString (order, 'amountFilled');
594
+ const fee = undefined;
595
+ const price = this.safeString (order, 'price');
596
+ const average = this.safeString (order, 'volumeWeightedAveragePrice');
597
+ const clientOrderId = this.safeString (order, 'clientOrderIdentifier');
598
+ const id = this.safeString (order, 'id');
599
+ const postOnlyString = this.safeString (order, 'postOnly');
600
+ const postOnly = (postOnlyString === 'True');
601
+ return this.safeOrder ({
602
+ 'id': id,
603
+ 'clientOrderId': clientOrderId,
604
+ 'info': order,
605
+ 'timestamp': timestamp,
606
+ 'datetime': this.iso8601 (timestamp),
607
+ 'lastTradeTimestamp': undefined,
608
+ 'status': this.parseOrderStatus (this.safeString (order, 'status')),
609
+ 'symbol': symbol,
610
+ 'type': type,
611
+ 'timeInForce': undefined,
612
+ 'postOnly': postOnly,
613
+ 'side': side,
614
+ 'price': price,
615
+ 'stopPrice': undefined,
616
+ 'cost': undefined,
617
+ 'average': average,
618
+ 'amount': amount,
619
+ 'filled': filled,
620
+ 'remaining': undefined,
621
+ 'fee': fee,
622
+ // 'trades': this.parseTrades (order['trades'], market),
623
+ 'trades': undefined,
624
+ }, market);
625
+ }
626
+
627
+ nonce () {
628
+ return this.milliseconds ();
629
+ }
630
+
631
+ async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
632
+ await this.loadMarkets ();
633
+ if (type === 'market') {
634
+ throw new ExchangeError (this.id + ' createOrder() allows limit orders only');
635
+ }
636
+ const walletIdInParams = ('walletId' in params);
637
+ if (!walletIdInParams) {
638
+ throw new ExchangeError (this.id + ' createOrder() requires a walletId parameter');
639
+ }
640
+ amount = amount.toString ();
641
+ price = price.toString ();
642
+ const market = this.market (symbol);
643
+ const request = {
644
+ 'side': side,
645
+ 'type': type,
646
+ 'currency': market['id'].replace (market['quote'], ''),
647
+ 'amount': amount,
648
+ 'display': amount,
649
+ 'price': price,
650
+ 'instrument': market['id'],
651
+ };
652
+ const response = await this.privatePostWalletsWalletIdOrders (this.extend (request, params));
653
+ return {
654
+ 'info': response,
655
+ 'id': response['id'],
656
+ };
657
+ }
658
+
659
+ async fetchOrder (id, symbol = undefined, params = {}) {
660
+ await this.loadMarkets ();
661
+ const walletIdInParams = ('walletId' in params);
662
+ if (!walletIdInParams) {
663
+ throw new ExchangeError (this.id + ' fetchOrder() requires a walletId parameter');
664
+ }
665
+ const request = {
666
+ 'id': id,
667
+ };
668
+ const response = await this.privateGetWalletsWalletIdOrdersId (this.extend (request, params));
669
+ return this.parseOrder (response);
670
+ }
671
+
672
+ async cancelOrder (id, symbol = undefined, params = {}) {
673
+ const walletIdInParams = ('walletId' in params);
674
+ if (!walletIdInParams) {
675
+ throw new ExchangeError (this.id + ' cancelOrder() requires a walletId parameter');
676
+ }
677
+ const request = {
678
+ 'id': id,
679
+ };
680
+ return await this.privateDeleteWalletsWalletIdOrdersId (this.extend (request, params));
681
+ }
682
+
683
+ sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
684
+ let url = this.urls['api'] + '/' + this.version + '/' + this.implodeParams (path, params);
685
+ const query = this.omit (params, this.extractParams (path));
686
+ if (method === 'GET' && Object.keys (query).length) {
687
+ url += '?' + this.urlencode (query);
688
+ }
689
+ if (method === 'POST' && Object.keys (query).length) {
690
+ body = this.json (query);
691
+ }
692
+ if (api === 'private') {
693
+ this.checkRequiredCredentials ();
694
+ const nonce = this.nonce ().toString ();
695
+ const timestamp = nonce;
696
+ const authBody = (method === 'POST') ? body : '';
697
+ const auth = [ method, url, authBody, nonce, timestamp ];
698
+ const message = nonce + this.json (auth).replace ('\\/', '/');
699
+ const hash = this.hash (this.encode (message), 'sha256', 'binary');
700
+ const binaryUrl = this.stringToBinary (this.encode (url));
701
+ const binhash = this.binaryConcat (binaryUrl, hash);
702
+ const signature = this.hmac (binhash, this.encode (this.secret), 'sha512', 'base64');
703
+ headers = {
704
+ 'Authorization': this.apiKey + ':' + signature,
705
+ 'Content-Type': 'application/json',
706
+ 'X-Auth-Timestamp': timestamp,
707
+ 'X-Auth-Nonce': nonce,
708
+ };
709
+ }
710
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
711
+ }
712
+
713
+ handleErrors (httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
714
+ if (response === undefined) {
715
+ return;
716
+ }
717
+ const code = this.safeString (response, 'code');
718
+ if (code !== undefined) {
719
+ throw new ExchangeError (this.id + ' ' + this.json (response));
720
+ }
721
+ }
722
+ };