use serde_json::Value;
use std::fmt;
use utils::f64_from_string;
use uuid::Uuid;
use super::DateTime;
use utils::datetime_from_string;
use utils::usize_from_string;
#[derive(Serialize, Deserialize, Debug)]
pub struct Account {
pub id: Uuid,
pub currency: String,
#[serde(deserialize_with = "f64_from_string")]
pub balance: f64,
#[serde(deserialize_with = "f64_from_string")]
pub available: f64,
#[serde(deserialize_with = "f64_from_string")]
pub hold: f64,
pub profile_id: Uuid,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct AccountHistory {
pub id: usize,
pub created_at: DateTime,
#[serde(deserialize_with = "f64_from_string")]
pub amount: f64,
#[serde(deserialize_with = "f64_from_string")]
pub balance: f64,
#[serde(skip_deserializing)]
pub _type: AccountHistoryType,
#[serde(flatten)]
pub details: AccountHistoryDetails, }
#[derive(Serialize, Deserialize, Debug)]
pub enum AccountHistoryType {
Fee,
Match,
Rebate,
Transfer,
NotSet,
}
impl Default for AccountHistoryType {
fn default() -> Self {
AccountHistoryType::NotSet
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "type", content = "details")]
#[serde(rename_all = "camelCase")]
pub enum AccountHistoryDetails {
Fee {
order_id: Uuid,
product_id: String,
#[serde(deserialize_with = "usize_from_string")]
trade_id: usize,
},
Match {
order_id: Uuid,
product_id: String,
#[serde(deserialize_with = "usize_from_string")]
trade_id: usize,
},
Rebate {
order_id: Uuid,
product_id: String,
#[serde(deserialize_with = "usize_from_string")]
trade_id: usize,
},
Transfer {
transfer_id: Uuid,
transfer_type: AccountHistoryDetailsTransferType,
},
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub enum AccountHistoryDetailsTransferType {
Deposit,
Withdraw,
}
impl<'a> From<&'a AccountHistoryDetails> for AccountHistoryType {
fn from(item: &'a AccountHistoryDetails) -> Self {
match item {
AccountHistoryDetails::Fee { .. } => AccountHistoryType::Fee,
AccountHistoryDetails::Match { .. } => AccountHistoryType::Match,
AccountHistoryDetails::Transfer { .. } => AccountHistoryType::Transfer,
AccountHistoryDetails::Rebate { .. } => AccountHistoryType::Rebate,
}
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct AccountHolds {
pub id: Uuid,
pub account_id: Uuid,
pub created_at: DateTime,
pub updated_at: DateTime,
pub amount: f64,
#[serde(rename = "type")]
pub _type: AccountHoldsType,
#[serde(rename = "ref")]
pub _ref: Uuid,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub enum AccountHoldsType {
Order,
Transfer,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Order {
pub id: Uuid,
#[serde(deserialize_with = "f64_from_string")]
pub size: f64,
pub product_id: String,
pub side: super::reqs::OrderSide,
pub stp: Option<String>, #[serde(flatten)]
pub _type: OrderType,
pub post_only: bool,
pub created_at: DateTime,
#[serde(deserialize_with = "f64_from_string")]
pub fill_fees: f64,
#[serde(deserialize_with = "f64_from_string")]
pub filled_size: f64,
#[serde(deserialize_with = "f64_from_string")]
pub executed_value: f64,
pub status: OrderStatus,
pub settled: bool,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
#[serde(tag = "type")]
pub enum OrderType {
Limit {
#[serde(deserialize_with = "f64_from_string")]
price: f64,
#[serde(flatten)]
time_in_force: OrderTimeInForce,
},
Market {
#[serde(default)]
#[serde(deserialize_with = "f64_from_string")]
funds: f64,
},
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "time_in_force")]
pub enum OrderTimeInForce {
GTC,
GTT {
#[serde(deserialize_with = "datetime_from_string")]
expire_time: DateTime,
},
IOC,
FOK,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub enum OrderStatus {
Open,
Done,
Pending,
Active,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Fill {
pub trade_id: usize,
pub product_id: String,
#[serde(deserialize_with = "f64_from_string")]
pub price: f64,
#[serde(deserialize_with = "f64_from_string")]
pub size: f64,
pub order_id: Uuid,
pub created_at: DateTime,
pub liquidity: FillLiquidity,
#[serde(deserialize_with = "f64_from_string")]
pub fee: f64,
pub settled: bool,
pub side: super::reqs::OrderSide,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum FillLiquidity {
M,
T,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct TrailingVolume {
pub product_id: String,
#[serde(deserialize_with = "f64_from_string")]
pub exchange_volume: f64,
#[serde(deserialize_with = "f64_from_string")]
pub volume: f64,
pub recorded_at: DateTime,
}