WinningPositionCollector Datasheet
What This Class Does
WinningPositionCollector is a scheduled task component that continuously monitors open trading positions. When a position's unrealized profit meets or exceeds the target profit threshold, it automatically executes a close order via the broker service to secure gains.
Overview
- Package:
online.projectchimba.robot.closers - Class:
WinningPositionCollector - Annotations:
@Configuration,@EnableScheduling
Configuration & Parameters
| Parameter | Type | Default / Value | Description |
|---|---|---|---|
PROFIT |
Double |
42.00 |
The unrealized profit-loss target threshold required to trigger a position closure. |
Math & Profit Calculation Logic
The profit evaluation and trigger evaluation relies on a direct mathematical comparison between the live unrealized profit-loss of a trading position and the configured target constant:
- Unrealized P&L Extraction:
$$\text{unrealizedProfitLoss} = \text{position.getUnrealizedPL().doubleValue()}$$
- Profit Target Condition:
$$\text{isHittingProfitTarget} = \text{unrealizedProfitLoss} \ge \text{PROFIT}$$
When this logical condition evaluates to true ($\text{unrealizedProfitLoss} \ge 42.00$), the system immediately invokes the broker service to close the targeted instrument position and lock in the financial returns.
Core Methods & Tasks
1. launchScheduledWork()
- Access Modifier:
private(@Scheduled) - Schedule Rate: Every 10 seconds (
fixedRate = 1000 * 1 * 10) - Description: Periodically retrieves all open positions from the Oanda broker service, evaluates their unrealized profit/loss against the threshold math, and automatically closes any position meeting or exceeding the
PROFITtarget.