keep_position=true.
How It Works
When an executor terminates, it can either:- Close the position and report realized P&L
- Hand over the position to the agent’s inventory for later management
keep_position Behavior
| Setting | Behavior |
|---|---|
true | Position added to inventory, no P&L attributed yet |
false | Position closed, realized P&L calculated and reported |
Executor Defaults
| Executor | keep_position | Rationale |
|---|---|---|
| Order Executor | true (always) | Builds positions for other executors |
| Position Executor | Configurable | Usually closes on barrier hit |
| Grid Executor | Configurable | Can accumulate or close per-level |
| DCA Executor | Configurable | Often accumulates across levels |
| LP Executor | Configurable | Always closes on-chain, optionally tracks tokens |
The Handover Flow
1. Executor Creates Trades
2. Executor Terminates
When the executor terminates (e.g., stop loss hit withkeep_position=true):
3. Position Added to Inventory
The Position Hold aggregates with any existing position:4. Agent Manages on Next Tick
On the next tick, the agent sees the position:- Wait for recovery
- Spawn a new executor to exit
- Hedge with another position
- Add to the position
Example: Grid Stop-Loss Recovery
LP Position Handover
LP positions work differently:- On-chain position always closes when executor terminates
- If
keep_position=true, the net token change is tracked - ADD events → SELL (tokens left wallet)
- REMOVE events → BUY (tokens + fees returned)
Position Accumulation
Multiple executors can add to the same position:When to Use keep_position
| Scenario | Setting | Why |
|---|---|---|
| Building a position over time | true | Accumulate across multiple executors |
| Quick scalp trade | false | Clean exit, immediate P&L |
| Grid accumulation | true | Keep inventory for later exit |
| Range trading grid | false | Lock in profits per level |
| Recovery from stop loss | true | Allow agent to manage exit |
Related
- Inventory - The virtual portfolio concept
- Executors Overview - All executor types

