1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#![allow(unused)]

use crate::prelude::*;

#[derive(Debug, Deserialize, Serialize, Clone)]
#[allow(missing_docs)]
pub struct HistoryItem {
    pub average: f64,
    pub date: String,
    pub highest: f64,
    pub lowest: f64,
    pub order_count: i64,
    pub volume: i64,
}

#[derive(Debug, Deserialize)]
#[allow(missing_docs)]
pub struct MarketOrder {
    pub duration: i32,
    pub is_buy_order: bool,
    pub issued: String,
    pub location_id: i64,
    pub min_volume: i32,
    pub order_id: i64,
    pub price: f64,
    pub range: String,
    pub system_id: i32,
    pub type_id: i32,
    pub volume_remain: i32,
    pub volume_total: i32,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[allow(missing_docs)]
pub struct PriceItem {
    pub adjusted_price: Option<f64>,
    pub average_price: Option<f64>,
    pub type_id: i32,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[allow(missing_docs)]
pub struct CharacterOrder {
    pub duration: i32,
    pub escrow: Option<f64>,
    pub is_buy_order: Option<bool>,
    pub is_corporation: bool,
    pub issued: String,
    pub location_id: i64,
    pub min_volume: Option<i32>,
    pub order_id: i64,
    pub price: f64,
    pub range: String,
    pub region_id: i32,
    pub type_id: i32,
    pub volume_remain: i32,
    pub volume_total: i32,
}

/// Endpoints for Market
pub struct MarketGroup<'a> {
    pub(crate) esi: &'a Esi,
}

impl<'a> MarketGroup<'a> {
    api_get!(
        /// Get a list of historical market statistics for the specified type in a region
        get_region_history,
        "get_markets_region_id_history",
        RequestType::Public,
        Vec<HistoryItem>,
        (region_id: i32) => "{region_id}";
        (type_id: i32) => "type_id"
    );

    api_get!(
        /// Get a list of orders in a region
        get_region_orders,
        "get_markets_region_id_orders",
        RequestType::Public,
        Vec<MarketOrder>,
        (region_id: i32) => "{region_id}";
        Optional(order_type: String) => "order_type",
        Optional(page: i32) => "page",
        Optional(type_id: i32) => "type_id"
    );

    api_get!(
        /// Get a list of average and adjusted prices
        get_market_prices,
        "get_markets_prices",
        RequestType::Public,
        Vec<PriceItem>,
    );

    api_get!(
        /// List open market orders placed by a character
        get_character_orders,
        "get_characters_character_id_orders",
        RequestType::Authenticated,
        Vec<CharacterOrder>,
        (character_id: i32) => "{character_id}"
    );
}