ibtwsapi/core/
scanner.rs

1//! Types for dealing with scanner data and scanner subscriptions
2use std::fmt::{Display, Error, Formatter};
3
4use serde::{Deserialize, Serialize};
5
6use crate::core::contract::ContractDetails;
7
8//==================================================================================================
9
10#[derive(Serialize, Deserialize, Clone, Default, Debug)]
11pub struct ScanData {
12    pub contract: ContractDetails,
13    pub rank: i32,
14    pub distance: String,
15    pub benchmark: String,
16    pub projection: String,
17    pub legs: String,
18}
19
20impl ScanData {
21    pub fn new(
22        contract: ContractDetails,
23        rank: i32,
24        distance: String,
25        benchmark: String,
26        projection: String,
27        legs: String,
28    ) -> Self {
29        ScanData {
30            contract,
31            rank,
32            distance,
33            benchmark,
34            projection,
35            legs,
36        }
37    }
38}
39
40impl Display for ScanData {
41    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
42        write!(f, "Rank: {}, Symbol: {}, SecType: {}, Currency: {}, Distance: {}, Benchmark: {}, Projection: {}, Legs: {}",
43               self.rank, self.contract.contract.symbol, self.contract.contract.sec_type, self.contract.contract.currency,
44               self.distance, self.benchmark, self.projection, self.legs)
45    }
46}
47
48//==================================================================================================
49#[derive(Serialize, Deserialize, Debug, Clone, Default)]
50pub struct ScannerSubscription {
51    pub number_of_rows: i32,
52    pub instrument: String,
53    pub location_code: String,
54    pub scan_code: String,
55    pub above_price: f64,
56    pub below_price: f64,
57    pub above_volume: i32,
58    pub market_cap_above: f64,
59    pub market_cap_below: f64,
60    pub moody_rating_above: String,
61    pub moody_rating_below: String,
62    pub sp_rating_above: String,
63    pub sp_rating_below: String,
64    pub maturity_date_above: String,
65    pub maturity_date_below: String,
66    pub coupon_rate_above: f64,
67    pub coupon_rate_below: f64,
68    pub exclude_convertible: bool,
69    pub average_option_volume_above: i32,
70    pub scanner_setting_pairs: String,
71    pub stock_type_filter: String,
72}
73
74impl ScannerSubscription {
75    pub fn new(
76        number_of_rows: i32,
77        instrument: String,
78        location_code: String,
79        scan_code: String,
80        above_price: f64,
81        below_price: f64,
82        above_volume: i32,
83        market_cap_above: f64,
84        market_cap_below: f64,
85        moody_rating_above: String,
86        moody_rating_below: String,
87        sp_rating_above: String,
88        sp_rating_below: String,
89        maturity_date_above: String,
90        maturity_date_below: String,
91        coupon_rate_above: f64,
92        coupon_rate_below: f64,
93        exclude_convertible: bool,
94        average_option_volume_above: i32,
95        scanner_setting_pairs: String,
96        stock_type_filter: String,
97    ) -> Self {
98        ScannerSubscription {
99            number_of_rows,
100            instrument,
101            location_code,
102            scan_code,
103            above_price,
104            below_price,
105            above_volume,
106            market_cap_above,
107            market_cap_below,
108            moody_rating_above,
109            moody_rating_below,
110            sp_rating_above,
111            sp_rating_below,
112            maturity_date_above,
113            maturity_date_below,
114            coupon_rate_above,
115            coupon_rate_below,
116            exclude_convertible,
117            average_option_volume_above,
118            scanner_setting_pairs,
119            stock_type_filter,
120        }
121    }
122}
123
124impl Display for ScannerSubscription {
125    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
126        write!(
127            f,
128            "Instrument: {}, LocationCode: {}, ScanCode: {}",
129            self.instrument, self.location_code, self.scan_code
130        )
131    }
132}