1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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");
}
}