use serde::Serialize;
#[derive(Debug, Clone, Default, Serialize)]
pub struct FlexibleLoanCollateralAssetsRequest {
#[serde(skip_serializing_if = "Option::is_none")]
ccy: Option<String>,
#[serde(rename = "ordId", skip_serializing_if = "Option::is_none")]
ord_id: Option<String>,
}
impl FlexibleLoanCollateralAssetsRequest {
pub fn new() -> Self {
Self::default()
}
pub fn currency(mut self, value: impl Into<String>) -> Self {
self.ccy = Some(value.into());
self
}
pub fn order_id(mut self, value: impl Into<String>) -> Self {
self.ord_id = Some(value.into());
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct FlexibleLoanMaxLoanRequest {
#[serde(rename = "borrowCcy")]
borrow_ccy: String,
#[serde(rename = "collateralCcy", skip_serializing_if = "Option::is_none")]
collateral_ccy: Option<String>,
#[serde(rename = "collateralAmt", skip_serializing_if = "Option::is_none")]
collateral_amt: Option<String>,
#[serde(rename = "ordId", skip_serializing_if = "Option::is_none")]
ord_id: Option<String>,
}
impl FlexibleLoanMaxLoanRequest {
pub fn new(borrow_ccy: impl Into<String>) -> Self {
Self {
borrow_ccy: borrow_ccy.into(),
collateral_ccy: None,
collateral_amt: None,
ord_id: None,
}
}
pub fn collateral(mut self, ccy: impl Into<String>, amt: impl Into<String>) -> Self {
self.collateral_ccy = Some(ccy.into());
self.collateral_amt = Some(amt.into());
self
}
pub fn order_id(mut self, value: impl Into<String>) -> Self {
self.ord_id = Some(value.into());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct FlexibleLoanMaxRedeemRequest {
#[serde(skip_serializing_if = "Option::is_none")]
ccy: Option<String>,
#[serde(rename = "ordId", skip_serializing_if = "Option::is_none")]
ord_id: Option<String>,
}
impl FlexibleLoanMaxRedeemRequest {
pub fn new() -> Self {
Self::default()
}
pub fn currency(mut self, value: impl Into<String>) -> Self {
self.ccy = Some(value.into());
self
}
pub fn order_id(mut self, value: impl Into<String>) -> Self {
self.ord_id = Some(value.into());
self
}
}
#[derive(Debug, Clone, Serialize)]
pub struct FlexibleLoanAdjustCollateralRequest {
#[serde(rename = "ordId")]
ord_id: String,
#[serde(rename = "collateralCcy")]
collateral_ccy: String,
amt: String,
#[serde(rename = "type")]
adjustment_type: String,
}
impl FlexibleLoanAdjustCollateralRequest {
pub fn new(
ord_id: impl Into<String>,
collateral_ccy: impl Into<String>,
amt: impl Into<String>,
adjustment_type: impl Into<String>,
) -> Self {
Self {
ord_id: ord_id.into(),
collateral_ccy: collateral_ccy.into(),
amt: amt.into(),
adjustment_type: adjustment_type.into(),
}
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct FlexibleLoanInfoRequest {
#[serde(rename = "ordId", skip_serializing_if = "Option::is_none")]
ord_id: Option<String>,
}
impl FlexibleLoanInfoRequest {
pub fn new() -> Self {
Self::default()
}
pub fn order_id(mut self, value: impl Into<String>) -> Self {
self.ord_id = Some(value.into());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct FlexibleLoanHistoryRequest {
#[serde(rename = "ordId", skip_serializing_if = "Option::is_none")]
ord_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
after: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
before: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
limit: Option<u32>,
}
impl FlexibleLoanHistoryRequest {
pub fn new() -> Self {
Self::default()
}
pub fn order_id(mut self, value: impl Into<String>) -> Self {
self.ord_id = Some(value.into());
self
}
pub fn after(mut self, value: impl Into<String>) -> Self {
self.after = Some(value.into());
self
}
pub fn before(mut self, value: impl Into<String>) -> Self {
self.before = Some(value.into());
self
}
pub fn limit(mut self, value: u32) -> Self {
self.limit = Some(value);
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct FlexibleLoanInterestAccruedRequest {
#[serde(rename = "ordId", skip_serializing_if = "Option::is_none")]
ord_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
ccy: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
after: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
before: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
limit: Option<u32>,
}
impl FlexibleLoanInterestAccruedRequest {
pub fn new() -> Self {
Self::default()
}
pub fn order_id(mut self, value: impl Into<String>) -> Self {
self.ord_id = Some(value.into());
self
}
pub fn currency(mut self, value: impl Into<String>) -> Self {
self.ccy = Some(value.into());
self
}
pub fn after(mut self, value: impl Into<String>) -> Self {
self.after = Some(value.into());
self
}
pub fn before(mut self, value: impl Into<String>) -> Self {
self.before = Some(value.into());
self
}
pub fn limit(mut self, value: u32) -> Self {
self.limit = Some(value);
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn max_loan_requires_complete_collateral_pair() {
let request = FlexibleLoanMaxLoanRequest::new("USDT");
let mut value = serde_json::to_value(request).unwrap();
value["collateralCcy"] = serde_json::Value::String("BTC".into());
assert_eq!(value["borrowCcy"], "USDT");
}
}