Contributing Guide¶
Contributions are welcome! Whether it's bug fixes, new features, documentation improvements, or test coverage.
Development Setup¶
git clone https://github.com/jordantete/grid_trading_bot.git
cd grid_trading_bot
uv sync --all-extras --dev
Running Tests¶
All tests (unit + integration)¶
Single test file¶
Single test¶
Integration tests (E2E backtest)¶
Zero mocks — runs the full bot stack against real CSV data:
Sandbox smoke tests¶
Requires network access. Validates CCXT (and the aiohttp transport it brings) against live exchange APIs:
Persistence layer tests¶
Tests for SQLite state persistence, serialization, and recovery logic:
Update snapshots¶
The backtest snapshots in tests/integration/snapshots/ hold every performance metric at full precision, the final balances and the list of fills. A missing snapshot fails its test with a message naming the option below.
After an intentional behavior change, rewrite them:
The tests pass, and the end of the run lists every field and fill that changed against the previous files. Read that list before committing the new snapshots.
Linting, Formatting and Type Checking¶
The project uses Ruff for linting and formatting, and mypy for type checking:
# Lint with auto-fix
uv run ruff check --fix .
# Format
uv run ruff format .
# Type check (src/ only, must report 0 errors)
uv run mypy
# Run all pre-commit hooks
uv run pre-commit run --all-files
mypy is configured in pyproject.toml. A # type: ignore needs its error code and a one-line reason, for example # type: ignore[arg-type] # ccxt declares str, the API takes int.
The pre-commit hooks for Ruff and mypy run from the project environment (uv run --frozen --no-sync), so they need an existing .venv: run uv sync --all-extras --dev once before the first commit.
Code Style¶
- Line length: 120 characters
- Python version: 3.12+
- Quotes: Double quotes
- Imports: Sorted by isort (via Ruff), full package paths (
from grid_trading_bot.config.X import Y)
Pre-commit hooks enforce:
- Ruff lint + format and mypy, with the versions pinned in
pyproject.toml - Trailing whitespace removal
- Valid YAML/JSON/TOML
- No merge conflict markers
- No debug statements
- No blanket
noqa/type: ignore - No deprecated
log.warn()
Project Structure¶
- Source code:
src/grid_trading_bot/ - Tests:
tests/(mirrors source structure) - Persistence tests:
tests/persistence/ - Integration tests:
tests/integration/ - Config files:
config/ - Monitoring stack:
monitoring/
Continuous Integration¶
.github/workflows/ci.yml runs on every push to master and every pull request:
test: the test suite on Python 3.12 and 3.14, with coverage uploaded to Codecov from 3.12lint:ruff check,ruff format --checkandmypy
Releasing¶
The version is written once, in pyproject.toml. grid_trading_bot.__version__ and grid_trading_bot --version read it from the installed package.
- Set
versioninpyproject.toml, runuv lock(the lock records the project version), commit both onmasterand push. - Tag that commit and push the tag:
- The
releaseworkflow checks that the tag isvplus thepyproject.tomlversion and that the commit is onmaster(scripts/verify_release_tag.sh), runs the CI, builds the package and checks it withtwine check. - Publishing waits for approval of the
pypienvironment: open the run in the Actions tab and approve the deployment. The package goes to PyPI, then the GitHub release is created with generated notes.
If the tag check fails, delete the tag (git push --delete origin vX.Y.Z and git tag -d vX.Y.Z), fix the cause, and tag again.
Pull Request Process¶
- Fork the repository and create a feature branch from
master - Make your changes following the code style above
- Add or update tests as appropriate
- Ensure all tests pass and pre-commit hooks succeed
- Submit a pull request with a clear description of the changes
Reporting Issues¶
If you encounter bugs or have feature requests, please open an issue on GitHub.