1#![allow(unused)]
2
3use crate::prelude::*;
4
5#[derive(Debug, Deserialize, Serialize, Clone)]
6#[allow(missing_docs)]
7pub struct HistoryItem {
8 pub average: f64,
9 pub date: String,
10 pub highest: f64,
11 pub lowest: f64,
12 pub order_count: i64,
13 pub volume: i64,
14}
15
16#[derive(Debug, Deserialize)]
17#[allow(missing_docs)]
18pub struct MarketOrder {
19 pub duration: i64,
20 pub is_buy_order: bool,
21 pub issued: String,
22 pub location_id: i64,
23 pub min_volume: i64,
24 pub order_id: i64,
25 pub price: f64,
26 pub range: String,
27 pub system_id: i64,
28 pub type_id: i64,
29 pub volume_remain: i64,
30 pub volume_total: i64,
31}
32
33#[derive(Debug, Deserialize, Serialize, Clone)]
34#[allow(missing_docs)]
35pub struct PriceItem {
36 pub adjusted_price: Option<f64>,
37 pub average_price: Option<f64>,
38 pub type_id: i64,
39}
40
41#[derive(Debug, Deserialize, Serialize, Clone)]
42#[allow(missing_docs)]
43pub struct CharacterOrder {
44 pub duration: i64,
45 pub escrow: Option<f64>,
46 pub is_buy_order: Option<bool>,
47 pub is_corporation: bool,
48 pub issued: String,
49 pub location_id: i64,
50 pub min_volume: Option<i64>,
51 pub order_id: i64,
52 pub price: f64,
53 pub range: String,
54 pub region_id: i64,
55 pub type_id: i64,
56 pub volume_remain: i64,
57 pub volume_total: i64,
58}
59
60pub struct MarketGroup<'a> {
62 pub(crate) esi: &'a Esi,
63}
64
65impl MarketGroup<'_> {
66 api_get!(
67 get_region_history,
69 "GetMarketsRegionIdHistory",
70 RequestType::Public,
71 Vec<HistoryItem>,
72 (region_id: i64) => "{region_id}";
73 (type_id: i64) => "type_id"
74 );
75
76 api_get!(
77 get_region_orders,
79 "GetMarketsRegionIdOrders",
80 RequestType::Public,
81 Vec<MarketOrder>,
82 (region_id: i64) => "{region_id}";
83 Optional(order_type: String) => "order_type",
84 Optional(page: i32) => "page",
85 Optional(type_id: i64) => "type_id"
86 );
87
88 api_get!(
89 get_market_prices,
91 "GetMarketsPrices",
92 RequestType::Public,
93 Vec<PriceItem>,
94 );
95
96 api_get!(
97 get_character_orders,
99 "GetCharactersCharacterIdOrders",
100 RequestType::Authenticated,
101 Vec<CharacterOrder>,
102 (character_id: i64) => "{character_id}"
103 );
104}
105
106#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
108#[allow(missing_docs)]
109pub struct MarketGroupInfo {
110 pub description: String,
111 pub market_group_id: i64,
112 pub name: String,
113 pub parent_group_id: Option<i64>,
114 pub types: Vec<i64>,
115}
116
117impl MarketGroup<'_> {
118 api_get!(
119 get_groups,
121 "GetMarketsGroups",
122 RequestType::Public,
123 Vec<i64>,
124 );
125
126 api_get!(
127 get_group,
129 "GetMarketsGroupsMarketGroupId",
130 RequestType::Public,
131 MarketGroupInfo,
132 (market_group_id: i64) => "{market_group_id}"
133 );
134
135 api_get!(
136 get_region_types,
138 "GetMarketsRegionIdTypes",
139 RequestType::Public,
140 Vec<i64>,
141 (region_id: i64) => "{region_id}";
142 Optional(page: i32) => "page"
143 );
144}
145
146#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
148pub enum OrderRange {
149 #[serde(rename = "station")]
151 Station,
152 #[serde(rename = "region")]
154 Region,
155 #[serde(rename = "solarsystem")]
157 SolarSystem,
158 #[serde(rename = "1")]
160 Jumps1,
161 #[serde(rename = "2")]
163 Jumps2,
164 #[serde(rename = "3")]
166 Jumps3,
167 #[serde(rename = "4")]
169 Jumps4,
170 #[serde(rename = "5")]
172 Jumps5,
173 #[serde(rename = "10")]
175 Jumps10,
176 #[serde(rename = "20")]
178 Jumps20,
179 #[serde(rename = "30")]
181 Jumps30,
182 #[serde(rename = "40")]
184 Jumps40,
185 #[serde(other)]
187 Unrecognized,
188}
189
190#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
192#[serde(rename_all = "snake_case")]
193pub enum ClosedOrderState {
194 Cancelled,
196 Expired,
198 #[serde(other)]
200 Unrecognized,
201}
202
203#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
205#[allow(missing_docs)]
206pub struct CharacterOrderHistory {
207 pub duration: i64,
208 pub escrow: Option<f64>,
209 pub is_buy_order: Option<bool>,
210 pub is_corporation: bool,
211 pub issued: String,
212 pub location_id: i64,
213 pub min_volume: Option<i64>,
214 pub order_id: i64,
215 pub price: f64,
216 pub range: OrderRange,
217 pub region_id: i64,
218 pub state: ClosedOrderState,
219 pub type_id: i64,
220 pub volume_remain: i64,
221 pub volume_total: i64,
222}
223
224#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
226#[allow(missing_docs)]
227pub struct CorporationOrder {
228 pub duration: i64,
229 pub escrow: Option<f64>,
230 pub is_buy_order: Option<bool>,
231 pub issued: String,
232 pub issued_by: i64,
233 pub location_id: i64,
234 pub min_volume: Option<i64>,
235 pub order_id: i64,
236 pub price: f64,
237 pub range: OrderRange,
238 pub region_id: i64,
239 pub type_id: i64,
240 pub volume_remain: i64,
241 pub volume_total: i64,
242 pub wallet_division: i64,
243}
244
245#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
247#[allow(missing_docs)]
248pub struct CorporationOrderHistory {
249 pub duration: i64,
250 pub escrow: Option<f64>,
251 pub is_buy_order: Option<bool>,
252 pub issued: String,
253 pub issued_by: Option<i64>,
254 pub location_id: i64,
255 pub min_volume: Option<i64>,
256 pub order_id: i64,
257 pub price: f64,
258 pub range: OrderRange,
259 pub region_id: i64,
260 pub state: ClosedOrderState,
261 pub type_id: i64,
262 pub volume_remain: i64,
263 pub volume_total: i64,
264 pub wallet_division: i64,
265}
266
267#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
269#[allow(missing_docs)]
270pub struct StructureOrder {
271 pub duration: i64,
272 pub is_buy_order: bool,
273 pub issued: String,
274 pub location_id: i64,
275 pub min_volume: i64,
276 pub order_id: i64,
277 pub price: f64,
278 pub range: OrderRange,
279 pub type_id: i64,
280 pub volume_remain: i64,
281 pub volume_total: i64,
282}
283
284impl MarketGroup<'_> {
285 api_get!(
286 get_character_orders_history,
288 "GetCharactersCharacterIdOrdersHistory",
289 RequestType::Authenticated,
290 Vec<CharacterOrderHistory>,
291 (character_id: i64) => "{character_id}";
292 Optional(page: i32) => "page"
293 );
294
295 api_get!(
296 get_corporation_orders,
298 "GetCorporationsCorporationIdOrders",
299 RequestType::Authenticated,
300 Vec<CorporationOrder>,
301 (corporation_id: i64) => "{corporation_id}";
302 Optional(page: i32) => "page"
303 );
304
305 api_get!(
306 get_corporation_orders_history,
308 "GetCorporationsCorporationIdOrdersHistory",
309 RequestType::Authenticated,
310 Vec<CorporationOrderHistory>,
311 (corporation_id: i64) => "{corporation_id}";
312 Optional(page: i32) => "page"
313 );
314
315 api_get!(
316 get_structure_orders,
318 "GetMarketsStructuresStructureId",
319 RequestType::Authenticated,
320 Vec<StructureOrder>,
321 (structure_id: i64) => "{structure_id}";
322 Optional(page: i32) => "page"
323 );
324}
325
326#[cfg(test)]
327mod order_history_tests {
328 use super::*;
329
330 #[test]
331 fn test_parse_ranges_and_states() {
332 let ranges: Vec<OrderRange> =
333 serde_json::from_str(r#"["station","solarsystem","10","weird"]"#).unwrap();
334 assert_eq!(
335 ranges,
336 [
337 OrderRange::Station,
338 OrderRange::SolarSystem,
339 OrderRange::Jumps10,
340 OrderRange::Unrecognized
341 ]
342 );
343 let order: CorporationOrderHistory = serde_json::from_str(
344 r#"{"duration":90,"issued":"x","location_id":1,"order_id":2,"price":1.5,"range":"region",
345 "region_id":3,"state":"expired","type_id":4,"volume_remain":0,"volume_total":5,"wallet_division":1}"#,
346 )
347 .unwrap();
348 assert_eq!(order.state, ClosedOrderState::Expired);
349 assert!(order.issued_by.is_none());
350 }
351}