Skip to main content

longbridge/sharelist/
types.rs

1#![allow(missing_docs)]
2
3use rust_decimal::Decimal;
4use serde::{Deserialize, Serialize};
5use time::OffsetDateTime;
6
7use crate::utils::counter::deserialize_counter_id_as_symbol;
8
9/// Response for [`crate::SharelistContext::list`] and
10/// [`crate::SharelistContext::popular`]
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct SharelistList {
13    /// User's own and followed sharelists
14    pub sharelists: Vec<SharelistInfo>,
15    /// Subscribed sharelists (may be absent in popular response)
16    #[serde(default)]
17    pub subscribed_sharelists: Vec<SharelistInfo>,
18    /// Pagination cursor for subscribed list
19    #[serde(default)]
20    pub tail_mark: String,
21}
22
23/// Response for [`crate::SharelistContext::detail`]
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct SharelistDetail {
26    /// Sharelist info
27    pub sharelist: SharelistInfo,
28    /// Subscription scopes
29    pub scopes: SharelistScopes,
30}
31
32/// Sharelist information
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct SharelistInfo {
35    /// Sharelist ID (may be string or integer in API)
36    #[serde(deserialize_with = "crate::serde_utils::deserialize_id_as_i64")]
37    pub id: i64,
38    /// Name
39    pub name: String,
40    /// Description
41    #[serde(default)]
42    pub description: String,
43    /// Cover image URL
44    #[serde(default)]
45    pub cover: String,
46    /// Number of subscribers (may be null)
47    #[serde(default)]
48    pub subscribers_count: i64,
49    /// Creation time
50    #[serde(deserialize_with = "crate::serde_utils::deserialize_timestamp")]
51    pub created_at: OffsetDateTime,
52    /// Last stock edit time
53    #[serde(deserialize_with = "crate::serde_utils::deserialize_timestamp")]
54    pub edited_at: OffsetDateTime,
55    /// YTD change percentage
56    #[serde(default, with = "crate::serde_utils::decimal_opt_str_is_none")]
57    pub this_year_chg: Option<Decimal>,
58    /// Creator info
59    pub creator: serde_json::Value,
60    /// Constituent stocks
61    pub stocks: Vec<SharelistStock>,
62    /// Whether the current user is subscribed
63    pub subscribed: bool,
64    /// Day change percentage
65    #[serde(default, with = "crate::serde_utils::decimal_opt_str_is_none")]
66    pub chg: Option<Decimal>,
67    /// Sharelist type: 0=regular, 3=official, 4=industry
68    pub sharelist_type: i32,
69    /// Industry code (for industry sharelists)
70    #[serde(default)]
71    pub industry_code: String,
72}
73
74/// Stock in a sharelist
75#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct SharelistStock {
77    /// Security symbol
78    #[serde(
79        rename = "counter_id",
80        deserialize_with = "deserialize_counter_id_as_symbol"
81    )]
82    pub symbol: String,
83    /// Security name
84    #[serde(default)]
85    pub name: String,
86    /// Market, e.g. `"HK"`
87    #[serde(default)]
88    pub market: String,
89    /// Ticker code
90    #[serde(default)]
91    pub code: String,
92    /// Brief description
93    #[serde(default)]
94    pub intro: String,
95    /// Unread change log category
96    #[serde(default)]
97    pub unread_change_log_category: String,
98    /// Day change percentage
99    #[serde(default, with = "crate::serde_utils::decimal_opt_str_is_none")]
100    pub change: Option<Decimal>,
101    /// Latest price
102    #[serde(default, with = "crate::serde_utils::decimal_opt_str_is_none")]
103    pub last_done: Option<Decimal>,
104    /// Trade status code
105    #[serde(default)]
106    pub trade_status: Option<i32>,
107    /// Whether delayed quote
108    #[serde(default)]
109    pub latency: Option<bool>,
110}
111
112/// Sharelist subscription scopes
113#[derive(Debug, Clone, Serialize, Deserialize)]
114pub struct SharelistScopes {
115    /// Whether the current user is subscribed
116    pub subscription: bool,
117    /// Whether the current user is the creator
118    #[serde(rename = "self")]
119    pub is_self: bool,
120}