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. If not set value from Logon<A> will be used.
27    pub heartbeat_interval: Option<u64>,
28    /// Timeout \[s\] for `Logon<A>` message, when reached, connection is dropped.
29    #[serde(deserialize_with = "duration_from_seconds")]
30    pub auto_disconnect_after_no_logon_received: Duration,
31    /// How many times `TestRequest<1> `is sent when inbound timeout is reached,
32    /// before connection is dropped.
33    pub auto_disconnect_after_no_heartbeat: u32,
34    /// Timeout for waiting for Logout<5> acknowledgment during graceful
35    /// session termination. If exceeded, the session terminates forcefully.
36    #[serde(deserialize_with = "duration_from_seconds")]
37    pub auto_disconnect_after_no_logout: Duration,
38}
39
40#[derive(Clone, Debug, Deserialize)]
41pub struct SessionSettings {
42    pub session_id: SessionId,
43    // TODO: Optional
44    pub session_time: RangeInclusive<NaiveTime>,
45    pub logon_time: RangeInclusive<NaiveTime>,
46
47    pub send_redundant_resend_requests: bool,
48    pub check_comp_id: bool,
49
50    /// Maximum allowed difference between message SendingTime(52) and current
51    /// time. If `None`, SendingTime is not validated. If `Some`, messages with
52    /// SendingTime differing by more than this duration are rejected.
53    pub max_latency: Option<Duration>,
54
55    pub reset_on_logon: bool,
56    pub reset_on_logout: bool,
57    pub reset_on_disconnect: bool,
58
59    pub refresh_on_logon: bool,
60
61    pub sender_default_appl_ver_id: FixString,
62    pub target_default_appl_ver_id: FixString,
63
64    /// Enable the next expected message sequence number (optional tag 789
65    /// on Logon) on sent Logon message and use value of tag 789 on received
66    /// Logon message to synchronize session.
67    pub enable_next_expected_msg_seq_num: bool,
68
69    /// Enable messages persistence.
70    pub persist: bool,
71
72    /// Enable Logout<5> verification.
73    pub verify_logout: bool,
74
75    /// When enabled, idle session auto-close grace period counter will only
76    /// reset when incoming heartbeat's TestReqID tag value matches value
77    /// from one of outgoing grace period's TestRequests.
78    pub verify_test_request_id: bool,
79}