lightcone_sdk/api/types/
trade.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
7#[serde(rename_all = "UPPERCASE")]
8pub enum ApiTradeSide {
9 Bid,
11 Ask,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct Trade {
18 pub id: i64,
20 pub orderbook_id: String,
22 pub taker_pubkey: String,
24 pub maker_pubkey: String,
26 pub side: ApiTradeSide,
28 pub size: String,
30 pub price: String,
32 pub taker_fee: String,
34 pub maker_fee: String,
36 pub executed_at: i64,
38}
39
40#[derive(Debug, Clone, Default, Serialize, Deserialize)]
42pub struct TradesParams {
43 pub orderbook_id: String,
45 #[serde(skip_serializing_if = "Option::is_none")]
47 pub user_pubkey: Option<String>,
48 #[serde(skip_serializing_if = "Option::is_none")]
50 pub from: Option<i64>,
51 #[serde(skip_serializing_if = "Option::is_none")]
53 pub to: Option<i64>,
54 #[serde(skip_serializing_if = "Option::is_none")]
56 pub cursor: Option<i64>,
57 #[serde(skip_serializing_if = "Option::is_none")]
59 pub limit: Option<u32>,
60}
61
62impl TradesParams {
63 pub fn new(orderbook_id: impl Into<String>) -> Self {
65 Self {
66 orderbook_id: orderbook_id.into(),
67 ..Default::default()
68 }
69 }
70
71 pub fn with_user(mut self, user_pubkey: impl Into<String>) -> Self {
73 self.user_pubkey = Some(user_pubkey.into());
74 self
75 }
76
77 pub fn with_time_range(mut self, from: i64, to: i64) -> Self {
79 self.from = Some(from);
80 self.to = Some(to);
81 self
82 }
83
84 pub fn with_cursor(mut self, cursor: i64) -> Self {
86 self.cursor = Some(cursor);
87 self
88 }
89
90 pub fn with_limit(mut self, limit: u32) -> Self {
92 self.limit = Some(limit);
93 self
94 }
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize)]
99pub struct TradesResponse {
100 pub orderbook_id: String,
102 pub trades: Vec<Trade>,
104 pub next_cursor: Option<i64>,
106 pub has_more: bool,
108}