use serde::{Deserialize, Serialize};
use crate::api::{Requests, Response};
use crate::client::TradingClient;
use crate::error::Error;
use chrono::prelude::*;
#[derive(Serialize, Deserialize, Debug)]
pub struct WithdrawalRequest {
amount: usize,
pin: i64,
idempotency: Option<String>,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Withdrawal {
pub id: String,
pub amount: i64,
pub created_at: DateTime<Utc>,
pub date: DateTime<Utc>,
pub idempotency: Option<String>,
}
impl TradingClient {
pub fn get_account_withdrawls(
&self,
_limit: Option<i32>,
_page: Option<i32>,
) -> Result<Response, Error> {
const PATH: &str = "account/withdrawals";
let resp = self.get::<Response>(PATH);
match resp {
Ok(r) => Ok(r),
Err(e) => Err(e),
}
}
pub fn post_withdrawal(&self, withdrawal: WithdrawalRequest) -> Result<Response, Error> {
const PATH: &str = "account/withdrawals/";
let resp = self.post::<Response, WithdrawalRequest>(PATH, withdrawal);
match resp {
Ok(r) => Ok(r),
Err(e) => Err(e),
}
}
}
#[cfg(test)]
mod tests {
use std::env;
use super::*;
#[test]
fn test_get_account_withdrawls() {
dotenv::dotenv().unwrap();
let api_key = env::var("LEMON_MARKET_TRADING_API_KEY").unwrap();
let client = TradingClient::paper_client(&api_key);
let resp = client.get_account_withdrawls(None, None).unwrap();
assert_eq!(resp.status, "ok");
}
#[test]
fn test_post_withdrawal() {
dotenv::dotenv().unwrap();
let api_key = env::var("LEMON_MARKET_TRADING_API_KEY").unwrap();
let client = TradingClient::paper_client(&api_key);
let withdrawal = WithdrawalRequest {
amount: 100, pin: 1234,
idempotency: None,
};
let resp = client.post_withdrawal(withdrawal).unwrap();
assert_eq!(resp.status, "ok");
}
}