ccxt 4.2.73 → 4.2.74

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 (267) hide show
  1. package/README.md +5 -5
  2. package/build.sh +1 -1
  3. package/dist/ccxt.browser.js +181 -100
  4. package/dist/ccxt.browser.min.js +2 -2
  5. package/dist/cjs/ccxt.js +1 -1
  6. package/dist/cjs/src/base/Exchange.js +1 -1
  7. package/dist/cjs/src/bitget.js +62 -50
  8. package/dist/cjs/src/bybit.js +90 -30
  9. package/dist/cjs/src/coinbaseinternational.js +1 -1
  10. package/dist/cjs/src/htx.js +16 -9
  11. package/dist/cjs/src/hyperliquid.js +2 -1
  12. package/dist/cjs/src/pro/krakenfutures.js +8 -7
  13. package/examples/README.md +308 -0
  14. package/examples/ccxt.pro/html/watchTicker.html +51 -0
  15. package/examples/ccxt.pro/js/binance-fetch-balance-snapshot-watch-balance-updates.js +55 -0
  16. package/examples/ccxt.pro/js/binance-https-proxy.js +48 -0
  17. package/examples/ccxt.pro/js/binance-watch-ohlcv-many-symbols-continuously.js +38 -0
  18. package/examples/ccxt.pro/js/binance-watch-ohlcv-many-symbols.js +64 -0
  19. package/examples/ccxt.pro/js/binance-watch-ticker-many-symbols.js +62 -0
  20. package/examples/ccxt.pro/js/build-ohlcv-many-symbols.js +68 -0
  21. package/examples/ccxt.pro/js/calculate-ohlcvs-from-trades-warmup.js +82 -0
  22. package/examples/ccxt.pro/js/calculate-ohlcvs-from-trades.js +59 -0
  23. package/examples/ccxt.pro/js/exchange-capabitities.js +72 -0
  24. package/examples/ccxt.pro/js/exchange-close.js +46 -0
  25. package/examples/ccxt.pro/js/gateio-swap-watch-many-orderbooks.js +30 -0
  26. package/examples/ccxt.pro/js/gateio-watch-balance.js +23 -0
  27. package/examples/ccxt.pro/js/gateio-watch-order-book.js +71 -0
  28. package/examples/ccxt.pro/js/graceful-shutdown.js +43 -0
  29. package/examples/ccxt.pro/js/many-exchanges-many-streams.js +37 -0
  30. package/examples/ccxt.pro/js/okex-create-futures-order.js +48 -0
  31. package/examples/ccxt.pro/js/okex-watch-balance-and-create-order.js +54 -0
  32. package/examples/ccxt.pro/js/okx-watch-tickers.js +31 -0
  33. package/examples/ccxt.pro/js/one-exchange-many-different-streams.js +46 -0
  34. package/examples/ccxt.pro/js/one-exchange-many-streams-2.js +26 -0
  35. package/examples/ccxt.pro/js/one-exchange-many-streams.js +28 -0
  36. package/examples/ccxt.pro/js/socks-binance-watch-orderbook.js +30 -0
  37. package/examples/ccxt.pro/js/watch-fetch-many-exchanges-many-ordersbooks.js +40 -0
  38. package/examples/ccxt.pro/js/watch-many-exchanges-many-ordersbooks.js +38 -0
  39. package/examples/ccxt.pro/js/watch-many-exchanges-many-symbols.js +40 -0
  40. package/examples/ccxt.pro/js/watch-many-orderbooks.js +27 -0
  41. package/examples/ccxt.pro/js/watch-new-trades-only.js +43 -0
  42. package/examples/ccxt.pro/js/watch-new-trades.js +42 -0
  43. package/examples/ccxt.pro/js/watch-trades-many-symbols.js +29 -0
  44. package/examples/ccxt.pro/js/watch-vs-fetch.js +29 -0
  45. package/examples/cs/Examples.sln +22 -0
  46. package/examples/cs/c#.csproj +19 -0
  47. package/examples/html/basic-cors-proxy.html +46 -0
  48. package/examples/html/basic-inheritance.html +47 -0
  49. package/examples/html/basic-poller.html +52 -0
  50. package/examples/html/basic-rate-limiting.html +49 -0
  51. package/examples/html/basic.html +43 -0
  52. package/examples/html/binance-cors-proxy.html +28 -0
  53. package/examples/html/bitmex-browser-cors-proxy.js +7 -0
  54. package/examples/html/bitmex-cors.html +46 -0
  55. package/examples/html/tradingview-charts.html +61 -0
  56. package/examples/html/webworker/index.html +97 -0
  57. package/examples/html/webworker/worker.js +43 -0
  58. package/examples/js/README.md +15 -0
  59. package/examples/js/advanced-error-handling.js +39 -0
  60. package/examples/js/aggregate-orderbook.js +54 -0
  61. package/examples/js/arbitrage-pairs.js +130 -0
  62. package/examples/js/basic-chart.js +29 -0
  63. package/examples/js/basic-orderbook-polling.js +13 -0
  64. package/examples/js/bcc-vs-bch.js +115 -0
  65. package/examples/js/binance-fetch-all-deposits.js +45 -0
  66. package/examples/js/binance-fetch-ohlcv-many-symbols-async-await.js +34 -0
  67. package/examples/js/binance-fetch-ohlcv-many-symbols-promise-then-callbacks.js +33 -0
  68. package/examples/js/binance-fetchTicker-delivery-vs-future.js +31 -0
  69. package/examples/js/binance-futures-transfer-from-sub-account-to-master.js +41 -0
  70. package/examples/js/binance-margin-stop-order.js +39 -0
  71. package/examples/js/binance-server-time.js +34 -0
  72. package/examples/js/binance-universal-transfer.js +16 -0
  73. package/examples/js/bitfinex-fetch-trades.js +35 -0
  74. package/examples/js/bitfinex2-fetch-trades.js +35 -0
  75. package/examples/js/bitmex-browser-cors-proxy.js +7 -0
  76. package/examples/js/bitpanda-fetchMyTrades-reduce.js +36 -0
  77. package/examples/js/bitrue-fetch-balance.js +28 -0
  78. package/examples/js/bitstamp-private-api.js +115 -0
  79. package/examples/js/bitstamp-public-api.js +39 -0
  80. package/examples/js/bittrex-balance.js +50 -0
  81. package/examples/js/bittrex-fetch-closed-orders-history.js +69 -0
  82. package/examples/js/blockchaincom-withdrawal.js +59 -0
  83. package/examples/js/build-ohlcv-bars.js +48 -0
  84. package/examples/js/builtin-rate-limiting-rest-poller.js +25 -0
  85. package/examples/js/bybit-trailing.js +62 -0
  86. package/examples/js/bybit-updated.cjs +154 -0
  87. package/examples/js/cli.js +405 -0
  88. package/examples/js/coinbase-fetch-all-balances.js +36 -0
  89. package/examples/js/coinex-fetch-all-deposit-addresses-using-fetchDepositAddress.js +47 -0
  90. package/examples/js/coinex-futures.js +75 -0
  91. package/examples/js/coinone-fetch-tickers.js +54 -0
  92. package/examples/js/coinone-markets.js +16 -0
  93. package/examples/js/compare-two-exchanges-capabilities.js +36 -0
  94. package/examples/js/cors-proxy.js +5 -0
  95. package/examples/js/create-order-handle-errors.js +55 -0
  96. package/examples/js/create-order-position-with-takeprofit-stoploss.js +71 -0
  97. package/examples/js/create-order-with-retry.js +65 -0
  98. package/examples/js/create-order-ws-example.js +25 -0
  99. package/examples/js/create-orders-example.js +17 -0
  100. package/examples/js/create-trailing-amount-order.js +36 -0
  101. package/examples/js/create-trailing-percent-order.js +36 -0
  102. package/examples/js/credentials.json +5 -0
  103. package/examples/js/custom-proxy-agent-for-js.js +10 -0
  104. package/examples/js/custom-proxy-url.js +23 -0
  105. package/examples/js/delta-maintenance-margin-rate-max-leverage.js +60 -0
  106. package/examples/js/env-variables.js +26 -0
  107. package/examples/js/error-handling.js +89 -0
  108. package/examples/js/exchange-capabilities.js +135 -0
  109. package/examples/js/exchanges-by-volume.js +60 -0
  110. package/examples/js/exchanges.js +40 -0
  111. package/examples/js/fetch-all-balances.js +219 -0
  112. package/examples/js/fetch-all-tickers-to-files-2.js +53 -0
  113. package/examples/js/fetch-all-tickers-to-files.js +77 -0
  114. package/examples/js/fetch-balance.js +28 -0
  115. package/examples/js/fetch-create-deposit-address.js +101 -0
  116. package/examples/js/fetch-from-many-exchanges-simultaneously.js +21 -0
  117. package/examples/js/fetch-funding-rate-history.js +25 -0
  118. package/examples/js/fetch-futures/prettier.config.js +5 -0
  119. package/examples/js/fetch-futures/src/index.js +25 -0
  120. package/examples/js/fetch-ohlcv-from-to-mark-index-premium.js +72 -0
  121. package/examples/js/fetch-ohlcv-many-exchanges-continuosly.js +39 -0
  122. package/examples/js/fetch-ohlcv.js +16 -0
  123. package/examples/js/fetch-okex-futures.js +22 -0
  124. package/examples/js/fetch-orders.js +27 -0
  125. package/examples/js/fetch-ticker-from-multiple-exchanges.js +35 -0
  126. package/examples/js/fetch-ticker-where-available.js +75 -0
  127. package/examples/js/fetch-tickers/build/index.js +19 -0
  128. package/examples/js/fetch-tickers/prettier.config.js +5 -0
  129. package/examples/js/fetch-tickers/src/index.js +17 -0
  130. package/examples/js/gateio-create-batch-order.js +43 -0
  131. package/examples/js/gateio-futures.js +49 -0
  132. package/examples/js/gateio-open-close-contract.js +49 -0
  133. package/examples/js/gateio-swaps.js +74 -0
  134. package/examples/js/gdax-fetch-trades-pagination.js +29 -0
  135. package/examples/js/hitbtc2-withdraw.js +61 -0
  136. package/examples/js/how-to-import-one-exchange-esm.js +10 -0
  137. package/examples/js/huobi-futures.js +71 -0
  138. package/examples/js/huobi-open-close-contract.js +63 -0
  139. package/examples/js/huobi-swaps.js +70 -0
  140. package/examples/js/huobipro-market-buy-sell-fetch-trading-limits.js +98 -0
  141. package/examples/js/hybridCJSExample.cjs +19 -0
  142. package/examples/js/hybridESMExample.js +19 -0
  143. package/examples/js/idex-fetch-balance.js +13 -0
  144. package/examples/js/instantiate-all-at-once.js +46 -0
  145. package/examples/js/instantiate-all-from-json.js +31 -0
  146. package/examples/js/kraken-create-and-close-position.js +54 -0
  147. package/examples/js/kraken-fetch-order-trades.js +33 -0
  148. package/examples/js/kraken-margin-trading.js +89 -0
  149. package/examples/js/kucoin-rate-limit.js +38 -0
  150. package/examples/js/latoken-example.js +108 -0
  151. package/examples/js/live-orderbook.js +106 -0
  152. package/examples/js/live-ticker.js +80 -0
  153. package/examples/js/live-tickers.js +74 -0
  154. package/examples/js/load-all-contracts.js +41 -0
  155. package/examples/js/load-all-symbols-at-once.js +69 -0
  156. package/examples/js/load-all-tickers-at-once.js +91 -0
  157. package/examples/js/load-markets-to-files.js +57 -0
  158. package/examples/js/looping-over-all-symbols-of-specific-exchanges.js +61 -0
  159. package/examples/js/looping-over-specific-symbols-of-all-exchanges.js +91 -0
  160. package/examples/js/margin-loan-borrow-buy-sell-repay.js +70 -0
  161. package/examples/js/market-status-and-currency-status.js +29 -0
  162. package/examples/js/ohlcv-console-chart.js +29 -0
  163. package/examples/js/okex-fetch-closed-orders-archive.js +31 -0
  164. package/examples/js/okex-transfer.js +51 -0
  165. package/examples/js/okx-poll-fetch-my-trades.js +37 -0
  166. package/examples/js/okx-poll-rate-limit.js +48 -0
  167. package/examples/js/order-book-extra-level-depth-param.js +20 -0
  168. package/examples/js/phemex-create-order-position-with-takeprofit-stoploss.js +49 -0
  169. package/examples/js/poll-ohlcv.js +43 -0
  170. package/examples/js/poloniex-fetch-order-books.js +35 -0
  171. package/examples/js/poloniex-limits-amount-min.js +62 -0
  172. package/examples/js/proxy-round-robin.js +98 -0
  173. package/examples/js/proxy-usage.js +32 -0
  174. package/examples/js/sample-local-proxy-server-with-cors.js +12 -0
  175. package/examples/js/search-all-exchanges.js +159 -0
  176. package/examples/js/shared-load-markets.js +80 -0
  177. package/examples/js/sort-swap-markets-by-hourly-price-change.js +55 -0
  178. package/examples/js/symbols.js +110 -0
  179. package/examples/js/theocean.js +41 -0
  180. package/examples/js/tickers.js +106 -0
  181. package/examples/js/validate-paginated-data.js +61 -0
  182. package/examples/js/watch-OHLCV-For-Symbols.js +15 -0
  183. package/examples/js/watch-OHLCV.js +12 -0
  184. package/examples/js/watch-OrderBook-For-Symbols.js +11 -0
  185. package/examples/js/watch-Trades-For-Symbols.js +11 -0
  186. package/examples/js/watch-tickers.js +11 -0
  187. package/examples/js/watchOHLCVForSymbols.js +15 -0
  188. package/examples/js/watchOrderBookForSymbols.js +11 -0
  189. package/examples/js/watchPositions-many-exchanges-continuosly.d.ts +2 -0
  190. package/examples/js/watchPositions-many-exchanges-continuosly.d.ts.map +1 -0
  191. package/examples/js/watchPositions-many-exchanges-continuosly.js +49 -0
  192. package/examples/js/watchPositions.d.ts +2 -0
  193. package/examples/js/watchPositions.d.ts.map +1 -0
  194. package/examples/js/watchPositions.js +13 -0
  195. package/examples/js/watchPositionsForSymbols.d.ts +2 -0
  196. package/examples/js/watchPositionsForSymbols.d.ts.map +1 -0
  197. package/examples/js/watchPositionsForSymbols.js +14 -0
  198. package/examples/js/watchTradesForSymbols.js +11 -0
  199. package/examples/js/withdraw-from-one-exchange-to-another.js +50 -0
  200. package/examples/php/README.md +7 -0
  201. package/examples/py/README.md +15 -0
  202. package/examples/py/playing_with_ccxt_example.ipynb +222 -0
  203. package/examples/ts/.eslintrc +111 -0
  204. package/examples/ts/build-ohlcv-bars.ts +53 -0
  205. package/examples/ts/cli.ts +397 -0
  206. package/examples/ts/compare-two-exchanges-capabilities.ts +36 -0
  207. package/examples/ts/create-order-position-with-takeprofit-stoploss.ts +89 -0
  208. package/examples/ts/create-order-ws-example.ts +33 -0
  209. package/examples/ts/create-orders-example.ts +21 -0
  210. package/examples/ts/create-trailing-amount-order.ts +37 -0
  211. package/examples/ts/create-trailing-percent-order.ts +37 -0
  212. package/examples/ts/custom-proxy-agent-for-js.ts +14 -0
  213. package/examples/ts/fetch-futures/package-lock.json +116 -0
  214. package/examples/ts/fetch-futures/package.json +34 -0
  215. package/examples/ts/fetch-futures/prettier.config.js +4 -0
  216. package/examples/ts/fetch-futures/src/index.ts +28 -0
  217. package/examples/ts/fetch-futures/tsconfig.json +28 -0
  218. package/examples/ts/fetch-ohlcv-many-exchanges-continuosly.ts +44 -0
  219. package/examples/ts/fetch-ohlcv.ts +17 -0
  220. package/examples/ts/fetch-tickers/package-lock.json +116 -0
  221. package/examples/ts/fetch-tickers/package.json +34 -0
  222. package/examples/ts/fetch-tickers/prettier.config.js +4 -0
  223. package/examples/ts/fetch-tickers/src/index.ts +21 -0
  224. package/examples/ts/fetch-tickers/tsconfig.json +28 -0
  225. package/examples/ts/how-to-import-one-exchange-esm.ts +11 -0
  226. package/examples/ts/kraken-create-and-close-position.ts +69 -0
  227. package/examples/ts/margin-loan-borrow-buy-sell-repay.ts +72 -0
  228. package/examples/ts/nextjs-page-router/.eslintrc.json +3 -0
  229. package/examples/ts/nextjs-page-router/README.md +43 -0
  230. package/examples/ts/nextjs-page-router/next.config.js +6 -0
  231. package/examples/ts/nextjs-page-router/package-lock.json +7425 -0
  232. package/examples/ts/nextjs-page-router/package.json +28 -0
  233. package/examples/ts/nextjs-page-router/postcss.config.js +6 -0
  234. package/examples/ts/nextjs-page-router/public/favicon.ico +0 -0
  235. package/examples/ts/nextjs-page-router/src/pages/_app.tsx +6 -0
  236. package/examples/ts/nextjs-page-router/src/pages/_document.tsx +13 -0
  237. package/examples/ts/nextjs-page-router/src/pages/balance.tsx +46 -0
  238. package/examples/ts/nextjs-page-router/src/pages/index.tsx +8 -0
  239. package/examples/ts/nextjs-page-router/src/pages/tickers.tsx +61 -0
  240. package/examples/ts/nextjs-page-router/src/styles/globals.css +27 -0
  241. package/examples/ts/nextjs-page-router/tailwind.config.ts +20 -0
  242. package/examples/ts/nextjs-page-router/tsconfig.json +22 -0
  243. package/examples/ts/phemex-create-order-position-with-takeprofit-stoploss.ts +62 -0
  244. package/examples/ts/proxy-usage.ts +41 -0
  245. package/examples/ts/sample-local-proxy-server-with-cors.ts +15 -0
  246. package/examples/ts/watch-OHLCV-For-Symbols.ts +17 -0
  247. package/examples/ts/watch-OHLCV.ts +14 -0
  248. package/examples/ts/watch-OrderBook-For-Symbols.ts +13 -0
  249. package/examples/ts/watch-Trades-For-Symbols.ts +13 -0
  250. package/examples/ts/watch-tickers.ts +13 -0
  251. package/examples/ts/watchPositions-many-exchanges-continuosly.ts +53 -0
  252. package/examples/ts/watchPositions.ts +15 -0
  253. package/examples/ts/watchPositionsForSymbols.ts +16 -0
  254. package/examples/tsconfig.json +27 -0
  255. package/js/ccxt.d.ts +1 -1
  256. package/js/ccxt.js +1 -1
  257. package/js/src/base/Exchange.d.ts +2 -2
  258. package/js/src/base/Exchange.js +1 -1
  259. package/js/src/bitget.js +62 -50
  260. package/js/src/bybit.d.ts +3 -1
  261. package/js/src/bybit.js +90 -30
  262. package/js/src/coinbaseinternational.js +1 -1
  263. package/js/src/htx.js +16 -9
  264. package/js/src/hyperliquid.js +2 -1
  265. package/js/src/pro/krakenfutures.js +8 -7
  266. package/package.json +4 -1
  267. package/skip-tests.json +214 -424
package/js/src/bitget.js CHANGED
@@ -1343,10 +1343,10 @@ export default class bitget extends Exchange {
1343
1343
  },
1344
1344
  'fetchOHLCV': {
1345
1345
  'spot': {
1346
- 'method': 'publicSpotGetV2SpotMarketCandles', // or publicSpotGetV2SpotMarketHistoryCandles
1346
+ 'method': 'publicSpotGetV2SpotMarketCandles', // publicSpotGetV2SpotMarketCandles or publicSpotGetV2SpotMarketHistoryCandles
1347
1347
  },
1348
1348
  'swap': {
1349
- 'method': 'publicMixGetV2MixMarketCandles', // or publicMixGetV2MixMarketHistoryCandles or publicMixGetV2MixMarketHistoryIndexCandles or publicMixGetV2MixMarketHistoryMarkCandles
1349
+ 'method': 'publicMixGetV2MixMarketCandles', // publicMixGetV2MixMarketCandles or publicMixGetV2MixMarketHistoryCandles or publicMixGetV2MixMarketHistoryIndexCandles or publicMixGetV2MixMarketHistoryMarkCandles
1350
1350
  },
1351
1351
  'maxDaysPerTimeframe': {
1352
1352
  '1m': 30,
@@ -3316,11 +3316,13 @@ export default class bitget extends Exchange {
3316
3316
  * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
3317
3317
  */
3318
3318
  await this.loadMarkets();
3319
- const maxLimit = 1000; // max 1000
3319
+ const defaultLimit = 100; // default 100, max 1000
3320
+ const maxLimitForRecentEndpoint = 1000;
3321
+ const maxLimitForHistoryEndpoint = 200; // note, max 1000 bars are supported for "recent-candles" endpoint, but "historical-candles" support only max 200
3320
3322
  let paginate = false;
3321
3323
  [paginate, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'paginate');
3322
3324
  if (paginate) {
3323
- return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, maxLimit);
3325
+ return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, maxLimitForHistoryEndpoint);
3324
3326
  }
3325
3327
  const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
3326
3328
  let market = undefined;
@@ -3333,32 +3335,17 @@ export default class bitget extends Exchange {
3333
3335
  }
3334
3336
  const marketType = market['spot'] ? 'spot' : 'swap';
3335
3337
  const timeframes = this.options['timeframes'][marketType];
3336
- const selectedTimeframe = this.safeString(timeframes, timeframe, timeframe);
3338
+ const msInDay = 86400000;
3337
3339
  const duration = this.parseTimeframe(timeframe) * 1000;
3338
3340
  const request = {
3339
3341
  'symbol': market['id'],
3340
- 'granularity': selectedTimeframe,
3342
+ 'granularity': this.safeString(timeframes, timeframe, timeframe),
3341
3343
  };
3342
- const defaultLimit = 100; // by default, exchange returns 100 items
3343
- const msInDay = 1000 * 60 * 60 * 24;
3344
- if (limit !== undefined) {
3345
- limit = Math.min(limit, maxLimit);
3346
- request['limit'] = limit;
3347
- }
3348
3344
  const until = this.safeInteger2(params, 'until', 'till');
3345
+ const limitDefined = limit !== undefined;
3346
+ const sinceDefined = since !== undefined;
3347
+ const untilDefined = until !== undefined;
3349
3348
  params = this.omit(params, ['until', 'till']);
3350
- if (until !== undefined) {
3351
- request['endTime'] = until;
3352
- }
3353
- if (since !== undefined) {
3354
- request['startTime'] = since;
3355
- if (market['spot'] && (until === undefined)) {
3356
- // for spot we need to send "entTime" too
3357
- const limitForEnd = (limit !== undefined) ? limit : defaultLimit;
3358
- const calculatedEnd = this.sum(since, duration * limitForEnd);
3359
- request['endTime'] = calculatedEnd;
3360
- }
3361
- }
3362
3349
  let response = undefined;
3363
3350
  const now = this.milliseconds();
3364
3351
  // retrievable periods listed here:
@@ -3366,21 +3353,47 @@ export default class bitget extends Exchange {
3366
3353
  // - https://www.bitget.com/api-doc/contract/market/Get-Candle-Data#description
3367
3354
  const ohlcOptions = this.safeDict(this.options, 'fetchOHLCV', {});
3368
3355
  const retrievableDaysMap = this.safeDict(ohlcOptions, 'maxDaysPerTimeframe', {});
3369
- const maxRetrievableDaysForNonHistory = this.safeInteger(retrievableDaysMap, timeframe, 30); // default to safe minimum
3370
- const endpointTsBoundary = now - maxRetrievableDaysForNonHistory * msInDay;
3371
- // checks if we need history endpoint
3372
- let needsHistoryEndpoint = false;
3373
- const displaceByLimit = (limit === undefined) ? 0 : limit * duration;
3374
- if (since !== undefined && since < endpointTsBoundary) {
3375
- // if since it earlier than the allowed diapason
3376
- needsHistoryEndpoint = true;
3377
- }
3378
- else if (until !== undefined && until - displaceByLimit < endpointTsBoundary) {
3379
- // if until is earlier than the allowed diapason
3380
- needsHistoryEndpoint = true;
3356
+ const maxRetrievableDaysForRecent = this.safeInteger(retrievableDaysMap, timeframe, 30); // default to safe minimum
3357
+ const endpointTsBoundary = now - maxRetrievableDaysForRecent * msInDay;
3358
+ if (limitDefined) {
3359
+ limit = Math.min(limit, maxLimitForRecentEndpoint);
3360
+ request['limit'] = limit;
3381
3361
  }
3362
+ else {
3363
+ limit = defaultLimit;
3364
+ }
3365
+ const limitMultipliedDuration = limit * duration;
3366
+ // exchange aligns from endTime, so it's important, not startTime
3367
+ // startTime is supported only on "recent" endpoint, not on "historical" endpoint
3368
+ let calculatedStartTime = undefined;
3369
+ let calculatedEndTime = undefined;
3370
+ if (sinceDefined) {
3371
+ calculatedStartTime = since;
3372
+ request['startTime'] = since;
3373
+ if (!untilDefined) {
3374
+ calculatedEndTime = this.sum(calculatedStartTime, limitMultipliedDuration);
3375
+ request['endTime'] = calculatedEndTime;
3376
+ }
3377
+ }
3378
+ if (untilDefined) {
3379
+ calculatedEndTime = until;
3380
+ request['endTime'] = calculatedEndTime;
3381
+ if (!sinceDefined) {
3382
+ calculatedStartTime = calculatedEndTime - limitMultipliedDuration;
3383
+ // we do not need to set "startTime" here
3384
+ }
3385
+ }
3386
+ const historicalEndpointNeeded = (calculatedStartTime !== undefined) && (calculatedStartTime <= endpointTsBoundary);
3387
+ if (historicalEndpointNeeded) {
3388
+ // only for "historical-candles" - ensure we use correct max limit
3389
+ if (limitDefined) {
3390
+ request['limit'] = Math.min(limit, maxLimitForHistoryEndpoint);
3391
+ }
3392
+ }
3393
+ // make request
3382
3394
  if (market['spot']) {
3383
- if (needsHistoryEndpoint) {
3395
+ // checks if we need history endpoint
3396
+ if (historicalEndpointNeeded) {
3384
3397
  response = await this.publicSpotGetV2SpotMarketHistoryCandles(this.extend(request, params));
3385
3398
  }
3386
3399
  else {
@@ -3388,19 +3401,18 @@ export default class bitget extends Exchange {
3388
3401
  }
3389
3402
  }
3390
3403
  else {
3391
- const maxDistanceDaysForContracts = 90; // maximum 90 days allowed between start-end times
3392
- let distanceError = false;
3393
- if (limit !== undefined && limit * duration > maxDistanceDaysForContracts * msInDay) {
3394
- distanceError = true;
3395
- }
3396
- else if (since !== undefined && until !== undefined && until - since > maxDistanceDaysForContracts * msInDay) {
3397
- distanceError = true;
3398
- }
3399
- if (distanceError) {
3400
- throw new BadRequest(this.id + ' fetchOHLCV() between start and end must be less than ' + maxDistanceDaysForContracts.toString() + ' days');
3404
+ const maxDistanceDaysForContracts = 90; // for contract, maximum 90 days allowed between start-end times
3405
+ // only correct the request to fix 90 days if until was auto-calculated
3406
+ if (sinceDefined) {
3407
+ if (!untilDefined) {
3408
+ request['endTime'] = Math.min(calculatedEndTime, this.sum(since, maxDistanceDaysForContracts * msInDay));
3409
+ }
3410
+ else if (calculatedEndTime - calculatedStartTime > maxDistanceDaysForContracts * msInDay) {
3411
+ throw new BadRequest(this.id + ' fetchOHLCV() between start and end must be less than ' + maxDistanceDaysForContracts.toString() + ' days');
3412
+ }
3401
3413
  }
3402
- const priceType = this.safeString(params, 'price');
3403
- params = this.omit(params, ['price']);
3414
+ let priceType = undefined;
3415
+ [priceType, params] = this.handleParamString(params, 'price');
3404
3416
  let productType = undefined;
3405
3417
  [productType, params] = this.handleProductTypeAndParams(market, params);
3406
3418
  request['productType'] = productType;
@@ -3413,7 +3425,7 @@ export default class bitget extends Exchange {
3413
3425
  response = await this.publicMixGetV2MixMarketHistoryIndexCandles(extended);
3414
3426
  }
3415
3427
  else {
3416
- if (needsHistoryEndpoint) {
3428
+ if (historicalEndpointNeeded) {
3417
3429
  response = await this.publicMixGetV2MixMarketHistoryCandles(extended);
3418
3430
  }
3419
3431
  else {
package/js/src/bybit.d.ts CHANGED
@@ -191,7 +191,6 @@ export default class bybit extends Exchange {
191
191
  };
192
192
  fetchDerivativesMarketLeverageTiers(symbol: string, params?: {}): Promise<any[]>;
193
193
  fetchMarketLeverageTiers(symbol: string, params?: {}): Promise<any[]>;
194
- parseMarketLeverageTiers(info: any, market?: Market): any[];
195
194
  parseTradingFee(fee: any, market?: Market): {
196
195
  info: any;
197
196
  symbol: string;
@@ -254,6 +253,9 @@ export default class bybit extends Exchange {
254
253
  };
255
254
  fetchMyLiquidations(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Liquidation[]>;
256
255
  parseLiquidation(liquidation: any, market?: Market): Liquidation;
256
+ fetchLeverageTiers(symbols?: Strings, params?: {}): Promise<{}>;
257
+ parseLeverageTiers(response: any, symbols?: Strings, marketIdKey?: any): {};
258
+ parseMarketLeverageTiers(info: any, market?: Market): any[];
257
259
  sign(path: any, api?: string, method?: string, params?: {}, headers?: any, body?: any): {
258
260
  url: string;
259
261
  method: string;
package/js/src/bybit.js CHANGED
@@ -82,6 +82,7 @@ export default class bybit extends Exchange {
82
82
  'fetchIsolatedBorrowRates': false,
83
83
  'fetchLedger': true,
84
84
  'fetchLeverage': true,
85
+ 'fetchLeverageTiers': true,
85
86
  'fetchMarketLeverageTiers': true,
86
87
  'fetchMarkets': true,
87
88
  'fetchMarkOHLCV': true,
@@ -7272,36 +7273,6 @@ export default class bybit extends Exchange {
7272
7273
  request['symbol'] = market['id'];
7273
7274
  return await this.fetchDerivativesMarketLeverageTiers(symbol, params);
7274
7275
  }
7275
- parseMarketLeverageTiers(info, market = undefined) {
7276
- //
7277
- // {
7278
- // "id": 1,
7279
- // "symbol": "BTCUSD",
7280
- // "riskLimitValue": "150",
7281
- // "maintenanceMargin": "0.5",
7282
- // "initialMargin": "1",
7283
- // "isLowestRisk": 1,
7284
- // "maxLeverage": "100.00"
7285
- // }
7286
- //
7287
- let minNotional = 0;
7288
- const tiers = [];
7289
- for (let i = 0; i < info.length; i++) {
7290
- const item = info[i];
7291
- const maxNotional = this.safeNumber(item, 'riskLimitValue');
7292
- tiers.push({
7293
- 'tier': this.sum(i, 1),
7294
- 'currency': market['base'],
7295
- 'minNotional': minNotional,
7296
- 'maxNotional': maxNotional,
7297
- 'maintenanceMarginRate': this.safeNumber(item, 'maintenanceMargin'),
7298
- 'maxLeverage': this.safeNumber(item, 'maxLeverage'),
7299
- 'info': item,
7300
- });
7301
- minNotional = maxNotional;
7302
- }
7303
- return tiers;
7304
- }
7305
7276
  parseTradingFee(fee, market = undefined) {
7306
7277
  //
7307
7278
  // {
@@ -8006,6 +7977,95 @@ export default class bybit extends Exchange {
8006
7977
  'datetime': this.iso8601(timestamp),
8007
7978
  });
8008
7979
  }
7980
+ async fetchLeverageTiers(symbols = undefined, params = {}) {
7981
+ /**
7982
+ * @method
7983
+ * @name bybit#fetchLeverageTiers
7984
+ * @see https://bybit-exchange.github.io/docs/v5/market/risk-limit
7985
+ * @description retrieve information on the maximum leverage, for different trade sizes
7986
+ * @param {string[]} [symbols] a list of unified market symbols
7987
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
7988
+ * @param {string} [params.subType] market subType, ['linear', 'inverse'], default is 'linear'
7989
+ * @returns {object} a dictionary of [leverage tiers structures]{@link https://docs.ccxt.com/#/?id=leverage-tiers-structure}, indexed by market symbols
7990
+ */
7991
+ await this.loadMarkets();
7992
+ let market = undefined;
7993
+ if (symbols !== undefined) {
7994
+ market = this.market(symbols[0]);
7995
+ if (market['spot']) {
7996
+ throw new NotSupported(this.id + ' fetchLeverageTiers() is not supported for spot market');
7997
+ }
7998
+ }
7999
+ let subType = undefined;
8000
+ [subType, params] = this.handleSubTypeAndParams('fetchTickers', market, params, 'linear');
8001
+ const request = {
8002
+ 'category': subType,
8003
+ };
8004
+ const response = await this.publicGetV5MarketRiskLimit(this.extend(request, params));
8005
+ const result = this.safeDict(response, 'result', {});
8006
+ const data = this.safeList(result, 'list', []);
8007
+ symbols = this.marketSymbols(symbols);
8008
+ return this.parseLeverageTiers(data, symbols, 'symbol');
8009
+ }
8010
+ parseLeverageTiers(response, symbols = undefined, marketIdKey = undefined) {
8011
+ //
8012
+ // [
8013
+ // {
8014
+ // "id": 1,
8015
+ // "symbol": "BTCUSD",
8016
+ // "riskLimitValue": "150",
8017
+ // "maintenanceMargin": "0.5",
8018
+ // "initialMargin": "1",
8019
+ // "isLowestRisk": 1,
8020
+ // "maxLeverage": "100.00"
8021
+ // }
8022
+ // ]
8023
+ //
8024
+ const tiers = {};
8025
+ const marketIds = this.marketIds(symbols);
8026
+ const filteredResults = this.filterByArray(response, marketIdKey, marketIds, false);
8027
+ const grouped = this.groupBy(filteredResults, marketIdKey);
8028
+ const keys = Object.keys(grouped);
8029
+ for (let i = 0; i < keys.length; i++) {
8030
+ const marketId = keys[i];
8031
+ const entry = grouped[marketId];
8032
+ const market = this.safeMarket(marketId, undefined, undefined, 'contract');
8033
+ const symbol = market['symbol'];
8034
+ tiers[symbol] = this.parseMarketLeverageTiers(entry, market);
8035
+ }
8036
+ return tiers;
8037
+ }
8038
+ parseMarketLeverageTiers(info, market = undefined) {
8039
+ //
8040
+ // [
8041
+ // {
8042
+ // "id": 1,
8043
+ // "symbol": "BTCUSD",
8044
+ // "riskLimitValue": "150",
8045
+ // "maintenanceMargin": "0.5",
8046
+ // "initialMargin": "1",
8047
+ // "isLowestRisk": 1,
8048
+ // "maxLeverage": "100.00"
8049
+ // }
8050
+ // ]
8051
+ //
8052
+ const tiers = [];
8053
+ for (let i = 0; i < info.length; i++) {
8054
+ const tier = info[i];
8055
+ const marketId = this.safeString(info, 'symbol');
8056
+ market = this.safeMarket(marketId);
8057
+ tiers.push({
8058
+ 'tier': this.safeInteger(tier, 'id'),
8059
+ 'currency': market['settle'],
8060
+ 'minNotional': undefined,
8061
+ 'maxNotional': undefined,
8062
+ 'maintenanceMarginRate': this.safeNumber(tier, 'maintenanceMargin'),
8063
+ 'maxLeverage': this.safeNumber(tier, 'maxLeverage'),
8064
+ 'info': tier,
8065
+ });
8066
+ }
8067
+ return tiers;
8068
+ }
8009
8069
  sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
8010
8070
  let url = this.implodeHostname(this.urls['api'][api]) + '/' + path;
8011
8071
  if (api === 'public') {
@@ -118,7 +118,7 @@ export default class coinbaseinternational extends Exchange {
118
118
  'test': {
119
119
  'rest': 'https://api-n5e1.coinbase.com/api',
120
120
  },
121
- 'www': 'https://www.coinbaseinternational.com/international-exchange',
121
+ 'www': 'https://international.coinbase.com',
122
122
  'doc': [
123
123
  'https://docs.cloud.coinbaseinternational.com/intx/docs',
124
124
  ],
package/js/src/htx.js CHANGED
@@ -952,6 +952,9 @@ export default class htx extends Exchange {
952
952
  },
953
953
  },
954
954
  },
955
+ 'fetchOHLCV': {
956
+ 'useHistoricalEndpointForSpot': true,
957
+ },
955
958
  'withdraw': {
956
959
  'includeFee': false,
957
960
  },
@@ -2959,6 +2962,7 @@ export default class htx extends Exchange {
2959
2962
  * @param {int} [limit] the maximum amount of candles to fetch
2960
2963
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2961
2964
  * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2965
+ * @param {string} [params.useHistoricalEndpointForSpot] true/false - whether use the historical candles endpoint for spot markets or default klines endpoint
2962
2966
  * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
2963
2967
  */
2964
2968
  await this.loadMarkets();
@@ -3065,19 +3069,22 @@ export default class htx extends Exchange {
3065
3069
  }
3066
3070
  }
3067
3071
  else {
3068
- if (since !== undefined) {
3069
- request['from'] = this.parseToInt(since / 1000);
3070
- }
3071
- if (limit !== undefined) {
3072
- request['size'] = limit; // max 2000
3073
- }
3074
3072
  request['symbol'] = market['id'];
3075
- if (timeframe === '1M' || timeframe === '1y') {
3076
- // for some reason 1M and 1Y does not work with the regular endpoint
3077
- // https://github.com/ccxt/ccxt/issues/18006
3073
+ let useHistorical = undefined;
3074
+ [useHistorical, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'useHistoricalEndpointForSpot', true);
3075
+ if (!useHistorical) {
3076
+ // `limit` only available for the this endpoint
3077
+ if (limit !== undefined) {
3078
+ request['size'] = limit; // max 2000
3079
+ }
3078
3080
  response = await this.spotPublicGetMarketHistoryKline(this.extend(request, params));
3079
3081
  }
3080
3082
  else {
3083
+ // `since` only available for the this endpoint
3084
+ if (since !== undefined) {
3085
+ // default 150 bars
3086
+ request['from'] = this.parseToInt(since / 1000);
3087
+ }
3081
3088
  response = await this.spotPublicGetMarketHistoryCandles(this.extend(request, params));
3082
3089
  }
3083
3090
  }
@@ -368,7 +368,7 @@ export default class hyperliquid extends Exchange {
368
368
  'optionType': undefined,
369
369
  'precision': {
370
370
  'amount': this.parseNumber(this.parsePrecision(this.safeString(market, 'szDecimals'))),
371
- 'price': this.parseNumber('5'), // significant digits
371
+ 'price': 5, // significant digits
372
372
  },
373
373
  'limits': {
374
374
  'leverage': {
@@ -850,6 +850,7 @@ export default class hyperliquid extends Exchange {
850
850
  throw new ArgumentsRequired(this.id + ' market orders require price to calculate the max slippage price. Default slippage can be set in options (default is 5%).');
851
851
  }
852
852
  px = (isBuy) ? Precise.stringMul(price, Precise.stringAdd('1', slippage)) : Precise.stringMul(price, Precise.stringSub('1', slippage));
853
+ px = this.priceToPrecision(symbol, px); // round after adding slippage
853
854
  }
854
855
  else {
855
856
  px = this.priceToPrecision(symbol, price);
@@ -470,16 +470,17 @@ export default class krakenfutures extends krakenfuturesRest {
470
470
  const market = this.market(marketId);
471
471
  const symbol = market['symbol'];
472
472
  const messageHash = 'trade:' + symbol;
473
- let tradesArray = this.safeValue(this.trades, symbol);
474
- if (tradesArray === undefined) {
473
+ if (this.safeList(this.trades, symbol) === undefined) {
475
474
  const tradesLimit = this.safeInteger(this.options, 'tradesLimit', 1000);
476
- tradesArray = new ArrayCache(tradesLimit);
477
- this.trades[symbol] = tradesArray;
475
+ this.trades[symbol] = new ArrayCache(tradesLimit);
478
476
  }
477
+ const tradesArray = this.trades[symbol];
479
478
  if (channel === 'trade_snapshot') {
480
- const trades = this.safeValue(message, 'trades', []);
481
- for (let i = 0; i < trades.length; i++) {
482
- const item = trades[i];
479
+ const trades = this.safeList(message, 'trades', []);
480
+ const length = trades.length;
481
+ for (let i = 0; i < length; i++) {
482
+ const index = length - 1 - i; // need reverse to correct chronology
483
+ const item = trades[index];
483
484
  const trade = this.parseWsTrade(item);
484
485
  tradesArray.append(trade);
485
486
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.2.73",
3
+ "version": "4.2.74",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.js",
6
6
  "type": "module",
@@ -10,6 +10,9 @@
10
10
  "require": "./dist/ccxt.cjs"
11
11
  }
12
12
  },
13
+ "bin": {
14
+ "ccxt": "examples/js/cli.js"
15
+ },
13
16
  "engines": {
14
17
  "node": ">=15.0.0"
15
18
  },