Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ models/
*.jsonl
*.json
*.csv
!rust_hft/data/backtest/*.manifest.json
!rust_hft/prediction-markets/**/*.json
!rust_hft/prediction-markets/**/*.jsonl
!rust_hft/prediction-markets/**/*.csv
Expand Down
2 changes: 1 addition & 1 deletion deploy/Dockerfile.hft
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ENV HFT_TARGET=${TARGET}

# 健康檢查
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD if [ "$HFT_TARGET" = "live" ]; then curl --fail --silent http://localhost:9090/readiness; else exit 0; fi
CMD if [ "$HFT_TARGET" = "live" ]; then curl --fail --silent http://localhost:9090/health; else exit 0; fi

# 默認暴露端口
EXPOSE 9090 9092
Expand Down
18 changes: 18 additions & 0 deletions rust_hft/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust_hft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ members = [
"data-pipelines/adapters-common",
"data-pipelines/adapters/adapter-bitget",
"data-pipelines/adapters/adapter-binance",
"data-pipelines/adapters/adapter-binance-prediction",
"data-pipelines/adapters/adapter-backpack",
"data-pipelines/adapters/adapter-mock",
"data-pipelines/adapters/adapter-replay",
Expand Down
18 changes: 16 additions & 2 deletions rust_hft/alpha-harness/app/src/loop_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,10 @@ mod tests {
metrics: BTreeMap::from([
("gross_pnl_coverage_complete".to_string(), 1.0),
("mark_coverage_complete".to_string(), 1.0),
("authoritative_account_snapshot_coverage".to_string(), 1.0),
("venue_reconciliation_complete".to_string(), 1.0),
("venue_reconciliation_healthy".to_string(), 1.0),
("venue_reconciliation_age_us".to_string(), 1_000.0),
]),
reason: None,
observed_at: now + Duration::seconds(1),
Expand Down Expand Up @@ -1130,7 +1134,12 @@ mod tests {
account_id: Some(account_id.clone()),
venue: Some(venue.clone()),
symbol: None,
metrics: BTreeMap::new(),
metrics: BTreeMap::from([
("authoritative_account_snapshot_coverage".to_string(), 1.0),
("venue_reconciliation_complete".to_string(), 1.0),
("venue_reconciliation_healthy".to_string(), 1.0),
("venue_reconciliation_age_us".to_string(), 1_000.0),
]),
reason: None,
observed_at: now,
},
Expand Down Expand Up @@ -1862,7 +1871,12 @@ mod tests {
account_id: Some("account-1".to_string()),
venue: Some("binance".to_string()),
symbol: None,
metrics: BTreeMap::new(),
metrics: BTreeMap::from([
("authoritative_account_snapshot_coverage".to_string(), 1.0),
("venue_reconciliation_complete".to_string(), 1.0),
("venue_reconciliation_healthy".to_string(), 1.0),
("venue_reconciliation_age_us".to_string(), 1_000.0),
]),
reason: None,
observed_at: now,
},
Expand Down
40 changes: 40 additions & 0 deletions rust_hft/alpha-harness/domain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,7 @@ pub fn runtime_stage_is_healthy(
}
if event.outcome == AttributionOutcome::Healthy
&& event.kind == AttributionKind::PortfolioSnapshot
&& portfolio_snapshot_has_authoritative_truth(event)
{
if let Some(strategy_id) = event.strategy_id.as_ref() {
health
Expand Down Expand Up @@ -1387,6 +1388,27 @@ pub fn runtime_stage_is_healthy(
})
}

const MAX_RUNTIME_RECONCILIATION_AGE_US: f64 = 30_000_000.0;

fn portfolio_snapshot_has_authoritative_truth(event: &RuntimeAttributionEvent) -> bool {
let metric_is_one = |name: &str| {
event
.metrics
.get(name)
.is_some_and(|value| value.is_finite() && *value >= 1.0)
};
let age_is_fresh = event
.metrics
.get("venue_reconciliation_age_us")
.is_some_and(|value| {
value.is_finite() && *value >= 0.0 && *value <= MAX_RUNTIME_RECONCILIATION_AGE_US
});
metric_is_one("authoritative_account_snapshot_coverage")
&& metric_is_one("venue_reconciliation_complete")
&& metric_is_one("venue_reconciliation_healthy")
&& age_is_fresh
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct LearningDirective {
pub directive_id: String,
Expand Down Expand Up @@ -2614,6 +2636,24 @@ mod tests {
AttributionOutcome::Healthy,
Some("strategy-1"),
));
assert!(!runtime_stage_is_healthy(
&events,
"candidate-1",
AttributionMode::Shadow
));
let snapshot = events.last_mut().unwrap();
snapshot
.metrics
.insert("authoritative_account_snapshot_coverage".to_string(), 1.0);
snapshot
.metrics
.insert("venue_reconciliation_complete".to_string(), 1.0);
snapshot
.metrics
.insert("venue_reconciliation_healthy".to_string(), 1.0);
snapshot
.metrics
.insert("venue_reconciliation_age_us".to_string(), 1_000.0);
assert!(runtime_stage_is_healthy(
&events,
"candidate-1",
Expand Down
4 changes: 3 additions & 1 deletion rust_hft/apps/backtest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ ordered-float = "3.9"
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
serde_yaml = "0.9"
sha2 = { workspace = true }
hex = { workspace = true }
hft-collector = { path = "../../tools/collector", default-features = false }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }

Loading
Loading