Alice — an open-source AI trading bot covering equities, crypto, commodities, forex, and macro
Fix mypy errors in cli.py: type STRATEGIES dict, cast trade values
Camo67 committed
Oct 12, 2026 at 12:06 UTC
298135ece6188c9e81f583294e6325ea66d927b6
1 file changed
+6
-6
src/open_alice/cli.py
+6
-6
@@ -14,7 +14,7 @@ from open_alice.strategies import (
14
Strategy,
15
)
16
17
-STRATEGIES = {
17
+STRATEGIES: dict[str, type[Strategy]] = {
18
"sma_crossover": SmaCrossover,
19
"rsi": RsiStrategy,
20
"macd": MacdStrategy,
@@ -102,16 +102,16 @@ def _run_paper(args: argparse.Namespace) -> None:
102
print(f" Total Trades: {len(portfolio.trades):>10d}")
103
104
if portfolio.trades:
105
- total_pnl = sum(t.get("pnl", 0) for t in portfolio.trades)
105
+ total_pnl = sum(float(t.get("pnl", 0)) for t in portfolio.trades)
106
print(f" Total P&L: ${total_pnl:>10,.2f}")
107
108
print("\n --- Trade Log ---")
109
for t in portfolio.trades[:20]:
110
- pnl_str = f" P&L: ${t['pnl']:,.2f}" if "pnl" in t else ""
110
+ pnl_str = f" P&L: ${float(t['pnl']):,.2f}" if "pnl" in t else ""
111
print(
112
- f" {t['time'].strftime('%Y-%m-%d %H:%M')} | {t['action']:>4} | "
113
- f"{t.get('symbol', ''):>6} | {t.get('shares', 0):>6} @ "
114
- f"${t.get('price', 0):>8.2f}{pnl_str}"
112
+ f" {str(t['time'])} | {str(t['action']):>4} | "
113
+ f"{str(t.get('symbol', '')):>6} | {int(t.get('shares', 0)):>6} @ "
114
+ f"${float(t.get('price', 0)):>8.2f}{pnl_str}"
115
)
116
117
if len(portfolio.trades) > 20: