Skip to main content

esi_openapi/groups/
market.rs

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
60/// Endpoints for Market
61pub struct MarketGroup<'a> {
62    pub(crate) esi: &'a Esi,
63}
64
65impl MarketGroup<'_> {
66    api_get!(
67        /// Get a list of historical market statistics for the specified type in a region
68        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 a list of orders in a region
78        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 a list of average and adjusted prices
90        get_market_prices,
91        "GetMarketsPrices",
92        RequestType::Public,
93        Vec<PriceItem>,
94    );
95
96    api_get!(
97        /// List open market orders placed by a character
98        get_character_orders,
99        "GetCharactersCharacterIdOrders",
100        RequestType::Authenticated,
101        Vec<CharacterOrder>,
102        (character_id: i64) => "{character_id}"
103    );
104}
105
106/// Information about a market group.
107#[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        /// List the IDs of all market groups.
120        get_groups,
121        "GetMarketsGroups",
122        RequestType::Public,
123        Vec<i64>,
124    );
125
126    api_get!(
127        /// Get information about a market group.
128        get_group,
129        "GetMarketsGroupsMarketGroupId",
130        RequestType::Public,
131        MarketGroupInfo,
132        (market_group_id: i64) => "{market_group_id}"
133    );
134
135    api_get!(
136        /// List the type IDs that have active orders in a region.
137        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/// How far away a market order can be matched.
147#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
148pub enum OrderRange {
149    /// Only at the order's station.
150    #[serde(rename = "station")]
151    Station,
152    /// Within the whole region.
153    #[serde(rename = "region")]
154    Region,
155    /// Within the solar system.
156    #[serde(rename = "solarsystem")]
157    SolarSystem,
158    /// Within 1 jump.
159    #[serde(rename = "1")]
160    Jumps1,
161    /// Within 2 jumps.
162    #[serde(rename = "2")]
163    Jumps2,
164    /// Within 3 jumps.
165    #[serde(rename = "3")]
166    Jumps3,
167    /// Within 4 jumps.
168    #[serde(rename = "4")]
169    Jumps4,
170    /// Within 5 jumps.
171    #[serde(rename = "5")]
172    Jumps5,
173    /// Within 10 jumps.
174    #[serde(rename = "10")]
175    Jumps10,
176    /// Within 20 jumps.
177    #[serde(rename = "20")]
178    Jumps20,
179    /// Within 30 jumps.
180    #[serde(rename = "30")]
181    Jumps30,
182    /// Within 40 jumps.
183    #[serde(rename = "40")]
184    Jumps40,
185    /// A range this version of the crate does not know about.
186    #[serde(other)]
187    Unrecognized,
188}
189
190/// Final state of a market order that is no longer open.
191#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
192#[serde(rename_all = "snake_case")]
193pub enum ClosedOrderState {
194    /// The order was cancelled.
195    Cancelled,
196    /// The order expired.
197    Expired,
198    /// A state this version of the crate does not know about.
199    #[serde(other)]
200    Unrecognized,
201}
202
203/// A closed market order of a character.
204#[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/// An open market order of a corporation.
225#[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/// A closed market order of a corporation.
246#[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/// An order in a player-owned structure market.
268#[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        /// List cancelled and expired market orders placed by a character (up to 90 days).
287        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        /// List open market orders placed on behalf of a corporation.
297        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        /// List cancelled and expired market orders placed on behalf of a corporation.
307        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        /// List orders in a structure's market.
317        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}