Skip to content
Open RaamTrade

RC2_EXIT_NO_KWARGS

Exit verbs don’t take percent= or qty= — the quantity is positional.

What it means

sell and buy_to_cover take their quantity as the second positional argument, and only there. qty= and percent= are sizing overrides, and sizing is an entry-side concept: it answers “how big should this new position be”, from capital and price. An exit doesn’t open anything — it reduces what you already hold, so the only sensible quantity is one you compute from the position itself.

Why it happens

Symmetry with the entry verbs, where qty= and percent= are exactly right:

class ExitOverride(Strategy):
trade = Symbol()
sizing = FixedCapital()
def execute(self):
if self.trade.is_flat:
self.buy(self.trade)
if self.trade.is_long:
self.sell(self.trade, self.trade.position, percent=50)

Which of the two exit diagnostics you get

The positional quantity is checked first. So self.sell(self.trade, qty=100) — kwarg, no positional — reports RC2_EXIT_NO_QTY, not this code. RC2_EXIT_NO_KWARGS is what you see once a positional quantity is present and a sizing kwarg came along with it.

How to fix it

Express the partial exit in the positional quantity — it is an ordinary decimal expression, so arithmetic on self.trade.position says exactly what you mean.

class PartialExit(Strategy):
trade = Symbol()
sizing = FixedCapital()
def execute(self):
if self.trade.is_flat:
self.buy(self.trade)
if self.trade.is_long:
self.sell(self.trade, self.trade.position / 2, reason="half off")

Other shapes: self.trade.position (everything), self.trade.position / 3 (a third), 50 (a fixed count).