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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//! Types for dealing with scanner data and scanner subscriptions
use std::fmt::{Display, Error, Formatter};

use serde::{Deserialize, Serialize};

use crate::core::contract::ContractDetails;

//==================================================================================================

#[derive(Serialize, Deserialize, Clone, Default, Debug)]
pub struct ScanData {
    pub contract: ContractDetails,
    pub rank: i32,
    pub distance: String,
    pub benchmark: String,
    pub projection: String,
    pub legs: String,
}

impl ScanData {
    pub fn new(
        contract: ContractDetails,
        rank: i32,
        distance: String,
        benchmark: String,
        projection: String,
        legs: String,
    ) -> Self {
        ScanData {
            contract,
            rank,
            distance,
            benchmark,
            projection,
            legs,
        }
    }
}

impl Display for ScanData {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
        write!(f, "Rank: {}, Symbol: {}, SecType: {}, Currency: {}, Distance: {}, Benchmark: {}, Projection: {}, Legs: {}",
               self.rank, self.contract.contract.symbol, self.contract.contract.sec_type, self.contract.contract.currency,
               self.distance, self.benchmark, self.projection, self.legs)
    }
}

//==================================================================================================
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct ScannerSubscription {
    pub number_of_rows: i32,
    pub instrument: String,
    pub location_code: String,
    pub scan_code: String,
    pub above_price: f64,
    pub below_price: f64,
    pub above_volume: i32,
    pub market_cap_above: f64,
    pub market_cap_below: f64,
    pub moody_rating_above: String,
    pub moody_rating_below: String,
    pub sp_rating_above: String,
    pub sp_rating_below: String,
    pub maturity_date_above: String,
    pub maturity_date_below: String,
    pub coupon_rate_above: f64,
    pub coupon_rate_below: f64,
    pub exclude_convertible: bool,
    pub average_option_volume_above: i32,
    pub scanner_setting_pairs: String,
    pub stock_type_filter: String,
}

impl ScannerSubscription {
    pub fn new(
        number_of_rows: i32,
        instrument: String,
        location_code: String,
        scan_code: String,
        above_price: f64,
        below_price: f64,
        above_volume: i32,
        market_cap_above: f64,
        market_cap_below: f64,
        moody_rating_above: String,
        moody_rating_below: String,
        sp_rating_above: String,
        sp_rating_below: String,
        maturity_date_above: String,
        maturity_date_below: String,
        coupon_rate_above: f64,
        coupon_rate_below: f64,
        exclude_convertible: bool,
        average_option_volume_above: i32,
        scanner_setting_pairs: String,
        stock_type_filter: String,
    ) -> Self {
        ScannerSubscription {
            number_of_rows,
            instrument,
            location_code,
            scan_code,
            above_price,
            below_price,
            above_volume,
            market_cap_above,
            market_cap_below,
            moody_rating_above,
            moody_rating_below,
            sp_rating_above,
            sp_rating_below,
            maturity_date_above,
            maturity_date_below,
            coupon_rate_above,
            coupon_rate_below,
            exclude_convertible,
            average_option_volume_above,
            scanner_setting_pairs,
            stock_type_filter,
        }
    }
}

impl Display for ScannerSubscription {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
        write!(
            f,
            "Instrument: {}, LocationCode: {}, ScanCode: {}",
            self.instrument, self.location_code, self.scan_code
        )
    }
}