deribit_http/model/
funding.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/// Funding chart data structure
10#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
11pub struct FundingChartData {
12    /// Current interest rate
13    pub current_interest: f64,
14    /// 8h interest rate
15    pub interest_8h: f64,
16    /// Historical funding data points
17    pub data: Vec<FundingDataPoint>,
18}
19
20impl FundingChartData {
21    /// Create new funding chart data
22    pub fn new() -> Self {
23        Self {
24            current_interest: 0.0,
25            interest_8h: 0.0,
26            data: Vec::new(),
27        }
28    }
29}
30
31impl Default for FundingChartData {
32    fn default() -> Self {
33        Self::new()
34    }
35}
36
37/// Funding data point structure
38#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
39pub struct FundingDataPoint {
40    /// Index price at the time
41    pub index_price: f64,
42    /// 8h interest rate
43    pub interest_8h: f64,
44    /// Timestamp of the data point
45    pub timestamp: u64,
46}
47
48impl FundingDataPoint {
49    /// Create new funding data point
50    pub fn new(index_price: f64, interest_8h: f64, timestamp: u64) -> Self {
51        Self {
52            index_price,
53            interest_8h,
54            timestamp,
55        }
56    }
57}
58
59/// Funding rate data structure for historical funding rates
60#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
61pub struct FundingRateData {
62    /// Timestamp of the funding event
63    pub timestamp: u64,
64    /// Index price at the time
65    pub index_price: f64,
66    /// 8h interest rate
67    pub interest_8h: f64,
68    /// 1h interest rate
69    pub interest_1h: f64,
70    /// Previous index price
71    pub prev_index_price: f64,
72}
73
74impl FundingRateData {
75    /// Create new funding rate data
76    pub fn new(
77        timestamp: u64,
78        index_price: f64,
79        interest_8h: f64,
80        interest_1h: f64,
81        prev_index_price: f64,
82    ) -> Self {
83        Self {
84            timestamp,
85            index_price,
86            interest_8h,
87            interest_1h,
88            prev_index_price,
89        }
90    }
91}