deribit_http/model/
tradingview.rs

1/******************************************************************************
2   Author: Joaquín Béjar García
3   Email: jb@taunais.com
4   Date: 15/9/25
5******************************************************************************/
6use pretty_simple_display::{DebugPretty, DisplaySimple};
7use serde::{Deserialize, Serialize};
8
9/// TradingView chart data structure
10#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
11pub struct TradingViewChartData {
12    /// Status of the data
13    pub status: String,
14    /// Array of timestamps
15    pub ticks: Vec<u64>,
16    /// Array of open prices
17    pub open: Vec<f64>,
18    /// Array of high prices
19    pub high: Vec<f64>,
20    /// Array of low prices
21    pub low: Vec<f64>,
22    /// Array of close prices
23    pub close: Vec<f64>,
24    /// Array of volumes
25    pub volume: Vec<f64>,
26    /// Array of costs
27    pub cost: Vec<f64>,
28}
29
30impl TradingViewChartData {
31    /// Create new TradingView chart data
32    pub fn new() -> Self {
33        Self {
34            status: "ok".to_string(),
35            ticks: Vec::new(),
36            open: Vec::new(),
37            high: Vec::new(),
38            low: Vec::new(),
39            close: Vec::new(),
40            volume: Vec::new(),
41            cost: Vec::new(),
42        }
43    }
44
45    /// Add a new candle to the data
46    #[allow(clippy::too_many_arguments)]
47    pub fn add_candle(
48        &mut self,
49        timestamp: u64,
50        open: f64,
51        high: f64,
52        low: f64,
53        close: f64,
54        volume: f64,
55        cost: f64,
56    ) {
57        self.ticks.push(timestamp);
58        self.open.push(open);
59        self.high.push(high);
60        self.low.push(low);
61        self.close.push(close);
62        self.volume.push(volume);
63        self.cost.push(cost);
64    }
65}
66
67impl Default for TradingViewChartData {
68    fn default() -> Self {
69        Self::new()
70    }
71}