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
use serde::{Deserialize, Serialize};

use crate::{client::Client, error::Error};

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StockListFilter {
    pub country_codes: Vec<String>,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StockListSortBy {
    pub field: String,
    pub order: String,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StockListRequest {
    pub filter: StockListFilter,
    pub limit: u32,
    pub offset: u32,
    pub sort_by: StockListSortBy,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Instrument {
    pub orderbook_id: String,
    pub r#type: String,
    pub name: String,
    pub short_name: String,
    pub currency: String,
    pub country_code: String,
    pub direct_yield: f64,
    pub price_earnings_ratio: f64,
    pub number_of_owners: u32,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StockListResponsePagination {
    pub offset: u32,
    pub limit: u32
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StockListResponse {
    pub stocks: Vec<Instrument>,
    pub total_number_of_orderbooks: u32,
    pub pagination: StockListResponsePagination,
}

impl Client {
    pub async fn get_stock_list(
        &self,
        request: &StockListRequest,
    ) -> Result<StockListResponse, Error> {
        let res = self
            .http_client
            .post(&self.config.urls.stock_list)
            .body_json(&request)?
            .recv_json::<StockListResponse>()
            .await?;
        return Ok(res);
    }
}