Fix forced-paper execution semantics and add minimum forced notional control
This commit is contained in:
30
bot.py
30
bot.py
@@ -69,6 +69,12 @@ def run_cycle():
|
||||
memory_hits = qdrant_similar(symbol, json.dumps(news)[:2000], limit=5)
|
||||
decision = llm_final_decision(symbol, news, strat, memory_hits)
|
||||
|
||||
if settings.paper_mode and settings.force_paper_trades and decision["action"] == "hold":
|
||||
decision["action"] = "buy"
|
||||
decision["confidence"] = max(decision.get("confidence", 0.0), settings.min_confidence)
|
||||
decision["order_usd"] = max(decision.get("order_usd", 0.0), settings.force_paper_min_usd)
|
||||
decision["reason"] = f"{decision.get('reason','')} | force_paper_trades"
|
||||
|
||||
drow = BotDecision(
|
||||
symbol=symbol,
|
||||
action=decision["action"],
|
||||
@@ -82,11 +88,6 @@ def run_cycle():
|
||||
db.commit()
|
||||
db.refresh(drow)
|
||||
|
||||
if settings.paper_mode and settings.force_paper_trades and decision["action"] == "hold":
|
||||
decision["action"] = "buy"
|
||||
decision["confidence"] = max(decision.get("confidence", 0.0), settings.min_confidence)
|
||||
decision["reason"] = f"{decision.get('reason','')} | force_paper_trades"
|
||||
|
||||
should_trade = decision["action"] in {"buy", "sell"} and decision["confidence"] >= settings.min_confidence
|
||||
|
||||
if should_trade:
|
||||
@@ -103,15 +104,16 @@ def run_cycle():
|
||||
drow.status = "executed" if ok else "failed"
|
||||
db.add(drow)
|
||||
|
||||
trade = TradeExecution(
|
||||
symbol=symbol,
|
||||
side=decision["action"],
|
||||
qty=float((res or {}).get("json", {}).get("qty", 0) or 0),
|
||||
notional=notional,
|
||||
alpaca_order_id=(res or {}).get("json", {}).get("id", ""),
|
||||
raw=json.dumps({"decision": decision, "strategy": strat, "memory": memory_hits, "broker": res})[:60000],
|
||||
)
|
||||
db.add(trade)
|
||||
if ok:
|
||||
trade = TradeExecution(
|
||||
symbol=symbol,
|
||||
side=decision["action"],
|
||||
qty=float((res or {}).get("json", {}).get("qty", 0) or 0),
|
||||
notional=notional,
|
||||
alpaca_order_id=(res or {}).get("json", {}).get("id", ""),
|
||||
raw=json.dumps({"decision": decision, "strategy": strat, "memory": memory_hits, "broker": res})[:60000],
|
||||
)
|
||||
db.add(trade)
|
||||
db.commit()
|
||||
|
||||
# learning memory + notes + orchestration signal
|
||||
|
||||
Reference in New Issue
Block a user