rusty_feeder/exchange/bybit/data/
trade.rs1use rust_decimal::Decimal;
2use rusty_common::collections::FxHashMap;
3use serde::{Deserialize, Serialize};
4use simd_json::OwnedValue as Value;
5use smartstring::alias::String;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct TradeResponse {
10 pub topic: String,
12 pub data: Vec<TradeData>,
14 pub ts: u64,
16 pub type_field: Option<String>,
18}
19
20#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct TradeData {
23 pub symbol: String,
25 pub tick_direction: String,
27 pub price: Decimal,
29 pub size: Decimal,
31 pub timestamp: String,
33 pub trade_time_ms: u64,
35 pub side: String,
37 pub trade_id: String,
39 #[serde(default)]
41 pub is_block_trade: bool,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct TradeHistoryResponse {
47 pub ret_code: i32,
49 pub ret_msg: String,
51 pub result: TradeHistoryResult,
53 pub ext_info: Option<FxHashMap<String, Value>>,
55 pub time_now: String,
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
61pub struct TradeHistoryResult {
62 pub list: Vec<TradeData>,
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct PingRequest {
69 pub op: String,
71 pub args: Vec<String>,
73}
74
75impl Default for PingRequest {
76 fn default() -> Self {
77 Self::new()
78 }
79}
80
81impl PingRequest {
82 #[must_use]
84 pub fn new() -> Self {
85 Self {
86 op: "ping".into(),
87 args: vec![],
88 }
89 }
90}
91
92#[cfg(test)]
93mod tests {
94 use super::*;
95
96 #[test]
97 fn test_ping_request_serialization() {
98 let ping = PingRequest::new();
99 let json = simd_json::to_string(&ping).unwrap();
100 let json = String::from(&json);
101 assert_eq!(json, r#"{"op":"ping","args":[]}"#);
102 }
103}