Replace the V1 commands/services split with a flat, direct architecture: - cli.py dispatches directly to service functions - New services: account, market, trade, opportunity - Thin Binance wrappers: spot_client, um_futures_client - Add audit logging, runtime paths, and TOML config - Remove legacy V1 code: commands/, precheck, review engine, smart executor - Add ruff + mypy toolchain and fix edge cases in trade params Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3.4 KiB
3.4 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Development commands
- Install (dev):
pip install -e ".[dev]" - Run CLI locally:
python -m coinhunter --help - Run tests:
pytestorpython -m pytest tests/ - Run single test file:
pytest tests/test_cli.py -v - Lint:
ruff check src tests - Format:
ruff format src tests - Type-check:
mypy src
Architecture
CoinHunter V2 is a Binance-first crypto trading CLI with a flat, direct architecture:
src/coinhunter/cli.py— Single entrypoint (main()). Usesargparseto parse commands and directly dispatches to service functions. There is no separatecommands/adapter layer.src/coinhunter/services/— Contains all domain logic:account_service.py— balances, positions, overviewmarket_service.py— tickers, klines, scan universe, symbol normalizationtrade_service.py— spot and USDT-M futures order executionopportunity_service.py— portfolio recommendations and market scanning
src/coinhunter/binance/— Thin wrappers around official Binance connectors:spot_client.pywrapsbinance.spot.Spotum_futures_client.pywrapsbinance.um_futures.UMFuturesBoth normalize request errors intoRuntimeErrorand handle single/multi-symbol ticker responses.
src/coinhunter/config.py—load_config(),get_binance_credentials(),ensure_init_files().src/coinhunter/runtime.py—RuntimePaths,get_runtime_paths(),print_json().src/coinhunter/audit.py— Writes JSONL audit events to dated files.
Runtime and environment
User data lives in ~/.coinhunter/ by default (override with COINHUNTER_HOME):
config.toml— runtime, binance, trading, and opportunity settings.env—BINANCE_API_KEYandBINANCE_API_SECRETlogs/audit_YYYYMMDD.jsonl— structured audit log
Run coinhunter init to generate the config and env templates.
Key conventions
- Symbol normalization:
market_service.normalize_symbol()strips/,-,_, and uppercases the symbol. CLI inputs likeETH/USDT,eth-usdt, andETHUSDTare all normalized toETHUSDT. - Dry-run behavior: Trade commands support
--dry-run. If omitted, the default falls back totrading.dry_run_defaultinconfig.toml. - Client injection: Service functions accept
spot_client/futures_clientas keyword arguments. This enables easy unit testing with mocks. - Error handling: Binance client wrappers catch
requests.exceptions.SSLErrorandRequestExceptionand re-raise as human-readableRuntimeError. The CLI catches all exceptions inmain()and printserror: {message}to stderr with exit code 1.
Testing
Tests live in tests/ and use unittest.TestCase with unittest.mock.patch. The test suite covers:
test_cli.py— parser smoke tests and dispatch behaviortest_config_runtime.py— config loading, env parsing, path resolutiontest_account_market_services.py— balance/position/ticker/klines logic with mocked clientstest_trade_service.py— spot and futures trade execution pathstest_opportunity_service.py— portfolio and scan scoring logic
Notes
AGENTS.mdin this repo is stale and describes a prior V1 architecture (commands/, smart executor, precheck, review engine). Do not rely on it.