bybit_rust_api/rest/account/dto/
transaction_log.rs1use crate::rest::enums::account_type::AccountType;
2use crate::rest::enums::category::Category;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Serialize, Deserialize, Default)]
7pub struct GetTransactionLogParams {
8 #[serde(rename = "accountType", skip_serializing_if = "Option::is_none")]
9 pub account_type: Option<AccountType>,
10 #[serde(rename = "category", skip_serializing_if = "Option::is_none")]
11 pub category: Option<Category>,
12 #[serde(rename = "currency", skip_serializing_if = "Option::is_none")]
13 pub currency: Option<String>,
14 #[serde(rename = "baseCoin", skip_serializing_if = "Option::is_none")]
15 pub base_coin: Option<String>,
16 #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
17 pub log_type: Option<String>,
18 #[serde(rename = "startTime", skip_serializing_if = "Option::is_none")]
19 pub start_time: Option<i64>,
20 #[serde(rename = "endTime", skip_serializing_if = "Option::is_none")]
21 pub end_time: Option<i64>,
22 #[serde(rename = "limit", skip_serializing_if = "Option::is_none")]
23 pub limit: Option<i32>,
24 #[serde(rename = "cursor", skip_serializing_if = "Option::is_none")]
25 pub cursor: Option<String>,
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct TransactionLog {
30 pub id: String,
31 pub symbol: String,
32 pub side: String,
33 pub funding: String,
34 #[serde(rename = "orderLinkId")]
35 pub order_link_id: String,
36 #[serde(rename = "orderId")]
37 pub order_id: String,
38 pub fee: String,
39 pub change: String,
40 #[serde(rename = "cashFlow")]
41 pub cash_flow: String,
42 #[serde(rename = "transactionTime")]
43 pub transaction_time: String,
44 #[serde(rename = "type")]
45 pub r#type: String,
46 #[serde(rename = "feeRate")]
47 pub fee_rate: String,
48 #[serde(rename = "bonusChange")]
49 pub bonus_change: String,
50 pub size: String,
51 pub qty: String,
52 #[serde(rename = "cashBalance")]
53 pub cash_balance: String,
54 pub currency: String,
55 pub category: String,
56 #[serde(rename = "tradePrice")]
57 pub trade_price: String,
58 #[serde(rename = "tradeId")]
59 pub trade_id: String,
60}
61
62#[derive(Debug, Clone, Serialize, Deserialize)]
63pub struct TransactionLogResult {
64 #[serde(rename = "nextPageCursor")]
65 pub next_page_cursor: String,
66 pub list: Vec<TransactionLog>,
67}
68
69#[cfg(test)]
70mod tests {
71 use super::*;
72 use crate::rest::client::ServerResponse;
73 use serde_json::from_str;
74
75 #[test]
76 fn test_deserialize_transaction_log() {
77 let json_data = r#"
78 {
79 "retCode": 0,
80 "retMsg": "OK",
81 "result": {
82 "nextPageCursor": "cursor123",
83 "list": [
84 {
85 "id": "12345",
86 "symbol": "BTCUSDT",
87 "side": "Buy",
88 "funding": "0.0001",
89 "orderLinkId": "link123",
90 "orderId": "order123",
91 "fee": "0.0005",
92 "change": "0.1",
93 "cashFlow": "0.05",
94 "transactionTime": "1690872862481",
95 "type": "TRADE",
96 "feeRate": "0.0006",
97 "bonusChange": "0",
98 "size": "100",
99 "qty": "0.1",
100 "cashBalance": "1000",
101 "currency": "USDT",
102 "category": "spot",
103 "tradePrice": "30000",
104 "tradeId": "trade123"
105 }
106 ]
107 },
108 "retExtInfo": {},
109 "time": 1690872862481
110 }
111 "#;
112 let response: ServerResponse<TransactionLogResult> =
113 from_str(json_data).expect("Failed to deserialize TransactionLogResult");
114 assert_eq!(response.ret_code, 0);
115 let result = response.result;
116 assert_eq!(result.list.len(), 1);
117 assert_eq!(result.list[0].symbol, "BTCUSDT");
118 assert_eq!(result.list[0].trade_id, "trade123");
119 }
120}