Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,11 @@ def main():
```

**Phase 5 Deliverables:**
- [ ] `trainer/runner.py`
- [ ] `thinker/runner.py`
- [ ] `trader/runner.py`
- [ ] `scripts/run_trainer.py`, `run_thinker.py`, `run_trader.py`
- [ ] Integration tests (runners with mock clients)
- [x] `trainer/runner.py` — orchestrates training across coins/timeframes with checkpoint resume and stop signal
- [x] `thinker/runner.py` — continuous signal generation with hot-reload of coin list
- [x] `trader/runner.py` — trade execution with position sync, entry/DCA/exit management
- [x] `scripts/run_trainer.py`, `run_thinker.py`, `run_trader.py` — entry points with dependency wiring
- [x] Integration tests (runners with mock clients) — 41 tests covering all three runners
- [ ] Verify identical behavior to original scripts

---
Expand Down Expand Up @@ -805,10 +805,10 @@ tests/
│ └── trainer/
│ └── test_memory.py # Memory I/O, checkpoints, distance, progress ✅ done (32 tests) — split in Phase 4
├── integration/
│ ├── test_trainer_runner.py # Full training with mock market Phase 5
│ ├── test_thinker_runner.py # Signal gen with mock data Phase 5
│ ├── test_trader_runner.py # Trade execution with paper client Phase 5
│ └── test_file_ipc.py # End-to-end file-based communication Phase 5
│ ├── test_trainer_runner.py # Full training with mock market Phase 5
│ ├── test_thinker_runner.py # Signal gen with mock data Phase 5
│ ├── test_trader_runner.py # Trade execution with paper client Phase 5
│ └── test_file_ipc.py # End-to-end file-based communication (in test_trader_runner.py) ✅ Phase 5
└── conftest.py # Shared fixtures (mock clients, temp dirs) ✅ done
```

Expand Down
34 changes: 31 additions & 3 deletions scripts/run_thinker.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
#!/usr/bin/env python3
"""Entry point for the PowerTrader Thinker / Signal Generator (thin wrapper)."""
"""Entry point for the PowerTrader Thinker / Signal Generator.

Usage::

python scripts/run_thinker.py
"""

from __future__ import annotations

from pathlib import Path


def main() -> None:
raise NotImplementedError(
"Thinker runner not yet migrated — use pt_thinker.py directly."
from powertrader.core.config import TradingConfig
from powertrader.core.constants import SETTINGS_FILENAME
from powertrader.core.logging_setup import setup_logger
from powertrader.core.market_client import KuCoinMarketClient
from powertrader.core.storage import FileStore
from powertrader.thinker.runner import ThinkerRunner

base_dir = Path.cwd()
setup_logger("thinker", base_dir / "logs")
setup_logger("powertrader", base_dir / "logs")

config = TradingConfig.from_file(base_dir / SETTINGS_FILENAME)
market = KuCoinMarketClient()
store = FileStore()

runner = ThinkerRunner(
market=market,
config=config,
store=store,
base_dir=base_dir,
)
runner.run()


if __name__ == "__main__":
Expand Down
69 changes: 66 additions & 3 deletions scripts/run_trader.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,74 @@
#!/usr/bin/env python3
"""Entry point for the PowerTrader Trade Executor (thin wrapper)."""
"""Entry point for the PowerTrader Trade Executor.

Usage::

python scripts/run_trader.py # Live trading (Binance)
python scripts/run_trader.py --paper # Paper trading (simulated)
"""

from __future__ import annotations

import sys
from pathlib import Path


def main() -> None:
raise NotImplementedError(
"Trader runner not yet migrated — use pt_trader.py directly."
from powertrader.core.config import TradingConfig
from powertrader.core.constants import SETTINGS_FILENAME
from powertrader.core.credentials import BinanceCredentials
from powertrader.core.logging_setup import setup_logger
from powertrader.core.storage import FileStore
from powertrader.core.trading_client import TradingClient
from powertrader.trader.dca_engine import DCAEngine
from powertrader.trader.entry_engine import EntryEngine
from powertrader.trader.runner import TraderRunner
from powertrader.trader.trailing_engine import TrailingProfitEngine

base_dir = Path.cwd()
setup_logger("trader", base_dir / "logs")
setup_logger("powertrader", base_dir / "logs")

config = TradingConfig.from_file(base_dir / SETTINGS_FILENAME)
store = FileStore()

# Select trading client
paper_mode = "--paper" in sys.argv
client: TradingClient

if paper_mode:
from powertrader.core.market_client import KuCoinMarketClient
from powertrader.core.paper_client import PaperTradingClient

market = KuCoinMarketClient()
client = PaperTradingClient(market=market)
else:
from powertrader.core.trading_client import BinanceTradingClient

creds = BinanceCredentials.load(base_dir)
if not creds.is_valid:
print("ERROR: No valid Binance credentials found.")
print(
"Set BINANCE_API_KEY/BINANCE_API_SECRET env vars or create b_key.txt/b_secret.txt"
)
sys.exit(1)
client = BinanceTradingClient(creds)

# Wire up engines
entry = EntryEngine(config)
dca = DCAEngine(config)
trailing = TrailingProfitEngine(config)

runner = TraderRunner(
trading_client=client,
entry=entry,
dca=dca,
trailing=trailing,
config=config,
store=store,
base_dir=base_dir,
)
runner.run()


if __name__ == "__main__":
Expand Down
50 changes: 47 additions & 3 deletions scripts/run_trainer.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,55 @@
#!/usr/bin/env python3
"""Entry point for the PowerTrader Trainer (thin wrapper)."""
"""Entry point for the PowerTrader Trainer.

Usage::

python scripts/run_trainer.py # Train all configured coins
python scripts/run_trainer.py BTC # Train a specific coin
python scripts/run_trainer.py ETH reprocess_yes # Retrain with full reprocessing
"""

from __future__ import annotations

import sys
from pathlib import Path


def main() -> None:
raise NotImplementedError(
"Trainer runner not yet migrated — use pt_trainer.py directly."
from powertrader.core.config import TradingConfig
from powertrader.core.constants import SETTINGS_FILENAME
from powertrader.core.logging_setup import setup_logger
from powertrader.core.market_client import KuCoinMarketClient
from powertrader.core.storage import FileStore
from powertrader.trainer.runner import TrainerRunner

base_dir = Path.cwd()
setup_logger("trainer", base_dir / "logs")
setup_logger("powertrader", base_dir / "logs")

config = TradingConfig.from_file(base_dir / SETTINGS_FILENAME)
market = KuCoinMarketClient()
store = FileStore()

# Parse CLI args: [coin] [reprocess_yes|reprocess_no]
coins: list[str] | None = None
reprocess = False

args = sys.argv[1:]
for arg in args:
if arg.lower() in ("reprocess_yes", "reprocess"):
reprocess = True
elif arg.lower() == "reprocess_no":
reprocess = False
else:
coins = [arg.upper()]

runner = TrainerRunner(
market=market,
config=config,
store=store,
base_dir=base_dir,
)
runner.run(coins=coins, reprocess=reprocess)


if __name__ == "__main__":
Expand Down
Loading
Loading