ig_client/session/
response.rs1#[derive(serde::Deserialize)]
3pub struct SessionResp {
4 #[serde(alias = "accountId")]
6 #[serde(alias = "currentAccountId")]
7 pub account_id: String,
8
9 #[serde(alias = "clientId")]
11 pub client_id: Option<String>,
12 #[serde(alias = "timezoneOffset")]
14 pub timezone_offset: Option<i32>,
15}
16
17#[derive(serde::Serialize)]
19pub struct AccountSwitchRequest {
20 #[serde(rename = "accountId")]
22 pub account_id: String,
23 #[serde(rename = "defaultAccount")]
25 pub default_account: Option<bool>,
26}
27
28#[derive(serde::Deserialize, Debug)]
30pub struct AccountSwitchResponse {
31 #[serde(rename = "dealingEnabled")]
33 pub dealing_enabled: Option<bool>,
34 #[serde(rename = "hasActiveDemoAccounts")]
36 pub has_active_demo_accounts: Option<bool>,
37 #[serde(rename = "hasActiveLiveAccounts")]
39 pub has_active_live_accounts: Option<bool>,
40 #[serde(rename = "trailingStopsEnabled")]
42 pub trailing_stops_enabled: Option<bool>,
43}
44
45#[derive(serde::Deserialize, serde::Serialize, Debug, Clone)]
47pub struct OAuthToken {
48 pub access_token: String,
50 pub refresh_token: String,
52 pub scope: String,
54 pub token_type: String,
56 pub expires_in: String,
58 #[serde(skip, default = "chrono::Utc::now")]
60 pub created_at: chrono::DateTime<chrono::Utc>,
61}
62
63impl OAuthToken {
64 pub fn is_expired(&self, margin_seconds: i64) -> bool {
72 let expires_in_secs = self.expires_in.parse::<i64>().unwrap_or(0);
73 let expiry_time = self.created_at + chrono::Duration::seconds(expires_in_secs);
74 let now = chrono::Utc::now();
75 let margin = chrono::Duration::seconds(margin_seconds);
76
77 expiry_time - margin <= now
78 }
79}
80
81#[derive(serde::Deserialize, Debug)]
83pub struct SessionV3Resp {
84 #[serde(rename = "clientId")]
86 pub client_id: String,
87 #[serde(rename = "accountId")]
89 pub account_id: String,
90 #[serde(rename = "timezoneOffset")]
92 pub timezone_offset: i32,
93 #[serde(rename = "lightstreamerEndpoint")]
95 pub lightstreamer_endpoint: String,
96 #[serde(rename = "oauthToken")]
98 pub oauth_token: OAuthToken,
99}