futu_cache/static_data/
readiness.rs1#[derive(Debug, Clone, PartialEq, Eq)]
2pub struct StockListSyncStatus {
3 pub first_sync_done: bool,
4 pub started_total: u64,
5 pub finished_total: u64,
6 pub failed_total: u64,
7 pub recoverable_retry_total: u64,
8 pub zero_delta_total: u64,
9 pub converged: bool,
10 pub last_version: u64,
11 pub last_total_stocks: u64,
12 pub last_cached_count: u64,
13 pub last_finished_ms: Option<u64>,
14}
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub enum StaticDataReadiness {
18 Empty,
19 BootstrapOnly,
20 SyncInProgress,
21 RecoverableRetrying,
22 FailedBeforeFirstSync,
23 FirstSyncReady,
24 Converged,
25 ConvergedAfterRecoverableRetry,
26 ConvergedWithFailures,
27}
28
29impl StaticDataReadiness {
30 pub fn as_str(self) -> &'static str {
31 match self {
32 Self::Empty => "empty",
33 Self::BootstrapOnly => "bootstrap_only",
34 Self::SyncInProgress => "sync_in_progress",
35 Self::RecoverableRetrying => "recoverable_retrying",
36 Self::FailedBeforeFirstSync => "failed_before_first_sync",
37 Self::FirstSyncReady => "first_sync_ready",
38 Self::Converged => "converged",
39 Self::ConvergedAfterRecoverableRetry => "converged_after_recoverable_retry",
40 Self::ConvergedWithFailures => "converged_with_failures",
41 }
42 }
43}
44
45impl StockListSyncStatus {
46 pub fn readiness_for_security_count(&self, security_count: usize) -> StaticDataReadiness {
47 if !self.first_sync_done {
48 if self.started_total > self.finished_total {
49 if self.recoverable_retry_total > 0 {
50 return StaticDataReadiness::RecoverableRetrying;
51 }
52 return StaticDataReadiness::SyncInProgress;
53 }
54 if security_count > 0 {
55 return StaticDataReadiness::BootstrapOnly;
56 }
57 if self.failed_total > 0 {
58 return StaticDataReadiness::FailedBeforeFirstSync;
59 }
60 return StaticDataReadiness::Empty;
61 }
62
63 if self.converged {
64 if self.failed_total > 0 {
65 return StaticDataReadiness::ConvergedWithFailures;
66 }
67 if self.recoverable_retry_total > 0 {
68 return StaticDataReadiness::ConvergedAfterRecoverableRetry;
69 }
70 return StaticDataReadiness::Converged;
71 }
72
73 if self.started_total > self.finished_total {
74 if self.recoverable_retry_total > 0 {
75 return StaticDataReadiness::RecoverableRetrying;
76 }
77 return StaticDataReadiness::SyncInProgress;
78 }
79
80 StaticDataReadiness::FirstSyncReady
81 }
82}