use crate::client::BybitClient;
use crate::error::Result;
use crate::models::account::*;
use crate::models::*;
impl BybitClient {
pub async fn get_wallet_balance(&self, account_type: AccountType) -> Result<WalletBalance> {
let account_type_str = account_type.to_string();
let params = vec![("accountType", account_type_str.as_str())];
self.get("/v5/account/wallet-balance", ¶ms).await
}
pub async fn get_account_info(&self) -> Result<AccountInfo> {
self.get("/v5/account/info", &[]).await
}
pub async fn get_fee_rate(&self, category: Category, symbol: Option<&str>) -> Result<FeeRates> {
let cat_str = category.to_string();
let mut params = vec![("category", cat_str.as_str())];
if let Some(s) = symbol {
params.push(("symbol", s));
}
self.get("/v5/account/fee-rate", ¶ms).await
}
pub async fn get_transaction_log(
&self,
category: Option<Category>,
limit: Option<u32>,
) -> Result<TransactionLogs> {
let limit_str = limit.unwrap_or(20).to_string();
let mut params = vec![("limit", limit_str.as_str())];
let cat_str;
if let Some(c) = category {
cat_str = c.to_string();
params.push(("category", cat_str.as_str()));
}
self.get("/v5/account/transaction-log", ¶ms).await
}
pub async fn set_margin_mode(&self, margin_mode: MarginMode) -> Result<serde_json::Value> {
let params = SetMarginModeParams {
set_margin_mode: margin_mode.to_string(),
};
self.post("/v5/account/set-margin-mode", ¶ms).await
}
pub async fn get_collateral_info(&self, currency: Option<&str>) -> Result<CollateralInfo> {
let mut params = vec![];
if let Some(c) = currency {
params.push(("currency", c));
}
self.get("/v5/account/collateral-info", ¶ms).await
}
pub async fn get_borrow_history(
&self,
currency: Option<&str>,
limit: Option<u32>,
) -> Result<BorrowHistory> {
let limit_str = limit.unwrap_or(20).to_string();
let mut params = vec![("limit", limit_str.as_str())];
if let Some(c) = currency {
params.push(("currency", c));
}
self.get("/v5/account/borrow-history", ¶ms).await
}
pub async fn batch_set_collateral(
&self,
params: BatchSetCollateralParams,
) -> Result<BatchSetCollateralResponse> {
self.post("/v5/account/set-collateral-switch-batch", ¶ms)
.await
}
pub async fn get_account_instruments(
&self,
category: Category,
symbol: Option<&str>,
limit: Option<u32>,
cursor: Option<&str>,
) -> Result<GetAccountInstrumentsResponse> {
let cat_str = category.to_string();
let limit_str;
let mut params = vec![("category", cat_str.as_str())];
if let Some(s) = symbol {
params.push(("symbol", s));
}
if let Some(l) = limit {
limit_str = l.to_string();
params.push(("limit", limit_str.as_str()));
}
if let Some(c) = cursor {
params.push(("cursor", c));
}
self.get("/v5/account/instruments-info", ¶ms).await
}
pub async fn get_coin_greeks(&self, base_coin: Option<&str>) -> Result<GetCoinGreeksResponse> {
let mut params = vec![];
if let Some(b) = base_coin {
params.push(("baseCoin", b));
}
self.get("/v5/asset/coin-greeks", ¶ms).await
}
pub async fn get_dcp_info(&self) -> Result<GetDcpInfoResponse> {
self.get("/v5/account/query-dcp-info", &[]).await
}
pub async fn get_group_fee_rate(
&self,
product_type: &str,
group_id: Option<&str>,
) -> Result<GetGroupFeeRateResponse> {
let mut params = vec![("productType", product_type)];
if let Some(g) = group_id {
params.push(("groupId", g));
}
self.get_public("/v5/market/fee-group-info", ¶ms).await
}
pub async fn get_mmp_state(&self, base_coin: &str) -> Result<GetMmpStateResponse> {
let params = vec![("baseCoin", base_coin)];
self.get("/v5/account/mmp-state", ¶ms).await
}
pub async fn get_smp_group(&self) -> Result<GetSmpGroupResponse> {
self.get("/v5/account/smp-group", &[]).await
}
pub async fn get_transferable_amount(
&self,
coin_name: &str,
) -> Result<GetTransferableAmountResponse> {
let params = vec![("coinName", coin_name)];
self.get("/v5/account/withdrawal", ¶ms).await
}
pub async fn get_user_settings(&self) -> Result<GetUserSettingsResponse> {
self.get("/v5/account/user-setting-config", &[]).await
}
pub async fn manual_borrow(&self, params: ManualBorrowParams) -> Result<ManualBorrowResponse> {
self.post("/v5/account/borrow", ¶ms).await
}
pub async fn manual_repay(&self, params: ManualRepayParams) -> Result<ManualRepayResponse> {
self.post("/v5/account/repay", ¶ms).await
}
pub async fn no_convert_repay(
&self,
params: NoConvertRepayParams,
) -> Result<NoConvertRepayResponse> {
self.post("/v5/account/no-convert-repay", ¶ms).await
}
pub async fn one_click_repay(
&self,
params: OneClickRepayParams,
) -> Result<OneClickRepayResponse> {
self.post("/v5/account/quick-repayment", ¶ms).await
}
pub async fn reset_mmp(&self, params: ResetMmpParams) -> Result<ResetMmpResponse> {
self.post("/v5/account/mmp-reset", ¶ms).await
}
pub async fn set_collateral_coin(
&self,
params: SetCollateralCoinParams,
) -> Result<serde_json::Value> {
self.post("/v5/account/set-collateral-switch", ¶ms)
.await
}
pub async fn set_mmp(&self, params: SetMmpParams) -> Result<SetMmpResponse> {
self.post("/v5/account/mmp-modify", ¶ms).await
}
pub async fn set_price_limit(
&self,
params: SetPriceLimitParams,
) -> Result<SetPriceLimitResponse> {
self.post("/v5/account/set-limit-px-action", ¶ms).await
}
pub async fn set_spot_hedging(
&self,
params: SetSpotHedgingParams,
) -> Result<SetSpotHedgingResponse> {
self.post("/v5/account/set-hedging-mode", ¶ms).await
}
pub async fn upgrade_to_uta_pro(&self) -> Result<UpgradeToUtaProResponse> {
self.post("/v5/account/upgrade-to-uta", &serde_json::json!({}))
.await
}
}