Implement Trader V4 training artifact pipeline
This commit is contained in:
@@ -30,10 +30,16 @@ public class JdbcTraderDecisionTraceWriter implements TraderDecisionTraceWriter
|
||||
TraderMarketSnapshot snapshot,
|
||||
TraderModelOutput modelOutput,
|
||||
TraderPositionState positionState,
|
||||
TraderAccountState accountState,
|
||||
TraderExecutionState executionState,
|
||||
TraderPositionManagerDecision pmDecision,
|
||||
TraderRiskDecision riskDecision,
|
||||
TraderAction action) {
|
||||
upsertRun(cycle);
|
||||
insertMarketSnapshot(snapshot);
|
||||
insertPositionState(positionState, "PM_INPUT");
|
||||
insertAccountState(accountState, "PM_INPUT");
|
||||
insertExecutionState(executionState, "PM_INPUT");
|
||||
insertCycle(cycle, positionState, riskDecision);
|
||||
insertModelOutput(modelOutput, snapshot);
|
||||
insertPmDecision(pmDecision);
|
||||
@@ -66,6 +72,63 @@ public class JdbcTraderDecisionTraceWriter implements TraderDecisionTraceWriter
|
||||
Timestamp.from(cycle.cycleTime()));
|
||||
}
|
||||
|
||||
void insertMarketSnapshot(TraderMarketSnapshot snapshot) {
|
||||
jdbcTemplate.update("""
|
||||
insert into trader_market_snapshot
|
||||
(run_id, cycle_id, snapshot_id, symbol, snapshot_time, feature_version,
|
||||
mark_price, index_price, spread_bps, funding_rate_bps,
|
||||
depth_notional_5bps, depth_notional_10bps, depth_notional_25bps,
|
||||
data_ready, feature_json, data_quality_json)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
snapshot.runId(), snapshot.cycleId(), snapshot.snapshotId(), snapshot.symbol(),
|
||||
Timestamp.from(snapshot.snapshotTime()), snapshot.featureVersion(), snapshot.markPrice(),
|
||||
snapshot.indexPrice(), snapshot.spreadBps(), snapshot.fundingRateBps(),
|
||||
snapshot.depthNotional5Bps(), snapshot.depthNotional10Bps(), snapshot.depthNotional25Bps(),
|
||||
snapshot.dataReady(), jsonCodec.toJson(snapshot.featureJson()), jsonCodec.toJson(snapshot.dataQualityJson()));
|
||||
}
|
||||
|
||||
void insertPositionState(TraderPositionState state, String role) {
|
||||
jdbcTemplate.update("""
|
||||
insert into trader_position_state
|
||||
(run_id, cycle_id, position_state_id, state_role, symbol, side, position_ratio,
|
||||
average_entry_price, current_price, unrealized_pnl_bps, liquidation_buffer_bps,
|
||||
add_count, remaining_add_capacity, last_add_time)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
state.runId(), state.cycleId(), state.positionStateId(), role, state.symbol(), state.side().name(),
|
||||
state.positionRatio(), state.averageEntryPrice(), state.currentPrice(), state.unrealizedPnlBps(),
|
||||
state.liquidationBufferBps(), state.addCount(), state.remainingAddCapacity(),
|
||||
state.lastAddTime() == null ? null : Timestamp.from(state.lastAddTime()));
|
||||
}
|
||||
|
||||
void insertAccountState(TraderAccountState state, String role) {
|
||||
jdbcTemplate.update("""
|
||||
insert into trader_account_state
|
||||
(run_id, cycle_id, account_state_id, state_role, daily_drawdown_bps,
|
||||
portfolio_exposure_ratio, remaining_symbol_capacity_ratio, consecutive_losses)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
state.runId(), state.cycleId(), state.accountStateId(), role, state.dailyDrawdownBps(),
|
||||
state.portfolioExposureRatio(), state.remainingSymbolCapacityRatio(), state.consecutiveLosses());
|
||||
}
|
||||
|
||||
void insertExecutionState(TraderExecutionState state, String role) {
|
||||
jdbcTemplate.update("""
|
||||
insert into trader_execution_state
|
||||
(run_id, cycle_id, execution_state_id, state_role, symbol, open_orders_json,
|
||||
expected_slippage_bps, exchange_latency_ms, api_error_count, maker_fee_bps,
|
||||
taker_fee_bps, min_notional, price_tick_size, lot_size_step_size,
|
||||
market_lot_size_step_size, liquidity_capacity_ratio)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
state.runId(), state.cycleId(), state.executionStateId(), role, state.symbol(),
|
||||
jsonCodec.toJson(state.openOrders()), state.expectedSlippageBps(), state.exchangeLatencyMs(),
|
||||
state.apiErrorCount(), state.makerFeeBps(), state.takerFeeBps(), state.minNotional(),
|
||||
state.priceTickSize(), state.lotSizeStepSize(), state.marketLotSizeStepSize(),
|
||||
state.liquidityCapacityRatio());
|
||||
}
|
||||
|
||||
void insertCycle(TraderDecisionCycle cycle, TraderPositionState positionState, TraderRiskDecision riskDecision) {
|
||||
jdbcTemplate.update("""
|
||||
insert into trader_decision_cycle
|
||||
@@ -83,14 +146,15 @@ public class JdbcTraderDecisionTraceWriter implements TraderDecisionTraceWriter
|
||||
insert into trader_model_output
|
||||
(run_id, cycle_id, model_output_id, model_bundle_version, calibration_bundle_version,
|
||||
direction_json, entry_json, continue_json, exit_json, risk_json,
|
||||
uncertainty, ood_score, usable, blocker)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
metadata_json, uncertainty, ood_score, usable, blocker)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
modelOutput.runId(), modelOutput.cycleId(), modelOutput.modelOutputId(),
|
||||
modelOutput.modelBundleVersion(), modelOutput.calibrationBundleVersion(),
|
||||
modelOutput.metadata().modelBundleVersion(), modelOutput.metadata().calibrationBundleVersion(),
|
||||
jsonCodec.toJson(modelOutput.direction()), jsonCodec.toJson(modelOutput.entry()),
|
||||
jsonCodec.toJson(modelOutput.continuation()), jsonCodec.toJson(modelOutput.exit()),
|
||||
jsonCodec.toJson(modelOutput.risk()), modelOutput.uncertainty(), modelOutput.oodScore(),
|
||||
jsonCodec.toJson(modelOutput.risk()), jsonCodec.toJson(modelOutput.metadata()),
|
||||
modelOutput.metadata().uncertainty(), modelOutput.metadata().oodScore(),
|
||||
snapshot.dataReady(), snapshot.dataReady() ? null : "DATA_NOT_READY");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user