use std::fmt;
use chrono::{DateTime, Utc};
use serde::Deserialize;
use uuid::Uuid;
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct CrossFunding {
time: DateTime<Utc>,
settlement_id: Uuid,
fee: i64,
}
impl CrossFunding {
pub fn time(&self) -> DateTime<Utc> {
self.time
}
pub fn settlement_id(&self) -> Uuid {
self.settlement_id
}
pub fn fee(&self) -> i64 {
self.fee
}
pub fn as_data_str(&self) -> String {
format!(
"time: {}\nsettlement_id: {}\nfee: {}",
self.time.to_rfc3339(),
self.settlement_id,
self.fee
)
}
}
impl fmt::Display for CrossFunding {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Cross Funding:")?;
for line in self.as_data_str().lines() {
write!(f, "\n {line}")?;
}
Ok(())
}
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IsolatedFunding {
time: DateTime<Utc>,
settlement_id: Uuid,
trade_id: Uuid,
fee: i64,
}
impl IsolatedFunding {
pub fn time(&self) -> DateTime<Utc> {
self.time
}
pub fn settlement_id(&self) -> Uuid {
self.settlement_id
}
pub fn trade_id(&self) -> Uuid {
self.trade_id
}
pub fn fee(&self) -> i64 {
self.fee
}
pub fn as_data_str(&self) -> String {
format!(
"time: {}\nsettlement_id: {}\ntrade_id: {}\nfee: {}",
self.time.to_rfc3339(),
self.settlement_id,
self.trade_id,
self.fee
)
}
}
impl fmt::Display for IsolatedFunding {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Isolated Funding:")?;
for line in self.as_data_str().lines() {
write!(f, "\n {line}")?;
}
Ok(())
}
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct FundingSettlement {
id: Uuid,
time: DateTime<Utc>,
fixing_price: f64,
funding_rate: f64,
}
impl FundingSettlement {
pub fn id(&self) -> Uuid {
self.id
}
pub fn time(&self) -> DateTime<Utc> {
self.time
}
pub fn fixing_price(&self) -> f64 {
self.fixing_price
}
pub fn funding_rate(&self) -> f64 {
self.funding_rate
}
pub fn as_data_str(&self) -> String {
format!(
"id: {}\ntime: {}\nfixing_price: {}\nfunding_rate: {:.6}",
self.id,
self.time.to_rfc3339(),
self.fixing_price,
self.funding_rate
)
}
}
impl fmt::Display for FundingSettlement {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Funding Settlement:")?;
for line in self.as_data_str().lines() {
write!(f, "\n {line}")?;
}
Ok(())
}
}