Skip to Content
While25SDK docs
Trading

Two strategies, one account

Tags, my_position() and order streams that keep strategies on one account apart.

A live strategy trades the account, not a private book. Everything it reads back is account-wide:

  • while25.portfolio.position(key) is the account's net position on that instrument — another strategy's trades and a trade worked by hand in the platform included. Size an exit from my_position(), what your module holds now, never from position(), or it can sell someone else's shares. A count of your own (the fills of the order ids you got back) goes stale when the whole position is squared off: read it again from my_position() on POSITION_SQUARED_OFF.
  • @on.order and @on.fill deliver every order event on the account — another strategy's, and the human's. There is no owner field; match on the order_id your call returned, or on a tag you set on your own orders.

The broker nets every fill on an instrument into one position; While25 keeps each strategy's PART of it apart (2026-10-18). Two strategies may trade one instrument at once: each keeps its own part — changed by its own orders, ended only by a square off of the whole position (below) — its own stops, measured against that part, and its own Stop, which squares off that part and nothing else; the broker nets the parts. Brackets too: two strategies' brackets stand side by side on one instrument, each sized to its own fills.

A coin held outright (crypto spot) can never be sold short, so there a strategy sells only what its own part holds, less its sells already working (SELL_EXCEEDS_PART beyond that; a short bracket entry likewise). One strategy can never sell another's coins, or the human's.

Where the venue takes its fees from the holding itself and does not report them per fill — Alpaca today; each broker adapter declares it — nobody can say whose fill paid the fee, so While25 cannot keep separate parts of a coin: every stop and bracket on it follows the account's whole holding, and one strategy at a time trades it. A second strategy's order there (plain or bracket) is refused LONG_ONLY_ONE_STRATEGY while the first holds a part, has a working order or a live bracket, in words, naming it. A venue that reports its fees per fill has no such rule: its coins keep parts per strategy like everything else.

Two Strategy classes inside one App are ONE owner. The App's orders, grant and part are the App's (py:<app id>), whichever of its strategies placed them — so one of them can flatten the other's bracketed position exactly as a trade by hand could. Keep strategies that share an instrument in separate modules.

What the parts do not cover: a trade made by hand still nets against a strategy's position (it is the account owner's intent). A strategy stopped with a position open keeps it as its own part unless the Stop squared that part off: the part stays under the strategy's id through the Stop and through a restart of the app, and the Positions tab shows it under the strategy. Deployed again, the same strategy (the same id) reads it with while25.portfolio.my_position(key) and goes on from there, and its brackets and working orders are its own again.

A square off of the whole position takes every strategy's units on it: Square off on the position's row in the Positions tab, the daily loss limit's close, or the broker's own square off. Each strategy's part, brackets and combo parts on that position end at once (their stops and take-profits come off; the one close sells the units with the rest), and the strategy keeps running. Its module hears POSITION_SQUARED_OFF for each thing taken, my_position() no longer counts it from that moment, and what the units sold for counts in its closed P&L where that close's own fills state it.