Rewrite trader service for V4 P0
This commit is contained in:
@@ -1,30 +1,54 @@
|
||||
package com.quantai.trader.domain;
|
||||
|
||||
import com.quantai.trader.enums.TraderActionType;
|
||||
import com.quantai.trader.enums.TraderSide;
|
||||
import static com.quantai.trader.util.TraderNumbers.*;
|
||||
|
||||
import com.quantai.trader.enums.PositionSide;
|
||||
import com.quantai.trader.enums.TraderActionType;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public record TraderAction(
|
||||
String actionId,
|
||||
String runId,
|
||||
String cycleId,
|
||||
String actionId,
|
||||
String modelOutputId,
|
||||
String pmDecisionId,
|
||||
String riskDecisionId,
|
||||
TraderActionType actionType,
|
||||
String playbookId,
|
||||
String playbookVersion,
|
||||
String symbol,
|
||||
TraderSide side,
|
||||
BigDecimal price,
|
||||
PositionSide side,
|
||||
String pricePlanId,
|
||||
String pricePlanConfigHash,
|
||||
BigDecimal positionRatio,
|
||||
BigDecimal quantity,
|
||||
Instant actionTime,
|
||||
BigDecimal stopPrice,
|
||||
BigDecimal targetPrice,
|
||||
boolean reduceOnly,
|
||||
String idempotencyKey,
|
||||
String reason,
|
||||
Map<String, Object> actionContext,
|
||||
String sendStatus
|
||||
Map<String, Object> actionContextJson
|
||||
) {
|
||||
|
||||
public TraderAction {
|
||||
actionContext = Maps.immutable(actionContext);
|
||||
actionId = requiredText(actionId, "actionId");
|
||||
runId = requiredText(runId, "runId");
|
||||
cycleId = requiredText(cycleId, "cycleId");
|
||||
modelOutputId = requiredText(modelOutputId, "modelOutputId");
|
||||
pmDecisionId = requiredText(pmDecisionId, "pmDecisionId");
|
||||
riskDecisionId = requiredText(riskDecisionId, "riskDecisionId");
|
||||
actionType = Objects.requireNonNull(actionType, "actionType is required");
|
||||
symbol = requiredText(symbol, "symbol");
|
||||
side = Objects.requireNonNull(side, "side is required");
|
||||
idempotencyKey = requiredText(idempotencyKey, "idempotencyKey");
|
||||
reason = requiredText(reason, "reason");
|
||||
actionContextJson = Map.copyOf(actionContextJson == null ? Map.of() : actionContextJson);
|
||||
if (actionType.increasesExposure()) {
|
||||
pricePlanId = requiredText(pricePlanId, "pricePlanId");
|
||||
pricePlanConfigHash = requiredText(pricePlanConfigHash, "pricePlanConfigHash");
|
||||
positionRatio = positive(positionRatio, "positionRatio");
|
||||
}
|
||||
if (actionType.reducesExposure() && !reduceOnly) {
|
||||
throw new IllegalArgumentException("reduce/close action must be reduceOnly");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user