Skip to main content

longbridge/calendar/
types.rs

1#![allow(missing_docs)]
2
3use rust_decimal::Decimal;
4use serde::{Deserialize, Serialize};
5
6use crate::utils::counter::deserialize_counter_id_as_symbol;
7
8/// Response for [`crate::CalendarContext::finance_calendar`]
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct CalendarEventsResponse {
11    /// Start date of the query window
12    pub date: String,
13    /// Per-day event groups
14    pub list: Vec<CalendarDateGroup>,
15    /// Pagination cursor; pass as `start` to fetch the next page, empty when
16    /// there are no more pages
17    #[serde(default)]
18    pub next_date: String,
19}
20
21/// Events for one calendar date
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct CalendarDateGroup {
24    /// Date string, e.g. `"2025-05-02"`
25    pub date: String,
26    /// Total event count for this date
27    pub count: i32,
28    /// Event details
29    pub infos: Vec<CalendarEventInfo>,
30}
31
32/// One financial calendar event
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct CalendarEventInfo {
35    /// Security symbol
36    #[serde(
37        rename = "counter_id",
38        deserialize_with = "deserialize_counter_id_as_symbol"
39    )]
40    pub symbol: String,
41    /// Market, e.g. `"HK"`
42    pub market: String,
43    /// Event content description
44    pub content: String,
45    /// Security name
46    pub counter_name: String,
47    /// Date type label, e.g. `"盘前"`
48    #[serde(default)]
49    pub date_type: String,
50    /// Event date string, e.g. `"2025.05.02"`
51    pub date: String,
52    /// Chart UID (may be empty)
53    #[serde(default)]
54    pub chart_uid: String,
55    /// Structured data key-value pairs
56    pub data_kv: Vec<CalendarDataKv>,
57    /// Event type code, e.g. `"financial"`
58    #[serde(rename = "type")]
59    pub event_type: String,
60    /// Event datetime (unix timestamp string)
61    pub datetime: String,
62    /// Icon URL
63    #[serde(default)]
64    pub icon: String,
65    /// Importance star rating (0–3)
66    pub star: i32,
67    /// Associated live stream (usually null)
68    pub live: Option<serde_json::Value>,
69    /// Internal event ID
70    pub id: String,
71    /// Financial market session time string
72    #[serde(default)]
73    pub financial_market_time: String,
74    /// Currency
75    #[serde(default)]
76    pub currency: String,
77    /// Extended data (structure varies by event type)
78    pub ext: Option<serde_json::Value>,
79    /// Activity type code
80    #[serde(default)]
81    pub activity_type: String,
82}
83
84/// One key-value data pair in a calendar event
85#[derive(Debug, Clone, Serialize, Deserialize)]
86pub struct CalendarDataKv {
87    /// Key (may be empty)
88    pub key: String,
89    /// Formatted display value
90    pub value: String,
91    /// Value type code, e.g. `"estimate_eps"`
92    #[serde(rename = "type")]
93    pub value_type: String,
94    /// Raw numeric value (may be empty or non-numeric)
95    #[serde(default, with = "crate::serde_utils::decimal_opt_str_is_none")]
96    pub value_raw: Option<Decimal>,
97}
98
99/// Calendar event category
100#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
101pub enum CalendarCategory {
102    /// Earnings reports
103    #[serde(rename = "report")]
104    Report,
105    /// Dividend events
106    #[serde(rename = "dividend")]
107    Dividend,
108    /// Stock splits
109    #[serde(rename = "split")]
110    Split,
111    /// IPOs
112    #[serde(rename = "ipo")]
113    Ipo,
114    /// Macro-economic data releases
115    #[serde(rename = "macrodata")]
116    MacroData,
117    /// Market closure days
118    #[serde(rename = "closed")]
119    Closed,
120    /// Shareholder / analyst meetings
121    #[serde(rename = "meeting")]
122    Meeting,
123    /// Stock consolidations / mergers
124    #[serde(rename = "merge")]
125    Merge,
126}