Package-level declarations

Types

Link copied to clipboard

Pipeline-owned lifecycle for one-shot DSL exit hooks.

Link copied to clipboard
interface FeedLossReads

Whether a session stopped because its live feed was lost rather than because it was asked to.

Link copied to clipboard
data class FlattenResult(val verifiedFlat: Boolean, val remainingTickets: List<String> = emptyList(), val detail: String? = null)

Result returned to an operator after an emergency flatten attempt.

Link copied to clipboard
interface HaltReads

What a session can say about being halted. A handle that cannot halt answers "no" to everything; a live session answers from its risk state, e.g. haltReason() = "operator", haltScope() = PERSISTENT, haltedAtMs() = 1789950000000.

Link copied to clipboard

Gives a plain opposite-side BUY/SELL its netting meaning on a hedging venue.

Link copied to clipboard

Pre-feeds historical ticks through the pipeline before live signal evaluation.

Link copied to clipboard

How a bar's intrabar ticks must be resolved for tick-resolved fills (--bars --tick-fills).

Link copied to clipboard
class LatchManager(clock: Clock, defaultEmit: (OrderRequest) -> Unit? = null)

Holds armed latches and resolves them on ticks.

Link copied to clipboard

Decides, once, what a fill of each leaf in OrderRequest means to the position ledger.

Link copied to clipboard
class LegIntentResolver(orderFor: (clientOrderId: String) -> OrderRequest?, legByTicket: (strategyId: String, symbol: String, ticket: String) -> PositionLeg?, positionMode: (symbol: String) -> PositionAccountingMode)

Recovers the LegIntent behind an execution, in a fixed precedence:

Link copied to clipboard

Source used for standalone live strategy equity and equity-based sizing.

Link copied to clipboard
class LiveSession(strategies: List<Pair<String, Strategy>>, strategyCommentNames: Map<String, String> = emptyMap(), rules: List<RiskRule> = emptyList(), haltRules: List<HaltRule> = emptyList(), source: MarketSource, symbols: List<String>, feedSymbols: List<String> = symbols, candleWindow: TimeWindow? = null, clock: Clock = SystemClock(), calendar: TradingCalendar = TradingCalendar.fxDefault(), accountingConfig: AccountingConfig = com.qkt.accounting.AccountingConfig(), equityBasis: LiveEquityBasis = LiveEquityBasis.VENUE, warmupOverride: WarmupSpec? = null, mdcStrategy: String? = null, candleHub: CandleHub? = null, onWarmupTick: (Tick) -> Unit = {}, onTrade: (Trade, BigDecimal, String) -> Unit = { _, _, _ -> }, onSignal: (Signal) -> Unit = {}, gate: () -> Boolean = { true }, bookRiskController: BookRiskController? = null, brokerFactories: Map<String, BrokerFactory> = emptyMap(), instrumentRegistry: InstrumentRegistry? = null, persistor: StatePersistor = com.qkt.persistence.NoopStatePersistor(), ignoreMismatches: Boolean = false, notifier: Notifier = NoopNotifier, notifyEvents: Set<NotifyEventKind> = emptySet(), perStrategyMaxDailyLoss: BigDecimal? = null, perStrategyMaxPositionSize: BigDecimal? = null, perStrategyMaxOpenPositions: Int? = null, perStrategyMaxDrawdownPct: BigDecimal? = null, perStrategyMaxDailyDrawdownPct: BigDecimal? = null, perStrategyMaxTradesPerDay: Int? = null, perStrategyCooldownAfterLossMs: Long? = null, perStrategyCooldownAfterLossAfterConsecutive: Int = 1, perStrategyLossStreakHalt: Int? = null, perStrategyLossStreakHaltScope: HaltScope = com.qkt.risk.HaltScope.PERSISTENT, initialBalance: BigDecimal = java.math.BigDecimal.ZERO, totalDdBasis: DrawdownBasis = com.qkt.risk.DrawdownBasis.STATIC, dailyDdBasis: DailyDrawdownBasis = com.qkt.risk.DailyDrawdownBasis.BALANCE, maxOrderQty: BigDecimal = com.qkt.risk.rules.PreTradeControls.DEFAULT_MAX_ORDER_QTY, maxOrderNotional: BigDecimal = com.qkt.risk.rules.PreTradeControls.DEFAULT_MAX_ORDER_NOTIONAL, priceCollarFrac: BigDecimal = com.qkt.risk.rules.PreTradeControls.DEFAULT_PRICE_COLLAR_FRAC, runawayMaxRoundTrips: Int = com.qkt.risk.RunawayBreaker.DEFAULT_MAX_ROUND_TRIPS, runawayMaxRejections: Int = com.qkt.risk.RunawayBreaker.DEFAULT_MAX_REJECTIONS, marginFloorPct: BigDecimal = java.math.BigDecimal("200"), measuredUsageHours: Long = 0, measuredUsageMaxQty: BigDecimal = com.qkt.risk.rules.MeasuredUsage.DEFAULT_MEASURED_MAX_QTY, journal: OrderJournal? = null, auditJournal: EngineAuditJournal? = null, insightsSink: InsightsSink? = null, insightsEvents: Set<InsightsEventFamily> = emptySet(), insightsStrategyMetadata: Map<String, Map<String, Any?>> = emptyMap(), insightsDeployedIds: () -> Collection<String> = { emptyList() }, insightsStatePollMs: Long, insightsSharedDeals: SharedDealFetch = com.qkt.observe.insights .SharedDealFetch(), insightsDealBackfillDays: Long = 30, marketDataGateConfig: MarketDataGateConfig = com.qkt.marketdata.MarketDataGateConfig.DEFAULT, latencyEnabled: Boolean = System.getenv("QKT_LATENCY_TRACKING") == "1", scheduleHeartbeatIntervalMs: Long = 1000, candleCloseGraceMs: Long = DEFAULT_CANDLE_CLOSE_GRACE_MS, startingBalances: Map<String, BigDecimal> = emptyMap(), bookBalance: BookBalanceView? = null, busOverride: EventBus? = null, reconcileReadBackoffMs: Long = 500, brokerEquityPollMs: Long = BROKER_EQUITY_POLL_MS, brokerEquityStaleMs: Long = BROKER_EQUITY_STALE_MS)

Runs one or more strategies against a live or paper data source, end to end.

Link copied to clipboard

Operator handle for a running LiveSession.

Link copied to clipboard
Link copied to clipboard
class OrderManager(broker: Broker, bus: EventBus, priceProvider: MarketPriceProvider, clock: Clock, persistor: StatePersistor = NoopStatePersistor(), closeTicketFor: (String, String) -> String?? = null, closePrimaryTicketFor: (String, String) -> String?? = null, requireArmedTrailTicket: Boolean = false, instruments: InstrumentRegistry = NoopInstrumentRegistry, trackRisk: Boolean = false, onProtectionFailure: (strategyId: String, message: String) -> Unit = { _, _ -> }, engineHeldSubmissionBlockReason: (OrderRequest) -> String? = { null }, isRiskReducingForHalt: (OrderRequest) -> Boolean = { false }, strategyNetQty: (strategyId: String, symbol: String) -> BigDecimal? = null, positionMode: (symbol: String) -> PositionAccountingMode = { PositionAccountingMode.UNKNOWN }, bookedVenueTickets: (strategyId: String) -> Set<String> = { emptySet() }, openLegQuantity: (strategyId: String, legId: String) -> BigDecimal?? = null) : PendingOrderExposureProvider

Manages the lifecycle of every order from signal to fill.

Link copied to clipboard
data class PositionDelta(val symbol: String, val engineQty: BigDecimal, val brokerQty: BigDecimal, val side: Side? = null)

One symbol where engine and broker disagree on net quantity.

Link copied to clipboard
data class PositionProtectionDelta(val ticket: String, val symbol: String, val requestedStopLoss: BigDecimal?, val brokerStopLoss: BigDecimal?, val requestedTakeProfit: BigDecimal?, val brokerTakeProfit: BigDecimal?)

One venue ticket whose attached protection differs from qkt's last requested levels.

Link copied to clipboard
class RecentTrades(capacity: Int = DEFAULT_CAPACITY)

Bounded buffer of the most recent fills, feeding LiveSessionHandle.recentTrades and the daemon status snapshot. Keeps the last capacity trades and silently drops older ones, so a session running for months holds a fixed amount of trade history, not all of it.

Link copied to clipboard

Thrown by LiveSession.start when persisted leg state and broker positions don't agree, and the operator hasn't opted into ignore-mismatch attachment via the --reconcile=ignore-mismatches flag.

Link copied to clipboard
data class ReconcileReport(val deltas: List<PositionDelta>, val engineEquity: BigDecimal, val brokerEquity: BigDecimal?, val protectionDeltas: List<PositionProtectionDelta> = emptyList(), val brokerReadFailed: Boolean = false, val brokerReadError: String? = null)

Result of an engine-vs-broker reconcile pass.

Link copied to clipboard
data class SessionPnl(val equity: BigDecimal, val balance: BigDecimal, val realized: BigDecimal, val unrealized: BigDecimal)

A point-in-time P&L reading for one strategy, surfaced through /status.

Link copied to clipboard
class TradingPipeline(val clock: Clock, val ids: IdGenerator, val sequencer: SequenceGenerator, val priceTracker: MarketPriceTracker, val positions: PositionProvider, val pnl: PnLCalculator, val strategyPositions: StrategyPositionTracker, val strategyPnL: StrategyPnL, val bus: EventBus, val broker: Broker, val engine: Engine, val strategies: List<Pair<String, Strategy>>, val riskEngine: RiskEngine, val riskState: RiskState, val mode: Mode, val replayCandleCloseGraceMs: Long = LiveSession.DEFAULT_CANDLE_CLOSE_GRACE_MS, val replayHeartbeatIntervalMs: Long, val positionMode: (symbol: String) -> PositionAccountingMode = { PositionAccountingMode.UNKNOWN }, val calendar: TradingCalendar, val source: MarketSource, val candleWindow: TimeWindow? = null, val candleHub: CandleHub = CandleHub(), val onFilled: (Trade, BigDecimal, String) -> Unit = { _, _, _ -> }, val onAccountedFill: (Trade, ConvertedMoney, String, FillState) -> Unit = { _, _, _, _ -> }, val onRejected: (RiskRejectedEvent) -> Unit = {}, val onCandle: (Candle) -> Unit = {}, val preCandle: (Candle) -> Unit = {}, val gate: () -> Boolean = { true }, val gateFor: (String) -> Boolean = { true }, val persistor: StatePersistor = NoopStatePersistor(), val instruments: InstrumentRegistry = NoopInstrumentRegistry, val commissionBook: CommissionBook = CommissionBook(), val accounting: AccountingEngine = AccountingEngine(), val tradeHistory: TradeHistory = TradeHistory(persistor = persistor), val onProtectionFailure: (strategyId: String, message: String) -> Unit = { _, _ -> }, val pacerLedger: PacerLedger = PacerLedger(), pacerCooldownDurationMs: Long? = null, pacerCooldownAfterConsecutive: Int = 1, pacerCooldownDurationMsFor: (String) -> Long?? = null, pacerCooldownAfterConsecutiveFor: (String) -> Int? = null, val latencyEnabled: Boolean = System.getenv("QKT_LATENCY_TRACKING") == "1", val brokerZoneIdFor: (String) -> ZoneId?? = null, runawayBreaker: RunawayBreaker? = null, marketDataGate: MarketDataGate? = null, bookScaleFor: (String) -> BigDecimal = { BigDecimal.ONE }, bookBalance: BookBalanceView? = null)

The reusable end-to-end wiring of bus + engine + risk + order management + broker.

Link copied to clipboard
class WarmupFailedException(val streamAlias: String, val qktSymbol: String, cause: Throwable) : RuntimeException

Thrown when the broker historical-bar API fails during a deploy's pre-warmup phase. Aborts deploy before any rule fires, so the strategy never starts in a half-warm state. Operator sees a pointed error naming the stream + symbol + underlying cause.

Link copied to clipboard
class WarmupUnderfilledException(symbol: String, window: TimeWindow, requested: Int, available: Int, upperMs: Long, searchedDurationMs: Long) : RuntimeException

Indicates that a live strategy could not obtain enough closed bars to initialize its indicators.

Functions

Link copied to clipboard
fun main()
fun main()
fun main()
Link copied to clipboard
fun reconcileDeltas(ownerId: String, brokerTickets: List<BrokerPositionTicket>, attribution: TicketAttribution, engineLegs: List<PositionLeg>, accountingModes: Map<String, PositionAccountingMode> = emptyMap()): List<PositionDelta>

Engine-vs-broker position deltas for one strategy on a (possibly shared) account.

Link copied to clipboard

Protection drift for tickets owned by ownerId and carrying qkt-requested levels.