bpx_api_types/
fill.rs

1use super::{history::SortDirection, markets::MarketType, order::Side};
2use rust_decimal::Decimal;
3
4#[derive(
5    Debug, strum::Display, Clone, Copy, serde::Serialize, serde::Deserialize, strum::EnumString, PartialEq, Eq, Hash,
6)]
7#[strum(serialize_all = "PascalCase")]
8#[serde(rename_all = "PascalCase")]
9pub enum FillType {
10    User,
11    BookLiquidation,
12    Adl,
13    Backstop,
14    Liquidation,
15    AllLiquidation,
16    CollateralConversion,
17    CollateralConversionAndSpotLiquidation,
18}
19
20#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
21#[serde(rename_all = "camelCase")]
22pub struct Fill {
23    pub trade_id: Option<i64>,
24    pub client_id: Option<String>,
25    pub order_id: String,
26    pub symbol: String,
27    pub fee_symbol: String,
28    pub price: Decimal,
29    pub quantity: Decimal,
30    pub fee: Decimal,
31    pub side: Side,
32    pub timestamp: String,
33    pub is_maker: bool,
34    pub system_order_type: Option<String>,
35}
36
37#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
38pub struct FillsHistoryParams {
39    /// Filter by symbol
40    pub symbol: Option<String>,
41    /// From timestamp in milliseconds
42    pub from: Option<i64>,
43    /// To timestamp in milliseconds
44    pub to: Option<i64>,
45    /// Filter by fill type
46    pub fill_type: Option<FillType>,
47    /// Filter by market type
48    pub market_type: Option<MarketType>,
49    /// Filter by order ID
50    pub order_id: Option<String>,
51    /// Filter by strategy ID
52    pub strategy_id: Option<String>,
53    /// Maximum number of results to return
54    pub limit: Option<u64>,
55    /// Offset for pagination - default to 0
56    pub offset: Option<u64>,
57    /// Sort direction
58    pub sort_direction: Option<SortDirection>,
59}
60
61impl FillsHistoryParams {
62    pub fn with_symbol<S: Into<String>>(mut self, symbol: S) -> Self {
63        self.symbol = Some(symbol.into());
64        self
65    }
66
67    pub fn with_from(mut self, from: i64) -> Self {
68        self.from = Some(from);
69        self
70    }
71
72    pub fn with_to(mut self, to: i64) -> Self {
73        self.to = Some(to);
74        self
75    }
76
77    pub fn with_fill_type(mut self, fill_type: FillType) -> Self {
78        self.fill_type = Some(fill_type);
79        self
80    }
81
82    pub fn with_market_type(mut self, market_type: MarketType) -> Self {
83        self.market_type = Some(market_type);
84        self
85    }
86
87    pub fn with_order_id<S: Into<String>>(mut self, order_id: S) -> Self {
88        self.order_id = Some(order_id.into());
89        self
90    }
91
92    pub fn with_strategy_id<S: Into<String>>(mut self, strategy_id: S) -> Self {
93        self.strategy_id = Some(strategy_id.into());
94        self
95    }
96
97    pub fn with_limit(mut self, limit: u64) -> Self {
98        self.limit = Some(limit);
99        self
100    }
101
102    pub fn with_offset(mut self, offset: u64) -> Self {
103        self.offset = Some(offset);
104        self
105    }
106
107    pub fn with_sort_direction(mut self, sort_direction: SortDirection) -> Self {
108        self.sort_direction = Some(sort_direction);
109        self
110    }
111}