use crate::client::BybitClient;
use crate::error::Result;
use crate::models::crypto_loan::*;
impl BybitClient {
pub async fn adjust_ltv(&self, params: AdjustLtvParams) -> Result<AdjustLtvResponse> {
self.post("/v5/crypto-loan-common/adjust-ltv", ¶ms)
.await
}
pub async fn calculate_max_loan(
&self,
params: CalculateMaxLoanParams,
) -> Result<CalculateMaxLoanResponse> {
self.post("/v5/crypto-loan-common/max-loan", ¶ms).await
}
pub async fn cancel_fixed_borrow_order(
&self,
params: CancelFixedBorrowOrderParams,
) -> Result<CancelFixedBorrowOrderResponse> {
self.post("/v5/crypto-loan-fixed/borrow-order-cancel", ¶ms)
.await
}
pub async fn create_fixed_borrow(
&self,
params: CreateFixedBorrowParams,
) -> Result<CreateFixedBorrowResponse> {
self.post("/v5/crypto-loan-fixed/borrow", ¶ms).await
}
pub async fn fully_repay_fixed_loan(
&self,
params: FullyRepayFixedLoanParams,
) -> Result<FullyRepayFixedLoanResponse> {
self.post("/v5/crypto-loan-fixed/fully-repay", ¶ms)
.await
}
pub async fn get_adjustment_history(
&self,
adjust_id: Option<i64>,
collateral_currency: Option<&str>,
limit: Option<i64>,
cursor: Option<i64>,
) -> Result<GetAdjustmentHistoryResponse> {
let adjust_id_str = adjust_id.map(|v| v.to_string());
let limit_str = limit.map(|v| v.to_string());
let cursor_str = cursor.map(|v| v.to_string());
let mut params: Vec<(&str, &str)> = vec![];
if let Some(ref s) = adjust_id_str {
params.push(("adjustId", s.as_str()));
}
if let Some(s) = collateral_currency {
params.push(("collateralCurrency", s));
}
if let Some(ref s) = limit_str {
params.push(("limit", s.as_str()));
}
if let Some(ref s) = cursor_str {
params.push(("cursor", s.as_str()));
}
self.get("/v5/crypto-loan-common/adjustment-history", ¶ms)
.await
}
pub async fn get_collateral_data(
&self,
currency: Option<&str>,
) -> Result<GetCollateralDataResponse> {
let mut params: Vec<(&str, &str)> = vec![];
if let Some(s) = currency {
params.push(("currency", s));
}
self.get_public("/v5/crypto-loan-common/collateral-data", ¶ms)
.await
}
pub async fn get_fixed_repayment_history(&self) -> Result<serde_json::Value> {
self.get("/v5/crypto-loan-fixed/repayment-history", &[])
.await
}
pub async fn get_fixed_supply_contract_info(&self) -> Result<serde_json::Value> {
self.get("/v5/crypto-loan-fixed/supply-contract-info", &[])
.await
}
pub async fn get_fixed_supply_order_info(&self) -> Result<serde_json::Value> {
self.get("/v5/crypto-loan-fixed/supply-order-info", &[])
.await
}
pub async fn get_fixed_supply_order_quote(
&self,
) -> Result<GetCryptoLoanFixedSupplyOrderQuoteResponse> {
self.get_public("/v5/crypto-loan-fixed/supply-order-quote", &[])
.await
}
pub async fn get_flexible_borrow_history(
&self,
) -> Result<GetCryptoLoanFlexibleBorrowHistoryResponse> {
self.get("/v5/crypto-loan-flexible/borrow-history", &[])
.await
}
pub async fn get_flexible_ongoing_coin(&self) -> Result<serde_json::Value> {
self.get("/v5/crypto-loan-flexible/ongoing-coin", &[]).await
}
pub async fn get_flexible_repayment_history(
&self,
) -> Result<GetCryptoLoanFlexibleRepaymentHistoryResponse> {
self.get("/v5/crypto-loan-flexible/repayment-history", &[])
.await
}
pub async fn get_fixed_borrow_contract_info(
&self,
order_id: Option<&str>,
loan_id: Option<&str>,
order_currency: Option<&str>,
term: Option<&str>,
limit: Option<i64>,
cursor: Option<i64>,
) -> Result<serde_json::Value> {
let limit_str = limit.map(|v| v.to_string());
let cursor_str = cursor.map(|v| v.to_string());
let mut params: Vec<(&str, &str)> = vec![];
if let Some(s) = order_id {
params.push(("orderId", s));
}
if let Some(s) = loan_id {
params.push(("loanId", s));
}
if let Some(s) = order_currency {
params.push(("orderCurrency", s));
}
if let Some(s) = term {
params.push(("term", s));
}
if let Some(ref s) = limit_str {
params.push(("limit", s.as_str()));
}
if let Some(ref s) = cursor_str {
params.push(("cursor", s.as_str()));
}
self.get("/v5/crypto-loan-fixed/borrow-contract-info", ¶ms)
.await
}
pub async fn get_fixed_borrow_order_info(
&self,
order_id: Option<&str>,
order_currency: Option<&str>,
state: Option<&str>,
term: Option<&str>,
limit: Option<i64>,
cursor: Option<i64>,
) -> Result<serde_json::Value> {
let limit_str = limit.map(|v| v.to_string());
let cursor_str = cursor.map(|v| v.to_string());
let mut params: Vec<(&str, &str)> = vec![];
if let Some(s) = order_id {
params.push(("orderId", s));
}
if let Some(s) = order_currency {
params.push(("orderCurrency", s));
}
if let Some(s) = state {
params.push(("state", s));
}
if let Some(s) = term {
params.push(("term", s));
}
if let Some(ref s) = limit_str {
params.push(("limit", s.as_str()));
}
if let Some(ref s) = cursor_str {
params.push(("cursor", s.as_str()));
}
self.get("/v5/crypto-loan-fixed/borrow-order-info", ¶ms)
.await
}
pub async fn get_fixed_borrow_order_quote(
&self,
order_currency: Option<&str>,
term: Option<&str>,
order_by: Option<&str>,
sort: Option<i64>,
limit: Option<i64>,
) -> Result<GetFixedBorrowOrderQuoteResponse> {
let sort_str = sort.map(|v| v.to_string());
let limit_str = limit.map(|v| v.to_string());
let mut params: Vec<(&str, &str)> = vec![];
if let Some(s) = order_currency {
params.push(("orderCurrency", s));
}
if let Some(s) = term {
params.push(("term", s));
}
if let Some(s) = order_by {
params.push(("orderBy", s));
}
if let Some(ref s) = sort_str {
params.push(("sort", s.as_str()));
}
if let Some(ref s) = limit_str {
params.push(("limit", s.as_str()));
}
self.get_public("/v5/crypto-loan-fixed/borrow-order-quote", ¶ms)
.await
}
pub async fn get_fixed_renew_info(
&self,
order_id: Option<&str>,
order_currency: Option<&str>,
limit: Option<i64>,
cursor: Option<i64>,
) -> Result<serde_json::Value> {
let limit_str = limit.map(|v| v.to_string());
let cursor_str = cursor.map(|v| v.to_string());
let mut params: Vec<(&str, &str)> = vec![];
if let Some(s) = order_id {
params.push(("orderId", s));
}
if let Some(s) = order_currency {
params.push(("orderCurrency", s));
}
if let Some(ref s) = limit_str {
params.push(("limit", s.as_str()));
}
if let Some(ref s) = cursor_str {
params.push(("cursor", s.as_str()));
}
self.get("/v5/crypto-loan-fixed/renew-info", ¶ms).await
}
pub async fn get_loan_position(&self) -> Result<GetLoanPositionResponse> {
self.get("/v5/crypto-loan-common/position", &[]).await
}
pub async fn get_loanable_data(
&self,
currency: Option<&str>,
vip_level: Option<&str>,
) -> Result<GetLoanableDataResponse> {
let mut params: Vec<(&str, &str)> = vec![];
if let Some(s) = currency {
params.push(("currency", s));
}
if let Some(s) = vip_level {
params.push(("vipLevel", s));
}
self.get_public("/v5/crypto-loan-common/loanable-data", ¶ms)
.await
}
pub async fn get_max_collateral_amount(
&self,
currency: &str,
) -> Result<GetMaxCollateralAmountResponse> {
let params = vec![("currency", currency)];
self.get("/v5/crypto-loan-common/max-collateral-amount", ¶ms)
.await
}
pub async fn repay_fixed_collateral(
&self,
params: PostCryptoLoanFixedRepayCollateralParams,
) -> Result<PostCryptoLoanFixedRepayCollateralResponse> {
self.post("/v5/crypto-loan-fixed/repay-collateral", ¶ms)
.await
}
pub async fn create_fixed_supply(
&self,
params: PostCryptoLoanFixedSupplyParams,
) -> Result<serde_json::Value> {
self.post("/v5/crypto-loan-fixed/supply", ¶ms).await
}
pub async fn cancel_fixed_supply_order(
&self,
params: PostCryptoLoanFixedSupplyOrderCancelParams,
) -> Result<PostCryptoLoanFixedSupplyOrderCancelResponse> {
self.post("/v5/crypto-loan-fixed/supply-order-cancel", ¶ms)
.await
}
pub async fn create_flexible_borrow(
&self,
params: PostCryptoLoanFlexibleBorrowParams,
) -> Result<PostCryptoLoanFlexibleBorrowResponse> {
self.post("/v5/crypto-loan-flexible/borrow", ¶ms).await
}
pub async fn repay_flexible_loan(
&self,
params: PostCryptoLoanFlexibleRepayParams,
) -> Result<serde_json::Value> {
self.post("/v5/crypto-loan-flexible/repay", ¶ms).await
}
pub async fn repay_flexible_collateral(
&self,
params: PostCryptoLoanFlexibleRepayCollateralParams,
) -> Result<PostCryptoLoanFlexibleRepayCollateralResponse> {
self.post("/v5/crypto-loan-flexible/repay-collateral", ¶ms)
.await
}
pub async fn renew_fixed_loan(
&self,
params: RenewFixedLoanParams,
) -> Result<serde_json::Value> {
self.post("/v5/crypto-loan-fixed/renew", ¶ms).await
}
}