cripsy_binary_api/broker/
session.rs1use serde::{Deserialize, Serialize};
4
5use crate::domain::AccountType;
6
7#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8pub struct Session {
9 pub broker_name: String,
10 pub connected_at: i64,
12 pub account_id: Option<String>,
13 pub balance_id: Option<i64>,
15 pub account_type: AccountType,
16 pub server_time_offset_ms: i64,
18}
19
20impl Session {
21 pub fn broker_time_ms(&self, now_ms: i64) -> i64 {
23 now_ms + self.server_time_offset_ms
24 }
25
26 pub fn broker_time_secs(&self, now_ms: i64) -> i64 {
28 self.broker_time_ms(now_ms) / 1000
29 }
30}
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35
36 #[test]
37 fn offset_de_tiempo() {
38 let s = Session {
39 broker_name: "iq_option".into(),
40 connected_at: 0,
41 account_id: None,
42 balance_id: Some(7),
43 account_type: AccountType::Practice,
44 server_time_offset_ms: 250,
45 };
46 assert_eq!(s.broker_time_ms(1000), 1250);
47 assert_eq!(s.broker_time_secs(1000), 1);
48 }
49}