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
use crate::FuturesTypes;
use crate::{Error, Result};

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
/// Define the Exchange configuration
pub struct Config {
    /// The maker fee as a fraction. e.g.: 2.5 basis points rebate -> -0.00025
    fee_maker: f64,
    /// The taker fee as a fraction. e.g.: 10 basis points -> 0.0010
    fee_taker: f64,
    /// The starting balance of account
    starting_balance: f64,
    /// The leverage used for the position
    leverage: f64,
    /// The type of futures to simulate
    futures_type: FuturesTypes,
}

impl Config {
    /// Create a new Config
    /// # Returns
    /// Either a valid Config or an Error
    #[must_use]
    #[inline]
    pub fn new(
        fee_maker: f64,
        fee_taker: f64,
        starting_balance: f64,
        leverage: f64,
        futures_type: FuturesTypes,
    ) -> Result<Config> {
        if leverage < 1.0 {
            return Err(Error::ConfigWrongLeverage);
        }
        if starting_balance <= 0.0 {
            return Err(Error::ConfigWrongStartingBalance);
        }
        Ok(Config {
            fee_maker,
            fee_taker,
            starting_balance,
            leverage,
            futures_type,
        })
    }

    /// Return the maker fee of this config
    #[inline(always)]
    pub fn fee_maker(&self) -> f64 {
        self.fee_maker
    }

    /// Return the taker fee of this config
    #[inline(always)]
    pub fn fee_taker(&self) -> f64 {
        self.fee_taker
    }

    /// Return the starting wallet balance of this Config
    #[inline(always)]
    pub fn starting_balance(&self) -> f64 {
        self.starting_balance
    }

    /// Return the leverage of the Config
    #[inline(always)]
    pub fn leverage(&self) -> f64 {
        self.leverage
    }

    /// Return the FuturesType of the Config
    #[inline(always)]
    pub fn futures_type(&self) -> FuturesTypes {
        self.futures_type
    }
}