Support for CCXT#59
Open
gbeced wants to merge 31 commits into
Open
Conversation
Bug fixed. lastTradeTimestamp might be None.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new CCXT-based exchange integration (including websocket event sources) and extends Basana’s precision handling to support decimal places, significant digits, and tick-size-based precision, aligning precision behavior across backtesting and external exchanges.
Changes:
- Introduces
basana.external.ccxtwith anExchangewrapper plus websocket-backed bar/trade/order-book/order event sources. - Adds
PrecisionModeand extendsPairInfo+ core helper utilities to support rounding/truncation via decimal places, significant digits, or tick size. - Updates backtesting/exchange and Binance integration to use the unified
PairInfoprecision helpers; adds tests/docs/samples for the new CCXT functionality.
Reviewed changes
Copilot reviewed 36 out of 37 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_pair.py | Adds unit tests for PairInfo precision/rounding behavior across precision modes. |
| tests/test_core_helpers.py | Adds tests for significant-digits precision and tick-size helpers (round/truncate + decimal-place derivation). |
| tests/test_ccxt_exchange.py | Adds end-to-end tests for the CCXT exchange wrapper and websocket event sources. |
| tests/test_binance_exchange.py | Updates Binance pair-info tests to assert tick-size precision mode and tick sizes. |
| tests/test_backtesting_exchange_orders.py | Adds backtesting tests to ensure tick-size precision limits are enforced in order validation. |
| tests/fixtures/ccxt.py | Adds CCXT fixtures/mocks to support CCXT integration tests. |
| tests/conftest.py | Registers CCXT fixtures for the test suite. |
| samples/ccxt_websockets.py | Adds a usage sample showing CCXT websocket subscriptions for bars/trades/order-book. |
| README.md | Documents CCXT integration and the new optional extra (basana[ccxt]). |
| pyproject.toml | Adds an optional dependency group for CCXT. |
| docs/quickstart.rst | Updates install instructions to include the ccxt extra. |
| docs/index.rst | Updates docs overview to mention CCXT exchange support. |
| docs/ccxt_trades.rst | Adds API reference page for CCXT trades module/classes. |
| docs/ccxt_orders.rst | Adds API reference page for CCXT orders module/classes. |
| docs/ccxt_order_book.rst | Adds API reference page for CCXT order book module/classes. |
| docs/ccxt_exchange.rst | Adds API reference page for CCXT exchange wrapper and DTOs. |
| docs/api.rst | Adds CCXT modules to the API reference TOC. |
| CHANGELOG.md | Notes CCXT integration as a new feature. |
| basana/external/ccxt/trades.py | Implements trade DTO + trade websocket event source. |
| basana/external/ccxt/requests.py | Adds CCXT order-request wrappers for market/limit/stop/stop-limit creation. |
| basana/external/ccxt/orders.py | Implements order DTO + private orders websocket event source. |
| basana/external/ccxt/order_book.py | Implements partial order book DTO + order book websocket event source. |
| basana/external/ccxt/helpers.py | Adds CCXT helper conversions (symbols, decimals, pair-info mapping, etc.). |
| basana/external/ccxt/exchange.py | Adds the CCXT Exchange wrapper (balances, orders, pair info, subscriptions, close). |
| basana/external/ccxt/bars.py | Implements OHLCV websocket bar event source. |
| basana/external/ccxt/init.py | Introduces the CCXT integration package. |
| basana/external/binance/exchange.py | Updates Binance PairInfo construction to use tick sizes + PrecisionMode.TICK_SIZE. |
| basana/core/pair.py | Extends PairInfo with PrecisionMode, tick sizes, and convenience round/truncate methods. |
| basana/core/helpers.py | Adds precision-mode-aware rounding/truncation, significant-digits logic, and tick-size utilities. |
| basana/core/enums.py | Adds PrecisionMode enum. |
| basana/backtesting/requests.py | Uses PairInfo precision helpers in validation + improves precision error messages for tick size. |
| basana/backtesting/prices.py | Uses PairInfo.truncate_quote() for bid/ask spread precision behavior. |
| basana/backtesting/orders.py | Uses PairInfo precision helpers for fills and slippage price rounding. |
| basana/backtesting/order_mgr.py | Uses PairInfo precision helpers for rounding balances/fees. |
| basana/backtesting/charts.py | Uses PairInfo.truncate_quote() for chart fill-price calculations. |
| basana/init.py | Exposes PrecisionMode at the package level. |
Comment on lines
+34
to
+39
| def get_quantizer(precision: int) -> Decimal: | ||
| ret = QUANTIZERS_CACHE.get(precision) | ||
| if ret is None: | ||
| ret = Decimal(f"1e-{precision}") | ||
| QUANTIZERS_CACHE[precision] = ret | ||
| return ret |
Owner
Author
There was a problem hiding this comment.
In this context precision is always >= 0. I added an assert. Check 228b257.
#59 (comment) Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
#59 (comment) Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
#59 (comment) Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.