1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//! Broker account and session status models.
use super::error::ErrorCode;
use super::identifiers::{AccountId, AccountIdHash};
use super::money::CurrencyCode;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
/// Broker backend kind.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum BrokerBackendKind {
/// Local Interactive Brokers Client Portal Gateway.
ClientPortalGateway,
/// Deterministic fake backend for offline validation.
Fake,
}
/// Externally visible broker session status.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum BrokerSessionVisibility {
/// Broker session can serve read-only data.
Usable,
/// Manual user action is required.
ManualActionRequired,
/// Backend is unavailable.
Unavailable,
}
/// Broker session status without secrets.
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct BrokerSessionStatus {
/// Visible session status.
pub status: BrokerSessionVisibility,
/// Backend that produced the status.
pub backend: BrokerBackendKind,
/// Timestamp when the status was checked.
#[serde(with = "time::serde::rfc3339")]
#[schemars(with = "String")]
pub checked_at: OffsetDateTime,
/// Last successful keepalive timestamp.
#[serde(with = "time::serde::rfc3339::option")]
#[schemars(with = "Option<String>")]
pub last_keepalive_at: Option<OffsetDateTime>,
/// Safe manual action when required.
pub user_action: Option<String>,
/// Optional stable error code.
pub error_code: Option<ErrorCode>,
}
/// Account mode reported by broker metadata or local config.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum AccountMode {
/// Paper account.
Paper,
/// Live account.
Live,
/// Mode is not known yet.
Unknown,
}
/// Safe account metadata visible to the local user and MCP clients.
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct BrokerAccount {
/// Raw broker account id, never used directly in audit.
pub account_id: AccountId,
/// HMAC account hash for audit correlation.
pub account_id_hash: AccountIdHash,
/// Optional safe display label.
pub account_label: Option<String>,
/// Paper/live/unknown mode.
pub account_mode: AccountMode,
/// Base currency when known.
pub base_currency: Option<CurrencyCode>,
/// Whether source metadata was redacted.
pub metadata_redacted: bool,
}
/// Cash or margin account classification when the broker reports it safely.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum AccountMarginProfile {
/// Cash account.
Cash,
/// Margin account.
Margin,
/// Profile is not known.
Unknown,
}
/// Safe account capabilities and restrictions visible to agents.
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct AccountCapabilityProfile {
/// Raw broker account id, never used directly in audit.
pub account_id: AccountId,
/// Paper/live/unknown mode.
pub account_mode: AccountMode,
/// Base currency when known.
pub base_currency: Option<CurrencyCode>,
/// Cash or margin account classification.
pub margin_profile: AccountMarginProfile,
/// Product permissions reported safely by the broker.
pub product_permissions: Vec<String>,
/// Option approval level when known.
pub option_level: Option<String>,
/// Whether shorting is known to be allowed.
pub shorting_allowed: Option<bool>,
/// Pattern day trader status when known.
pub pdt_status: Option<String>,
/// Good-faith violation status when known.
pub gfv_status: Option<String>,
/// Safe restriction labels.
pub restrictions: Vec<String>,
/// Whether source metadata was redacted.
pub metadata_redacted: bool,
}