Skip to content
Merged
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
15 changes: 2 additions & 13 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions crates/hotfix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ anyhow = { workspace = true }
aws-config = { version = "1", optional = true }
aws-sdk-dynamodb = { version = "^0.39", optional = true }
async-trait = "^0.1.73"
chrono = { version = "0.4", features = ["serde"] }
futures = "^0.3.28"
hotfix-message = { version = "0.0.23", path = "../hotfix-message" }
mongodb = { version = "^2.7", optional = true }
Expand All @@ -36,8 +37,6 @@ serde_dynamo = { version = "^4.2.12", features = ["aws-sdk-dynamodb+0_39"], opti
thiserror = { workspace = true }
tokio = { version = "^1", features = ["full"] }
tokio-rustls = "^0.24.1"
tokio-stream = "^0.1.14"
toml = { workspace = true }
tracing = { workspace = true }
log = "0.4.20"
uuid = { version = "1.5.0", features = ["v4"] }
89 changes: 89 additions & 0 deletions crates/hotfix/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! config file. See the
//! [example project's config file](https://github.com/Validus-Risk-Management/hotfix/blob/main/examples/simple-new-order/config/test-config.toml)
//! for more detail.
use chrono::{NaiveTime, Weekday};
use serde::Deserialize;
use std::fs;
use std::path::Path;
Expand All @@ -30,6 +31,17 @@ pub struct TlsConfig {
pub ca_certificate_path: String,
}

/// Session schedule configuration
#[derive(Clone, Debug, Deserialize, PartialEq)]
pub struct ScheduleConfig {
pub start_time: Option<NaiveTime>,
pub end_time: Option<NaiveTime>,
pub start_day: Option<Weekday>,
pub end_day: Option<Weekday>,
#[serde(default)]
pub weekdays: Vec<Weekday>,
}

fn default_reconnect_interval() -> u64 {
30
}
Expand Down Expand Up @@ -61,12 +73,16 @@ pub struct SessionConfig {
/// The interval we should attempt to reconnect at in seconds.
pub reconnect_interval: u64,
/// Specifies whether we should reset the state of the message store on logon.
#[serde(default)]
pub reset_on_logon: bool,
/// The schedule configuration for the session
pub schedule: Option<ScheduleConfig>,
}

#[cfg(test)]
mod tests {
use crate::config::{Config, TlsConfig};
use chrono::{NaiveTime, Weekday};

#[test]
fn test_simple_config() {
Expand Down Expand Up @@ -104,4 +120,77 @@ reset_on_logon = false
assert_eq!(session_config.tls_config, Some(expected_tls_config));
assert_eq!(session_config.reconnect_interval, 30);
}

#[test]
fn test_schedule_config_weekdays() {
let config_contents = r#"
[[sessions]]
begin_string = "FIX.4.4"
sender_comp_id = "send-comp-id"
target_comp_id = "target-comp-id"
heartbeat_interval = 30

connection_port = 443
connection_host = "127.0.0.1"

[sessions.schedule]
start_time = "00:00:00"
end_time = "23:55:00"
weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
"#;

let config: Config = toml::from_str(config_contents).unwrap();
assert_eq!(config.sessions.len(), 1);
let session = config.sessions.first().unwrap();

assert!(session.schedule.is_some());
let schedule = session.schedule.as_ref().unwrap();

assert_eq!(schedule.start_time, NaiveTime::from_hms_opt(0, 0, 0));
assert_eq!(schedule.end_time, NaiveTime::from_hms_opt(23, 55, 0));
assert_eq!(
schedule.weekdays,
vec![
Weekday::Mon,
Weekday::Tue,
Weekday::Wed,
Weekday::Thu,
Weekday::Fri
]
);
assert_eq!(schedule.start_day, None);
assert_eq!(schedule.end_day, None);
}

#[test]
fn test_schedule_config_weeklong_session() {
let config_contents = r#"
[[sessions]]
begin_string = "FIX.4.4"
sender_comp_id = "send-comp-id"
target_comp_id = "target-comp-id"
heartbeat_interval = 30

connection_port = 443
connection_host = "127.0.0.1"

[sessions.schedule]
start_time = "00:00:00"
end_time = "23:55:00"
start_day = "Monday"
end_day = "Friday"
"#;

let config: Config = toml::from_str(config_contents).unwrap();
assert_eq!(config.sessions.len(), 1);
let session = config.sessions.first().unwrap();

assert!(session.schedule.is_some());
let schedule = session.schedule.as_ref().unwrap();

assert_eq!(schedule.start_time, NaiveTime::from_hms_opt(0, 0, 0));
assert_eq!(schedule.end_time, NaiveTime::from_hms_opt(23, 55, 0));
assert_eq!(schedule.start_day, Some(Weekday::Mon));
assert_eq!(schedule.end_day, Some(Weekday::Fri));
}
}
6 changes: 6 additions & 0 deletions crates/hotfix/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ pub enum MessageVerificationError {
#[error("incorrect comp id {0}")]
IncorrectCompId(String),
}

#[derive(Debug, Error)]
pub enum SessionError {
#[error("Schedule configuration is invalid: {0}")]
InvalidSchedule(String),
}
1 change: 1 addition & 0 deletions crates/hotfix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub mod initiator;
pub mod message;
mod message_utils;
pub(crate) mod session;
mod session_schedule;
pub mod store;
pub(crate) mod transport;

Expand Down
Loading