longbridge 4.5.0

Longbridge OpenAPI SDK for Rust
Documentation
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
use std::sync::Arc;

use tokio::sync::mpsc;

use crate::{
    Config, Result,
    blocking::runtime::BlockingRuntime,
    fundamental::{FundamentalContext, types::*},
};

/// Blocking fundamental data context
pub struct FundamentalContextSync {
    rt: BlockingRuntime<FundamentalContext>,
}

impl FundamentalContextSync {
    /// Create a [`FundamentalContextSync`]
    pub fn new(config: Arc<Config>) -> Result<Self> {
        let rt = BlockingRuntime::try_new(
            move || {
                let ctx = FundamentalContext::new(config);
                let (tx, rx) = mpsc::unbounded_channel::<std::convert::Infallible>();
                std::mem::forget(tx);
                Ok::<_, crate::Error>((ctx, rx))
            },
            |_: std::convert::Infallible| {},
        )?;
        Ok(Self { rt })
    }

    /// Get financial reports
    pub fn financial_report(
        &self,
        symbol: impl Into<String> + Send + 'static,
        kind: FinancialReportKind,
        period: Option<FinancialReportPeriod>,
    ) -> Result<FinancialReports> {
        self.rt
            .call(move |ctx| async move { ctx.financial_report(symbol, kind, period).await })
    }

    /// Get analyst ratings (latest + summary)
    pub fn institution_rating(
        &self,
        symbol: impl Into<String> + Send + 'static,
    ) -> Result<InstitutionRating> {
        self.rt
            .call(move |ctx| async move { ctx.institution_rating(symbol).await })
    }

    /// Get historical analyst rating details
    pub fn institution_rating_detail(
        &self,
        symbol: impl Into<String> + Send + 'static,
    ) -> Result<InstitutionRatingDetail> {
        self.rt
            .call(move |ctx| async move { ctx.institution_rating_detail(symbol).await })
    }

    /// Get dividend history
    pub fn dividend(&self, symbol: impl Into<String> + Send + 'static) -> Result<DividendList> {
        self.rt
            .call(move |ctx| async move { ctx.dividend(symbol).await })
    }

    /// Get detailed dividend information
    pub fn dividend_detail(
        &self,
        symbol: impl Into<String> + Send + 'static,
    ) -> Result<DividendList> {
        self.rt
            .call(move |ctx| async move { ctx.dividend_detail(symbol).await })
    }

    /// Get EPS forecasts
    pub fn forecast_eps(&self, symbol: impl Into<String> + Send + 'static) -> Result<ForecastEps> {
        self.rt
            .call(move |ctx| async move { ctx.forecast_eps(symbol).await })
    }

    /// Get financial consensus estimates
    pub fn consensus(
        &self,
        symbol: impl Into<String> + Send + 'static,
    ) -> Result<FinancialConsensus> {
        self.rt
            .call(move |ctx| async move { ctx.consensus(symbol).await })
    }

    /// Get valuation metrics
    pub fn valuation(&self, symbol: impl Into<String> + Send + 'static) -> Result<ValuationData> {
        self.rt
            .call(move |ctx| async move { ctx.valuation(symbol).await })
    }

    /// Get historical valuation data
    pub fn valuation_history(
        &self,
        symbol: impl Into<String> + Send + 'static,
    ) -> Result<ValuationHistoryResponse> {
        self.rt
            .call(move |ctx| async move { ctx.valuation_history(symbol).await })
    }

    /// Get industry peer valuation comparison
    pub fn industry_valuation(
        &self,
        symbol: impl Into<String> + Send + 'static,
    ) -> Result<IndustryValuationList> {
        self.rt
            .call(move |ctx| async move { ctx.industry_valuation(symbol).await })
    }

    /// Get industry valuation distribution
    pub fn industry_valuation_dist(
        &self,
        symbol: impl Into<String> + Send + 'static,
    ) -> Result<IndustryValuationDist> {
        self.rt
            .call(move |ctx| async move { ctx.industry_valuation_dist(symbol).await })
    }

    /// Get company overview
    pub fn company(&self, symbol: impl Into<String> + Send + 'static) -> Result<CompanyOverview> {
        self.rt
            .call(move |ctx| async move { ctx.company(symbol).await })
    }

    /// Get executive and board member information
    pub fn executive(&self, symbol: impl Into<String> + Send + 'static) -> Result<ExecutiveList> {
        self.rt
            .call(move |ctx| async move { ctx.executive(symbol).await })
    }

    /// Get major shareholders
    pub fn shareholder(
        &self,
        symbol: impl Into<String> + Send + 'static,
    ) -> Result<ShareholderList> {
        self.rt
            .call(move |ctx| async move { ctx.shareholder(symbol).await })
    }

    /// Get fund and ETF holders
    pub fn fund_holder(&self, symbol: impl Into<String> + Send + 'static) -> Result<FundHolders> {
        self.rt
            .call(move |ctx| async move { ctx.fund_holder(symbol).await })
    }

    /// Get corporate actions
    pub fn corp_action(&self, symbol: impl Into<String> + Send + 'static) -> Result<CorpActions> {
        self.rt
            .call(move |ctx| async move { ctx.corp_action(symbol).await })
    }

    /// Get investor relations data
    pub fn invest_relation(
        &self,
        symbol: impl Into<String> + Send + 'static,
    ) -> Result<InvestRelations> {
        self.rt
            .call(move |ctx| async move { ctx.invest_relation(symbol).await })
    }

    /// Get operating metrics and financial summaries
    pub fn operating(&self, symbol: impl Into<String> + Send + 'static) -> Result<OperatingList> {
        self.rt
            .call(move |ctx| async move { ctx.operating(symbol).await })
    }

    /// Get buyback data
    pub fn buyback(&self, symbol: impl Into<String> + Send + 'static) -> Result<BuybackData> {
        self.rt
            .call(move |ctx| async move { ctx.buyback(symbol).await })
    }

    /// Get stock ratings
    pub fn ratings(&self, symbol: impl Into<String> + Send + 'static) -> Result<StockRatings> {
        self.rt
            .call(move |ctx| async move { ctx.ratings(symbol).await })
    }

    /// Get latest business segment breakdown
    pub fn business_segments(
        &self,
        symbol: impl Into<String> + Send + 'static,
    ) -> Result<BusinessSegments> {
        self.rt
            .call(move |ctx| async move { ctx.business_segments(symbol).await })
    }

    /// Get historical business segment breakdowns
    pub fn business_segments_history(
        &self,
        symbol: impl Into<String> + Send + 'static,
        report: Option<&'static str>,
        cate: Option<String>,
    ) -> Result<BusinessSegmentsHistory> {
        self.rt.call(
            move |ctx| async move { ctx.business_segments_history(symbol, report, cate).await },
        )
    }

    /// Get historical institutional rating views
    pub fn institution_rating_views(
        &self,
        symbol: impl Into<String> + Send + 'static,
    ) -> Result<InstitutionRatingViews> {
        self.rt
            .call(move |ctx| async move { ctx.institution_rating_views(symbol).await })
    }

    /// Get industry rank for a market
    pub fn industry_rank(
        &self,
        market: impl Into<String> + Send + 'static,
        indicator: impl Into<String> + Send + 'static,
        sort_type: impl Into<String> + Send + 'static,
        limit: u32,
    ) -> Result<IndustryRankResponse> {
        self.rt.call(move |ctx| async move {
            ctx.industry_rank(market, indicator, sort_type, limit).await
        })
    }

    /// Get industry peer chain
    pub fn industry_peers(
        &self,
        counter_id: impl Into<String> + Send + 'static,
        market: impl Into<String> + Send + 'static,
        industry_id: Option<String>,
    ) -> Result<IndustryPeersResponse> {
        self.rt.call(
            move |ctx| async move { ctx.industry_peers(counter_id, market, industry_id).await },
        )
    }

    /// Get financial report snapshot (earnings snapshot)
    pub fn financial_report_snapshot(
        &self,
        symbol: impl Into<String> + Send + 'static,
        report: Option<&'static str>,
        fiscal_year: Option<i32>,
        fiscal_period: Option<&'static str>,
    ) -> Result<FinancialReportSnapshot> {
        self.rt.call(move |ctx| async move {
            ctx.financial_report_snapshot(symbol, report, fiscal_year, fiscal_period)
                .await
        })
    }

    /// Get ranked list of top shareholders
    pub fn shareholder_top(
        &self,
        symbol: impl Into<String> + Send + 'static,
    ) -> Result<ShareholderTopResponse> {
        self.rt
            .call(move |ctx| async move { ctx.shareholder_top(symbol).await })
    }

    /// Get holding history and detail for one shareholder object
    pub fn shareholder_detail(
        &self,
        symbol: impl Into<String> + Send + 'static,
        object_id: i64,
    ) -> Result<ShareholderDetailResponse> {
        self.rt
            .call(move |ctx| async move { ctx.shareholder_detail(symbol, object_id).await })
    }

    /// Get valuation comparison between a security and optional peers
    pub fn valuation_comparison(
        &self,
        symbol: impl Into<String> + Send + 'static,
        currency: impl Into<String> + Send + 'static,
        comparison_symbols: Option<Vec<String>>,
    ) -> Result<ValuationComparisonResponse> {
        self.rt.call(move |ctx| async move {
            ctx.valuation_comparison(symbol, currency, comparison_symbols)
                .await
        })
    }

    /// Get ETF asset allocation (holdings / regional / asset class /
    /// industry)
    pub fn etf_asset_allocation(
        &self,
        symbol: impl Into<String> + Send + 'static,
    ) -> Result<AssetAllocationResponse> {
        self.rt
            .call(move |ctx| async move { ctx.etf_asset_allocation(symbol).await })
    }

    /// List macroeconomic indicators
    pub fn macroeconomic_indicators(
        &self,
        country: Option<MacroeconomicCountry>,
        keyword: Option<impl Into<String> + Send + 'static>,
        offset: Option<i32>,
        limit: Option<i32>,
    ) -> Result<MacroeconomicIndicatorListResponse> {
        self.rt.call(move |ctx| async move {
            ctx.macroeconomic_indicators(country, keyword, offset, limit)
                .await
        })
    }

    /// Get historical data for a macroeconomic indicator
    pub fn macroeconomic(
        &self,
        indicator_code: impl Into<String> + Send + 'static,
        start_date: Option<impl Into<String> + Send + 'static>,
        end_date: Option<impl Into<String> + Send + 'static>,
        offset: Option<i32>,
        limit: Option<i32>,
    ) -> Result<MacroeconomicResponse> {
        self.rt.call(move |ctx| async move {
            ctx.macroeconomic(indicator_code, start_date, end_date, offset, limit)
                .await
        })
    }

    /// List macroeconomic indicators (v2) with optional keyword filter
    pub(crate) fn macroeconomic_indicators_v2(
        &self,
        country: Option<MacroeconomicCountry>,
        keyword: Option<impl Into<String> + Send + 'static>,
        offset: Option<i32>,
        limit: Option<i32>,
    ) -> Result<MacroeconomicIndicatorListResponse> {
        self.rt.call(move |ctx| async move {
            ctx.macroeconomic_indicators_v2(country, keyword, offset, limit)
                .await
        })
    }

    /// Get historical data for a macroeconomic indicator (v2) with sort support
    pub(crate) fn macroeconomic_v2(
        &self,
        indicator_code: impl Into<String> + Send + 'static,
        start_date: Option<impl Into<String> + Send + 'static>,
        end_date: Option<impl Into<String> + Send + 'static>,
        offset: Option<i32>,
        limit: Option<i32>,
        sort: Option<impl Into<String> + Send + 'static>,
    ) -> Result<MacroeconomicResponse> {
        self.rt.call(move |ctx| async move {
            ctx.macroeconomic_v2(indicator_code, start_date, end_date, offset, limit, sort)
                .await
        })
    }

    // ── US-market blocking wrappers ───────────────────────────────────────────

    /// Get US company overview (blocking)
    pub fn us_company_overview(
        &self,
        counter_id: impl Into<String> + Send + 'static,
    ) -> Result<USCompanyOverview> {
        self.rt
            .call(move |ctx| async move { ctx.us_company_overview(counter_id).await })
    }

    /// Get US valuation overview snapshot (blocking)
    pub fn us_valuation_overview(
        &self,
        counter_id: impl Into<String> + Send + 'static,
    ) -> Result<USValuationOverview> {
        self.rt
            .call(move |ctx| async move { ctx.us_valuation_overview(counter_id).await })
    }

    /// Get US financial overview (blocking)
    pub fn us_financial_overview(
        &self,
        counter_id: impl Into<String> + Send + 'static,
        report: impl Into<String> + Send + 'static,
    ) -> Result<USFinancialOverview> {
        self.rt
            .call(move |ctx| async move { ctx.us_financial_overview(counter_id, report).await })
    }

    /// Get US financial statement v3 (blocking)
    pub fn us_financial_statement(
        &self,
        counter_id: impl Into<String> + Send + 'static,
        kind: impl Into<String> + Send + 'static,
        report: impl Into<String> + Send + 'static,
    ) -> Result<USFinancialStatement> {
        self.rt.call(move |ctx| async move {
            ctx.us_financial_statement(counter_id, kind, report).await
        })
    }

    /// Get US key financial metrics (blocking)
    pub fn us_key_financial_metrics(
        &self,
        counter_id: impl Into<String> + Send + 'static,
        report: impl Into<String> + Send + 'static,
    ) -> Result<USKeyFinancialMetrics> {
        self.rt
            .call(move |ctx| async move { ctx.us_key_financial_metrics(counter_id, report).await })
    }

    /// Get US analyst consensus estimates (blocking)
    pub fn us_analyst_consensus(
        &self,
        counter_id: impl Into<String> + Send + 'static,
        report: impl Into<String> + Send + 'static,
    ) -> Result<USAnalystConsensus> {
        self.rt
            .call(move |ctx| async move { ctx.us_analyst_consensus(counter_id, report).await })
    }

    /// Get US ETF dividend history (blocking)
    pub fn us_etf_dividend_info(
        &self,
        counter_id: impl Into<String> + Send + 'static,
    ) -> Result<USETFDividendInfo> {
        self.rt
            .call(move |ctx| async move { ctx.us_etf_dividend_info(counter_id).await })
    }

    /// Get US company historical dividends (blocking)
    pub fn us_company_dividends(
        &self,
        counter_id: impl Into<String> + Send + 'static,
    ) -> Result<USCompanyDividends> {
        self.rt
            .call(move |ctx| async move { ctx.us_company_dividends(counter_id).await })
    }

    /// Get US ETF document list (blocking)
    pub fn us_etf_files(
        &self,
        counter_id: impl Into<String> + Send + 'static,
        size: Option<u32>,
    ) -> Result<USETFFilesResponse> {
        self.rt
            .call(move |ctx| async move { ctx.us_etf_files(counter_id, size).await })
    }
}