OrderManagerConfig
Configuration for OrderManager. Immutable configuration object using builder pattern.
OrderManagerConfig.java
package com.bookmap.ordermanagement.manager;
import java.time.Duration;
import java.time.LocalTime;
/**
* Configuration for OrderManager.
*
* Immutable configuration object using builder pattern.
*/
public class OrderManagerConfig {
// Order settings
private final int orderSize;
private final int takeProfitTicks;
private final int stopLossTicks;
// Instrument settings
private final double tickSize;
private final double tickValue;
// Timing settings
private final Duration cooldownDuration;
private final LocalTime sessionResetTime;
private final boolean autoSessionReset;
// Logging settings
private final boolean loggingEnabled;
private final String logPrefix;
private OrderManagerConfig(Builder builder) {
this.orderSize = builder.orderSize;
this.takeProfitTicks = builder.takeProfitTicks;
this.stopLossTicks = builder.stopLossTicks;
this.tickSize = builder.tickSize;
this.tickValue = builder.tickValue;
this.cooldownDuration = builder.cooldownDuration;
this.sessionResetTime = builder.sessionResetTime;
this.autoSessionReset = builder.autoSessionReset;
this.loggingEnabled = builder.loggingEnabled;
this.logPrefix = builder.logPrefix;
}
// =========================================================================
// Getters
// =========================================================================
public int getOrderSize() { return orderSize; }
public int getTakeProfitTicks() { return takeProfitTicks; }
public int getStopLossTicks() { return stopLossTicks; }
public double getTickSize() { return tickSize; }
public double getTickValue() { return tickValue; }
public Duration getCooldownDuration() { return cooldownDuration; }
public LocalTime getSessionResetTime() { return sessionResetTime; }
public boolean isAutoSessionReset() { return autoSessionReset; }
public boolean isLoggingEnabled() { return loggingEnabled; }
public String getLogPrefix() { return logPrefix; }
// =========================================================================
// Validation
// =========================================================================
/**
* Validates the configuration.
*
* @throws IllegalArgumentException if configuration is invalid
*/
public void validate() {
if (orderSize <= 0) {
throw new IllegalArgumentException("orderSize must be positive");
}
if (takeProfitTicks <= 0) {
throw new IllegalArgumentException("takeProfitTicks must be positive");
}
if (stopLossTicks <= 0) {
throw new IllegalArgumentException("stopLossTicks must be positive");
}
if (tickSize <= 0) {
throw new IllegalArgumentException("tickSize must be positive");
}
if (tickValue <= 0) {
throw new IllegalArgumentException("tickValue must be positive");
}
}
// =========================================================================
// Factory Methods
// =========================================================================
/**
* Creates a builder for ES futures with sensible defaults.
*/
public static Builder forES() {
return new Builder()
.tickSize(0.25)
.tickValue(12.50)
.orderSize(1)
.takeProfitTicks(16)
.stopLossTicks(8)
.cooldownDuration(Duration.ofMinutes(2))
.sessionResetTime(LocalTime.of(9, 30))
.autoSessionReset(true)
.loggingEnabled(true)
.logPrefix("[OrderMgr]");
}
public static Builder builder() {
return new Builder();
}
// =========================================================================
// Builder
// =========================================================================
public static class Builder {
private int orderSize = 1;
private int takeProfitTicks = 16;
private int stopLossTicks = 8;
private double tickSize = 0.25;
private double tickValue = 12.50;
private Duration cooldownDuration = Duration.ofMinutes(2);
private LocalTime sessionResetTime = LocalTime.of(9, 30);
private boolean autoSessionReset = true;
private boolean loggingEnabled = true;
private String logPrefix = "[OrderMgr]";
public Builder orderSize(int size) {
this.orderSize = size;
return this;
}
public Builder takeProfitTicks(int ticks) {
this.takeProfitTicks = ticks;
return this;
}
public Builder stopLossTicks(int ticks) {
this.stopLossTicks = ticks;
return this;
}
public Builder tickSize(double tickSize) {
this.tickSize = tickSize;
return this;
}
public Builder tickValue(double tickValue) {
this.tickValue = tickValue;
return this;
}
public Builder cooldownDuration(Duration duration) {
this.cooldownDuration = duration;
return this;
}
public Builder cooldownMinutes(int minutes) {
this.cooldownDuration = Duration.ofMinutes(minutes);
return this;
}
public Builder cooldownSeconds(int seconds) {
this.cooldownDuration = Duration.ofSeconds(seconds);
return this;
}
public Builder sessionResetTime(LocalTime time) {
this.sessionResetTime = time;
return this;
}
public Builder autoSessionReset(boolean enabled) {
this.autoSessionReset = enabled;
return this;
}
public Builder loggingEnabled(boolean enabled) {
this.loggingEnabled = enabled;
return this;
}
public Builder logPrefix(String prefix) {
this.logPrefix = prefix;
return this;
}
public OrderManagerConfig build() {
return new OrderManagerConfig(this);
}
}
@Override
public String toString() {
return String.format(
"OrderManagerConfig{size=%d, TP=%d, SL=%d, cooldown=%s, tickSize=%.4f}",
orderSize, takeProfitTicks, stopLossTicks, cooldownDuration, tickSize);
}
}