use crate::client::BybitClient;
use crate::error::Result;
use crate::models::asset::*;
use tracing::info;
use uuid::Uuid;
impl BybitClient {
pub async fn get_coin_info(&self, coin: Option<&str>) -> Result<CoinInfoResponse> {
let mut params = vec![];
if let Some(c) = coin {
params.push(("coin", c));
}
self.get("/v5/asset/coin/query-info", ¶ms).await
}
pub async fn internal_transfer(
&self,
coin: &str,
amount: &str,
from_account: &str,
to_account: &str,
) -> Result<TransferResponse> {
let params = InternalTransferParams {
transfer_id: Uuid::new_v4().to_string(),
coin: coin.to_string(),
amount: amount.to_string(),
from_account_type: from_account.to_string(),
to_account_type: to_account.to_string(),
};
params.validate()?;
info!(
coin = %coin,
amount = %amount,
from = %from_account,
to = %to_account,
"Internal transfer"
);
self.post("/v5/asset/transfer/inter-transfer", ¶ms)
.await
}
pub async fn get_internal_transfer_list(
&self,
coin: Option<&str>,
limit: Option<u32>,
) -> Result<TransferList> {
let limit_str = limit.unwrap_or(20).to_string();
let mut params = vec![("limit", limit_str.as_str())];
if let Some(c) = coin {
params.push(("coin", c));
}
self.get("/v5/asset/transfer/query-inter-transfer-list", ¶ms)
.await
}
pub async fn get_deposit_address(
&self,
coin: &str,
chain_type: Option<&str>,
) -> Result<DepositAddressResponse> {
let mut params = vec![("coin", coin)];
if let Some(ct) = chain_type {
params.push(("chainType", ct));
}
self.get("/v5/asset/deposit/query-address", ¶ms).await
}
pub async fn get_deposit_records(
&self,
coin: Option<&str>,
limit: Option<u32>,
) -> Result<DepositRecords> {
let limit_str = limit.unwrap_or(50).to_string();
let mut params = vec![("limit", limit_str.as_str())];
if let Some(c) = coin {
params.push(("coin", c));
}
self.get("/v5/asset/deposit/query-record", ¶ms).await
}
pub async fn withdraw(&self, params: WithdrawParams) -> Result<WithdrawResponse> {
params.validate()?;
info!(
coin = %params.coin,
chain = %params.chain,
address = %params.address,
amount = %params.amount,
"Initiating withdrawal"
);
self.post("/v5/asset/withdraw/create", ¶ms).await
}
pub async fn cancel_withdraw(&self, withdraw_id: &str) -> Result<serde_json::Value> {
let params = CancelWithdrawParams {
id: withdraw_id.to_string(),
};
info!(withdraw_id = %withdraw_id, "Cancelling withdrawal");
self.post("/v5/asset/withdraw/cancel", ¶ms).await
}
pub async fn get_withdraw_records(
&self,
coin: Option<&str>,
limit: Option<u32>,
) -> Result<WithdrawRecords> {
let limit_str = limit.unwrap_or(50).to_string();
let mut params = vec![("limit", limit_str.as_str())];
if let Some(c) = coin {
params.push(("coin", c));
}
self.get("/v5/asset/withdraw/query-record", ¶ms).await
}
pub async fn get_withdrawable_amount(&self, coin: &str) -> Result<WithdrawableAmount> {
let params = vec![("coin", coin)];
self.get("/v5/asset/withdraw/withdrawable-amount", ¶ms)
.await
}
}