-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathtypes.rs
More file actions
2113 lines (1937 loc) · 63 KB
/
Copy pathtypes.rs
File metadata and controls
2113 lines (1937 loc) · 63 KB
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
use longbridge::fundamental::types as lb;
use longbridge_python_macros::PyEnum;
use pyo3::{exceptions::PyRuntimeError, prelude::*};
/// Institutional analyst recommendation
#[pyclass(eq, eq_int, from_py_object)]
#[derive(Debug, PyEnum, Copy, Clone, Hash, Eq, PartialEq)]
#[py(remote = "longbridge::fundamental::types::InstitutionRecommend")]
pub(crate) enum InstitutionRecommend {
/// Unknown
Unknown,
/// Strong buy
StrongBuy,
/// Buy
Buy,
/// Hold
Hold,
/// Sell
Sell,
/// Strong sell
StrongSell,
/// Underperform
Underperform,
/// No opinion
NoOpinion,
}
// ── JsonValue: Clone + IntoPyObject wrapper ───────────────────────
#[derive(Debug, Clone)]
pub(crate) struct JsonValue(pub(crate) serde_json::Value);
impl<'py> IntoPyObject<'py> for JsonValue {
type Target = PyAny;
type Output = Bound<'py, PyAny>;
type Error = PyErr;
fn into_pyobject(self, py: Python<'py>) -> PyResult<Self::Output> {
pythonize::pythonize(py, &self.0).map_err(|e| PyRuntimeError::new_err(e.to_string()))
}
}
impl<'py> IntoPyObject<'py> for &JsonValue {
type Target = PyAny;
type Output = Bound<'py, PyAny>;
type Error = PyErr;
fn into_pyobject(self, py: Python<'py>) -> PyResult<Self::Output> {
pythonize::pythonize(py, &self.0).map_err(|e| PyRuntimeError::new_err(e.to_string()))
}
}
// ── FinancialReports ──────────────────────────────────────────────
/// Financial reports response.
///
/// The `list` field is a dict keyed by report kind (`"IS"`, `"BS"`, `"CF"`).
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct FinancialReports {
/// Raw nested financial data dict
pub list: JsonValue,
}
impl From<lb::FinancialReports> for FinancialReports {
fn from(v: lb::FinancialReports) -> Self {
Self {
list: JsonValue(v.list),
}
}
}
impl FinancialReports {
pub(crate) fn from_lb(_py: Python<'_>, v: lb::FinancialReports) -> PyResult<Self> {
Ok(v.into())
}
}
// ── DividendList / DividendItem ───────────────────────────────────
/// Dividend history response
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct DividendList {
/// List of dividend events
pub list: Vec<DividendItem>,
}
impl From<lb::DividendList> for DividendList {
fn from(v: lb::DividendList) -> Self {
Self {
list: v.list.into_iter().map(Into::into).collect(),
}
}
}
/// A single dividend event
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct DividendItem {
/// Security symbol, e.g. `"700.HK"`
pub symbol: String,
/// Internal record ID
pub id: String,
/// Human-readable description
pub desc: String,
/// Record / book-close date
pub record_date: String,
/// Ex-dividend date
pub ex_date: String,
/// Payment date
pub payment_date: String,
}
impl From<lb::DividendItem> for DividendItem {
fn from(v: lb::DividendItem) -> Self {
Self {
symbol: v.symbol,
id: v.id,
desc: v.desc,
record_date: v.record_date,
ex_date: v.ex_date,
payment_date: v.payment_date,
}
}
}
// ── InstitutionRating ─────────────────────────────────────────────
/// Combined analyst rating response
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct InstitutionRating {
/// Latest snapshot
pub latest: InstitutionRatingLatest,
/// Consensus summary
pub summary: InstitutionRatingSummary,
}
impl From<lb::InstitutionRating> for InstitutionRating {
fn from(v: lb::InstitutionRating) -> Self {
Self {
latest: v.latest.into(),
summary: v.summary.into(),
}
}
}
/// Latest analyst rating snapshot
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct InstitutionRatingLatest {
/// Rating distribution counts
pub evaluate: RatingEvaluate,
/// Target price range
pub target: RatingTarget,
/// Industry classification ID
pub industry_id: i64,
/// Industry name
pub industry_name: String,
/// Rank within the industry
pub industry_rank: i32,
/// Total securities in the industry
pub industry_total: i32,
/// Mean analyst count in the industry
pub industry_mean: i32,
/// Median analyst count in the industry
pub industry_median: i32,
}
impl From<lb::InstitutionRatingLatest> for InstitutionRatingLatest {
fn from(v: lb::InstitutionRatingLatest) -> Self {
Self {
evaluate: v.evaluate.into(),
target: v.target.into(),
industry_id: v.industry_id,
industry_name: v.industry_name,
industry_rank: v.industry_rank,
industry_total: v.industry_total,
industry_mean: v.industry_mean,
industry_median: v.industry_median,
}
}
}
/// Analyst rating distribution counts
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct RatingEvaluate {
/// Number of "Buy" ratings
pub buy: i32,
/// Number of "Strong Buy" / "Outperform" ratings
pub over: i32,
/// Number of "Hold" ratings
pub hold: i32,
/// Number of "Underperform" ratings
pub under: i32,
/// Number of "Sell" ratings
pub sell: i32,
/// Number of "No Opinion" ratings
pub no_opinion: i32,
/// Total analyst count
pub total: i32,
/// Window start (unix timestamp string)
pub start_date: String,
/// Window end (unix timestamp string)
pub end_date: String,
}
impl From<lb::RatingEvaluate> for RatingEvaluate {
fn from(v: lb::RatingEvaluate) -> Self {
Self {
buy: v.buy,
over: v.over,
hold: v.hold,
under: v.under,
sell: v.sell,
no_opinion: v.no_opinion,
total: v.total,
start_date: v.start_date,
end_date: v.end_date,
}
}
}
/// Analyst target price range
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct RatingTarget {
/// Highest price target
pub highest_price: Option<String>,
/// Lowest price target
pub lowest_price: Option<String>,
/// Previous close price
pub prev_close: Option<String>,
/// Window start (unix timestamp string)
pub start_date: String,
/// Window end (unix timestamp string)
pub end_date: String,
}
impl From<lb::RatingTarget> for RatingTarget {
fn from(v: lb::RatingTarget) -> Self {
Self {
highest_price: v.highest_price.map(|d| d.to_string()),
lowest_price: v.lowest_price.map(|d| d.to_string()),
prev_close: v.prev_close.map(|d| d.to_string()),
start_date: v.start_date,
end_date: v.end_date,
}
}
}
/// Consensus summary
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct InstitutionRatingSummary {
/// Currency symbol, e.g. `"HK$"`
pub ccy_symbol: String,
/// Change vs previous period
pub change: Option<String>,
/// Simplified rating distribution
pub evaluate: RatingSummaryEvaluate,
/// Consensus recommendation
pub recommend: InstitutionRecommend,
/// Consensus target price
pub target: Option<String>,
/// Last updated display string
pub updated_at: String,
}
impl From<lb::InstitutionRatingSummary> for InstitutionRatingSummary {
fn from(v: lb::InstitutionRatingSummary) -> Self {
Self {
ccy_symbol: v.ccy_symbol,
change: v.change.map(|d| d.to_string()),
evaluate: v.evaluate.into(),
recommend: v.recommend.into(),
target: v.target.map(|d| d.to_string()),
updated_at: v.updated_at,
}
}
}
/// Simplified rating distribution
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct RatingSummaryEvaluate {
/// Number of "Buy" ratings
pub buy: i32,
/// Date of the update
pub date: String,
/// Number of "Hold" ratings
pub hold: i32,
/// Number of "Sell" ratings
pub sell: i32,
/// Number of "Strong Buy" ratings
pub strong_buy: i32,
/// Number of "Underperform" ratings
pub under: i32,
}
impl From<lb::RatingSummaryEvaluate> for RatingSummaryEvaluate {
fn from(v: lb::RatingSummaryEvaluate) -> Self {
Self {
buy: v.buy,
date: v.date,
hold: v.hold,
sell: v.sell,
strong_buy: v.strong_buy,
under: v.under,
}
}
}
// ── InstitutionRatingDetail ───────────────────────────────────────
/// Historical analyst rating detail response
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct InstitutionRatingDetail {
/// Currency symbol
pub ccy_symbol: String,
/// Historical rating distribution time-series
pub evaluate: InstitutionRatingDetailEvaluate,
/// Historical target price time-series
pub target: InstitutionRatingDetailTarget,
}
impl From<lb::InstitutionRatingDetail> for InstitutionRatingDetail {
fn from(v: lb::InstitutionRatingDetail) -> Self {
Self {
ccy_symbol: v.ccy_symbol,
evaluate: v.evaluate.into(),
target: v.target.into(),
}
}
}
/// Historical rating distribution time-series
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct InstitutionRatingDetailEvaluate {
/// Weekly rating distribution snapshots
pub list: Vec<InstitutionRatingDetailEvaluateItem>,
}
impl From<lb::InstitutionRatingDetailEvaluate> for InstitutionRatingDetailEvaluate {
fn from(v: lb::InstitutionRatingDetailEvaluate) -> Self {
Self {
list: v.list.into_iter().map(Into::into).collect(),
}
}
}
/// One weekly rating distribution snapshot
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct InstitutionRatingDetailEvaluateItem {
/// Number of "Buy" ratings
pub buy: i32,
/// Date in `"2021/05/14"` format
pub date: String,
/// Number of "Hold" ratings
pub hold: i32,
/// Number of "Sell" ratings
pub sell: i32,
/// Number of "Strong Buy" / "Outperform" ratings
pub strong_buy: i32,
/// Number of "No Opinion" ratings
pub no_opinion: i32,
/// Number of "Underperform" ratings
pub under: i32,
}
impl From<lb::InstitutionRatingDetailEvaluateItem> for InstitutionRatingDetailEvaluateItem {
fn from(v: lb::InstitutionRatingDetailEvaluateItem) -> Self {
Self {
buy: v.buy,
date: v.date,
hold: v.hold,
sell: v.sell,
strong_buy: v.strong_buy,
no_opinion: v.no_opinion,
under: v.under,
}
}
}
/// Historical target price time-series
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct InstitutionRatingDetailTarget {
/// Prediction accuracy ratio (may be `None`)
pub data_percent: Option<String>,
/// Overall prediction accuracy
pub prediction_accuracy: Option<String>,
/// Last updated display string
pub updated_at: String,
/// Weekly target price snapshots
pub list: Vec<InstitutionRatingDetailTargetItem>,
}
impl From<lb::InstitutionRatingDetailTarget> for InstitutionRatingDetailTarget {
fn from(v: lb::InstitutionRatingDetailTarget) -> Self {
Self {
data_percent: v.data_percent.map(|d| d.to_string()),
prediction_accuracy: v.prediction_accuracy.map(|d| d.to_string()),
updated_at: v.updated_at,
list: v.list.into_iter().map(Into::into).collect(),
}
}
}
/// One weekly target price snapshot
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct InstitutionRatingDetailTargetItem {
/// Average target price
pub avg_target: Option<String>,
/// Date in `"2021/05/16"` format
pub date: String,
/// Highest target price
pub max_target: Option<String>,
/// Lowest target price
pub min_target: Option<String>,
/// Whether the stock price reached the target
pub meet: bool,
/// Actual stock price at this date
pub price: Option<String>,
/// Unix timestamp string
pub timestamp: String,
}
impl From<lb::InstitutionRatingDetailTargetItem> for InstitutionRatingDetailTargetItem {
fn from(v: lb::InstitutionRatingDetailTargetItem) -> Self {
Self {
avg_target: v.avg_target.map(|d| d.to_string()),
date: v.date,
max_target: v.max_target.map(|d| d.to_string()),
min_target: v.min_target.map(|d| d.to_string()),
meet: v.meet,
price: v.price.map(|d| d.to_string()),
timestamp: v.timestamp,
}
}
}
// ── ForecastEps ───────────────────────────────────────────────────
/// EPS forecast response
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct ForecastEps {
/// EPS forecast snapshots
pub items: Vec<ForecastEpsItem>,
}
impl From<lb::ForecastEps> for ForecastEps {
fn from(v: lb::ForecastEps) -> Self {
Self {
items: v.items.into_iter().map(Into::into).collect(),
}
}
}
/// One EPS forecast snapshot
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct ForecastEpsItem {
/// Median EPS estimate
pub forecast_eps_median: Option<String>,
/// Mean EPS estimate
pub forecast_eps_mean: Option<String>,
/// Lowest EPS estimate
pub forecast_eps_lowest: Option<String>,
/// Highest EPS estimate
pub forecast_eps_highest: Option<String>,
/// Total number of forecasting institutions
pub institution_total: i32,
/// Number of institutions that raised their estimate
pub institution_up: i32,
/// Number of institutions that lowered their estimate
pub institution_down: i32,
/// Forecast window start (datetime)
pub forecast_start_date: crate::time::PyOffsetDateTimeWrapper,
/// Forecast window end (datetime)
pub forecast_end_date: crate::time::PyOffsetDateTimeWrapper,
}
impl From<lb::ForecastEpsItem> for ForecastEpsItem {
fn from(v: lb::ForecastEpsItem) -> Self {
Self {
forecast_eps_median: v.forecast_eps_median.map(|d| d.to_string()),
forecast_eps_mean: v.forecast_eps_mean.map(|d| d.to_string()),
forecast_eps_lowest: v.forecast_eps_lowest.map(|d| d.to_string()),
forecast_eps_highest: v.forecast_eps_highest.map(|d| d.to_string()),
institution_total: v.institution_total,
institution_up: v.institution_up,
institution_down: v.institution_down,
forecast_start_date: crate::time::PyOffsetDateTimeWrapper(v.forecast_start_date),
forecast_end_date: crate::time::PyOffsetDateTimeWrapper(v.forecast_end_date),
}
}
}
// ── FinancialConsensus ────────────────────────────────────────────
/// Financial consensus estimates response
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct FinancialConsensus {
/// Per-period consensus reports
pub list: Vec<ConsensusReport>,
/// Index of the most recently released period
pub current_index: i32,
/// Reporting currency
pub currency: String,
/// Available period types
pub opt_periods: Vec<String>,
/// Currently returned period type
pub current_period: String,
}
impl From<lb::FinancialConsensus> for FinancialConsensus {
fn from(v: lb::FinancialConsensus) -> Self {
Self {
list: v.list.into_iter().map(Into::into).collect(),
current_index: v.current_index,
currency: v.currency,
opt_periods: v.opt_periods,
current_period: v.current_period,
}
}
}
/// Consensus report for one fiscal period
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct ConsensusReport {
/// Fiscal year
pub fiscal_year: i32,
/// Fiscal period code
pub fiscal_period: String,
/// Human-readable period label
pub period_text: String,
/// Per-metric consensus details
pub details: Vec<ConsensusDetail>,
}
impl From<lb::ConsensusReport> for ConsensusReport {
fn from(v: lb::ConsensusReport) -> Self {
Self {
fiscal_year: v.fiscal_year,
fiscal_period: v.fiscal_period,
period_text: v.period_text,
details: v.details.into_iter().map(Into::into).collect(),
}
}
}
/// Consensus estimate for one financial metric
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct ConsensusDetail {
/// Metric key, e.g. `"revenue"`
pub key: String,
/// Display name
pub name: String,
/// Metric description
pub description: String,
/// Actual reported value
pub actual: Option<String>,
/// Consensus estimate value
pub estimate: Option<String>,
/// Actual minus estimate
pub comp_value: Option<String>,
/// Beat/miss description
pub comp_desc: String,
/// Comparison result code
pub comp: String,
/// Whether actual results have been published
pub is_released: bool,
}
impl From<lb::ConsensusDetail> for ConsensusDetail {
fn from(v: lb::ConsensusDetail) -> Self {
Self {
key: v.key,
name: v.name,
description: v.description,
actual: v.actual.map(|d| d.to_string()),
estimate: v.estimate.map(|d| d.to_string()),
comp_value: v.comp_value.map(|d| d.to_string()),
comp_desc: v.comp_desc,
comp: v.comp,
is_released: v.is_released,
}
}
}
// ── ValuationData ─────────────────────────────────────────────────
/// Valuation metrics response
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct ValuationData {
/// Valuation metrics (PE / PB / PS / dividend yield)
pub metrics: ValuationMetricsData,
}
impl From<lb::ValuationData> for ValuationData {
fn from(v: lb::ValuationData) -> Self {
Self {
metrics: v.metrics.into(),
}
}
}
/// Container for valuation metrics
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct ValuationMetricsData {
/// Price-to-Earnings ratio history
pub pe: Option<ValuationMetricData>,
/// Price-to-Book ratio history
pub pb: Option<ValuationMetricData>,
/// Price-to-Sales ratio history
pub ps: Option<ValuationMetricData>,
/// Dividend yield history
pub dvd_yld: Option<ValuationMetricData>,
}
impl From<lb::ValuationMetricsData> for ValuationMetricsData {
fn from(v: lb::ValuationMetricsData) -> Self {
Self {
pe: v.pe.map(Into::into),
pb: v.pb.map(Into::into),
ps: v.ps.map(Into::into),
dvd_yld: v.dvd_yld.map(Into::into),
}
}
}
/// Historical time-series for one valuation metric
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct ValuationMetricData {
/// Human-readable description
pub desc: String,
/// Historical high
pub high: Option<String>,
/// Historical low
pub low: Option<String>,
/// Historical median
pub median: Option<String>,
/// Historical data points
pub list: Vec<ValuationPoint>,
}
impl From<lb::ValuationMetricData> for ValuationMetricData {
fn from(v: lb::ValuationMetricData) -> Self {
Self {
desc: v.desc,
high: v.high.map(|d| d.to_string()),
low: v.low.map(|d| d.to_string()),
median: v.median.map(|d| d.to_string()),
list: v.list.into_iter().map(Into::into).collect(),
}
}
}
/// One valuation data point
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct ValuationPoint {
/// Date of the data point (datetime)
pub timestamp: crate::time::PyOffsetDateTimeWrapper,
/// Metric value
pub value: Option<String>,
}
impl From<lb::ValuationPoint> for ValuationPoint {
fn from(v: lb::ValuationPoint) -> Self {
Self {
timestamp: crate::time::PyOffsetDateTimeWrapper(v.timestamp),
value: v.value.map(|d| d.to_string()),
}
}
}
// ── ValuationHistoryResponse ──────────────────────────────────────
/// Historical valuation response
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct ValuationHistoryResponse {
/// Historical valuation data
pub history: ValuationHistoryData,
}
impl From<lb::ValuationHistoryResponse> for ValuationHistoryResponse {
fn from(v: lb::ValuationHistoryResponse) -> Self {
Self {
history: v.history.into(),
}
}
}
/// Historical valuation container
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct ValuationHistoryData {
/// Historical metrics
pub metrics: ValuationHistoryMetrics,
}
impl From<lb::ValuationHistoryData> for ValuationHistoryData {
fn from(v: lb::ValuationHistoryData) -> Self {
Self {
metrics: v.metrics.into(),
}
}
}
/// Historical valuation metrics container
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct ValuationHistoryMetrics {
/// Price-to-Earnings history
pub pe: Option<ValuationHistoryMetric>,
/// Price-to-Book history
pub pb: Option<ValuationHistoryMetric>,
/// Price-to-Sales history
pub ps: Option<ValuationHistoryMetric>,
}
impl From<lb::ValuationHistoryMetrics> for ValuationHistoryMetrics {
fn from(v: lb::ValuationHistoryMetrics) -> Self {
Self {
pe: v.pe.map(Into::into),
pb: v.pb.map(Into::into),
ps: v.ps.map(Into::into),
}
}
}
/// Historical data for one valuation metric
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct ValuationHistoryMetric {
/// Human-readable description
pub desc: String,
/// Historical high over the period
pub high: Option<String>,
/// Historical low over the period
pub low: Option<String>,
/// Historical median over the period
pub median: Option<String>,
/// Historical data points
pub list: Vec<ValuationPoint>,
}
impl From<lb::ValuationHistoryMetric> for ValuationHistoryMetric {
fn from(v: lb::ValuationHistoryMetric) -> Self {
Self {
desc: v.desc,
high: v.high.map(|d| d.to_string()),
low: v.low.map(|d| d.to_string()),
median: v.median.map(|d| d.to_string()),
list: v.list.into_iter().map(Into::into).collect(),
}
}
}
// ── IndustryValuationList ─────────────────────────────────────────
/// Industry peer valuation comparison response
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct IndustryValuationList {
/// List of peer securities
pub list: Vec<IndustryValuationItem>,
}
impl From<lb::IndustryValuationList> for IndustryValuationList {
fn from(v: lb::IndustryValuationList) -> Self {
Self {
list: v.list.into_iter().map(Into::into).collect(),
}
}
}
/// Valuation data for one peer security
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct IndustryValuationItem {
/// Security symbol
pub symbol: String,
/// Company name
pub name: String,
/// Reporting currency
pub currency: String,
/// Total assets
pub assets: Option<String>,
/// Book value per share
pub bps: Option<String>,
/// Earnings per share
pub eps: Option<String>,
/// Dividends per share
pub dps: Option<String>,
/// Dividend yield
pub div_yld: Option<String>,
/// Dividend payout ratio
pub div_payout_ratio: Option<String>,
/// 5-year average dividends per share
pub five_y_avg_dps: Option<String>,
/// Current PE ratio
pub pe: Option<String>,
/// Historical PE/PB/PS snapshots
pub history: Vec<IndustryValuationHistory>,
}
impl From<lb::IndustryValuationItem> for IndustryValuationItem {
fn from(v: lb::IndustryValuationItem) -> Self {
Self {
symbol: v.symbol,
name: v.name,
currency: v.currency,
assets: v.assets.map(|d| d.to_string()),
bps: v.bps.map(|d| d.to_string()),
eps: v.eps.map(|d| d.to_string()),
dps: v.dps.map(|d| d.to_string()),
div_yld: v.div_yld.map(|d| d.to_string()),
div_payout_ratio: v.div_payout_ratio.map(|d| d.to_string()),
five_y_avg_dps: v.five_y_avg_dps.map(|d| d.to_string()),
pe: v.pe.map(|d| d.to_string()),
history: v.history.into_iter().map(Into::into).collect(),
}
}
}
/// Historical valuation snapshot for a peer
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct IndustryValuationHistory {
/// Unix timestamp string
pub date: String,
/// Price-to-Earnings ratio
pub pe: Option<String>,
/// Price-to-Book ratio
pub pb: Option<String>,
/// Price-to-Sales ratio
pub ps: Option<String>,
}
impl From<lb::IndustryValuationHistory> for IndustryValuationHistory {
fn from(v: lb::IndustryValuationHistory) -> Self {
Self {
date: v.date,
pe: v.pe.map(|d| d.to_string()),
pb: v.pb.map(|d| d.to_string()),
ps: v.ps.map(|d| d.to_string()),
}
}
}
// ── IndustryValuationDist ─────────────────────────────────────────
/// Industry valuation distribution response
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct IndustryValuationDist {
/// PE ratio distribution
pub pe: Option<ValuationDist>,
/// PB ratio distribution
pub pb: Option<ValuationDist>,
/// PS ratio distribution
pub ps: Option<ValuationDist>,
}
impl From<lb::IndustryValuationDist> for IndustryValuationDist {
fn from(v: lb::IndustryValuationDist) -> Self {
Self {
pe: v.pe.map(Into::into),
pb: v.pb.map(Into::into),
ps: v.ps.map(Into::into),
}
}
}
/// Distribution statistics for one valuation metric
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct ValuationDist {
/// Minimum value
pub low: Option<String>,
/// Maximum value
pub high: Option<String>,
/// Median value
pub median: Option<String>,
/// Current value of the queried security
pub value: Option<String>,
/// Percentile ranking (0–1)
pub ranking: Option<String>,
/// Ordinal rank index
pub rank_index: String,
/// Total securities in the industry
pub rank_total: String,
}
impl From<lb::ValuationDist> for ValuationDist {
fn from(v: lb::ValuationDist) -> Self {
Self {
low: v.low.map(|d| d.to_string()),
high: v.high.map(|d| d.to_string()),
median: v.median.map(|d| d.to_string()),
value: v.value.map(|d| d.to_string()),
ranking: v.ranking.map(|d| d.to_string()),
rank_index: v.rank_index,
rank_total: v.rank_total,
}
}
}
// ── CompanyOverview ───────────────────────────────────────────────
/// Company overview response
#[pyclass(get_all, skip_from_py_object)]
#[derive(Debug, Clone)]
pub(crate) struct CompanyOverview {
/// Short name
pub name: String,
/// Full legal name
pub company_name: String,
/// Founding date
pub founded: String,
/// Listing date
pub listing_date: String,
/// Primary listing market
pub market: String,
/// Market region code
pub region: String,
/// Registered address
pub address: String,
/// Principal office address
pub office_address: String,
/// Company website
pub website: String,
/// IPO issue price
pub issue_price: Option<String>,
/// Shares offered at IPO
pub shares_offered: String,
/// Chairman name
pub chairman: String,
/// Company secretary
pub secretary: String,
/// Auditing institution
pub audit_inst: String,
/// Company category
pub category: String,
/// Fiscal year end
pub year_end: String,
/// Number of employees
pub employees: String,
/// Phone number
pub phone: String,
/// Fax number
pub fax: String,
/// Email address
pub email: String,
/// Legal representative
pub legal_repr: String,
/// CEO / Managing Director
pub manager: String,
/// Business licence number
pub bus_license: String,
/// Accounting firm
pub accounting_firm: String,
/// Securities representative
pub securities_rep: String,
/// Legal counsel
pub legal_counsel: String,
/// Postal code
pub zip_code: String,
/// Exchange ticker code
pub ticker: String,
/// Logo icon URL
pub icon: String,
/// Business profile
pub profile: String,
/// ADS ratio
pub ads_ratio: String,
/// Industry sector code
pub sector: i32,
}
impl From<lb::CompanyOverview> for CompanyOverview {
fn from(v: lb::CompanyOverview) -> Self {
Self {
name: v.name,
company_name: v.company_name,