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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
use crate::client::SharedClient;
use anyhow::Result;
use reqwest::Method;
pub struct WithdrawsJpy {
client: SharedClient,
}
pub mod model {
use crate::types::*;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DisplayFromStr};
#[derive(Debug, Serialize, Deserialize)]
pub struct BankAccounts {
pub success: bool,
pub data: Vec<BankAccount>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct BankAccount {
pub id: IdType,
pub bank_name: String,
pub branch_name: String,
pub bank_account_type: String,
pub number: String,
pub name: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Withdraws {
pub success: bool,
pub pagination: Pagination,
pub data: Vec<Withdraw>,
}
#[serde_as]
#[derive(Debug, Serialize, Deserialize)]
pub struct Withdraw {
pub id: IdType,
pub status: String,
#[serde_as(as = "DisplayFromStr")]
pub amount: PriceType,
pub currency: String,
pub created_at: DateTime<Utc>,
pub bank_account_id: IdType,
#[serde_as(as = "DisplayFromStr")]
pub fee: PriceType,
pub is_fast: bool,
}
}
impl WithdrawsJpy {
pub fn new(client: SharedClient) -> Self {
Self { client }
}
const USE_AUTH: bool = true;
pub async fn bank_accounts(&mut self) -> Result<model::BankAccounts> {
self.client
.borrow_mut()
.request_and_get_json(Method::GET, "/api/bank_accounts", None, Self::USE_AUTH)
.await
}
pub async fn withdraws(&mut self) -> Result<model::Withdraws> {
self.client
.borrow_mut()
.request_and_get_json(Method::GET, "/api/withdraws", None, Self::USE_AUTH)
.await
}
}
#[cfg(test)]
mod tests {
use crate::Coincheck;
#[tokio::test]
#[serial_test::serial]
async fn private_withdraw_jpy_api() {
let mut coincheck = Coincheck::new_with_env_keys();
let api = &mut coincheck.private.withdraws_jpy;
assert!(api.bank_accounts().await.is_ok());
assert!(api.withdraws().await.is_ok());
}
}