Positions
A position represents an active token holding that is being monitored for price changes, stop loss, and DCA opportunities.
What is a Position?
When an agent executes a buy trade, a position is created. The position tracks:
- What you bought: Token address and symbol
- Purchase details: Price, amount, and total invested
- Current state: Value, P&L, stop loss level
- DCA history: Additional buys on dips
Position Properties
| Property | Description |
|---|---|
tokenAddress | Solana token mint address |
tokenSymbol | Token ticker (e.g., BONK) |
purchasePrice | Average price per token (weighted after DCAs) |
purchaseAmount | Total tokens held |
totalInvestedSol | Total SOL invested (original + DCAs) |
peakPrice | Highest price seen (for trailing stop) |
currentStopLossPercentage | Active stop loss level |
dcaCount | Number of DCA buys executed |
Position Lifecycle
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β OPENED ββββββΆβ MONITORED ββββββΆβ CLOSED β
β β β β β β
β Buy trade β β Price track β β Sell trade β
β executed β β Stop loss β β executed β
β β β DCA eval β β β
βββββββββββββββ βββββββββββββββ βββββββββββββββStage 1: Opened
A position is created when:
- Signal passes agent eligibility checks
- Position size is calculated
- Buy trade executes successfully
Stage 2: Monitored
While open, the position is continuously:
- Price tracked - Current price fetched from feeds
- P&L calculated - Profit/loss computed
- Stop loss evaluated - Checked for trigger
- DCA evaluated - Checked for buy opportunity
Stage 3: Closed
A position closes when:
- Stop loss triggers - Price below threshold
- Manual close - User closes via dashboard/API
- Stale trade - Auto-close after idle period (if configured)
Real-Time Monitoring
Positions are monitored with sub-second latency:
Price Updates
Price Feed (Pyth/DexScreener)
β
βΌ
ββββββββββββββββ
β Price Update β
β Manager β
ββββββββ¬ββββββββ
β
βΌ
ββββββββββββββββ ββββββββββββββββ
β Stop Loss β β WebSocket β
β Evaluator β β Broadcast β
ββββββββββββββββ ββββββββββββββββStop Loss Evaluation
Every price update triggers stop loss evaluation:
- Calculate price change from peak
- Determine current stop loss threshold
- If price β€ threshold β trigger sell
- Update position state
WebSocket Updates
The dashboard receives real-time updates:
{
"type": "position_update",
"data": {
"id": "position-123",
"current": {
"priceNative": 0.00000123,
"priceUsd": 0.00025,
"valueUsd": 125.50
},
"profitLoss": {
"percent": 15.5,
"usd": 16.82
},
"stopLoss": {
"percentage": 85
}
}
}Profit & Loss Calculation
Basic P&L
P&L % = ((Current Price - Purchase Price) / Purchase Price) Γ 100With DCA
When DCA buys occur, the average purchase price is recalculated:
New Average Price = Total Invested SOL / Total Tokens HeldExample:
| Event | SOL Spent | Tokens Received | Avg Price |
|---|---|---|---|
| Initial buy | 0.5 SOL | 1,000,000 | 0.0000005 |
| DCA buy | 0.25 SOL | 625,000 | 0.0000004 |
| Total | 0.75 SOL | 1,625,000 | 0.0000004615 |
Position States
Healthy Position
- Price above purchase price
- Positive P&L
- Stop loss trailing upward
At-Risk Position
- Price below purchase price
- Negative P&L
- Stop loss may trigger soon
DCA Opportunity
- Price dropped to DCA level
- Additional buy may execute
- Average cost will decrease
Viewing Positions
Dashboard
The Positions tab shows:
| Column | Description |
|---|---|
| Token | Symbol and address |
| Entry | Purchase price and time |
| Current | Current price and value |
| P&L | Profit/loss % and USD |
| Stop Loss | Current stop loss level |
| Actions | Close button |
API
# Get all positions for an agent
curl http://localhost:4000/api/v1/agent-positions/{agentId} \
-H "Authorization: Bearer <token>"Response:
[
{
"id": "position-123",
"tokenSymbol": "BONK",
"purchase": {
"priceNative": 0.0000005,
"amount": 1000000
},
"current": {
"priceNative": 0.00000058,
"valueUsd": 125.50
},
"profitLoss": {
"percent": 16.0,
"usd": 17.30
},
"stopLoss": {
"percentage": 85,
"peakPrice": 0.0000006
}
}
]Closing Positions
Manual Close
Via dashboard:
- Click on the position
- Click Close Position
- Select reason (Manual, Take Profit, Stop Loss)
- Confirm
Via API:
curl -X POST http://localhost:4000/api/v1/agent-positions/{agentId}/{positionId}/close \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"reason": "manual"}'Automatic Close
Positions close automatically when:
- Stop loss triggers - Price drops below threshold
- Stale trade - Position idle for configured duration with small P&L
Historical Swaps
When a position closes, it becomes a Historical Swap record:
| Field | Description |
|---|---|
| Entry price | Original purchase price |
| Exit price | Sell price |
| P&L SOL | Profit/loss in SOL |
| P&L USD | Profit/loss in USD |
| Hold time | Duration held |
| Close reason | Manual, stop_loss, stale_trade |
Historical swaps are permanent records for performance tracking.
Best Practices
1. Monitor Active Positions
Check positions regularly, especially during volatile markets.
2. Understand Stop Loss Behavior
Know at what price your position will sell.
3. Consider DCA Carefully
DCA increases your exposure. Ensure you're comfortable with more capital at risk.
4. Review Historical Swaps
Learn from past trades to improve future performance.
5. Don't Over-Leverage
Limit the number of concurrent positions based on your total capital.