rusty_feeder/exchange/coinbase/data/trade.rs
1use rust_decimal::Decimal;
2use serde::{Deserialize, Serialize};
3use smartstring::alias::String;
4
5/// Coinbase WebSocket match/trade message
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct TradeMessage {
8 /// Message type (always "match" or "last_match")
9 #[serde(rename = "type")]
10 pub message_type: String,
11 /// Unique trade identifier
12 pub trade_id: u64,
13 /// Order ID of the maker
14 pub maker_order_id: String,
15 /// Order ID of the taker
16 pub taker_order_id: String,
17 /// Side of the trade ("buy" or "sell")
18 pub side: String,
19 /// Quantity of the trade
20 pub size: Decimal,
21 /// Price of the trade
22 pub price: Decimal,
23 /// Trading pair identifier
24 pub product_id: String,
25 /// Sequence number for ordering
26 pub sequence: u64,
27 /// Trade timestamp in ISO 8601 format
28 pub time: String,
29}
30
31/// Coinbase WebSocket ticker message
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct TickerMessage {
34 /// Message type (always "ticker")
35 #[serde(rename = "type")]
36 pub message_type: String,
37 /// Sequence number for ordering
38 pub sequence: u64,
39 /// Trading pair identifier
40 pub product_id: String,
41 /// Current price
42 pub price: Decimal,
43 /// Opening price 24 hours ago
44 pub open_24h: Decimal,
45 /// Trading volume in the last 24 hours
46 pub volume_24h: Decimal,
47 /// Lowest price in the last 24 hours
48 pub low_24h: Decimal,
49 /// Highest price in the last 24 hours
50 pub high_24h: Decimal,
51 /// Trading volume in the last 30 days
52 pub volume_30d: Decimal,
53 /// Best bid price
54 pub best_bid: Decimal,
55 /// Best ask price
56 pub best_ask: Decimal,
57 /// Side of the last trade
58 pub side: String,
59 /// Timestamp in ISO 8601 format
60 pub time: String,
61 /// ID of the last trade
62 pub trade_id: u64,
63 /// Size of the last trade
64 pub last_size: Decimal,
65}
66
67/// Coinbase WebSocket heartbeat message
68#[derive(Debug, Clone, Serialize, Deserialize)]
69pub struct HeartbeatMessage {
70 /// Message type (always "heartbeat")
71 #[serde(rename = "type")]
72 pub message_type: String,
73 /// Sequence number for ordering
74 pub sequence: u64,
75 /// ID of the last trade
76 pub last_trade_id: u64,
77 /// Trading pair identifier
78 pub product_id: String,
79 /// Timestamp in ISO 8601 format
80 pub time: String,
81}
82
83/// Coinbase WebSocket status message
84#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct StatusMessage {
86 /// Message type (always "status")
87 #[serde(rename = "type")]
88 pub message_type: String,
89 /// List of product statuses
90 pub products: Vec<ProductStatus>,
91 /// List of currency statuses
92 pub currencies: Vec<CurrencyStatus>,
93}
94
95/// Product status information
96#[derive(Debug, Clone, Serialize, Deserialize)]
97pub struct ProductStatus {
98 /// Product identifier (e.g., "BTC-USD")
99 pub id: String,
100 /// Base currency code
101 pub base_currency: String,
102 /// Quote currency code
103 pub quote_currency: String,
104 /// Minimum order size in base currency
105 pub base_min_size: Decimal,
106 /// Maximum order size in base currency
107 pub base_max_size: Decimal,
108 /// Minimum price increment
109 pub quote_increment: Decimal,
110 /// Trading status (e.g., "online", "offline")
111 pub status: String,
112 /// Optional status message
113 pub status_message: Option<String>,
114}
115
116/// Currency status information
117#[derive(Debug, Clone, Serialize, Deserialize)]
118pub struct CurrencyStatus {
119 /// Currency identifier (e.g., "BTC")
120 pub id: String,
121 /// Human-readable currency name
122 pub name: String,
123 /// Minimum transaction size
124 pub min_size: Decimal,
125 /// Currency status (e.g., "online", "offline")
126 pub status: String,
127 /// Optional status message
128 pub status_message: Option<String>,
129}
130
131/// Coinbase WebSocket error message
132#[derive(Debug, Clone, Serialize, Deserialize)]
133pub struct ErrorMessage {
134 /// Message type (always "error")
135 #[serde(rename = "type")]
136 pub message_type: String,
137 /// Error message description
138 pub message: String,
139 /// Optional reason for the error
140 pub reason: Option<String>,
141}