skyblock_rs/objects/
bazaar.rs1#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
3pub struct Product {
4 pub product_id: String,
6 #[deprecated]
9 #[serde(skip_serializing_if = "Option::is_none")]
10 pub week_historic: Option<Vec<Historic>>,
11 #[serde(flatten)]
13 pub live_data: LiveProductData,
14}
15
16#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
18pub struct LiveProductData {
19 pub buy_summary: Vec<Order>,
21 pub sell_summary: Vec<Order>,
23 pub quick_status: QuickStatus,
25}
26
27impl LiveProductData {
28 pub fn top_buy(&self) -> f64 {
29 let mut top = f64::NEG_INFINITY;
30
31 for order in &self.buy_summary {
32 if top < order.price_per_unit {
33 top = order.price_per_unit
34 }
35 }
36
37 return top;
38 }
39
40 pub fn top_sell(&self) -> f64 {
41 let mut top = f64::INFINITY;
42
43 for order in &self.sell_summary {
44 if top > order.price_per_unit {
45 top = order.price_per_unit
46 }
47 }
48
49 return top;
50 }
51}
52
53#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
54pub struct QuickStatus {
55 #[serde(rename = "productId")]
56 pub product_id: String,
57 #[serde(rename = "buyPrice")]
59 pub buy_price: f32,
60 #[serde(rename = "buyVolume")]
62 pub buy_volume: f32,
63 #[serde(rename = "buyMovingWeek")]
65 pub buy_moving_week: f32,
66 #[serde(rename = "buyOrders")]
68 pub buy_orders: f32,
69 #[serde(rename = "sellPrice")]
71 pub sell_price: f32,
72 #[serde(rename = "sellVolume")]
74 pub sell_volume: f32,
75 #[serde(rename = "sellMovingWeek")]
77 pub sell_moving_week: f32,
78 #[serde(rename = "sellOrders")]
80 pub sell_orders: f32,
81}
82
83#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
84pub struct Historic {
85 #[serde(rename = "productId")]
86 pub product_id: String,
87 pub timestamp: i64,
88 #[serde(rename = "nowBuyVolume")]
90 pub market_demand: f32,
91 #[serde(rename = "nowSellVolume")]
93 pub market_supply: f32,
94 #[serde(rename = "buyCoins")]
96 pub buy_coins: f32,
97 #[serde(rename = "buyVolume")]
99 pub buy_volume: f32,
100 #[serde(rename = "buys")]
102 pub instant_buys: f32,
103 #[serde(rename = "sellCoins")]
105 pub sell_coins: f32,
106 #[serde(rename = "sellVolume")]
108 pub sell_volume: f32,
109 #[serde(rename = "sells")]
111 pub instant_sells: f32,
112}
113
114impl Historic {
115 pub fn recent_instant_buy_price(&self) -> f32 {
117 self.sell_coins / self.sell_volume
118 }
119
120 pub fn recent_instant_sell_price(&self) -> f32 {
122 self.buy_coins / self.buy_volume
123 }
124}
125
126#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
127pub struct Order {
128 pub amount: i32,
130 #[serde(rename = "pricePerUnit")]
132 pub price_per_unit: f64,
133 pub orders: i32,
135}