easyfix_session/
settings.rs

1use std::ops::RangeInclusive;
2
3use chrono::NaiveTime;
4use easyfix_messages::fields::FixString;
5use serde::{Deserialize, Deserializer};
6use tokio::time::Duration;
7
8use crate::session_id::SessionId;
9
10fn duration_from_seconds<'de, D>(deserializer: D) -> Result<Duration, D::Error>
11where
12    D: Deserializer<'de>,
13{
14    Ok(Duration::from_secs(u64::deserialize(deserializer)?))
15}
16
17/// FIX Trading Port session configuration.
18#[derive(Clone, Debug, Deserialize)]
19pub struct Settings {
20    /// FIX SenderCompID<49> field value for outgoing messages.
21    pub sender_comp_id: FixString,
22    /// FIX SenderSubID<50> field value for outgoing messages.
23    pub sender_sub_id: Option<FixString>,
24    /// Timeout \[s\] for inbound/outbound messages. When reached, `TestRequest<1>`
25    /// is sent when inbound message is missing or `Heartbeat<0>` is sent when
26    /// outbound message is missing.
27    #[serde(deserialize_with = "duration_from_seconds")]
28    pub heartbeat_interval: Duration,
29    /// Timeout \[s\] for `Logon<A>` message, when reached, connection is dropped.
30    #[serde(deserialize_with = "duration_from_seconds")]
31    pub auto_disconnect_after_no_logon_received: Duration,
32    /// How many times `TestRequest<1> `is sent when inbound timeout is reached,
33    /// before connection is dropped.
34    pub auto_disconnect_after_no_heartbeat: u32,
35}
36
37#[derive(Clone, Debug, Deserialize)]
38pub struct SessionSettings {
39    pub session_id: SessionId,
40    // TODO: Optional
41    pub session_time: RangeInclusive<NaiveTime>,
42    pub logon_time: RangeInclusive<NaiveTime>,
43
44    pub send_redundant_resend_requests: bool,
45    pub check_comp_id: bool,
46    pub check_latency: bool,
47    pub max_latency: Duration,
48
49    pub reset_on_logon: bool,
50    pub reset_on_logout: bool,
51    pub reset_on_disconnect: bool,
52
53    pub refresh_on_logon: bool,
54
55    pub sender_default_appl_ver_id: FixString,
56    pub target_default_appl_ver_id: FixString,
57
58    /// Enable the next expected message sequence number (optional tag 789
59    /// on Logon) on sent Logon message and use value of tag 789 on received
60    /// Logon message to synchronize session.
61    pub enable_next_expected_msg_seq_num: bool,
62
63    // Enable messages persistence.
64    pub persist: bool,
65
66    // Enable Logout<5> verification.
67    pub verify_logout: bool,
68
69    // When enabled, idle session auto-close grace period counter will only
70    // reset when incoming heartbeat's TestReqID tag value matches value
71    // from one of outgoing grace period's TestRequests.
72    pub verify_test_request_id: bool,
73}