finance-query-core 0.3.0

A Rust client library for Yahoo Finance API - fetch quotes, historical data, financials, streaming, and more
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
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
# finance-query-core

A Rust client library for Yahoo Finance API. Fetch quotes, historical data, financials, news, and more.

## Features

- Framework-agnostic design - use with any Rust application
- Automatic authentication handling with cookie/crumb management
- Strongly-typed data models for all Yahoo Finance responses
- Comprehensive error handling
- WebSocket support for real-time data
- Async streaming for continuous quote updates

## Installation

Add this to your `Cargo.toml`:

```toml
[dependencies]
finance-query-core = "0.1"
```

## Quick Start

```rust
use finance_query_core::{YahooFinanceClient, YahooAuthManager, FetchClient};
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let fetch_client = Arc::new(FetchClient::new(None)?);
    let cookie_jar = fetch_client.cookie_jar().clone();
    let auth_manager = Arc::new(YahooAuthManager::new(None, cookie_jar));
    let client = YahooFinanceClient::new(auth_manager.clone(), fetch_client);

    auth_manager.refresh().await?;
    let quote = client.get_quote("AAPL").await?;
    println!("Price: {}", quote["regularMarketPrice"]);

    Ok(())
}
```

## Models & JSON Formats

### Quote Models

#### SimpleQuote
Basic quote data for streaming and lists.

```json
{
  "symbol": "AAPL",
  "name": "Apple Inc.",
  "price": "278.85",
  "pre_market_price": "279.50",
  "after_hours_price": "278.37",
  "change": "+1.30",
  "percent_change": "+0.47%",
  "logo": "https://logo.clearbit.com/apple.com"
}
```

#### Quote
Full quote data with all available fields.

```json
{
  "symbol": "AAPL",
  "name": "Apple Inc.",
  "price": "278.85",
  "change": "+1.30",
  "percent_change": "+0.47%",
  "open": "277.26",
  "high": "279.00",
  "low": "275.99",
  "year_high": "280.38",
  "year_low": "169.21",
  "volume": 16129268,
  "avg_volume": 51432647,
  "market_cap": "4.14T",
  "beta": "1.11",
  "pe": "37.33",
  "eps": "7.47",
  "dividend": "1.04",
  "dividend_yield": "0.37%",
  "ex_dividend": "2025-11-10",
  "sector": "Technology",
  "industry": "Consumer Electronics",
  "about": "Apple Inc. designs, manufactures...",
  "employees": "164000",
  "earnings_date": "2025-01-30",
  "five_days_return": "4.73%",
  "one_month_return": "3.66%",
  "ytd_return": "11.35%",
  "year_return": "18.69%",
  "logo": "https://logo.clearbit.com/apple.com"
}
```

### Historical Models

#### HistoricalData
OHLCV price data for a single time period.

```json
{
  "open": 277.26,
  "high": 279.00,
  "low": 275.99,
  "close": 278.85,
  "volume": 16129268,
  "adj_close": 278.85,
  "sma": { "20": 262.64, "50": 245.30 },
  "ema": { "12": 270.50, "26": 258.20 }
}
```

#### HistoricalResponse
```json
{
  "data": {
    "2025-11-28": { "open": 277.26, "high": 279.00, "low": 275.99, "close": 278.85, "volume": 16129268 },
    "2025-11-27": { "open": 275.50, "high": 278.00, "low": 274.80, "close": 277.55, "volume": 18234567 }
  }
}
```

#### TimeRange
Options: `"1d"`, `"5d"`, `"1mo"`, `"3mo"`, `"6mo"`, `"1y"`, `"2y"`, `"5y"`, `"10y"`, `"ytd"`, `"max"`

#### Interval
Options: `"1m"`, `"3m"`, `"5m"`, `"10m"`, `"15m"`, `"20m"`, `"30m"`, `"65m"`, `"95m"`, `"1h"`, `"1d"`, `"1wk"`, `"1mo"`

### News

```json
{
  "title": "Apple Reports Record Q4 Earnings",
  "link": "https://finance.yahoo.com/news/apple-q4-earnings",
  "source": "Reuters",
  "img": "https://s.yimg.com/news/apple-earnings.jpg",
  "time": "2h ago"
}
```

### Search

#### SearchResult
```json
{
  "symbol": "AAPL",
  "name": "Apple Inc.",
  "exchange": "NASDAQ",
  "quote_type": "EQUITY"
}
```

#### SearchResponse
```json
{
  "results": [
    { "symbol": "AAPL", "name": "Apple Inc.", "exchange": "NASDAQ", "quote_type": "EQUITY" },
    { "symbol": "AAPL.MX", "name": "Apple Inc.", "exchange": "Mexico", "quote_type": "EQUITY" }
  ]
}
```

### Financial Models

#### FinancialStatement
```json
{
  "symbol": "AAPL",
  "statement_type": "income",
  "frequency": "annual",
  "statement": {
    "2024": {
      "TotalRevenue": 383285000000,
      "GrossProfit": 169148000000,
      "NetIncome": 96995000000
    },
    "2023": {
      "TotalRevenue": 394328000000,
      "GrossProfit": 169148000000,
      "NetIncome": 96995000000
    }
  }
}
```

#### StatementType
Options: `"income"`, `"balance"`, `"cashflow"`

#### Frequency
Options: `"annual"`, `"quarterly"`

### Market Movers

#### MarketMover
```json
{
  "symbol": "NVDA",
  "name": "NVIDIA Corporation",
  "price": "145.50",
  "change": "+8.25",
  "percentChange": "+6.01%"
}
```

#### MoverCount
Options: `"25"`, `"50"`, `"100"`

### Market Indices

#### MarketIndex
```json
{
  "name": "S&P 500",
  "value": 6032.38,
  "change": "+33.64",
  "percentChange": "+0.56%",
  "fiveDaysReturn": "1.06%",
  "oneMonthReturn": "5.73%",
  "ytdReturn": "26.47%",
  "yearReturn": "32.06%"
}
```

#### Region
Options: `"US"`, `"NA"`, `"SA"`, `"EU"`, `"AS"`, `"AF"`, `"ME"`, `"OCE"`, `"global"`

#### Index
Major indices: `"snp"`, `"djia"`, `"nasdaq"`, `"ftse-100"`, `"dax"`, `"nikkei-225"`, `"hang-seng"`, and 60+ more.

### Sectors

#### MarketSector
```json
{
  "sector": "Technology",
  "dayReturn": "+0.85%",
  "ytdReturn": "+32.45%",
  "yearReturn": "+45.67%",
  "threeYearReturn": "+78.90%",
  "fiveYearReturn": "+156.78%"
}
```

#### MarketSectorDetails
```json
{
  "sector": "Technology",
  "dayReturn": "+0.85%",
  "ytdReturn": "+32.45%",
  "yearReturn": "+45.67%",
  "threeYearReturn": "+78.90%",
  "fiveYearReturn": "+156.78%",
  "marketCap": "18.5T",
  "marketWeight": "32.5%",
  "industries": 8,
  "companies": 450,
  "topIndustries": ["Semiconductors", "Software", "Hardware"],
  "topCompanies": ["AAPL", "MSFT", "NVDA"]
}
```

### Holders

#### InstitutionalHolder
```json
{
  "holder": "Vanguard Group Inc",
  "shares": 1234567890,
  "dateReported": "2025-09-30T00:00:00Z",
  "percentOut": 8.45,
  "value": 344234567890
}
```

#### MutualFundHolder
```json
{
  "holder": "Vanguard Total Stock Market Index Fund",
  "shares": 234567890,
  "dateReported": "2025-09-30T00:00:00Z",
  "percentOut": 1.58,
  "value": 65234567890
}
```

#### InsiderTransaction
```json
{
  "startDate": "2025-11-15T00:00:00Z",
  "insider": "Tim Cook",
  "position": "CEO",
  "transaction": "Sale",
  "shares": 50000,
  "value": 13942500,
  "ownership": "D"
}
```

#### InsiderPurchase
```json
{
  "period": "Last 6 Months",
  "purchasesShares": 125000,
  "purchasesTransactions": 15,
  "salesShares": 450000,
  "salesTransactions": 25,
  "netShares": -325000,
  "netTransactions": -10
}
```

### Analysts

#### RecommendationData
```json
{
  "period": "2025-11",
  "strongBuy": 15,
  "buy": 25,
  "hold": 8,
  "sell": 2,
  "strongSell": 0
}
```

#### UpgradeDowngrade
```json
{
  "firm": "Morgan Stanley",
  "toGrade": "Overweight",
  "fromGrade": "Equal-Weight",
  "action": "upgrade",
  "date": "2025-11-20T00:00:00Z"
}
```

#### PriceTarget
```json
{
  "current": 278.85,
  "mean": 245.50,
  "median": 250.00,
  "low": 180.00,
  "high": 300.00
}
```

#### EarningsHistoryItem
```json
{
  "date": "2025-10-31T00:00:00Z",
  "epsActual": 1.64,
  "epsEstimate": 1.60,
  "surprise": 0.04,
  "surprisePercent": 2.5
}
```

### Earnings Transcripts

#### EarningsCallListing
```json
{
  "event_id": "abc123",
  "quarter": "Q4",
  "year": 2024,
  "title": "Apple Inc. Q4 2024 Earnings Call",
  "url": "https://finance.yahoo.com/transcript/aapl-q4-2024"
}
```

#### EarningsTranscript
```json
{
  "symbol": "AAPL",
  "quarter": "Q4",
  "year": 2024,
  "date": "2024-10-31T21:00:00Z",
  "title": "Apple Inc. Q4 2024 Earnings Call",
  "speakers": [
    { "name": "Tim Cook", "role": "CEO", "company": "Apple Inc." },
    { "name": "Luca Maestri", "role": "CFO", "company": "Apple Inc." }
  ],
  "paragraphs": [
    { "speaker": "Tim Cook", "text": "Good afternoon and thank you for joining us..." }
  ],
  "metadata": {}
}
```

### WebSocket Types

#### QuotesUpdate
```json
{
  "quotes": [
    { "symbol": "AAPL", "name": "Apple Inc.", "price": "278.85", "change": "+1.30", "percent_change": "+0.47%" }
  ],
  "timestamp": "2025-11-30T12:39:37.556245Z"
}
```

#### ProfileUpdate
```json
{
  "quote": { "symbol": "AAPL", "name": "Apple Inc.", "price": "278.85" },
  "similar": [{ "symbol": "MSFT", "name": "Microsoft", "price": "492.01" }],
  "sector_performance": { "sector": "Technology", "dayReturn": "+0.85%" },
  "news": [{ "title": "Apple News", "link": "...", "source": "Reuters" }]
}
```

#### MoversUpdate
```json
{
  "actives": [{ "symbol": "NVDA", "name": "NVIDIA", "price": "145.50", "percentChange": "+6.01%" }],
  "gainers": [{ "symbol": "XYZ", "name": "XYZ Corp", "price": "50.00", "percentChange": "+15.00%" }],
  "losers": [{ "symbol": "ABC", "name": "ABC Inc", "price": "25.00", "percentChange": "-10.00%" }]
}
```

#### MarketHours
```json
{
  "status": "open",
  "reason": null,
  "timestamp": "2025-11-30T14:30:00Z"
}
```

#### MovingAverageUpdate
```json
{
  "symbol": "AAPL",
  "indicator_type": "SMA",
  "period": 20,
  "value": 262.64,
  "timestamp": "2025-11-30T14:30:00Z"
}
```

## Streaming

### Quote Streaming

Create async streams for continuous quote updates:

```rust
use finance_query_core::QuoteStream;
use futures_util::StreamExt;
use std::time::Duration;

let symbols = vec!["AAPL".to_string(), "GOOGL".to_string()];
let mut stream = QuoteStream::new(client, symbols, Duration::from_secs(5));

while let Some(Ok(update)) = stream.next().await {
    for quote in &update.quotes {
        println!("{}: ${}", quote.symbol, quote.price);
    }
}
```

### Index Streaming

Stream real-time market index data:

```rust
use finance_query_core::IndexStream;
use futures_util::StreamExt;
use std::time::Duration;

// Stream major US indices (S&P 500, Dow Jones, NASDAQ)
let mut stream = IndexStream::us_major_indices(client.clone(), Duration::from_secs(5));

while let Some(Ok(indices)) = stream.next().await {
    for index in indices {
        println!("{}: {:.2} ({:+})", index.name, index.value, index.percent_change);
    }
}
```

Or stream custom indices:

```rust
// Stream any indices by symbol
let symbols = vec!["^GSPC".to_string(), "^FTSE".to_string(), "^N225".to_string()];
let mut stream = IndexStream::new(client, symbols, Duration::from_secs(5));

while let Some(Ok(indices)) = stream.next().await {
    for index in indices {
        println!("{}: {:.2}", index.name, index.value);
    }
}
```

### Movers Streaming

Stream real-time market movers (most active, top gainers, top losers):

```rust
use finance_query_core::{MoversStream, MoverCount};
use futures_util::StreamExt;
use std::time::Duration;

// Stream top 50 movers in each category
let mut stream = MoversStream::new(client, MoverCount::Fifty, Duration::from_secs(5));

while let Some(Ok(update)) = stream.next().await {
    println!("\nšŸ“ˆ Top 5 Gainers:");
    for (i, mover) in update.gainers.iter().take(5).enumerate() {
        println!("  {}. {} ({}): {} {}", 
            i + 1, mover.symbol, mover.name, mover.price, mover.percent_change);
    }
    
    println!("\nšŸ“‰ Top 5 Losers:");
    for (i, mover) in update.losers.iter().take(5).enumerate() {
        println!("  {}. {} ({}): {} {}", 
            i + 1, mover.symbol, mover.name, mover.price, mover.percent_change);
    }
    
    println!("\nšŸ”„ Top 5 Most Active:");
    for (i, mover) in update.actives.iter().take(5).enumerate() {
        println!("  {}. {} ({}): {} {}", 
            i + 1, mover.symbol, mover.name, mover.price, mover.percent_change);
    }
}
```

Or use defaults (50 movers, 5-second interval):

```rust
let mut stream = MoversStream::with_defaults(client);

while let Some(Ok(update)) = stream.next().await {
    println!("Actives: {}, Gainers: {}, Losers: {}", 
        update.actives.len(), update.gainers.len(), update.losers.len());
}
```

## Error Handling

```rust
use finance_query_core::YahooError;

match client.get_quote("INVALID").await {
    Ok(quote) => println!("Got quote"),
    Err(YahooError::NotFound(msg)) => println!("Not found: {}", msg),
    Err(YahooError::AuthFailed(msg)) => println!("Auth failed: {}", msg),
    Err(YahooError::RateLimited) => println!("Rate limited"),
    Err(YahooError::HttpError(code, msg)) => println!("HTTP {}: {}", code, msg),
    Err(YahooError::ParseError(msg)) => println!("Parse error: {}", msg),
    Err(YahooError::NetworkError(e)) => println!("Network error: {}", e),
}
```

## New Features (v0.2)

### Stock Actions (Dividends, Splits, Capital Gains)

```rust
// Get all stock actions
let actions = client.get_actions("AAPL", "5y").await?;
println!("Total dividends: ${:.2}", actions.total_dividends());

// Get just dividends
let dividends = client.get_dividends("AAPL", "1y").await?;
for div in &dividends {
    println!("{}: ${:.4}", div.date.format("%Y-%m-%d"), div.amount);
}

// Get stock splits
let splits = client.get_splits("AAPL", "max").await?;
```

### Options Data

```rust
// Get option expirations
let expirations = client.get_option_expirations("AAPL").await?;

// Get option chain for specific expiration
let chain = client.get_option_chain("AAPL", Some("2025-12-19")).await?;
for call in &chain.calls {
    println!("Strike: ${:.2}, IV: {:.2}%", call.strike, call.implied_volatility * 100.0);
}
```

### Calendar Events

```rust
let calendar = client.get_calendar("AAPL").await?;
if let Some(date) = calendar.earnings_date {
    println!("Next earnings: {}", date.format("%Y-%m-%d"));
}
```

### SEC Filings

```rust
let filings = client.get_sec_filings("AAPL").await?;
for filing in &filings.filings {
    println!("{}: {} - {}", filing.date.format("%Y-%m-%d"), filing.filing_type, filing.title);
}
```

### ESG/Sustainability Scores

```rust
let esg = client.get_sustainability("AAPL").await?;
if let Some(score) = esg.total_esg {
    println!("ESG Score: {:.1} (Rating: {})", score, esg.rating().unwrap_or("N/A"));
}
```

### Industry Data

```rust
let industry = client.get_industry("technology-hardware").await?;
println!("Industry: {} (Sector: {:?})", industry.name, industry.sector_name);
for company in &industry.top_performing_companies {
    println!("  {} ({})", company.name, company.symbol);
}
```

### Market Status & Summary

```rust
// Check if market is open
let status = client.get_market_status("us_market").await?;
println!("Market is {}", if status.is_open() { "open" } else { "closed" });

// Get market summary with indices
let summary = client.get_market_summary("us_market").await?;
for index in &summary.indices {
    println!("{}: {:.2} ({:+.2}%)", index.short_name, index.price, index.percent_change);
}
```

### Market Movers

```rust
use finance_query_core::MoverCount;

// Get top 50 movers in each category
let (actives, gainers, losers) = client.get_movers(MoverCount::Fifty).await?;

// Display top gainers
println!("Top Gainers:");
for mover in gainers.iter().take(10) {
    println!("  {} ({}): {} {}", 
        mover.symbol, mover.name, mover.price, mover.percent_change);
}

// Find extreme movers (>10% change)
let big_movers: Vec<_> = gainers.iter()
    .filter(|m| {
        m.percent_change
            .trim_start_matches('+')
            .trim_end_matches('%')
            .parse::<f64>()
            .unwrap_or(0.0) > 10.0
    })
    .collect();
```

## License

Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for details.