Ready for first real test
This commit is contained in:
1 parent
acddf9135f
commit
b91c81ebdf
46 files changed
+34903
-26
No files matched your search
@@ -24,6 +24,7 @@ from execution import broker as broker_mod # noqa: E402
|
||||
from execution import reconcile as reconcile_mod # noqa: E402
|
||||
from execution.guardrails import plan_orders # noqa: E402
|
||||
from orchestration.budget import next_market_trade_date # noqa: E402
|
||||
from reporting import email_report, report_writer # noqa: E402
|
||||
from state import db # noqa: E402
|
||||
from tools.market_data import latest_price # noqa: E402
|
||||
from tools.options import option_premium # noqa: E402
|
||||
@@ -168,6 +169,34 @@ def main(force: bool = False, date: str | None = None) -> int:
|
||||
|
||||
con.close()
|
||||
logger.info("=== execution complete: {} orders placed across accounts ===", total_placed)
|
||||
|
||||
# daily report: append execution results, render PDF, email it
|
||||
try:
|
||||
con2 = db.connect(s.db_path)
|
||||
rows = con2.execute(
|
||||
"SELECT agent, ticker, side, qty, status FROM orders WHERE trade_date=? "
|
||||
"ORDER BY agent, ticker",
|
||||
(trade_date,),
|
||||
).fetchall()
|
||||
lines = [f"**{total_placed} orders placed** across accounts for {trade_date}.", ""]
|
||||
for persona in PERSONAS:
|
||||
ords = [r for r in rows if r["agent"] == persona.id]
|
||||
snap = db.latest_snapshot(con2, persona.id)
|
||||
eq = f"${snap['equity']:,.2f}" if snap else "n/a"
|
||||
detail = ", ".join(
|
||||
f"{r['side']} {r['qty']} {r['ticker']} [{r['status']}]" for r in ords
|
||||
) or "no orders"
|
||||
lines.append(f"- **{persona.id}** (equity {eq}): {detail}")
|
||||
con2.close()
|
||||
exec_summary = "\n".join(lines)
|
||||
daily = report_writer.write_daily_report(trade_date, outputs, exec_summary=exec_summary)
|
||||
pdf = report_writer.to_pdf(daily)
|
||||
email_report.send_daily(
|
||||
trade_date, pdf, summary=f"{total_placed} orders placed for {trade_date}."
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning("daily report/email step failed: {}", e)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user