1use super::types::{BackgroundType, ButtonVisibility, GridLinesMode, PrecisionMode, WatermarkMode};
4use crate::chart::{PnlUnit, TradingLabelAlignment};
5use crate::model::LineStyle;
6use egui::Color32;
7
8#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
15#[serde(default)]
16pub struct CandleColorConfig {
17 pub color_by_previous_close: bool,
19 pub show_body: bool,
21 pub show_border: bool,
23 pub show_wick: bool,
25 pub body_up: Color32,
27 pub body_down: Color32,
29 pub border_up: Color32,
31 pub border_down: Color32,
33 pub wick_up: Color32,
35 pub wick_down: Color32,
37}
38
39impl CandleColorConfig {
40 pub fn from_theme(theme: &crate::theme::Theme) -> Self {
42 let chart = &theme.chart;
43 Self {
44 color_by_previous_close: false,
45 show_body: true,
46 show_border: false,
47 show_wick: true,
48 body_up: chart.candle_up,
49 body_down: chart.candle_down,
50 border_up: chart.candle_up,
51 border_down: chart.candle_down,
52 wick_up: chart.candle_up,
53 wick_down: chart.candle_down,
54 }
55 }
56}
57
58impl Default for CandleColorConfig {
59 fn default() -> Self {
60 Self::from_theme(&crate::theme::Theme::default())
61 }
62}
63
64#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
66#[serde(default)]
67pub struct StatusLineOptions {
68 pub show_logo: bool,
71 pub show_symbol: bool,
73 pub title_as_description: bool,
75 pub show_market_status: bool,
78 pub show_quote_boxes: bool,
80 pub show_indicator_titles: bool,
82 pub show_indicator_inputs: bool,
84 pub show_indicator_values: bool,
86 pub show_ohlc: bool,
88 pub show_change: bool,
90 pub show_change_percent: bool,
92 pub show_volume: bool,
94 pub show_last_day_change: bool,
96 pub indicator_background_opacity: u8,
98}
99
100impl Default for StatusLineOptions {
101 fn default() -> Self {
102 Self {
103 show_logo: true,
104 show_symbol: true,
105 title_as_description: true,
106 show_market_status: true,
107 show_quote_boxes: true,
108 show_indicator_titles: true,
109 show_indicator_inputs: true,
110 show_indicator_values: true,
111 show_ohlc: true,
112 show_change: true,
113 show_change_percent: true,
114 show_volume: true,
115 show_last_day_change: false,
116 indicator_background_opacity: 60,
117 }
118 }
119}
120
121#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
123pub struct ChartBasicStylesSettings {
124 pub background_type: BackgroundType,
126 pub background_color: Color32,
128 pub background_gradient_top: Color32,
130 pub background_gradient_bottom: Color32,
132}
133
134impl Default for ChartBasicStylesSettings {
135 fn default() -> Self {
136 Self {
137 background_type: BackgroundType::Solid,
138 background_color: Color32::PLACEHOLDER,
139 background_gradient_top: Color32::PLACEHOLDER,
140 background_gradient_bottom: Color32::PLACEHOLDER,
141 }
142 }
143}
144
145#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
147pub struct GridLinesSettings {
148 pub mode: GridLinesMode,
150 pub horizontal_color: Color32,
152 pub vertical_color: Color32,
154}
155
156impl Default for GridLinesSettings {
157 fn default() -> Self {
158 Self {
159 mode: GridLinesMode::Both,
160 horizontal_color: crate::theme::Theme::default().chart.grid_line,
161 vertical_color: crate::theme::Theme::default().chart.grid_line,
162 }
163 }
164}
165
166#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
168pub struct CrosshairSettings {
169 pub color: Color32,
171 pub line_width: f32,
173 pub line_style: LineStyle,
175}
176
177impl Default for CrosshairSettings {
178 fn default() -> Self {
179 Self {
180 color: crate::theme::Theme::default().chart.axis_text_secondary,
181 line_width: 1.0,
182 line_style: LineStyle::Dashed,
183 }
184 }
185}
186
187#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
189pub struct WatermarkSettings {
190 pub mode: WatermarkMode,
192 pub color: Color32,
194}
195
196impl Default for WatermarkSettings {
197 fn default() -> Self {
198 Self {
199 mode: WatermarkMode::ReplayMode,
200 color: crate::theme::Theme::default()
201 .ui
202 .text_muted
203 .gamma_multiply(0.2), }
205 }
206}
207
208#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
210pub struct ScalesAppearanceSettings {
211 pub text_color: Color32,
213 pub font_size: u8,
215 pub lines_color: Color32,
217}
218
219impl Default for ScalesAppearanceSettings {
220 fn default() -> Self {
221 Self {
222 text_color: crate::theme::Theme::default().ui.text_secondary,
223 font_size: 12,
224 lines_color: Color32::TRANSPARENT,
225 }
226 }
227}
228
229#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
231pub struct ButtonsSettings {
232 pub navigation: ButtonVisibility,
234 pub pane: ButtonVisibility,
236}
237
238impl Default for ButtonsSettings {
239 fn default() -> Self {
240 Self {
241 navigation: ButtonVisibility::Hidden,
242 pane: ButtonVisibility::VisibleOnMouseOver,
243 }
244 }
245}
246
247#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
249pub struct MarginsSettings {
250 pub top_percent: f32,
252 pub bottom_percent: f32,
254 pub right_bars: u32,
256}
257
258impl Default for MarginsSettings {
259 fn default() -> Self {
260 Self {
261 top_percent: 10.0,
262 bottom_percent: 8.0,
263 right_bars: 10,
264 }
265 }
266}
267
268#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
270#[serde(default)]
271pub struct ScalesAndLinesSettings {
272 pub show_currency: bool,
274 pub show_unit: bool,
276 pub show_scale_mode_buttons: bool,
278 pub show_plus_button: bool,
280 pub allow_label_overlap: bool,
282 pub lock_price_to_bar_ratio: bool,
284 pub price_to_bar_ratio: f64,
286 pub symbol_price_color: Option<Color32>,
288 pub show_study_values: bool,
290 pub study_value_color: Option<Color32>,
292 pub show_symbol_name: bool,
295 pub show_study_names: bool,
298 pub show_extended_session_price: bool,
300 pub extended_session_price_color: Color32,
302 pub auto_scale: bool,
304 pub log_scale: bool,
306 pub percentage_scale: bool,
308 pub invert_scale: bool,
310 pub price_scale_left: bool,
312 pub show_last_price_label: bool,
314 pub show_prev_close_label: bool,
316 pub show_price_line: bool,
318 pub show_countdown: bool,
320 pub show_bid_ask: bool,
322 pub show_high_low: bool,
324 pub show_prev_close: bool,
326}
327
328impl Default for ScalesAndLinesSettings {
329 fn default() -> Self {
330 Self {
331 show_currency: true,
332 show_unit: true,
333 show_scale_mode_buttons: true,
334 show_plus_button: true,
335 allow_label_overlap: false,
336 lock_price_to_bar_ratio: false,
337 price_to_bar_ratio: 1.0,
338 symbol_price_color: None,
339 show_study_values: true,
340 study_value_color: None,
341 show_symbol_name: false,
342 show_study_names: false,
343 show_extended_session_price: true,
344 extended_session_price_color: Color32::from_rgb(251, 142, 1),
345 auto_scale: true,
346 log_scale: false,
347 percentage_scale: false,
348 invert_scale: false,
349 price_scale_left: false,
350 show_last_price_label: true,
351 show_prev_close_label: false,
352 show_price_line: true,
353 show_countdown: true,
354 show_bid_ask: false,
355 show_high_low: false,
356 show_prev_close: false,
357 }
358 }
359}
360
361#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
366#[serde(default)]
367pub struct TradingSettings {
368 pub instant_orders: bool,
371 pub bid_ask_labels: bool,
373 pub play_execution_sound: bool,
376 pub execution_sound: String,
379 pub execution_sound_volume: f32,
381 pub notifications: TradingNotifications,
383 pub show_positions: bool,
385 pub position_pnl: bool,
387 pub position_pnl_unit: PnlUnit,
389 pub reverse_button: bool,
391 pub extend_lines: bool,
393 pub label_alignment: TradingLabelAlignment,
395 pub include_in_image: bool,
397 pub show_orders: bool,
399 pub bracket_pnl: bool,
401 pub bracket_pnl_unit: PnlUnit,
403 pub show_executions: bool,
405 #[serde(default)]
408 pub show_execution_labels: bool,
409}
410
411impl Default for TradingSettings {
412 fn default() -> Self {
413 Self {
414 instant_orders: false,
415 bid_ask_labels: false,
416 play_execution_sound: false,
417 execution_sound: String::new(),
418 execution_sound_volume: 1.0,
419 notifications: TradingNotifications::All,
420 show_positions: true,
421 position_pnl: true,
422 position_pnl_unit: PnlUnit::Money,
423 reverse_button: true,
424 extend_lines: true,
425 label_alignment: TradingLabelAlignment::Right,
426 include_in_image: false,
427 show_orders: true,
428 bracket_pnl: true,
429 bracket_pnl_unit: PnlUnit::Money,
430 show_executions: true,
431 show_execution_labels: true,
432 }
433 }
434}
435
436#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
438pub enum TradingNotifications {
439 #[default]
441 All,
442 Errors,
444 Off,
446}
447
448impl TradingNotifications {
449 pub const ALL: [Self; 3] = [Self::All, Self::Errors, Self::Off];
451
452 pub fn label(self) -> &'static str {
454 match self {
455 Self::All => "All events",
456 Self::Errors => "Errors only",
457 Self::Off => "Off",
458 }
459 }
460}
461
462#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
464#[serde(default)]
465pub struct AlertsSettings {
466 pub play_sound: bool,
468 pub sound: String,
470 pub sound_volume: f32,
472 pub show_alerts: bool,
474 pub show_alert_labels: bool,
476 pub alert_color: Color32,
478 pub show_active_only: bool,
480 pub notification_seconds: u32,
482}
483
484impl Default for AlertsSettings {
485 fn default() -> Self {
486 Self {
487 play_sound: false,
488 sound: String::new(),
489 sound_volume: 1.0,
490 show_alerts: true,
491 show_alert_labels: true,
492 alert_color: crate::studies::palette::WARM_ORANGE,
493 show_active_only: true,
494 notification_seconds: 5,
495 }
496 }
497}
498
499#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
501#[serde(default)]
502pub struct OrderFlowSettings {
503 pub show_heatmap: bool,
505 pub heatmap: crate::chart::overlays::LiquidityHeatmapConfig,
507 pub show_order_book: bool,
509 pub order_book: crate::chart::overlays::OrderBookView,
511 pub show_volume_bubbles: bool,
513 pub volume_bubbles: crate::chart::overlays::VolumeBubblesConfig,
515}
516
517#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
519pub struct ChartSettingsState {
520 #[serde(default)]
523 pub chart_type: crate::model::ChartType,
524 #[serde(default)]
526 pub chart_type_params: Option<crate::model::ChartTypeParams>,
527 #[serde(default)]
529 pub price_source: Option<crate::model::PriceSource>,
530 pub candle_colors: CandleColorConfig,
532 pub precision: PrecisionMode,
534 pub timezone: String,
536 #[serde(default)]
538 pub show_price_targets: bool,
539 #[serde(default)]
543 pub adjust_for_dividends: bool,
544
545 #[serde(default)]
548 pub order_flow: OrderFlowSettings,
549
550 pub status_line: StatusLineOptions,
553
554 pub scales_and_lines: ScalesAndLinesSettings,
557
558 pub chart_basic_styles: ChartBasicStylesSettings,
561 pub grid_lines: GridLinesSettings,
563 pub crosshair: CrosshairSettings,
565 pub watermark: WatermarkSettings,
567 pub scales_appearance: ScalesAppearanceSettings,
569 pub btns: ButtonsSettings,
571 pub margins: MarginsSettings,
573
574 pub trading: TradingSettings,
577
578 pub alerts: AlertsSettings,
581
582 pub events: crate::model::EventVisibility,
585}
586
587impl Default for ChartSettingsState {
588 fn default() -> Self {
589 let chart_basic_styles = ChartBasicStylesSettings::default();
590 let grid_lines = GridLinesSettings::default();
591
592 Self {
593 chart_type: crate::model::ChartType::default(),
594 chart_type_params: None,
595 price_source: None,
596 candle_colors: CandleColorConfig::default(),
597 precision: PrecisionMode::Default,
598 timezone: "UTC".to_string(),
599 show_price_targets: false,
600 adjust_for_dividends: false,
601
602 order_flow: OrderFlowSettings::default(),
603
604 status_line: StatusLineOptions::default(),
605
606 scales_and_lines: ScalesAndLinesSettings::default(),
607
608 chart_basic_styles: chart_basic_styles.clone(),
609 grid_lines: grid_lines.clone(),
610 crosshair: CrosshairSettings::default(),
611 watermark: WatermarkSettings::default(),
612 scales_appearance: ScalesAppearanceSettings::default(),
613 btns: ButtonsSettings::default(),
614 margins: MarginsSettings::default(),
615
616 trading: TradingSettings::default(),
617
618 alerts: AlertsSettings::default(),
619
620 events: crate::model::EventVisibility::default(),
621 }
622 }
623}