use crate::client::*;
use crate::errors::*;
use crate::rest_model::*;
use crate::util::*;
use std::collections::BTreeMap;
#[derive(Debug, Serialize, Deserialize, Clone)]
#[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<Network>,
#[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, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Network {
pub address_regex: String,
pub coin: String,
pub deposit_desc: Option<String>,
pub deposit_enable: bool,
pub is_default: bool,
pub memo_regex: String,
pub min_confirm: u32,
pub name: String,
pub network: String,
pub reset_address_status: bool,
pub special_tips: Option<String>,
pub un_lock_confirm: u32,
pub withdraw_desc: Option<String>,
pub withdraw_enable: bool,
#[serde(with = "string_or_float")]
pub withdraw_fee: f64,
#[serde(with = "string_or_float")]
pub withdraw_min: f64,
pub withdraw_integer_multiple: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[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,
pub deposit_tip: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct DepositAddress {
pub address: String,
pub coin: String,
pub tag: String,
pub url: String,
}
#[derive(Clone)]
pub struct Savings {
pub client: Client,
pub recv_window: u64,
}
impl Savings {
pub async fn get_all_coins(&self) -> Result<Vec<CoinInfo>> {
let request = build_signed_request(BTreeMap::new(), self.recv_window)?;
self.client
.get_signed_d("/sapi/v1/capital/config/getall", request.as_str())
.await
}
pub async fn asset_detail(&self, asset: Option<String>) -> Result<BTreeMap<String, AssetDetail>> {
let mut parameters = BTreeMap::new();
if let Some(asset) = asset {
parameters.insert("asset".into(), asset);
}
let request = build_signed_request(parameters, self.recv_window)?;
self.client
.get_signed_d("/sapi/v1/asset/assetDetail", request.as_str())
.await
}
pub async fn deposit_address<S>(&self, coin: S, network: Option<String>) -> Result<DepositAddress>
where
S: Into<String>,
{
let mut parameters = BTreeMap::new();
parameters.insert("coin".into(), coin.into());
if let Some(network) = network {
parameters.insert("network".into(), network);
}
let request = build_signed_request(parameters, self.recv_window)?;
self.client
.get_signed_d("/sapi/v1/capital/deposit/address", request.as_str())
.await
}
}