Skip to content

Commit fbf97af

Browse files
committed
Drop config path as CLI arg
1 parent 1a7f8f6 commit fbf97af

4 files changed

Lines changed: 23 additions & 32 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-fields/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ hotfix-message = { path = "../../crates/hotfix-message" }
1212

1313
anyhow.workspace = true
1414
async-trait.workspace = true
15-
clap = { workspace = true, features = ["derive"] }
1615
tokio = { workspace = true, features = ["full"] }
1716
tracing.workspace = true
1817
tracing-subscriber = { workspace = true, features = ["env-filter"] }

examples/custom-fields/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ docker compose -f example.compose.yml up --build dummy-executor
4444
In another, from the repo root, run the example:
4545

4646
```shell
47-
cargo run -p custom-fields -- --config examples/custom-fields/config/test-config.toml
47+
cargo run -p custom-fields
4848
```
4949

5050
Expected log output:

examples/custom-fields/src/main.rs

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::sync::Arc;
66
use std::time::Duration;
77

88
use anyhow::{Context, Result, anyhow};
9-
use clap::Parser;
109
use hotfix::config::Config;
1110
use hotfix::field_types::Timestamp;
1211
use hotfix::initiator::Initiator;
@@ -19,28 +18,21 @@ use tracing_subscriber::EnvFilter;
1918
use crate::application::TestApplication;
2019
use crate::messages::{ExecReportSummary, NewOrderSingle, OutboundMsg};
2120

21+
const CONFIG_PATH: &str = "examples/custom-fields/config/test-config.toml";
2222
const LOGON_TIMEOUT: Duration = Duration::from_secs(10);
2323
const FILL_TIMEOUT: Duration = Duration::from_secs(10);
2424
const STRATEGY_ID: i32 = 42;
2525
const CL_ORD_ID: &str = "demo-1";
2626

27-
#[derive(Parser, Debug)]
28-
#[command(author, version, about)]
29-
struct Args {
30-
#[arg(short, long)]
31-
config: String,
32-
}
33-
3427
#[tokio::main]
3528
async fn main() -> Result<()> {
36-
let args = Args::parse();
37-
3829
tracing_subscriber::fmt()
39-
.with_env_filter(EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")))
30+
.with_env_filter(
31+
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
32+
)
4033
.init();
4134

42-
let mut config = Config::load_from_path(&args.config)
43-
.context("failed to load config")?;
35+
let mut config = Config::load_from_path(CONFIG_PATH).context("failed to load config")?;
4436
let session_config = config
4537
.sessions
4638
.pop()
@@ -54,13 +46,10 @@ async fn main() -> Result<()> {
5446
exec_tx,
5547
};
5648

57-
let initiator: Initiator<OutboundMsg> = Initiator::start(
58-
session_config,
59-
app,
60-
InMemoryMessageStore::default(),
61-
)
62-
.await
63-
.context("failed to start initiator")?;
49+
let initiator: Initiator<OutboundMsg> =
50+
Initiator::start(session_config, app, InMemoryMessageStore::default())
51+
.await
52+
.context("failed to start initiator")?;
6453

6554
info!("waiting for logon (up to {:?})", LOGON_TIMEOUT);
6655
timeout(LOGON_TIMEOUT, logon_signal.notified())
@@ -75,9 +64,7 @@ async fn main() -> Result<()> {
7564
transact_time: Timestamp::utc_now(),
7665
client_strategy_id: STRATEGY_ID,
7766
};
78-
info!(
79-
"sending NewOrderSingle ClOrdID={CL_ORD_ID} ClientStrategyId={STRATEGY_ID}"
80-
);
67+
info!("sending NewOrderSingle ClOrdID={CL_ORD_ID} ClientStrategyId={STRATEGY_ID}");
8168
initiator
8269
.send(OutboundMsg::NewOrderSingle(order))
8370
.await
@@ -99,27 +86,33 @@ async fn wait_for_fill(exec_rx: &mut mpsc::UnboundedReceiver<ExecReportSummary>)
9986
loop {
10087
let remaining = deadline.saturating_duration_since(tokio::time::Instant::now());
10188
if remaining.is_zero() {
102-
return Err(anyhow!("did not receive a Filled ExecutionReport within {FILL_TIMEOUT:?}"));
89+
return Err(anyhow!(
90+
"did not receive a Filled ExecutionReport within {FILL_TIMEOUT:?}"
91+
));
10392
}
10493

10594
let summary = match timeout(remaining, exec_rx.recv()).await {
10695
Ok(Some(s)) => s,
10796
Ok(None) => return Err(anyhow!("execution-report channel closed unexpectedly")),
108-
Err(_) => return Err(anyhow!("did not receive a Filled ExecutionReport within {FILL_TIMEOUT:?}")),
97+
Err(_) => {
98+
return Err(anyhow!(
99+
"did not receive a Filled ExecutionReport within {FILL_TIMEOUT:?}"
100+
));
101+
}
109102
};
110103

111104
info!(
112105
"received ExecutionReport ClOrdID={} OrdStatus={:?} ClientStrategyId={:?}",
113106
summary.cl_ord_id, summary.ord_status, summary.client_strategy_id,
114107
);
115108

116-
let echoed = summary
117-
.client_strategy_id
118-
.ok_or_else(|| anyhow!(
109+
let echoed = summary.client_strategy_id.ok_or_else(|| {
110+
anyhow!(
119111
"ExecutionReport for ClOrdID={} did not echo ClientStrategyId — \
120112
the acceptor likely doesn't know about tag 6001",
121113
summary.cl_ord_id,
122-
))?;
114+
)
115+
})?;
123116

124117
if echoed != STRATEGY_ID {
125118
return Err(anyhow!(

0 commit comments

Comments
 (0)