use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use super::string_or_float;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SystemStatus {
pub status: u32,
pub msg: String,
}
impl SystemStatus {
pub fn is_normal(&self) -> bool {
self.status == 0
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CoinNetwork {
#[serde(default)]
pub address_regex: Option<String>,
pub coin: String,
#[serde(default)]
pub deposit_desc: Option<String>,
pub deposit_enable: bool,
pub is_default: bool,
#[serde(default)]
pub memo_regex: Option<String>,
pub min_confirm: u32,
pub name: String,
pub network: String,
#[serde(default)]
pub special_tips: Option<String>,
#[serde(default)]
pub un_lock_confirm: Option<u32>,
#[serde(default)]
pub withdraw_desc: Option<String>,
pub withdraw_enable: bool,
#[serde(with = "string_or_float")]
pub withdraw_fee: f64,
#[serde(default, with = "string_or_float_option")]
pub withdraw_integer_multiple: Option<f64>,
#[serde(with = "string_or_float")]
pub withdraw_max: f64,
#[serde(with = "string_or_float")]
pub withdraw_min: f64,
#[serde(default)]
pub same_address: Option<bool>,
#[serde(default)]
pub estimated_arrival_time: Option<u64>,
#[serde(default)]
pub busy: Option<bool>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CoinInfo {
pub coin: String,
pub deposit_all_enable: bool,
#[serde(with = "string_or_float")]
pub free: f64,
#[serde(with = "string_or_float")]
pub freeze: f64,
#[serde(with = "string_or_float")]
pub ipoable: f64,
#[serde(with = "string_or_float")]
pub ipoing: f64,
pub is_legal_money: bool,
#[serde(with = "string_or_float")]
pub locked: f64,
pub name: String,
pub network_list: Vec<CoinNetwork>,
#[serde(with = "string_or_float")]
pub storage: f64,
pub trading: bool,
pub withdraw_all_enable: bool,
#[serde(with = "string_or_float")]
pub withdrawing: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DepositAddress {
pub address: String,
pub coin: String,
pub tag: String,
#[serde(default)]
pub url: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DepositRecord {
#[serde(with = "string_or_float")]
pub amount: f64,
pub coin: String,
pub network: String,
pub status: DepositStatus,
pub address: String,
#[serde(default)]
pub address_tag: Option<String>,
pub tx_id: String,
pub insert_time: u64,
#[serde(default)]
pub transfer_type: Option<u32>,
#[serde(default)]
pub confirm_times: Option<String>,
#[serde(default)]
pub unlock_confirm: Option<u32>,
#[serde(default)]
pub id: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize_repr, Deserialize_repr)]
#[repr(u8)]
pub enum DepositStatus {
Pending = 0,
Success = 1,
CreditedCannotWithdraw = 6,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WithdrawRecord {
pub address: String,
#[serde(with = "string_or_float")]
pub amount: f64,
pub apply_time: String,
pub coin: String,
pub id: String,
#[serde(default)]
pub withdraw_order_id: Option<String>,
pub network: String,
#[serde(default)]
pub transfer_type: Option<u32>,
pub status: WithdrawStatus,
#[serde(with = "string_or_float")]
pub transaction_fee: f64,
#[serde(default)]
pub confirm_no: Option<u32>,
#[serde(default)]
pub info: Option<String>,
#[serde(default)]
pub tx_id: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize_repr, Deserialize_repr)]
#[repr(u8)]
pub enum WithdrawStatus {
EmailSent = 0,
Cancelled = 1,
AwaitingApproval = 2,
Rejected = 3,
Processing = 4,
Failure = 5,
Completed = 6,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WithdrawResponse {
pub id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AssetDetail {
#[serde(with = "string_or_float")]
pub min_withdraw_amount: f64,
pub deposit_status: bool,
#[serde(with = "string_or_float")]
pub withdraw_fee: f64,
pub withdraw_status: bool,
#[serde(default)]
pub deposit_tip: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TradeFee {
pub symbol: String,
#[serde(with = "string_or_float")]
pub maker_commission: f64,
#[serde(with = "string_or_float")]
pub taker_commission: f64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum UniversalTransferType {
MainUmfuture,
MainCmfuture,
MainMargin,
UmfutureMain,
UmfutureMargin,
CmfutureMain,
CmfutureMargin,
MarginMain,
MarginUmfuture,
MarginCmfuture,
MainIsolatedMargin,
IsolatedMarginMain,
IsolatedMarginIsolatedMargin,
MainFunding,
FundingMain,
FundingUmfuture,
UmfutureFunding,
MarginFunding,
FundingMargin,
FundingCmfuture,
CmfutureFunding,
}
impl UniversalTransferType {
pub fn as_str(self) -> &'static str {
match self {
Self::MainUmfuture => "MAIN_UMFUTURE",
Self::MainCmfuture => "MAIN_CMFUTURE",
Self::MainMargin => "MAIN_MARGIN",
Self::UmfutureMain => "UMFUTURE_MAIN",
Self::UmfutureMargin => "UMFUTURE_MARGIN",
Self::CmfutureMain => "CMFUTURE_MAIN",
Self::CmfutureMargin => "CMFUTURE_MARGIN",
Self::MarginMain => "MARGIN_MAIN",
Self::MarginUmfuture => "MARGIN_UMFUTURE",
Self::MarginCmfuture => "MARGIN_CMFUTURE",
Self::MainIsolatedMargin => "MAIN_ISOLATED_MARGIN",
Self::IsolatedMarginMain => "ISOLATED_MARGIN_MAIN",
Self::IsolatedMarginIsolatedMargin => "ISOLATED_MARGIN_ISOLATED_MARGIN",
Self::MainFunding => "MAIN_FUNDING",
Self::FundingMain => "FUNDING_MAIN",
Self::FundingUmfuture => "FUNDING_UMFUTURE",
Self::UmfutureFunding => "UMFUTURE_FUNDING",
Self::MarginFunding => "MARGIN_FUNDING",
Self::FundingMargin => "FUNDING_MARGIN",
Self::FundingCmfuture => "FUNDING_CMFUTURE",
Self::CmfutureFunding => "CMFUTURE_FUNDING",
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TransferResponse {
pub tran_id: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TransferRecord {
pub asset: String,
#[serde(with = "string_or_float")]
pub amount: f64,
#[serde(rename = "type")]
pub transfer_type: UniversalTransferType,
pub status: String,
pub tran_id: u64,
pub timestamp: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TransferHistory {
pub total: u64,
pub rows: Vec<TransferRecord>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WalletBalance {
pub activate: bool,
#[serde(with = "string_or_float")]
pub balance: f64,
pub wallet_name: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FundingAsset {
pub asset: String,
#[serde(with = "string_or_float")]
pub free: f64,
#[serde(with = "string_or_float")]
pub locked: f64,
#[serde(with = "string_or_float")]
pub freeze: f64,
#[serde(with = "string_or_float")]
pub withdrawing: f64,
#[serde(default, with = "string_or_float_option")]
pub btc_valuation: Option<f64>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum AccountSnapshotType {
Spot,
Margin,
Futures,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AccountSnapshot {
pub code: i32,
pub msg: String,
pub snapshot_vos: Vec<SnapshotData>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SnapshotData {
#[serde(rename = "type")]
pub snapshot_type: String,
pub update_time: u64,
pub data: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ApiKeyPermissions {
pub ip_restrict: bool,
pub create_time: u64,
pub enable_spot_and_margin_trading: bool,
pub enable_withdrawals: bool,
pub enable_internal_transfer: bool,
pub permits_universal_transfer: bool,
pub enable_vanilla_options: bool,
pub enable_reading: bool,
pub enable_futures: bool,
pub enable_margin: bool,
#[serde(default)]
pub trading_authority_expiration_time: Option<u64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AccountStatus {
pub data: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ApiTradingStatus {
pub data: ApiTradingStatusData,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ApiTradingStatusData {
pub is_locked: bool,
#[serde(default)]
pub planned_recover_time: Option<u64>,
pub trigger_condition: serde_json::Value,
pub update_time: u64,
}
mod string_or_float_option {
use serde::{self, Deserialize, Deserializer, Serializer};
pub fn serialize<S>(value: &Option<f64>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match value {
Some(v) => serializer.serialize_str(&v.to_string()),
None => serializer.serialize_none(),
}
}
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<f64>, D::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
#[serde(untagged)]
enum StringOrFloat {
String(String),
Float(f64),
}
let opt: Option<StringOrFloat> = Option::deserialize(deserializer)?;
match opt {
Some(StringOrFloat::Float(f)) => Ok(Some(f)),
Some(StringOrFloat::String(s)) => {
s.parse::<f64>().map(Some).map_err(serde::de::Error::custom)
}
None => Ok(None),
}
}
}