Fill journal for the whole account
Writes every execution on the account, from any strategy or by hand, to a CSV file in the workspace, one row per fill, and logs each order that ends refused or cancelled. A journal you can open in a spreadsheet at the end of the day.
Writes every execution on the account, from any strategy or by hand, to a CSV file in the workspace, one row per fill, and logs each order that ends refused or cancelled. A journal you can open in a spreadsheet at the end of the day.
Shows: Monitor, @on.fill and @on.order with no tag (account-wide), the event's exact Decimal figures, None on non-fill events, a CSV in data/, run as a module with no market data.
"""Fill journal for the whole account
Writes every execution on the account, from any strategy or by hand, to a
CSV file in the workspace, one row per fill, and logs each order that ends
refused or cancelled. A journal you can open in a spreadsheet at the end of
the day.
Shows: Monitor, @on.fill and @on.order with no tag (account-wide), the event's exact Decimal figures, None on non-fill events, a CSV in data/, run as a module with no market data.
"""
import csv
from datetime import datetime, timezone
from pathlib import Path
import while25
from while25 import Monitor, on
JOURNAL = Path("data/fill_journal.csv")
COLUMNS = ["time_utc", "order_id", "symbol", "side", "order_type", "quantity",
"price", "order_filled", "order_average", "tag", "held_by", "combo_id"]
def journal_row(ev):
"""One CSV row for a FILL event: its own execution figures, as text."""
t = datetime.fromtimestamp(ev["timestamp_ms"] / 1000, timezone.utc) if ev.get("timestamp_ms") else None
return {"time_utc": t.isoformat() if t else "",
"order_id": ev["order_id"], "symbol": ev["symbol"], "side": ev["side"],
"order_type": ev["order_type"],
"quantity": str(ev["last_fill_quantity"]), "price": str(ev["last_fill_price"]),
"order_filled": str(ev["filled_quantity"]),
"order_average": "" if ev["average_price"] is None else str(ev["average_price"]),
"tag": ev["tag"] or "", "held_by": ev["held_by"] or "",
"combo_id": ev["combo_id"] or ""}
def append(row, path=JOURNAL):
path.parent.mkdir(parents=True, exist_ok=True)
new = not path.exists()
with path.open("a", newline="") as f:
w = csv.DictWriter(f, fieldnames=COLUMNS)
if new:
w.writeheader()
w.writerow(row)
class FillJournal(Monitor):
id = "fill_journal"
label = "Fill journal"
@on.fill()
def on_fill(self, ctx, ev):
append(journal_row(ev))
@on.order()
def on_order(self, ctx, ev):
if ev["event"] in ("REJECT", "CANCEL"):
while25.log(f"{ev['event']} {ev['symbol']} {ev['side']} {ev['quantity']}: "
f"{ev['reason'] or 'no reason given'}")Breakout watch across several stocks, with an AI check
Watches AAPL, MSFT and NVDA on 15-minute bars and, when one closes above the high of its previous 20 bars, asks the AI whether it looks like a clean breakout or a likely fakeout. Each question is asked without waiting for the last, and only a "breakout" answer becomes a notice. It never trades.
Nasdaq-100 opening-gap scanner
Turns on live prices for every Nasdaq-100 member, and in the first minutes after the open lists the biggest gaps from yesterday's close, then sends one notice with the top names. Members come from the platform's dated index list, whose date it logs: the list is as of that day, not today.