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
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
mod info;
mod isin;
mod model;
mod options;
mod quote;
pub use crate::core::models::{FastInfo, MovingAverages};
pub use model::{Info, OptionChain, OptionContract};
use crate::core::{Action, Candle, HistoryMeta, Interval, Quote, Range};
use crate::fundamentals::{Calendar, ShareCount};
use crate::holders::{
InsiderRosterHolder, InsiderTransaction, InstitutionalHolder, MajorHolder,
NetSharePurchaseActivity,
};
use crate::news::NewsArticle;
use crate::profile::Profile;
use crate::{
EsgBuilder,
core::client::RetryConfig,
core::{CacheMode, CallOptions, DataQuality, YfClient, YfError, YfResponse},
esg::EsgSummary,
holders::HoldersBuilder,
news::NewsBuilder,
};
use crate::{
analysis::AnalysisBuilder, fundamentals::FundamentalsBuilder, history::HistoryBuilder,
};
use chrono::{DateTime, Utc};
use paft::fundamentals::analysis::{
Earnings, EarningsTrendRow, PriceTarget, RecommendationRow, RecommendationSummary,
UpgradeDowngradeRow,
};
use paft::fundamentals::statements::{BalanceSheetRow, CashflowRow, IncomeStatementRow};
use paft::fundamentals::statistics::KeyStatistics;
use paft::money::Currency;
/// A high-level interface for a single ticker symbol, providing convenient access to all available data.
///
/// This struct is designed to be the primary entry point for users who want to fetch
/// various types of financial data for a specific security, similar to the `Ticker`
/// object in the Python `yfinance` library.
///
/// A `Ticker` is created with a [`YfClient`] and a symbol. It then provides methods
/// to fetch quotes, historical prices, options chains, financials, and more.
///
/// # Example
///
/// ```no_run
/// # use yfinance_rs::{Ticker, YfClient};
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let client = YfClient::default();
/// let ticker = Ticker::new(&client, "TSLA");
///
/// // Get the latest quote
/// let quote = ticker.quote().await?;
/// if let Some(price) = "e.price {
/// println!("Tesla's last price: {price:?}");
/// }
///
/// // Get historical prices for the last year
/// let history = ticker.history(Some(yfinance_rs::Range::Y1), None, false).await?;
/// println!("Fetched {} days of history.", history.len());
/// # Ok(())
/// # }
/// ```
pub struct Ticker {
#[doc(hidden)]
pub(crate) client: YfClient,
#[doc(hidden)]
pub(crate) symbol: String,
#[doc(hidden)]
options: CallOptions,
}
impl Ticker {
/// Creates a new `Ticker` for a given symbol.
///
/// This is the standard way to create a ticker instance with default API endpoints.
pub fn new(client: &YfClient, symbol: impl Into<String>) -> Self {
Self {
client: client.clone(),
symbol: symbol.into(),
options: CallOptions::default(),
}
}
/// Sets the cache mode for all subsequent API calls made by this `Ticker` instance.
///
/// This allows you to override the client's default cache behavior for a specific ticker.
#[must_use]
pub const fn cache_mode(mut self, mode: CacheMode) -> Self {
self.options.cache_mode = mode;
self
}
/// Overrides the client's default retry policy for all subsequent API calls made by this `Ticker` instance.
#[must_use]
pub fn retry_policy(mut self, cfg: Option<RetryConfig>) -> Self {
self.options = self.options.with_retry_policy(cfg);
self
}
/// Sets how provider projection issues are handled for subsequent API calls.
///
/// Builders created from this ticker inherit this setting.
#[must_use]
pub const fn data_quality(mut self, policy: DataQuality) -> Self {
self.options.data_quality = policy;
self
}
/// Fails when Yahoo data cannot be projected losslessly.
#[must_use]
pub const fn strict(self) -> Self {
self.data_quality(DataQuality::Strict)
}
/// Fetches a comprehensive `Info` struct containing quote, profile, calendar, and analysis data.
///
/// This method conveniently aggregates data from multiple endpoints into a single struct,
/// similar to the `.info` attribute in the Python `yfinance` library. It makes several
/// API calls concurrently to gather the data efficiently.
///
/// If a non-essential part of the data fails to load (e.g., profile or analyst data),
/// the corresponding fields in the `Info` struct will be `None`.
///
/// # Errors
///
/// This method will return an error if the required quote data cannot be fetched
/// or strict data-quality mode rejects a projection issue.
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self), err, fields(symbol = %self.symbol)))]
pub async fn info(&self) -> Result<Info, YfError> {
info::fetch_info(&self.client, &self.symbol, &self.options).await
}
/// Fetches aggregate `Info` with projection diagnostics for optional submodules.
///
/// # Errors
///
/// This method will return an error if the required quote data cannot be fetched
/// or strict data-quality mode rejects a projection issue.
pub async fn info_with_diagnostics(&self) -> Result<YfResponse<Info>, YfError> {
info::fetch_info_with_diagnostics(&self.client, &self.symbol, &self.options).await
}
/// Fetches aggregate `Info` and fails if any optional submodule cannot be loaded.
///
/// # Errors
///
/// This method will return an error if the required quote data cannot be fetched
/// or any optional submodule fails to project cleanly.
pub async fn info_strict(&self) -> Result<Info, YfError> {
let options = self.options.clone().strict();
Ok(
info::fetch_info_with_diagnostics(&self.client, &self.symbol, &options)
.await?
.into_data(),
)
}
/// Fetches the company, ETF, or mutual-fund profile for the ticker.
///
/// This is the high-level convenience equivalent of [`crate::profile::load_profile`],
/// using this ticker's configured cache mode and retry policy.
///
/// # Errors
///
/// This method will return an error if the request fails, the response cannot be parsed,
/// or Yahoo does not provide a supported profile for the symbol.
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self), err, fields(symbol = %self.symbol)))]
pub async fn profile(&self) -> Result<Profile, YfError> {
Ok(self.profile_with_diagnostics().await?.into_data())
}
/// Fetches the company, ETF, or mutual-fund profile with projection diagnostics.
///
/// # Errors
///
/// This method will return an error if the request fails, the response cannot be parsed,
/// Yahoo does not provide a supported profile for the symbol, or strict data-quality mode
/// rejects a projection issue.
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self), err, fields(symbol = %self.symbol)))]
pub async fn profile_with_diagnostics(&self) -> Result<YfResponse<Profile>, YfError> {
crate::profile::load_profile_with_options_and_diagnostics(
&self.client,
&self.symbol,
&self.options,
)
.await
}
/* ---------------- Quotes ---------------- */
/// Fetches a detailed quote for the ticker.
///
/// # Errors
///
/// This method will return an error if the request fails, the response cannot be parsed,
/// or strict data-quality mode rejects a projection issue.
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self), err, fields(symbol = %self.symbol)))]
pub async fn quote(&self) -> Result<Quote, YfError> {
quote::fetch_quote(&self.client, &self.symbol, &self.options).await
}
/// Fetches a detailed quote with projection diagnostics.
///
/// # Errors
///
/// This method will return an error if the request fails, the response cannot be parsed,
/// or strict data-quality mode rejects a projection issue.
pub async fn quote_with_diagnostics(&self) -> Result<YfResponse<Quote>, YfError> {
quote::fetch_quote_with_diagnostics(&self.client, &self.symbol, &self.options).await
}
/// Fetches fast ticker information, including a quote snapshot and moving averages.
///
/// # Errors
///
/// This method will return an error if the request fails, the response cannot be parsed,
/// or strict data-quality mode rejects a projection issue.
pub async fn fast_info(&self) -> Result<FastInfo, YfError> {
quote::fetch_fast_info(&self.client, &self.symbol, &self.options).await
}
/// Fetches fast ticker information with projection diagnostics.
///
/// # Errors
///
/// This method will return an error if the request fails, the response cannot be parsed,
/// or strict data-quality mode rejects a projection issue.
pub async fn fast_info_with_diagnostics(&self) -> Result<YfResponse<FastInfo>, YfError> {
quote::fetch_fast_info_with_diagnostics(&self.client, &self.symbol, &self.options).await
}
/// Fetches valuation, dividend, volume, and risk statistics for the ticker.
///
/// The values are mapped into the provider-agnostic [`KeyStatistics`] model.
///
/// # Errors
///
/// This method will return an error if the request fails, the response cannot be parsed,
/// or strict data-quality mode rejects a projection issue.
pub async fn key_statistics(&self) -> Result<KeyStatistics, YfError> {
quote::fetch_key_statistics(&self.client, &self.symbol, &self.options).await
}
/// Fetches valuation, dividend, volume, and risk statistics with projection diagnostics.
///
/// # Errors
///
/// This method will return an error if the request fails, the response cannot be parsed,
/// or strict data-quality mode rejects a projection issue.
pub async fn key_statistics_with_diagnostics(
&self,
) -> Result<YfResponse<KeyStatistics>, YfError> {
quote::fetch_key_statistics_with_diagnostics(&self.client, &self.symbol, &self.options)
.await
}
/* ---------------- News convenience ---------------- */
/// Returns a `NewsBuilder` to construct a query for news articles.
#[must_use]
pub fn news_builder(&self) -> NewsBuilder {
NewsBuilder::new(&self.client, &self.symbol)
.cache_mode(self.options.cache_mode())
.data_quality(self.options.data_quality())
.retry_policy(self.options.retry_override().cloned())
}
/// Fetches the latest news articles for the ticker.
///
/// # Errors
///
/// This method will return an error if the request fails, the response cannot be parsed,
/// or strict data-quality mode rejects a projection issue.
pub async fn news(&self) -> Result<Vec<NewsArticle>, YfError> {
Ok(self.news_with_diagnostics().await?.into_data())
}
/// Fetches the latest news articles with projection diagnostics.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn news_with_diagnostics(&self) -> Result<YfResponse<Vec<NewsArticle>>, YfError> {
self.news_builder().fetch_with_diagnostics().await
}
/* ---------------- History helpers ---------------- */
/// Returns a `HistoryBuilder` to construct a detailed query for historical price data.
#[must_use]
pub fn history_builder(&self) -> HistoryBuilder {
HistoryBuilder::new(&self.client, &self.symbol)
.cache_mode(self.options.cache_mode())
.data_quality(self.options.data_quality())
.retry_policy(self.options.retry_override().cloned())
}
/// Fetches historical price candles with default settings.
///
/// Prices are automatically adjusted for splits and dividends. For more control, use [`Self::history_builder`].
///
/// # Arguments
/// * `range` - The relative time range for the data (e.g., `1y`, `6mo`). Defaults to `6mo` if `None`.
/// * `interval` - The time interval for each candle (e.g., `1d`, `1wk`). Defaults to `1d` if `None`.
/// * `prepost` - Whether to include pre-market and post-market data for intraday intervals.
///
/// # Errors
///
/// This method will return an error if the request fails, the response cannot be parsed,
/// or strict data-quality mode rejects a projection issue.
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self), err, fields(symbol = %self.symbol)))]
pub async fn history(
&self,
range: Option<Range>,
interval: Option<Interval>,
prepost: bool,
) -> Result<Vec<Candle>, crate::core::YfError> {
Ok(self
.history_with_diagnostics(range, interval, prepost)
.await?
.into_data())
}
/// Fetches historical price candles with projection diagnostics.
///
/// Prices are automatically adjusted for splits and dividends. For more control, use [`Self::history_builder`].
///
/// # Arguments
/// * `range` - The relative time range for the data (e.g., `1y`, `6mo`). Defaults to `6mo` if `None`.
/// * `interval` - The time interval for each candle (e.g., `1d`, `1wk`). Defaults to `1d` if `None`.
/// * `prepost` - Whether to include pre-market and post-market data for intraday intervals.
///
/// # Errors
///
/// This method will return an error if the request fails, the response cannot be parsed,
/// or strict data-quality mode rejects a projection issue.
pub async fn history_with_diagnostics(
&self,
range: Option<Range>,
interval: Option<Interval>,
prepost: bool,
) -> Result<YfResponse<Vec<Candle>>, YfError> {
let mut hb = self.history_builder();
if let Some(r) = range {
hb = hb.range(r);
}
if let Some(i) = interval {
hb = hb.interval(i);
}
hb = hb.auto_adjust(true).prepost(prepost).actions(true);
hb.fetch_with_diagnostics().await
}
/// Fetches all corporate actions (dividends, splits, and capital gains) for the given range.
///
/// Defaults to the maximum available range if `None`.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self), err, fields(symbol = %self.symbol)))]
pub async fn actions(&self, range: Option<Range>) -> Result<Vec<Action>, YfError> {
Ok(self.actions_with_diagnostics(range).await?.into_data())
}
/// Fetches all corporate actions with projection diagnostics.
///
/// Defaults to the maximum available range if `None`.
///
/// # Errors
///
/// This method will return an error if the request fails, the response cannot be parsed,
/// or strict data-quality mode rejects a projection issue.
pub async fn actions_with_diagnostics(
&self,
range: Option<Range>,
) -> Result<YfResponse<Vec<Action>>, YfError> {
let mut hb = self.history_builder();
hb = hb.range(range.unwrap_or(Range::Max));
Ok(hb
.auto_adjust(true)
.actions(true)
.fetch_full_with_diagnostics()
.await?
.map(|resp| {
let mut actions = resp.actions;
actions.sort_by_key(action_sort_key);
actions
}))
}
/// Fetches the metadata associated with the ticker's historical data, such as timezone.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self), err, fields(symbol = %self.symbol)))]
pub async fn get_history_metadata(
&self,
range: Option<Range>,
) -> Result<Option<HistoryMeta>, crate::core::YfError> {
Ok(self
.get_history_metadata_with_diagnostics(range)
.await?
.into_data())
}
/// Fetches the ticker's historical metadata with projection diagnostics.
///
/// # Errors
///
/// This method will return an error if the request fails, the response cannot be parsed,
/// or strict data-quality mode rejects a projection issue.
pub async fn get_history_metadata_with_diagnostics(
&self,
range: Option<Range>,
) -> Result<YfResponse<Option<HistoryMeta>>, YfError> {
let mut hb = self.history_builder();
if let Some(r) = range {
hb = hb.range(r);
}
Ok(hb
.fetch_full_with_diagnostics()
.await?
.map(|resp| resp.meta))
}
/// Fetches the ISIN for the ticker by searching on markets.businessinsider.com.
///
/// This mimics the approach used by the Python `yfinance` library.
/// It returns `None` for assets that don't have an ISIN, such as indices.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn isin(&self) -> Result<Option<String>, YfError> {
let symbol = crate::core::client::normalize_symbol(&self.symbol)?;
if symbol.contains('^') {
return Ok(None);
}
isin::fetch_isin(&self.client, &symbol, self.options.retry_override()).await
}
/* ---------------- Options ---------------- */
/// Fetches the available expiration dates for the ticker's options as Unix timestamps.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn options(&self) -> Result<Vec<i64>, YfError> {
options::expiration_dates(&self.client, &self.symbol, &self.options).await
}
/// Fetches the full option chain (calls and puts) for a specific expiration date.
///
/// If `date` is `None`, fetches the chain for the nearest expiration date.
///
/// # Errors
///
/// This method will return an error if the request fails, the response cannot be parsed,
/// or strict data-quality mode rejects a projection issue.
pub async fn option_chain(&self, date: Option<i64>) -> Result<OptionChain, YfError> {
options::option_chain(&self.client, &self.symbol, date, &self.options).await
}
/// Fetches the full option chain with projection diagnostics.
///
/// If `date` is `None`, fetches the chain for the nearest expiration date.
///
/// # Errors
///
/// This method will return an error if the request fails, the response cannot be parsed,
/// or strict data-quality mode rejects a projection issue.
pub async fn option_chain_with_diagnostics(
&self,
date: Option<i64>,
) -> Result<YfResponse<OptionChain>, YfError> {
options::option_chain_with_diagnostics(&self.client, &self.symbol, date, &self.options)
.await
}
/* ---------------- Holders convenience ---------------- */
fn holders_builder(&self) -> HoldersBuilder {
HoldersBuilder::new(&self.client, &self.symbol)
.cache_mode(self.options.cache_mode())
.data_quality(self.options.data_quality())
.retry_policy(self.options.retry_override().cloned())
}
/// Fetches the major holders breakdown (e.g., % insiders, % institutions).
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn major_holders(&self) -> Result<Vec<MajorHolder>, YfError> {
Ok(self.major_holders_with_diagnostics().await?.into_data())
}
/// Fetches the major holders breakdown with projection diagnostics.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn major_holders_with_diagnostics(
&self,
) -> Result<YfResponse<Vec<MajorHolder>>, YfError> {
self.holders_builder()
.major_holders_with_diagnostics()
.await
}
/// Fetches a list of the top institutional holders.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn institutional_holders(&self) -> Result<Vec<InstitutionalHolder>, YfError> {
Ok(self
.institutional_holders_with_diagnostics()
.await?
.into_data())
}
/// Fetches institutional holders with projection diagnostics.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn institutional_holders_with_diagnostics(
&self,
) -> Result<YfResponse<Vec<InstitutionalHolder>>, YfError> {
self.holders_builder()
.institutional_holders_with_diagnostics()
.await
}
/// Fetches a list of the top mutual fund holders.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn mutual_fund_holders(&self) -> Result<Vec<InstitutionalHolder>, YfError> {
Ok(self
.mutual_fund_holders_with_diagnostics()
.await?
.into_data())
}
/// Fetches mutual fund holders with projection diagnostics.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn mutual_fund_holders_with_diagnostics(
&self,
) -> Result<YfResponse<Vec<InstitutionalHolder>>, YfError> {
self.holders_builder()
.mutual_fund_holders_with_diagnostics()
.await
}
/// Fetches a list of recent insider transactions.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn insider_transactions(&self) -> Result<Vec<InsiderTransaction>, YfError> {
Ok(self
.insider_transactions_with_diagnostics()
.await?
.into_data())
}
/// Fetches insider transactions with projection diagnostics.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn insider_transactions_with_diagnostics(
&self,
) -> Result<YfResponse<Vec<InsiderTransaction>>, YfError> {
self.holders_builder()
.insider_transactions_with_diagnostics()
.await
}
/// Fetches a roster of company insiders and their holdings.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn insider_roster_holders(&self) -> Result<Vec<InsiderRosterHolder>, YfError> {
Ok(self
.insider_roster_holders_with_diagnostics()
.await?
.into_data())
}
/// Fetches insider roster holders with projection diagnostics.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn insider_roster_holders_with_diagnostics(
&self,
) -> Result<YfResponse<Vec<InsiderRosterHolder>>, YfError> {
self.holders_builder()
.insider_roster_holders_with_diagnostics()
.await
}
/// Fetches a summary of net insider purchase and sale activity.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn net_share_purchase_activity(
&self,
) -> Result<Option<NetSharePurchaseActivity>, YfError> {
Ok(self
.net_share_purchase_activity_with_diagnostics()
.await?
.into_data())
}
/// Fetches net insider purchase and sale activity with projection diagnostics.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn net_share_purchase_activity_with_diagnostics(
&self,
) -> Result<YfResponse<Option<NetSharePurchaseActivity>>, YfError> {
self.holders_builder()
.net_share_purchase_activity_with_diagnostics()
.await
}
/* ---------------- Analysis convenience ---------------- */
fn analysis_builder(&self) -> AnalysisBuilder {
AnalysisBuilder::new(&self.client, &self.symbol)
.cache_mode(self.options.cache_mode())
.data_quality(self.options.data_quality())
.retry_policy(self.options.retry_override().cloned())
}
/// Fetches the analyst recommendation trend.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn recommendations(&self) -> Result<Vec<RecommendationRow>, YfError> {
Ok(self.recommendations_with_diagnostics().await?.into_data())
}
/// Fetches analyst recommendation trends with projection diagnostics.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn recommendations_with_diagnostics(
&self,
) -> Result<YfResponse<Vec<RecommendationRow>>, YfError> {
self.analysis_builder()
.recommendations_with_diagnostics()
.await
}
/// Fetches a summary of the latest analyst recommendations.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn recommendations_summary(&self) -> Result<RecommendationSummary, YfError> {
Ok(self
.recommendations_summary_with_diagnostics()
.await?
.into_data())
}
/// Fetches the latest analyst recommendation summary with projection diagnostics.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn recommendations_summary_with_diagnostics(
&self,
) -> Result<YfResponse<RecommendationSummary>, YfError> {
self.analysis_builder()
.recommendations_summary_with_diagnostics()
.await
}
/// Fetches the history of analyst upgrades and downgrades.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn upgrades_downgrades(&self) -> Result<Vec<UpgradeDowngradeRow>, YfError> {
Ok(self
.upgrades_downgrades_with_diagnostics()
.await?
.into_data())
}
/// Fetches analyst upgrades and downgrades with projection diagnostics.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn upgrades_downgrades_with_diagnostics(
&self,
) -> Result<YfResponse<Vec<UpgradeDowngradeRow>>, YfError> {
self.analysis_builder()
.upgrades_downgrades_with_diagnostics()
.await
}
/// Fetches the analyst price target.
///
/// Provide `Some(currency)` to override the auto-resolved currency for this call;
/// pass `None` to enrich currency metadata from Yahoo and infer only when needed.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn analyst_price_target(
&self,
override_currency: Option<Currency>,
) -> Result<PriceTarget, YfError> {
Ok(self
.analyst_price_target_with_diagnostics(override_currency)
.await?
.into_data())
}
/// Fetches analyst price targets with projection diagnostics.
///
/// Provide `Some(currency)` to override the auto-resolved currency for this call;
/// pass `None` to enrich currency metadata from Yahoo and infer only when needed.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn analyst_price_target_with_diagnostics(
&self,
override_currency: Option<Currency>,
) -> Result<YfResponse<PriceTarget>, YfError> {
self.analysis_builder()
.analyst_price_target_with_diagnostics(override_currency)
.await
}
/// Fetches earnings trend data for the ticker.
///
/// This includes earnings estimates, revenue estimates, EPS trends, and EPS revisions for various periods.
///
/// Provide `Some(currency)` to override the auto-resolved currency for this call;
/// pass `None` to enrich currency metadata from Yahoo and infer only when needed.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn earnings_trend(
&self,
override_currency: Option<Currency>,
) -> Result<Vec<EarningsTrendRow>, YfError> {
Ok(self
.earnings_trend_with_diagnostics(override_currency)
.await?
.into_data())
}
/// Fetches earnings trend data with projection diagnostics.
///
/// This includes earnings estimates, revenue estimates, EPS trends, and EPS revisions for various periods.
///
/// Provide `Some(currency)` to override the auto-resolved currency for this call;
/// pass `None` to enrich currency metadata from Yahoo and infer only when needed.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn earnings_trend_with_diagnostics(
&self,
override_currency: Option<Currency>,
) -> Result<YfResponse<Vec<EarningsTrendRow>>, YfError> {
self.analysis_builder()
.earnings_trend_with_diagnostics(override_currency)
.await
}
/* ---------------- ESG / Sustainability ---------------- */
fn esg_builder(&self) -> EsgBuilder {
EsgBuilder::new(&self.client, &self.symbol)
.cache_mode(self.options.cache_mode())
.data_quality(self.options.data_quality())
.retry_policy(self.options.retry_override().cloned())
}
/// Fetches ESG (Environmental, Social, Governance) scores and involvement data for the ticker.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn sustainability(&self) -> Result<EsgSummary, YfError> {
self.esg_builder().fetch().await
}
/// Fetches ESG scores and involvement data with projection diagnostics.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode rejects a projection issue.
pub async fn sustainability_with_diagnostics(&self) -> Result<YfResponse<EsgSummary>, YfError> {
self.esg_builder().fetch_with_diagnostics().await
}
/* ---------------- Fundamentals convenience ---------------- */
fn fundamentals_builder(&self) -> FundamentalsBuilder {
FundamentalsBuilder::new(&self.client, &self.symbol)
.cache_mode(self.options.cache_mode())
.data_quality(self.options.data_quality())
.retry_policy(self.options.retry_override().cloned())
}
/// Fetches the annual income statement.
///
/// Provide `Some(currency)` to override the auto-resolved reporting currency for this call;
/// pass `None` to enrich currency metadata from Yahoo and infer only when needed.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn income_stmt(
&self,
override_currency: Option<Currency>,
) -> Result<Vec<IncomeStatementRow>, YfError> {
Ok(self
.income_stmt_with_diagnostics(override_currency)
.await?
.into_data())
}
/// Fetches the annual income statement with projection diagnostics.
///
/// Provide `Some(currency)` to override the auto-resolved reporting currency for this call;
/// pass `None` to enrich currency metadata from Yahoo and infer only when needed.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn income_stmt_with_diagnostics(
&self,
override_currency: Option<Currency>,
) -> Result<YfResponse<Vec<IncomeStatementRow>>, YfError> {
self.fundamentals_builder()
.income_statement_with_diagnostics(false, override_currency)
.await
}
/// Fetches the quarterly income statement.
///
/// Provide `Some(currency)` to override the auto-resolved reporting currency for this call;
/// pass `None` to enrich currency metadata from Yahoo and infer only when needed.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn quarterly_income_stmt(
&self,
override_currency: Option<Currency>,
) -> Result<Vec<IncomeStatementRow>, YfError> {
Ok(self
.quarterly_income_stmt_with_diagnostics(override_currency)
.await?
.into_data())
}
/// Fetches the quarterly income statement with projection diagnostics.
///
/// Provide `Some(currency)` to override the auto-resolved reporting currency for this call;
/// pass `None` to enrich currency metadata from Yahoo and infer only when needed.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn quarterly_income_stmt_with_diagnostics(
&self,
override_currency: Option<Currency>,
) -> Result<YfResponse<Vec<IncomeStatementRow>>, YfError> {
self.fundamentals_builder()
.income_statement_with_diagnostics(true, override_currency)
.await
}
/// Fetches the annual balance sheet.
///
/// Provide `Some(currency)` to override the auto-resolved reporting currency for this call;
/// pass `None` to enrich currency metadata from Yahoo and infer only when needed.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn balance_sheet(
&self,
override_currency: Option<Currency>,
) -> Result<Vec<BalanceSheetRow>, YfError> {
Ok(self
.balance_sheet_with_diagnostics(override_currency)
.await?
.into_data())
}
/// Fetches the annual balance sheet with projection diagnostics.
///
/// Provide `Some(currency)` to override the auto-resolved reporting currency for this call;
/// pass `None` to enrich currency metadata from Yahoo and infer only when needed.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn balance_sheet_with_diagnostics(
&self,
override_currency: Option<Currency>,
) -> Result<YfResponse<Vec<BalanceSheetRow>>, YfError> {
self.fundamentals_builder()
.balance_sheet_with_diagnostics(false, override_currency)
.await
}
/// Fetches the quarterly balance sheet.
///
/// Provide `Some(currency)` to override the auto-resolved reporting currency for this call;
/// pass `None` to enrich currency metadata from Yahoo and infer only when needed.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn quarterly_balance_sheet(
&self,
override_currency: Option<Currency>,
) -> Result<Vec<BalanceSheetRow>, YfError> {
Ok(self
.quarterly_balance_sheet_with_diagnostics(override_currency)
.await?
.into_data())
}
/// Fetches the quarterly balance sheet with projection diagnostics.
///
/// Provide `Some(currency)` to override the auto-resolved reporting currency for this call;
/// pass `None` to enrich currency metadata from Yahoo and infer only when needed.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn quarterly_balance_sheet_with_diagnostics(
&self,
override_currency: Option<Currency>,
) -> Result<YfResponse<Vec<BalanceSheetRow>>, YfError> {
self.fundamentals_builder()
.balance_sheet_with_diagnostics(true, override_currency)
.await
}
/// Fetches the annual cash flow statement.
///
/// Provide `Some(currency)` to override the auto-resolved reporting currency for this call;
/// pass `None` to enrich currency metadata from Yahoo and infer only when needed.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn cashflow(
&self,
override_currency: Option<Currency>,
) -> Result<Vec<CashflowRow>, YfError> {
Ok(self
.cashflow_with_diagnostics(override_currency)
.await?
.into_data())
}
/// Fetches the annual cash flow statement with projection diagnostics.
///
/// Provide `Some(currency)` to override the auto-resolved reporting currency for this call;
/// pass `None` to enrich currency metadata from Yahoo and infer only when needed.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn cashflow_with_diagnostics(
&self,
override_currency: Option<Currency>,
) -> Result<YfResponse<Vec<CashflowRow>>, YfError> {
self.fundamentals_builder()
.cashflow_with_diagnostics(false, override_currency)
.await
}
/// Fetches the quarterly cash flow statement.
///
/// Provide `Some(currency)` to override the auto-resolved reporting currency for this call;
/// pass `None` to enrich currency metadata from Yahoo and infer only when needed.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn quarterly_cashflow(
&self,
override_currency: Option<Currency>,
) -> Result<Vec<CashflowRow>, YfError> {
Ok(self
.quarterly_cashflow_with_diagnostics(override_currency)
.await?
.into_data())
}
/// Fetches the quarterly cash flow statement with projection diagnostics.
///
/// Provide `Some(currency)` to override the auto-resolved reporting currency for this call;
/// pass `None` to enrich currency metadata from Yahoo and infer only when needed.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn quarterly_cashflow_with_diagnostics(
&self,
override_currency: Option<Currency>,
) -> Result<YfResponse<Vec<CashflowRow>>, YfError> {
self.fundamentals_builder()
.cashflow_with_diagnostics(true, override_currency)
.await
}
/// Fetches earnings history and estimates.
///
/// Provide `Some(currency)` to override the auto-resolved reporting currency for this call;
/// pass `None` to enrich currency metadata from Yahoo and infer only when needed.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn earnings(&self, override_currency: Option<Currency>) -> Result<Earnings, YfError> {
Ok(self
.earnings_with_diagnostics(override_currency)
.await?
.into_data())
}
/// Fetches earnings history and estimates with projection diagnostics.
///
/// Provide `Some(currency)` to override the auto-resolved reporting currency for this call;
/// pass `None` to enrich currency metadata from Yahoo and infer only when needed.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn earnings_with_diagnostics(
&self,
override_currency: Option<Currency>,
) -> Result<YfResponse<Earnings>, YfError> {
self.fundamentals_builder()
.earnings_with_diagnostics(override_currency)
.await
}
/// Fetches corporate calendar events like earnings dates.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn calendar(&self) -> Result<Calendar, YfError> {
Ok(self.calendar_with_diagnostics().await?.into_data())
}
/// Fetches corporate calendar events with projection diagnostics.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn calendar_with_diagnostics(&self) -> Result<YfResponse<Calendar>, YfError> {
self.fundamentals_builder()
.calendar_with_diagnostics()
.await
}
/// Fetches historical annual shares outstanding.
///
/// This convenience method uses Yahoo's rolling 548-day share-count window, matching
/// Python yfinance's `get_shares_full(start=None, end=None)`. Use
/// [`Self::shares_between`] to request an explicit wider window.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn shares(&self) -> Result<Vec<ShareCount>, YfError> {
Ok(self.shares_with_diagnostics().await?.into_data())
}
/// Fetches historical annual shares outstanding with projection diagnostics.
///
/// This convenience method uses Yahoo's rolling 548-day share-count window, matching
/// Python yfinance's `get_shares_full(start=None, end=None)`. Use
/// [`Self::shares_between_with_diagnostics`] to request an explicit wider window.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn shares_with_diagnostics(&self) -> Result<YfResponse<Vec<ShareCount>>, YfError> {
self.fundamentals_builder()
.shares_with_diagnostics(false)
.await
}
/// Fetches historical annual shares outstanding within an explicit UTC time window.
///
/// # Errors
///
/// This method will return an error if the date range is invalid, the request fails,
/// or the response cannot be parsed.
pub async fn shares_between(
&self,
start: DateTime<Utc>,
end: DateTime<Utc>,
) -> Result<Vec<ShareCount>, YfError> {
Ok(self
.shares_between_with_diagnostics(start, end)
.await?
.into_data())
}
/// Fetches historical annual shares outstanding within an explicit UTC time window with diagnostics.
///
/// # Errors
///
/// This method will return an error if the date range is invalid, the request fails,
/// or strict data-quality mode rejects a projection issue.
pub async fn shares_between_with_diagnostics(
&self,
start: DateTime<Utc>,
end: DateTime<Utc>,
) -> Result<YfResponse<Vec<ShareCount>>, YfError> {
self.fundamentals_builder()
.shares_between_with_diagnostics(false, start, end)
.await
}
/// Fetches historical quarterly shares outstanding.
///
/// This convenience method uses Yahoo's rolling 548-day share-count window, matching
/// Python yfinance's `get_shares_full(start=None, end=None)`. Use
/// [`Self::quarterly_shares_between`] to request an explicit wider window.
///
/// # Errors
///
/// This method will return an error if the request fails or the response cannot be parsed.
pub async fn quarterly_shares(&self) -> Result<Vec<ShareCount>, YfError> {
Ok(self.quarterly_shares_with_diagnostics().await?.into_data())
}
/// Fetches historical quarterly shares outstanding with projection diagnostics.
///
/// This convenience method uses Yahoo's rolling 548-day share-count window, matching
/// Python yfinance's `get_shares_full(start=None, end=None)`. Use
/// [`Self::quarterly_shares_between_with_diagnostics`] to request an explicit wider window.
///
/// # Errors
///
/// This method will return an error if the request fails or strict data-quality mode
/// rejects a projection issue.
pub async fn quarterly_shares_with_diagnostics(
&self,
) -> Result<YfResponse<Vec<ShareCount>>, YfError> {
self.fundamentals_builder()
.shares_with_diagnostics(true)
.await
}
/// Fetches historical quarterly shares outstanding within an explicit UTC time window.
///
/// # Errors
///
/// This method will return an error if the date range is invalid, the request fails,
/// or the response cannot be parsed.
pub async fn quarterly_shares_between(
&self,
start: DateTime<Utc>,
end: DateTime<Utc>,
) -> Result<Vec<ShareCount>, YfError> {
Ok(self
.quarterly_shares_between_with_diagnostics(start, end)
.await?
.into_data())
}
/// Fetches historical quarterly shares outstanding within an explicit UTC time window with diagnostics.
///
/// # Errors
///
/// This method will return an error if the date range is invalid, the request fails,
/// or strict data-quality mode rejects a projection issue.
pub async fn quarterly_shares_between_with_diagnostics(
&self,
start: DateTime<Utc>,
end: DateTime<Utc>,
) -> Result<YfResponse<Vec<ShareCount>>, YfError> {
self.fundamentals_builder()
.shares_between_with_diagnostics(true, start, end)
.await
}
}
const fn action_sort_key(action: &Action) -> (bool, chrono::NaiveDate) {
match action {
Action::Dividend { date, .. }
| Action::Split { date, .. }
| Action::CapitalGain { date, .. } => (false, *date),
_ => (true, chrono::NaiveDate::MAX),
}
}