use jiff::Timestamp;
use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::{enums::SecurityType, rest_api::endpoint, web_socket_api::web_socket};
endpoint!(
"/api/v3/account",
Method::GET,
SecurityType::UserData,
AccountInformationEndpoint,
AccountInformationParams,
AccountInformationResponse
);
pub struct AccountInformationEndpoint<'r> {
client: &'r crate::rest_api::RestApiClient,
}
impl<'r> AccountInformationEndpoint<'r> {
pub fn new(client: &'r crate::rest_api::RestApiClient) -> Self {
Self { client }
}
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AccountInformationParams {
#[serde(skip_serializing_if = "Option::is_none")]
omit_zero_balances: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
recv_window: Option<i64>,
timestamp: i64,
}
impl Default for AccountInformationParams {
fn default() -> Self {
Self::new()
}
}
impl AccountInformationParams {
pub fn new() -> Self {
Self {
omit_zero_balances: None,
recv_window: None,
timestamp: Timestamp::now().as_millisecond(),
}
}
pub fn omit_zero_balances(mut self, omit_zero_balances: bool) -> Self {
self.omit_zero_balances = Some(omit_zero_balances);
self
}
pub fn recv_window(mut self, recv_window: i64) -> Self {
self.recv_window = Some(recv_window);
self
}
}
pub type AccountInformationResponse = Account;
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Account {
pub maker_commission: i64,
pub taker_commission: i64,
pub buyer_commission: i64,
pub seller_commission: i64,
pub commission_rates: CommissionRate,
pub can_trade: bool,
pub can_withdraw: bool,
pub can_deposit: bool,
pub brokered: bool,
pub require_self_trade_prevention: bool,
pub prevent_sor: bool,
pub update_time: i64,
pub account_type: String,
pub balances: Vec<Balance>,
pub permissions: Vec<String>,
pub uid: i64,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CommissionRate {
pub maker: String,
pub taker: String,
pub buyer: String,
pub seller: String,
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Balance {
pub asset: String,
pub free: String,
pub locked: String,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Discount {
pub enabled_for_account: bool,
pub enabled_for_symbol: bool,
pub discount_asset: Option<String>,
pub discount: String,
}
web_socket!(
"account.status",
AccountInformationWebSocket,
AccountInformationParams,
AccountInformationResponse
);
pub struct AccountInformationWebSocket<'w> {
client: &'w crate::web_socket_api::WebSocketApiClient,
}
impl<'w> AccountInformationWebSocket<'w> {
pub fn new(client: &'w crate::web_socket_api::WebSocketApiClient) -> Self {
Self { client }
}
}