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
use crate::FuturesTypes;
use crate::{Error, Result};
#[derive(Debug, Clone, 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,
/// To identify an exchange by a code
identification: String,
}
impl Config {
/// Create a new Config
/// # Arguments
/// fee_maker: The maker fee as fraction, e.g 6bp -> 0.0006
/// fee_taker: The taker fee as fraction
/// starting_balance: Initial Wallet Balance, denoted in QUOTE if using linear futures, denoted in BASE for inverse futures
/// leverage: The positions leverage
/// futures_type: The type of futures contract to simulate
/// identification: A way to identify an exchange
/// # 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,
identification: String,
) -> 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,
identification,
})
}
/// 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
}
/// Return the exchange identification
#[inline(always)]
pub fn identification(&self) -> &str {
&self.identification
}
}