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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//! Asset API endpoints.
use crate::client::BybitClient;
use crate::error::Result;
use crate::models::asset::*;
use tracing::info;
use uuid::Uuid;
impl BybitClient {
/// Get coin info.
///
/// # Arguments
/// * `coin` - Optional coin filter
pub async fn get_coin_info(&self, coin: Option<&str>) -> Result<CoinInfoResponse> {
let mut params = vec![];
if let Some(c) = coin {
params.push(("coin", c));
}
self.get("/v5/asset/coin/query-info", ¶ms).await
}
/// Internal transfer between accounts.
///
/// # Arguments
/// * `coin` - Coin to transfer
/// * `amount` - Amount to transfer
/// * `from_account` - Source account type
/// * `to_account` - Destination account type
pub async fn internal_transfer(
&self,
coin: &str,
amount: &str,
from_account: &str,
to_account: &str,
) -> Result<TransferResponse> {
let params = InternalTransferParams {
transfer_id: Uuid::new_v4().to_string(),
coin: coin.to_string(),
amount: amount.to_string(),
from_account_type: from_account.to_string(),
to_account_type: to_account.to_string(),
};
// Validate parameters
params.validate()?;
info!(
coin = %coin,
amount = %amount,
from = %from_account,
to = %to_account,
"Internal transfer"
);
self.post("/v5/asset/transfer/inter-transfer", ¶ms)
.await
}
/// Get internal transfer list.
///
/// # Arguments
/// * `coin` - Optional coin filter
/// * `limit` - Optional limit (default 20)
pub async fn get_internal_transfer_list(
&self,
coin: Option<&str>,
limit: Option<u32>,
) -> Result<TransferList> {
let limit_str = limit.unwrap_or(20).to_string();
let mut params = vec![("limit", limit_str.as_str())];
if let Some(c) = coin {
params.push(("coin", c));
}
self.get("/v5/asset/transfer/query-inter-transfer-list", ¶ms)
.await
}
/// Get deposit address.
///
/// # Arguments
/// * `coin` - Coin name
/// * `chain_type` - Optional chain type
pub async fn get_deposit_address(
&self,
coin: &str,
chain_type: Option<&str>,
) -> Result<DepositAddressResponse> {
let mut params = vec![("coin", coin)];
if let Some(ct) = chain_type {
params.push(("chainType", ct));
}
self.get("/v5/asset/deposit/query-address", ¶ms).await
}
/// Get deposit records.
///
/// # Arguments
/// * `coin` - Optional coin filter
/// * `limit` - Optional limit (default 50)
pub async fn get_deposit_records(
&self,
coin: Option<&str>,
limit: Option<u32>,
) -> Result<DepositRecords> {
let limit_str = limit.unwrap_or(50).to_string();
let mut params = vec![("limit", limit_str.as_str())];
if let Some(c) = coin {
params.push(("coin", c));
}
self.get("/v5/asset/deposit/query-record", ¶ms).await
}
/// Withdraw funds (REQUIRES STRICT VALIDATION).
///
/// # Arguments
/// * `params` - Withdraw parameters
///
/// # Safety
/// This function validates all parameters before sending to prevent fund loss.
pub async fn withdraw(&self, params: WithdrawParams) -> Result<WithdrawResponse> {
// CRITICAL: Validate all parameters (fund safety)
params.validate()?;
info!(
coin = %params.coin,
chain = %params.chain,
address = %params.address,
amount = %params.amount,
"Initiating withdrawal"
);
self.post("/v5/asset/withdraw/create", ¶ms).await
}
/// Cancel a pending withdrawal.
///
/// # Arguments
/// * `withdraw_id` - Withdraw ID to cancel
// FIXME(typed-signature): falls back to `serde_json::Value` because the
// OpenAPI spec referenced a response/request type that gen-sdk-rust could
// not auto-resolve. Replace with a typed struct in a follow-up PR.
pub async fn cancel_withdraw(&self, withdraw_id: &str) -> Result<serde_json::Value> {
let params = CancelWithdrawParams {
id: withdraw_id.to_string(),
};
info!(withdraw_id = %withdraw_id, "Cancelling withdrawal");
self.post("/v5/asset/withdraw/cancel", ¶ms).await
}
/// Get withdraw records.
///
/// # Arguments
/// * `coin` - Optional coin filter
/// * `limit` - Optional limit (default 50)
pub async fn get_withdraw_records(
&self,
coin: Option<&str>,
limit: Option<u32>,
) -> Result<WithdrawRecords> {
let limit_str = limit.unwrap_or(50).to_string();
let mut params = vec![("limit", limit_str.as_str())];
if let Some(c) = coin {
params.push(("coin", c));
}
self.get("/v5/asset/withdraw/query-record", ¶ms).await
}
/// Get withdrawable amount.
///
/// # Arguments
/// * `coin` - Coin name
pub async fn get_withdrawable_amount(&self, coin: &str) -> Result<WithdrawableAmount> {
let params = vec![("coin", coin)];
self.get("/v5/asset/withdraw/withdrawable-amount", ¶ms)
.await
}
}