use pretty_simple_display::{DebugPretty, DisplaySimple};
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use std::collections::HashMap;
#[skip_serializing_none]
#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
pub struct ApiError {
pub code: i32,
pub message: String,
pub data: Option<serde_json::Value>,
}
#[skip_serializing_none]
#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
pub struct AuthToken {
pub access_token: String,
pub token_type: String,
pub expires_in: u64,
pub refresh_token: Option<String>,
pub scope: String,
}
#[derive(DebugPretty, DisplaySimple, Clone, Default, Serialize, Deserialize)]
pub struct RequestParams {
params: HashMap<String, serde_json::Value>,
}
impl RequestParams {
pub fn new() -> Self {
Self::default()
}
pub fn add<T: Serialize>(mut self, key: &str, value: T) -> Self {
if let Ok(json_value) = serde_json::to_value(value) {
self.params.insert(key.to_string(), json_value);
}
self
}
pub fn to_json(&self) -> serde_json::Value {
serde_json::to_value(&self.params).unwrap_or(serde_json::Value::Null)
}
pub fn is_empty(&self) -> bool {
self.params.is_empty()
}
}
#[derive(DebugPretty, DisplaySimple, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum TimeInForce {
#[serde(rename = "good_til_cancelled")]
GoodTilCancelled,
#[serde(rename = "good_til_day")]
GoodTilDay,
#[serde(rename = "fill_or_kill")]
FillOrKill,
#[serde(rename = "immediate_or_cancel")]
ImmediateOrCancel,
}
impl TimeInForce {
pub fn as_str(&self) -> &'static str {
match self {
TimeInForce::GoodTilCancelled => "good_til_cancelled",
TimeInForce::GoodTilDay => "good_til_day",
TimeInForce::FillOrKill => "fill_or_kill",
TimeInForce::ImmediateOrCancel => "immediate_or_cancel",
}
}
}
#[skip_serializing_none]
#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
pub struct Withdrawal {
pub address: String,
pub amount: f64,
pub currency: String,
pub fee: f64,
pub id: u64,
pub priority: String,
pub state: String,
pub created_timestamp: u64,
pub updated_timestamp: Option<u64>,
pub transaction_id: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
#[non_exhaustive]
pub enum Direction {
Buy,
Sell,
#[default]
#[serde(other)]
Unknown,
}