Portfolio
Never cached. Figures are exact: Decimal, money as while25.Money (value, currency). A figure nobody stated is None, never 0.
PYwhile25.portfolio.position(symbol) → dict | None
The account’s position, other strategies’ and manual trades included; None when flat. Several products combine exactly: quantity summed, pnl only in one currency, average_price only on one side; rows keeps each broker row.
Keys
symbol / instrument_key / productstrrequired
quantityDecimalrequired
Signed.
average_price / last_priceDecimal | Nonerequired
Fees included where the broker sends them per fill.
pnlMoney | Nonerequired
Unrealised.
PYwhile25.portfolio.positions() → list[dict]
Every position of the account, one broker row each.
PYwhile25.portfolio.my_position(key) → dict | None · while25.portfolio.my_positions() → list[dict]
What this module holds, changed only by its own orders and kept across a Stop and an app restart. Keys: quantity (its part, outside brackets and combos), average_price, last_price, pnl, account_quantity (None until the broker’s first report), brackets (bracket_id group_label side product quantity_held entry_average last_price pnl broker_held waiting_for_entry), combos. NOT_READY means ask again, never flat.
PYwhile25.orders.mine(instrument_key=None) → list[dict]
Its working orders and the stops the engine holds for it: order_id instrument_key symbol side order_type product validity hours quantity filled_quantity price trigger_price status held_by tag bracket_id group_label role. A read: on_stop may call it.
PYwhile25.portfolio.funds() → dict | None
{"margin_used": Money, "margin_available": Money, "assets": [...]}, or None when the broker has not stated them (Upstox outside its service hours). Write if f is None:, never .get("margin_available", 0). funds_unavailable_reason() gives the broker’s words. There is no cash figure.
PYwhile25.portfolio.day_pnl() · realised_pnl() · unrealised_pnl() → Money | None
Account-level, from the broker’s own account line; never a sum over positions.
PYwhile25.portfolio.snapshot() → dict
The raw answer the calls above read from.
Two strategies, one account
The engine keeps each strategy’s part apart; the broker nets them. Size an exit from my_position(), never position(). A coin held outright is never sold short: a sell beyond the part is refused SELL_EXCEEDS_PART. Where the venue takes its fee from the holding (Alpaca), one strategy at a time trades a coin: a second one’s order is refused LONG_ONLY_ONE_STRATEGY. Both arrive as a REJECT event after the call returned.