adaq-data-stock-us 0.1.3

Rust reimplementation of yfinance for US equity market data from Yahoo Finance.
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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
//! Blocking (synchronous) facade over the async [`crate::Client`].
//!
//! Each method runs the corresponding async call on the shared runtime via
//! [`crate::block_on`]. This is the ergonomic entry point for callers who do
//! not want to write `async` (mirrors yfinance's synchronous API).

use chrono::{DateTime, Utc};

use crate::block_on;
use crate::client::{Client as AsyncClient, DownloadResult, Ticker as AsyncTicker};
use crate::config::Config;
use crate::error::Result;
use crate::history::{History, HistoryMeta, HistoryOptions};
use crate::quote::{Calendar, FundsData, NamedTable, SecFiling, UpgradesDowngrades};

/// Synchronous Yahoo Finance client.
#[derive(Clone)]
pub struct Client {
    inner: AsyncClient,
}

impl Client {
    /// Create a blocking client with default config.
    pub fn new() -> Result<Self> {
        Ok(Self {
            inner: AsyncClient::new()?,
        })
    }

    /// Create a blocking client with explicit config.
    pub fn with_config(config: Config) -> Result<Self> {
        Ok(Self {
            inner: AsyncClient::with_config(config)?,
        })
    }

    /// Price history for a single ticker.
    pub fn history(&self, ticker: &str, opts: &HistoryOptions) -> Result<History> {
        block_on(self.inner.history(ticker, opts))
    }

    /// Bulk download of many tickers.
    pub fn download(&self, tickers: &[&str], opts: &HistoryOptions) -> Result<DownloadResult> {
        block_on(crate::download(tickers, opts, &self.inner))
    }

    /// `info` blob.
    pub fn info(&self, ticker: &str) -> Result<crate::quote::Info> {
        block_on(self.inner.info(ticker))
    }

    /// `fast_info` subset.
    pub fn fast_info(&self, ticker: &str) -> Result<crate::quote::FastInfo> {
        block_on(self.inner.fast_info(ticker))
    }

    /// Holders.
    pub fn holders(&self, ticker: &str) -> Result<crate::quote::Holders> {
        block_on(self.inner.holders(ticker))
    }

    /// Sustainability / ESG.
    pub fn sustainability(&self, ticker: &str) -> Result<crate::quote::Sustainability> {
        block_on(self.inner.sustainability(ticker))
    }

    /// Analyst price targets.
    pub fn analyst_price_targets(&self, ticker: &str) -> Result<crate::quote::AnalystPriceTargets> {
        block_on(self.inner.analyst_price_targets(ticker))
    }

    /// Recommendation trend.
    pub fn recommendation_trend(
        &self,
        ticker: &str,
    ) -> Result<Vec<crate::quote::RecommendationTrend>> {
        block_on(self.inner.recommendation_trend(ticker))
    }

    /// Financial statement.
    pub fn financials(
        &self,
        ticker: &str,
        statement: crate::fundamentals::Statement,
        freq: crate::fundamentals::Freq,
    ) -> Result<crate::fundamentals::Financials> {
        block_on(self.inner.financials(ticker, statement, freq))
    }

    /// Option chain.
    pub fn option_chain(&self, ticker: &str) -> Result<crate::options::OptionChain> {
        block_on(self.inner.option_chain(ticker))
    }

    /// Free-text search.
    pub fn search(
        &self,
        query: &str,
        quotes_count: usize,
        news_count: usize,
    ) -> Result<crate::search::SearchResult> {
        block_on(self.inner.search(query, quotes_count, news_count))
    }

    /// Security lookup.
    pub fn lookup(
        &self,
        query: &str,
        limit: usize,
        lookup_type: &str,
    ) -> Result<crate::lookup::LookupResult> {
        block_on(self.inner.lookup(query, limit, lookup_type))
    }

    /// Market sector snapshot.
    pub fn sector(&self, key: &str) -> Result<crate::domain::Sector> {
        block_on(self.inner.sector(key))
    }

    /// Market industry snapshot.
    pub fn industry(&self, key: &str) -> Result<crate::domain::Industry> {
        block_on(self.inner.industry(key))
    }

    /// Market summary for a region.
    pub fn market(&self, region: crate::domain::MarketRegion) -> Result<crate::domain::Market> {
        block_on(self.inner.market(region))
    }

    /// Earnings calendar.
    pub fn earnings_calendar(
        &self,
        start: &str,
        end: &str,
        limit: usize,
    ) -> Result<Vec<crate::calendars::EarningsEvent>> {
        block_on(self.inner.earnings_calendar(start, end, limit))
    }

    /// IPO calendar.
    pub fn ipo_calendar(
        &self,
        start: &str,
        end: &str,
        limit: usize,
    ) -> Result<Vec<crate::calendars::IpoEvent>> {
        block_on(self.inner.ipo_calendar(start, end, limit))
    }

    /// Economic calendar.
    pub fn economic_calendar(
        &self,
        start: &str,
        end: &str,
        limit: usize,
    ) -> Result<Vec<crate::calendars::EconomicEvent>> {
        block_on(self.inner.economic_calendar(start, end, limit))
    }

    /// Splits calendar.
    pub fn splits_calendar(
        &self,
        start: &str,
        end: &str,
        limit: usize,
    ) -> Result<Vec<crate::calendars::SplitEvent>> {
        block_on(self.inner.splits_calendar(start, end, limit))
    }

    /// Run a screener query.
    pub fn screen(
        &self,
        query: impl Into<crate::screener::ScreenerQuery>,
        opts: &crate::screener::ScreenOptions,
    ) -> Result<crate::screener::ScreenerResult> {
        block_on(self.inner.screen(query, opts))
    }

    // --- Ticker identifier resolution + per-ticker news/earnings/ISIN ---

    /// Resolve an ISIN to a Yahoo ticker symbol.
    pub fn resolve_isin(&self, isin: &str) -> Result<String> {
        block_on(self.inner.resolve_isin(isin))
    }

    /// Latest news for a ticker. `tab` is `"news"`, `"all"`, or `"press releases"`.
    pub fn news(
        &self,
        ticker: &str,
        count: usize,
        tab: &str,
    ) -> Result<Vec<crate::news::NewsArticle>> {
        block_on(self.inner.news(ticker, count, tab))
    }

    /// Reverse lookup: ticker → ISIN.
    pub fn isin(&self, ticker: &str) -> Result<String> {
        block_on(self.inner.isin(ticker))
    }

    /// Scheduled / reported earnings dates for a ticker, newest first.
    pub fn earnings_dates(
        &self,
        ticker: &str,
        limit: usize,
    ) -> Result<Vec<crate::earnings::EarningsDate>> {
        block_on(self.inner.earnings_dates(ticker, limit))
    }

    // --- P2: analysis / estimates / funds / shares / valuation / calendar ---

    /// Earnings estimates table.
    pub fn earnings_estimate(&self, ticker: &str) -> Result<NamedTable> {
        block_on(self.inner.earnings_estimate(ticker))
    }

    /// Revenue estimates table.
    pub fn revenue_estimate(&self, ticker: &str) -> Result<NamedTable> {
        block_on(self.inner.revenue_estimate(ticker))
    }

    /// Reported vs estimated EPS history.
    pub fn earnings_history(&self, ticker: &str) -> Result<NamedTable> {
        block_on(self.inner.earnings_history(ticker))
    }

    /// EPS revision trend table.
    pub fn eps_trend(&self, ticker: &str) -> Result<NamedTable> {
        block_on(self.inner.eps_trend(ticker))
    }

    /// EPS revisions table.
    pub fn eps_revisions(&self, ticker: &str) -> Result<NamedTable> {
        block_on(self.inner.eps_revisions(ticker))
    }

    /// Growth estimates table.
    pub fn growth_estimates(&self, ticker: &str) -> Result<NamedTable> {
        block_on(self.inner.growth_estimates(ticker))
    }

    /// Recommendation summary.
    pub fn recommendations(&self, ticker: &str) -> Result<Vec<crate::quote::RecommendationTrend>> {
        block_on(self.inner.recommendations(ticker))
    }

    /// Upgrades / downgrades (rating changes).
    pub fn upgrades_downgrades(&self, ticker: &str) -> Result<Vec<UpgradesDowngrades>> {
        block_on(self.inner.upgrades_downgrades(ticker))
    }

    /// Valuation measures.
    pub fn valuation_measures(&self, ticker: &str) -> Result<NamedTable> {
        block_on(self.inner.valuation_measures(ticker))
    }

    /// Earnings / dividend calendar.
    pub fn calendar(&self, ticker: &str) -> Result<Calendar> {
        block_on(self.inner.calendar(ticker))
    }

    /// SEC filings.
    pub fn sec_filings(&self, ticker: &str) -> Result<Vec<SecFiling>> {
        block_on(self.inner.sec_filings(ticker))
    }

    /// Current shares outstanding.
    pub fn shares(&self, ticker: &str) -> Result<Option<f64>> {
        block_on(self.inner.shares(ticker))
    }

    /// Full share-count time series.
    pub fn shares_full(
        &self,
        ticker: &str,
        start: Option<DateTime<Utc>>,
        end: Option<DateTime<Utc>>,
    ) -> Result<Vec<(DateTime<Utc>, f64)>> {
        block_on(self.inner.shares_full(ticker, start, end))
    }

    /// Mutual-fund / ETF data.
    pub fn funds_data(&self, ticker: &str) -> Result<FundsData> {
        block_on(self.inner.funds_data(ticker))
    }

    /// Chart metadata.
    pub fn history_metadata(&self, ticker: &str) -> Result<HistoryMeta> {
        block_on(self.inner.history_metadata(ticker))
    }

    /// A blocking ticker from a `(symbol, MIC)` pair.
    pub fn ticker_from_mic(&self, symbol: &str, mic: &str) -> Result<Ticker> {
        Ok(Ticker {
            inner: AsyncTicker::from_mic(symbol, mic, self.inner.clone())?,
        })
    }

    /// A blocking ticker from an ISIN.
    pub fn ticker_from_isin(&self, isin: &str) -> Result<Ticker> {
        Ok(Ticker {
            inner: block_on(AsyncTicker::from_isin(isin, self.inner.clone()))?,
        })
    }

    /// A blocking ticker from any [`crate::TickerId`].
    pub fn ticker_from_id(&self, id: crate::TickerId) -> Result<Ticker> {
        Ok(Ticker {
            inner: block_on(AsyncTicker::from_id(id, self.inner.clone()))?,
        })
    }

    /// An auth/entitlement helper bound to this client's session.
    pub fn auth(&self) -> crate::auth::Auth {
        self.inner.auth()
    }

    /// A live-streaming client (no blocking needed — the stream runs on its own
    /// async runtime inside the call).
    pub fn live(&self) -> crate::live::LiveWebSocket {
        self.inner.live()
    }

    /// Blocking live price stream. Runs [`LiveWebSocket::stream`] to completion
    /// on the shared runtime. `handler` is invoked for each decoded tick.
    pub fn stream_live<F>(&self, symbols: &[&str], handler: F) -> Result<()>
    where
        F: FnMut(crate::live::PricingData) + Send,
    {
        block_on(self.inner.live().stream(symbols, handler))
    }

    /// A blocking ticker handle.
    pub fn ticker(&self, symbol: &str) -> Ticker {
        Ticker {
            inner: AsyncTicker::new(symbol, self.inner.clone()),
        }
    }
}

impl Default for Client {
    fn default() -> Self {
        Self::new().expect("default blocking client should build")
    }
}

/// Synchronous ticker handle.
#[derive(Clone)]
pub struct Ticker {
    inner: AsyncTicker,
}

impl Ticker {
    /// The ticker symbol.
    pub fn symbol(&self) -> &str {
        self.inner.symbol()
    }

    /// Price history.
    pub fn history(&self, opts: &HistoryOptions) -> Result<History> {
        block_on(self.inner.history(opts))
    }

    /// Dividends.
    pub fn dividends(&self, opts: &HistoryOptions) -> Result<Vec<crate::history::Dividend>> {
        block_on(self.inner.dividends(opts))
    }

    /// Stock splits.
    pub fn splits(&self, opts: &HistoryOptions) -> Result<Vec<crate::history::Split>> {
        block_on(self.inner.splits(opts))
    }

    /// All corporate actions.
    pub fn actions(&self, opts: &HistoryOptions) -> Result<Option<crate::history::Actions>> {
        block_on(self.inner.actions(opts))
    }

    /// `info`.
    pub fn info(&self) -> Result<crate::quote::Info> {
        block_on(self.inner.info())
    }

    /// `fast_info`.
    pub fn fast_info(&self) -> Result<crate::quote::FastInfo> {
        block_on(self.inner.fast_info())
    }

    /// Holders.
    pub fn holders(&self) -> Result<crate::quote::Holders> {
        block_on(self.inner.holders())
    }

    /// Sustainability.
    pub fn sustainability(&self) -> Result<crate::quote::Sustainability> {
        block_on(self.inner.sustainability())
    }

    /// Analyst price targets.
    pub fn analyst_price_targets(&self) -> Result<crate::quote::AnalystPriceTargets> {
        block_on(self.inner.analyst_price_targets())
    }

    /// Recommendation trend.
    pub fn recommendation_trend(&self) -> Result<Vec<crate::quote::RecommendationTrend>> {
        block_on(self.inner.recommendation_trend())
    }

    /// Financial statement.
    pub fn financials(
        &self,
        statement: crate::fundamentals::Statement,
        freq: crate::fundamentals::Freq,
    ) -> Result<crate::fundamentals::Financials> {
        block_on(self.inner.financials(statement, freq))
    }

    /// Option chain.
    pub fn option_chain(&self) -> Result<crate::options::OptionChain> {
        block_on(self.inner.option_chain())
    }

    /// Latest news for this ticker.
    pub fn news(&self, count: usize, tab: &str) -> Result<Vec<crate::news::NewsArticle>> {
        block_on(self.inner.news(count, tab))
    }

    /// Reverse lookup: this ticker's ISIN.
    pub fn isin(&self) -> Result<String> {
        block_on(self.inner.isin())
    }

    /// Scheduled / reported earnings dates for this ticker, newest first.
    pub fn earnings_dates(&self, limit: usize) -> Result<Vec<crate::earnings::EarningsDate>> {
        block_on(self.inner.earnings_dates(limit))
    }

    // --- P2: analysis / estimates / funds / shares / valuation / calendar ---

    /// Earnings estimates table.
    pub fn earnings_estimate(&self) -> Result<NamedTable> {
        block_on(self.inner.earnings_estimate())
    }

    /// Revenue estimates table.
    pub fn revenue_estimate(&self) -> Result<NamedTable> {
        block_on(self.inner.revenue_estimate())
    }

    /// Reported vs estimated EPS history.
    pub fn earnings_history(&self) -> Result<NamedTable> {
        block_on(self.inner.earnings_history())
    }

    /// EPS revision trend table.
    pub fn eps_trend(&self) -> Result<NamedTable> {
        block_on(self.inner.eps_trend())
    }

    /// EPS revisions table.
    pub fn eps_revisions(&self) -> Result<NamedTable> {
        block_on(self.inner.eps_revisions())
    }

    /// Growth estimates table.
    pub fn growth_estimates(&self) -> Result<NamedTable> {
        block_on(self.inner.growth_estimates())
    }

    /// Recommendation summary.
    pub fn recommendations(&self) -> Result<Vec<crate::quote::RecommendationTrend>> {
        block_on(self.inner.recommendations())
    }

    /// Upgrades / downgrades (rating changes).
    pub fn upgrades_downgrades(&self) -> Result<Vec<UpgradesDowngrades>> {
        block_on(self.inner.upgrades_downgrades())
    }

    /// Valuation measures.
    pub fn valuation_measures(&self) -> Result<NamedTable> {
        block_on(self.inner.valuation_measures())
    }

    /// Earnings / dividend calendar.
    pub fn calendar(&self) -> Result<Calendar> {
        block_on(self.inner.calendar())
    }

    /// SEC filings.
    pub fn sec_filings(&self) -> Result<Vec<SecFiling>> {
        block_on(self.inner.sec_filings())
    }

    /// Current shares outstanding.
    pub fn shares(&self) -> Result<Option<f64>> {
        block_on(self.inner.shares())
    }

    /// Full share-count time series.
    pub fn shares_full(
        &self,
        start: Option<DateTime<Utc>>,
        end: Option<DateTime<Utc>>,
    ) -> Result<Vec<(DateTime<Utc>, f64)>> {
        block_on(self.inner.shares_full(start, end))
    }

    /// Mutual-fund / ETF data.
    pub fn funds_data(&self) -> Result<FundsData> {
        block_on(self.inner.funds_data())
    }

    /// Chart metadata.
    pub fn history_metadata(&self) -> Result<HistoryMeta> {
        block_on(self.inner.history_metadata())
    }
}