nautilus_betfair/stream/config.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Configuration for the Betfair stream client.
17
18use crate::common::consts::{BETFAIR_STREAM_HOST, BETFAIR_STREAM_PORT};
19
20/// Configuration for the Betfair Exchange Stream API client.
21#[derive(Debug, Clone)]
22pub struct BetfairStreamConfig {
23 /// Stream host (default: `stream-api.betfair.com`).
24 pub host: String,
25 /// Stream TLS port (default: 443).
26 pub port: u16,
27 /// Interval between client heartbeat messages in milliseconds (default: 5 000).
28 pub heartbeat_ms: u64,
29 /// Idle read timeout in milliseconds; triggers reconnection if no data arrives (default: 60 000).
30 pub idle_timeout_ms: u64,
31 /// Initial reconnection back-off delay in milliseconds (default: 2 000).
32 pub reconnect_delay_initial_ms: u64,
33 /// Maximum reconnection back-off delay in milliseconds (default: 30 000).
34 pub reconnect_delay_max_ms: u64,
35 /// Use TLS (default: true). Override with `false` only for local testing.
36 #[doc(hidden)]
37 pub use_tls: bool,
38}
39
40impl Default for BetfairStreamConfig {
41 fn default() -> Self {
42 Self {
43 host: BETFAIR_STREAM_HOST.to_string(),
44 port: BETFAIR_STREAM_PORT,
45 heartbeat_ms: 5_000,
46 idle_timeout_ms: 60_000,
47 reconnect_delay_initial_ms: 2_000,
48 reconnect_delay_max_ms: 30_000,
49 use_tls: true,
50 }
51 }
52}
53
54#[cfg(test)]
55mod tests {
56 use rstest::rstest;
57
58 use super::*;
59
60 #[rstest]
61 fn test_stream_config_defaults() {
62 let config = BetfairStreamConfig::default();
63 assert_eq!(config.host, BETFAIR_STREAM_HOST);
64 assert_eq!(config.port, BETFAIR_STREAM_PORT);
65 assert_eq!(config.heartbeat_ms, 5_000);
66 assert_eq!(config.idle_timeout_ms, 60_000);
67 assert_eq!(config.reconnect_delay_initial_ms, 2_000);
68 assert_eq!(config.reconnect_delay_max_ms, 30_000);
69 assert!(config.use_tls);
70 }
71}