stonktop 0.3.0

A top-like terminal UI for monitoring stock and cryptocurrency prices
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
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
//! Application state and logic.
//!
//! Where we keep track of your hopes, dreams, and unrealized losses.

use crate::api::{expand_symbol, YahooFinanceClient};
use crate::cli::Args;
use crate::config::Config;
use crate::models::{Holding, Quote, SortDirection, SortOrder};
use anyhow::Result;
use crossterm::event::{KeyCode, KeyModifiers};
use std::collections::HashMap;
use std::time::{Duration, Instant};

/// Input mode for interactive commands.
/// Normal is for watching numbers move. AddSymbol is for adding more numbers to watch.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum InputMode {
    #[default]
    Normal,
    AddSymbol,
}

/// Application state.
/// Think of it as your financial life, but with better error handling.
pub struct App {
    /// Current quotes
    pub quotes: Vec<Quote>,
    /// Holdings/portfolio
    pub holdings: HashMap<String, Holding>,
    /// Symbols being watched
    pub symbols: Vec<String>,
    /// API client
    client: YahooFinanceClient,
    /// Last refresh time
    pub last_refresh: Option<Instant>,
    /// Refresh interval
    pub refresh_interval: Duration,
    /// Current sort order
    pub sort_order: SortOrder,
    /// Sort direction
    pub sort_direction: SortDirection,
    /// Current iteration count
    pub iteration: u64,
    /// Maximum iterations (0 = infinite)
    pub max_iterations: u64,
    /// Is the app running
    pub running: bool,
    /// Error message to display
    pub error: Option<String>,
    /// Selected row index
    pub selected: usize,
    /// Scroll offset for when you have more regrets than fit on screen
    pub scroll_offset: usize,
    /// Show help overlay
    pub show_help: bool,
    /// Show holdings view
    pub show_holdings: bool,
    /// Show fundamentals
    pub show_fundamentals: bool,
    /// Batch mode (non-interactive)
    pub batch_mode: bool,
    /// Secure mode (no interactive commands)
    pub secure_mode: bool,
    /// Active group index
    pub active_group: usize,
    /// Group names
    pub groups: Vec<String>,
    /// Verbose mode - for when you want MORE numbers to stress about
    pub verbose: bool,
    /// Color mode preference
    pub color_mode: crate::cli::ColorMode,
    /// Current input mode
    pub input_mode: InputMode,
    /// Input buffer for text entry
    pub input_buffer: String,
    /// Show detail popup for selected quote
    pub show_detail: bool,
}

impl App {
    /// Create a new application from CLI args and config.
    pub fn new(args: &Args, config: &Config) -> Result<Self> {
        let client = YahooFinanceClient::new(args.timeout)?;
        Self::build(args, config, client)
    }

    /// Create a new application with a custom API base URL (for testing).
    #[allow(dead_code)] // Used by e2e and unit tests via lib crate
    pub fn with_base_url(args: &Args, config: &Config, base_url: String) -> Result<Self> {
        let client = YahooFinanceClient::with_base_url(args.timeout, base_url)?;
        Self::build(args, config, client)
    }

    fn build(args: &Args, config: &Config, client: YahooFinanceClient) -> Result<Self> {
        // Merge symbols from args and config
        let mut symbols: Vec<String> = args.symbols.clone().unwrap_or_else(|| config.all_symbols());

        // Expand symbol shortcuts
        symbols = symbols.into_iter().map(|s| expand_symbol(&s)).collect();

        // Remove duplicates while preserving order
        let mut seen = std::collections::HashSet::new();
        symbols.retain(|s| seen.insert(s.clone()));

        // Build holdings map
        let holdings: HashMap<String, Holding> = config
            .get_holdings()
            .into_iter()
            .map(|h| (expand_symbol(&h.symbol), h))
            .collect();

        // Get groups
        let groups: Vec<String> = config.groups.keys().cloned().collect();
        // Enforce minimum refresh interval of 1.0 second
        let delay = if args.delay < 1.0 { 1.0 } else { args.delay };

        Ok(Self {
            quotes: Vec::new(),
            holdings,
            symbols,
            client,
            last_refresh: None,
            refresh_interval: Duration::from_secs_f64(delay),
            sort_order: args.sort.into(),
            sort_direction: if args.reverse {
                SortDirection::Ascending
            } else {
                SortDirection::Descending
            },
            iteration: 0,
            max_iterations: args.iterations,
            running: true,
            error: None,
            selected: 0,
            scroll_offset: 0,
            show_help: false,
            show_holdings: args.holdings || config.display.show_holdings,
            show_fundamentals: config.display.show_fundamentals,
            batch_mode: args.batch,
            secure_mode: args.secure,
            active_group: 0,
            groups,
            verbose: args.verbose,
            color_mode: args.color,
            input_mode: InputMode::Normal,
            input_buffer: String::new(),
            show_detail: false,
        })
    }

    /// Check if refresh is needed.
    pub fn needs_refresh(&self) -> bool {
        match self.last_refresh {
            None => true,
            Some(last) => last.elapsed() >= self.refresh_interval,
        }
    }

    /// Refresh quotes from API.
    pub async fn refresh(&mut self) -> Result<()> {
        if self.symbols.is_empty() {
            return Ok(());
        }

        match self.client.get_quotes(&self.symbols).await {
            Ok(quotes) => {
                self.quotes = quotes;
                self.sort_quotes();
                self.last_refresh = Some(Instant::now());
                self.iteration += 1;
                self.error = None;
            }
            Err(e) => {
                self.error = Some(format!("API Error: {}", e));
            }
        }

        Ok(())
    }

    /// Sort quotes according to current sort settings.
    pub fn sort_quotes(&mut self) {
        let direction = self.sort_direction;

        self.quotes.sort_by(|a, b| {
            let cmp = match self.sort_order {
                SortOrder::Symbol => a.symbol.cmp(&b.symbol),
                SortOrder::Name => a.name.cmp(&b.name),
                SortOrder::Price => a
                    .price
                    .partial_cmp(&b.price)
                    .unwrap_or(std::cmp::Ordering::Equal),
                SortOrder::Change => a
                    .change
                    .partial_cmp(&b.change)
                    .unwrap_or(std::cmp::Ordering::Equal),
                SortOrder::ChangePercent => a
                    .change_percent
                    .partial_cmp(&b.change_percent)
                    .unwrap_or(std::cmp::Ordering::Equal),
                SortOrder::Volume => a.volume.cmp(&b.volume),
                SortOrder::MarketCap => a.market_cap.cmp(&b.market_cap),
            };

            match direction {
                SortDirection::Ascending => cmp,
                SortDirection::Descending => cmp.reverse(),
            }
        });
    }

    /// Toggle sort direction.
    pub fn toggle_sort_direction(&mut self) {
        self.sort_direction = self.sort_direction.toggle();
        self.sort_quotes();
    }

    /// Cycle to next sort order.
    pub fn next_sort_order(&mut self) {
        self.sort_order = self.sort_order.next();
        self.sort_quotes();
    }

    /// Set specific sort order.
    pub fn set_sort_order(&mut self, order: SortOrder) {
        if self.sort_order == order {
            self.toggle_sort_direction();
        } else {
            self.sort_order = order;
            self.sort_direction = SortDirection::Descending;
        }
        self.sort_quotes();
    }

    /// Move selection up.
    pub fn select_up(&mut self) {
        if self.selected > 0 {
            self.selected -= 1;
            if self.selected < self.scroll_offset {
                self.scroll_offset = self.selected;
            }
        }
    }

    /// Move selection down.
    pub fn select_down(&mut self) {
        if self.selected < self.quotes.len().saturating_sub(1) {
            self.selected += 1;
        }
    }

    /// Move selection to top.
    pub fn select_top(&mut self) {
        self.selected = 0;
        self.scroll_offset = 0;
    }

    /// Move selection to bottom.
    pub fn select_bottom(&mut self) {
        self.selected = self.quotes.len().saturating_sub(1);
    }

    /// Toggle help display.
    pub fn toggle_help(&mut self) {
        if !self.secure_mode {
            self.show_help = !self.show_help;
        }
    }

    /// Toggle holdings view.
    pub fn toggle_holdings(&mut self) {
        if !self.secure_mode {
            self.show_holdings = !self.show_holdings;
        }
    }

    /// Toggle fundamentals display.
    pub fn toggle_fundamentals(&mut self) {
        if !self.secure_mode {
            self.show_fundamentals = !self.show_fundamentals;
        }
    }

    /// Toggle detail view for the selected quote.
    pub fn toggle_detail(&mut self) {
        if !self.secure_mode {
            self.show_detail = !self.show_detail;
        }
    }

    /// Quit the application.
    pub fn quit(&mut self) {
        self.running = false;
    }

    /// Check if max iterations reached.
    pub fn should_quit(&self) -> bool {
        !self.running || (self.max_iterations > 0 && self.iteration >= self.max_iterations)
    }

    /// Get total portfolio value.
    pub fn total_portfolio_value(&self) -> f64 {
        self.quotes
            .iter()
            .filter_map(|q| {
                self.holdings
                    .get(&q.symbol)
                    .map(|h| h.current_value(q.price))
            })
            .sum()
    }

    /// Get total portfolio cost.
    pub fn total_portfolio_cost(&self) -> f64 {
        self.holdings.values().map(|h| h.total_cost()).sum()
    }

    /// Get total portfolio profit/loss.
    pub fn total_portfolio_pnl(&self) -> f64 {
        self.total_portfolio_value() - self.total_portfolio_cost()
    }

    /// Get today's portfolio change.
    pub fn today_portfolio_change(&self) -> f64 {
        self.quotes
            .iter()
            .filter_map(|q| self.holdings.get(&q.symbol).map(|h| h.quantity * q.change))
            .sum()
    }

    /// Add a symbol to watch.
    /// For when FOMO hits and you need to track one more meme stock.
    pub fn add_symbol(&mut self, symbol: &str) {
        let expanded = expand_symbol(symbol);
        if !self.symbols.contains(&expanded) {
            self.symbols.push(expanded);
        }
    }

    /// Remove a symbol from watch.
    /// Denial is the first stage of grief. Removing it from your watchlist is the second.
    pub fn remove_symbol(&mut self, symbol: &str) {
        let expanded = expand_symbol(symbol);
        self.symbols.retain(|s| s != &expanded);
        self.quotes.retain(|q| q.symbol != expanded);
        if self.selected >= self.quotes.len() {
            self.selected = self.quotes.len().saturating_sub(1);
        }
    }

    /// Get the currently selected quote.
    /// Returns the quote you're currently staring at in disbelief.
    pub fn selected_quote(&self) -> Option<&Quote> {
        self.quotes.get(self.selected)
    }

    /// Get time since last refresh as human readable string.
    pub fn time_since_refresh(&self) -> String {
        match self.last_refresh {
            Some(t) => {
                let elapsed = t.elapsed().as_secs();
                if elapsed < 60 {
                    format!("{}s ago", elapsed)
                } else {
                    format!("{}m ago", elapsed / 60)
                }
            }
            None => "never".to_string(),
        }
    }

    /// Handle keyboard input.
    pub fn handle_key_event(&mut self, code: KeyCode, modifiers: KeyModifiers) {
        // Close detail view on any key
        if self.show_detail {
            self.show_detail = false;
            return;
        }

        // Handle symbol input mode
        if self.input_mode == InputMode::AddSymbol {
            match code {
                KeyCode::Enter => {
                    if !self.input_buffer.is_empty() {
                        let symbol = self.input_buffer.drain(..).collect::<String>();
                        self.add_symbol(&symbol.to_uppercase());
                        self.last_refresh = None; // trigger refresh
                    }
                    self.input_mode = InputMode::Normal;
                }
                KeyCode::Esc => {
                    self.input_buffer.clear();
                    self.input_mode = InputMode::Normal;
                }
                KeyCode::Backspace => {
                    self.input_buffer.pop();
                }
                KeyCode::Char(c) => {
                    self.input_buffer.push(c);
                }
                _ => {}
            }
            return;
        }

        // Close help overlay on any key
        if self.show_help {
            self.show_help = false;
            return;
        }

        // Clear error on any key
        if self.error.is_some() {
            self.error = None;
            return;
        }

        match code {
            // Quit
            KeyCode::Char('q') | KeyCode::Esc => self.quit(),
            KeyCode::Char('c') if modifiers.contains(KeyModifiers::CONTROL) => self.quit(),

            // Navigation
            KeyCode::Up | KeyCode::Char('k') => self.select_up(),
            KeyCode::Down | KeyCode::Char('j') => self.select_down(),
            KeyCode::Home | KeyCode::Char('g') => self.select_top(),
            KeyCode::End | KeyCode::Char('G') => self.select_bottom(),
            KeyCode::PageUp => {
                for _ in 0..10 {
                    self.select_up();
                }
            }
            KeyCode::PageDown => {
                for _ in 0..10 {
                    self.select_down();
                }
            }

            // Sorting
            KeyCode::Char('s') => self.next_sort_order(),
            KeyCode::Char('r') => self.toggle_sort_direction(),
            KeyCode::Char('1') => self.set_sort_order(SortOrder::Symbol),
            KeyCode::Char('2') => self.set_sort_order(SortOrder::Name),
            KeyCode::Char('3') => self.set_sort_order(SortOrder::Price),
            KeyCode::Char('4') => self.set_sort_order(SortOrder::Change),
            KeyCode::Char('5') => self.set_sort_order(SortOrder::ChangePercent),
            KeyCode::Char('6') => self.set_sort_order(SortOrder::Volume),
            KeyCode::Char('7') => self.set_sort_order(SortOrder::MarketCap),

            // Display toggles
            KeyCode::Char('H') => self.toggle_holdings(),
            KeyCode::Char('f') => self.toggle_fundamentals(),
            KeyCode::Char('h') | KeyCode::Char('?') => self.toggle_help(),

            // Symbol management
            KeyCode::Char('a') => {
                self.input_mode = InputMode::AddSymbol;
                self.input_buffer.clear();
            }
            KeyCode::Char('d') => {
                if let Some(quote) = self.selected_quote() {
                    let symbol = quote.symbol.clone();
                    self.remove_symbol(&symbol);
                }
            }

            // Detail view
            KeyCode::Enter => self.toggle_detail(),

            // Refresh
            KeyCode::Char(' ') | KeyCode::Char('R') => {
                self.last_refresh = None; // Force refresh on next tick
            }

            // Groups
            KeyCode::Tab => {
                if !self.groups.is_empty() {
                    self.active_group = (self.active_group + 1) % self.groups.len();
                }
            }

            _ => {}
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::cli::Args;
    use crate::config::Config;
    use crate::models::{Quote, SortOrder};
    use clap::Parser;
    use crossterm::event::{KeyCode, KeyModifiers};

    fn test_app() -> App {
        let args = Args::parse_from(["stonktop", "-s", "AAPL,GOOGL", "-b", "-n", "1"]);
        let config = Config::default();
        let mut app = App::with_base_url(&args, &config, "http://127.0.0.1:1".to_string()).unwrap();
        // Seed with test quotes so navigation has something to work with
        app.quotes = vec![
            Quote {
                symbol: "AAPL".into(),
                name: "Apple".into(),
                price: 195.0,
                change: 3.0,
                change_percent: 1.5,
                ..Quote::default()
            },
            Quote {
                symbol: "GOOGL".into(),
                name: "Alphabet".into(),
                price: 140.0,
                change: -2.0,
                change_percent: -1.4,
                ..Quote::default()
            },
        ];
        app
    }

    #[test]
    fn test_quit_q() {
        let mut app = test_app();
        app.handle_key_event(KeyCode::Char('q'), KeyModifiers::NONE);
        assert!(!app.running);
    }

    #[test]
    fn test_quit_ctrl_c() {
        let mut app = test_app();
        app.handle_key_event(KeyCode::Char('c'), KeyModifiers::CONTROL);
        assert!(!app.running);
    }

    #[test]
    fn test_navigation_j_k() {
        let mut app = test_app();
        assert_eq!(app.selected, 0);
        app.handle_key_event(KeyCode::Char('j'), KeyModifiers::NONE);
        assert_eq!(app.selected, 1);
        app.handle_key_event(KeyCode::Char('k'), KeyModifiers::NONE);
        assert_eq!(app.selected, 0);
    }

    #[test]
    fn test_navigation_g_and_big_g() {
        let mut app = test_app();
        app.handle_key_event(KeyCode::Char('G'), KeyModifiers::NONE);
        assert_eq!(app.selected, 1); // last
        app.handle_key_event(KeyCode::Char('g'), KeyModifiers::NONE);
        assert_eq!(app.selected, 0); // first
    }

    #[test]
    fn test_sort_cycle() {
        let mut app = test_app();
        let initial = app.sort_order;
        app.handle_key_event(KeyCode::Char('s'), KeyModifiers::NONE);
        assert_ne!(app.sort_order, initial);
    }

    #[test]
    fn test_sort_reverse() {
        let mut app = test_app();
        let initial = app.sort_direction;
        app.handle_key_event(KeyCode::Char('r'), KeyModifiers::NONE);
        assert_ne!(app.sort_direction, initial);
    }

    #[test]
    fn test_sort_number_keys() {
        let mut app = test_app();
        app.handle_key_event(KeyCode::Char('3'), KeyModifiers::NONE);
        assert_eq!(app.sort_order, SortOrder::Price);
        app.handle_key_event(KeyCode::Char('1'), KeyModifiers::NONE);
        assert_eq!(app.sort_order, SortOrder::Symbol);
    }

    #[test]
    fn test_toggle_holdings() {
        let mut app = test_app();
        assert!(!app.show_holdings);
        app.handle_key_event(KeyCode::Char('H'), KeyModifiers::NONE);
        assert!(app.show_holdings);
    }

    #[test]
    fn test_toggle_help() {
        let mut app = test_app();
        assert!(!app.show_help);
        app.handle_key_event(KeyCode::Char('h'), KeyModifiers::NONE);
        assert!(app.show_help);
    }

    #[test]
    fn test_help_dismissal() {
        let mut app = test_app();
        app.show_help = true;
        app.handle_key_event(KeyCode::Char('x'), KeyModifiers::NONE); // any key
        assert!(!app.show_help);
    }

    #[test]
    fn test_error_dismissal() {
        let mut app = test_app();
        app.error = Some("test error".to_string());
        app.handle_key_event(KeyCode::Char('x'), KeyModifiers::NONE);
        assert!(app.error.is_none());
    }

    #[test]
    fn test_detail_toggle() {
        let mut app = test_app();
        assert!(!app.show_detail);
        app.handle_key_event(KeyCode::Enter, KeyModifiers::NONE);
        assert!(app.show_detail);
        // Any key dismisses
        app.handle_key_event(KeyCode::Char('x'), KeyModifiers::NONE);
        assert!(!app.show_detail);
    }

    #[test]
    fn test_add_symbol_mode() {
        let mut app = test_app();
        app.handle_key_event(KeyCode::Char('a'), KeyModifiers::NONE);
        assert_eq!(app.input_mode, InputMode::AddSymbol);

        // Type "MSFT"
        app.handle_key_event(KeyCode::Char('m'), KeyModifiers::NONE);
        app.handle_key_event(KeyCode::Char('s'), KeyModifiers::NONE);
        app.handle_key_event(KeyCode::Char('f'), KeyModifiers::NONE);
        app.handle_key_event(KeyCode::Char('t'), KeyModifiers::NONE);
        assert_eq!(app.input_buffer, "msft");

        // Enter confirms
        app.handle_key_event(KeyCode::Enter, KeyModifiers::NONE);
        assert_eq!(app.input_mode, InputMode::Normal);
        assert!(app.symbols.contains(&"MSFT".to_string()));
    }

    #[test]
    fn test_add_symbol_cancel() {
        let mut app = test_app();
        app.handle_key_event(KeyCode::Char('a'), KeyModifiers::NONE);
        app.handle_key_event(KeyCode::Char('x'), KeyModifiers::NONE);
        app.handle_key_event(KeyCode::Esc, KeyModifiers::NONE);
        assert_eq!(app.input_mode, InputMode::Normal);
        assert!(app.input_buffer.is_empty());
    }

    #[test]
    fn test_remove_symbol() {
        let mut app = test_app();
        assert_eq!(app.selected, 0);
        let initial_count = app.quotes.len();
        app.handle_key_event(KeyCode::Char('d'), KeyModifiers::NONE);
        assert_eq!(app.quotes.len(), initial_count - 1);
    }

    // --- Navigation edge cases ---

    #[test]
    fn test_select_up_at_zero() {
        let mut app = test_app();
        app.selected = 0;
        app.select_up();
        assert_eq!(app.selected, 0);
    }

    #[test]
    fn test_select_down_at_end() {
        let mut app = test_app();
        app.selected = app.quotes.len() - 1;
        app.select_down();
        assert_eq!(app.selected, app.quotes.len() - 1);
    }

    #[test]
    fn test_select_top_bottom_empty() {
        let mut app = test_app();
        app.quotes.clear();
        app.select_top();
        assert_eq!(app.selected, 0);
        app.select_bottom();
        assert_eq!(app.selected, 0);
    }

    #[test]
    fn test_scroll_offset_updates() {
        let mut app = test_app();
        app.scroll_offset = 1;
        app.selected = 1;
        app.select_up(); // selected=0, should update scroll_offset
        assert_eq!(app.scroll_offset, 0);
    }

    // --- Portfolio math edge cases ---

    #[test]
    fn test_portfolio_zero_holdings() {
        let mut app = test_app();
        app.holdings.clear();
        assert_eq!(app.total_portfolio_value(), 0.0);
        assert_eq!(app.total_portfolio_cost(), 0.0);
        assert_eq!(app.total_portfolio_pnl(), 0.0);
        assert_eq!(app.today_portfolio_change(), 0.0);
    }
}