Skip to content

Commit 2f75568

Browse files
committed
style: _
1 parent 31dda1b commit 2f75568

File tree

5 files changed

+60
-63
lines changed

5 files changed

+60
-63
lines changed

discretionary_engine/src/config.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ pub struct AppConfig {
2727
#[settings(flatten)]
2828
pub risk: Option<RiskConfig>,
2929
}
30+
impl AppConfig {
31+
pub fn get_exchange(&self, exchange: ExchangeName) -> Result<&ExchangeConfig> {
32+
self.exchanges.get(&exchange.to_string()).ok_or_else(|| eyre!("{exchange} exchange config not found"))
33+
}
34+
}
3035

3136
#[derive(Clone, Debug, v_macros::MyConfigPrimitives)]
3237
pub struct ExchangeConfig {
@@ -65,9 +70,3 @@ pub struct RiskLayersConfig {
6570
#[serde(default)]
6671
pub lost_last_trade: bool,
6772
}
68-
69-
impl AppConfig {
70-
pub fn get_exchange(&self, exchange: ExchangeName) -> Result<&ExchangeConfig> {
71-
self.exchanges.get(&exchange.to_string()).ok_or_else(|| eyre!("{exchange} exchange config not found"))
72-
}
73-
}

discretionary_engine/src/exchange_apis/binance/info.rs

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -81,36 +81,6 @@ pub struct RateLimit {
8181
// multiplierDecimal: u32,
8282
//}
8383

84-
#[serde_as]
85-
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
86-
#[serde(rename_all = "camelCase")]
87-
pub struct FuturesSymbol {
88-
pub symbol: String,
89-
pub pair: String,
90-
pub contract_type: String,
91-
pub delivery_date: i64,
92-
pub onboard_date: i64,
93-
pub status: String,
94-
pub base_asset: String,
95-
pub quote_asset: String,
96-
pub margin_asset: String,
97-
pub price_precision: u32,
98-
pub quantity_precision: u32,
99-
pub base_asset_precision: u32,
100-
pub quote_precision: u32,
101-
pub underlying_type: String,
102-
pub underlying_sub_type: Vec<String>,
103-
pub settle_plan: Option<u32>,
104-
pub trigger_protect: String,
105-
pub filters: Vec<Value>,
106-
pub order_type: Option<Vec<String>>,
107-
pub time_in_force: Vec<String>,
108-
#[serde_as(as = "DisplayFromStr")]
109-
pub liquidation_fee: f64,
110-
#[serde_as(as = "DisplayFromStr")]
111-
pub market_take_bound: f64,
112-
}
113-
11484
#[derive(Clone, Debug, Deserialize, Serialize)]
11585
#[serde(tag = "filterType")]
11686
pub enum Filter {
@@ -196,6 +166,35 @@ pub struct PercentPriceFilter {
196166
pub multiplier_decimal: u8,
197167
}
198168

169+
#[serde_as]
170+
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
171+
#[serde(rename_all = "camelCase")]
172+
pub struct FuturesSymbol {
173+
pub symbol: String,
174+
pub pair: String,
175+
pub contract_type: String,
176+
pub delivery_date: i64,
177+
pub onboard_date: i64,
178+
pub status: String,
179+
pub base_asset: String,
180+
pub quote_asset: String,
181+
pub margin_asset: String,
182+
pub price_precision: u32,
183+
pub quantity_precision: u32,
184+
pub base_asset_precision: u32,
185+
pub quote_precision: u32,
186+
pub underlying_type: String,
187+
pub underlying_sub_type: Vec<String>,
188+
pub settle_plan: Option<u32>,
189+
pub trigger_protect: String,
190+
pub filters: Vec<Value>,
191+
pub order_type: Option<Vec<String>>,
192+
pub time_in_force: Vec<String>,
193+
#[serde_as(as = "DisplayFromStr")]
194+
pub liquidation_fee: f64,
195+
#[serde_as(as = "DisplayFromStr")]
196+
pub market_take_bound: f64,
197+
}
199198
impl FuturesSymbol {
200199
fn get_filter<T: for<'de> Deserialize<'de>>(&self, filter_type: &str) -> Option<T> {
201200
self.filters.iter().find_map(|filter| {

discretionary_engine/src/positions.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,18 @@ impl PositionAcquisition {
108108
}
109109
}
110110

111-
#[derive(Clone, Debug, Default, derive_new::new)]
112-
pub struct PositionFollowup {
113-
_acquisition: PositionAcquisition,
114-
protocols_spec: Vec<Protocol>,
115-
closed_notional: f64,
116-
}
117-
118111
#[derive(Clone, Debug, derive_new::new)]
119112
pub struct HubToPosition {
120113
pub sender: mpsc::Sender<ProtocolFills>,
121114
pub position_id: Uuid,
122115
}
123116

117+
#[derive(Clone, Debug, Default, derive_new::new)]
118+
pub struct PositionFollowup {
119+
_acquisition: PositionAcquisition,
120+
protocols_spec: Vec<Protocol>,
121+
closed_notional: f64,
122+
}
124123
impl PositionFollowup {
125124
#[instrument(skip(hub_tx, exchanges_arc))]
126125
pub async fn do_followup(__acquisition: PositionAcquisition, protocols: Vec<Protocol>, hub_tx: mpsc::Sender<PositionToHub>, exchanges_arc: Arc<Exchanges>) -> Result<Self> {

discretionary_engine/src/protocols/mod.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,6 @@ pub enum Protocol {
4444
ApproachingLimit(ApproachingLimitWrapper),
4545
DummyMarket(DummyMarketWrapper),
4646
}
47-
impl FromStr for Protocol {
48-
type Err = eyre::Report;
49-
50-
fn from_str(spec: &str) -> Result<Self> {
51-
if let Ok(ts) = TrailingStopWrapper::from_str(spec) {
52-
Ok(Protocol::TrailingStop(ts))
53-
} else if let Ok(sar) = SarWrapper::from_str(spec) {
54-
Ok(Protocol::Sar(sar))
55-
} else if let Ok(al) = ApproachingLimitWrapper::from_str(spec) {
56-
Ok(Protocol::ApproachingLimit(al))
57-
} else if let Ok(dm) = DummyMarketWrapper::from_str(spec) {
58-
Ok(Protocol::DummyMarket(dm))
59-
} else {
60-
bail!("Could not convert string to any Protocol\nString: {spec}")
61-
}
62-
}
63-
}
6447
impl Protocol {
6548
pub fn attach(&self, position_set: &mut JoinSet<Result<()>>, tx_orders: mpsc::Sender<ProtocolOrders>, asset: String, protocol_side: Side) -> Result<()> {
6649
match self {
@@ -107,6 +90,23 @@ impl Protocol {
10790
}
10891
}
10992
}
93+
impl FromStr for Protocol {
94+
type Err = eyre::Report;
95+
96+
fn from_str(spec: &str) -> Result<Self> {
97+
if let Ok(ts) = TrailingStopWrapper::from_str(spec) {
98+
Ok(Protocol::TrailingStop(ts))
99+
} else if let Ok(sar) = SarWrapper::from_str(spec) {
100+
Ok(Protocol::Sar(sar))
101+
} else if let Ok(al) = ApproachingLimitWrapper::from_str(spec) {
102+
Ok(Protocol::ApproachingLimit(al))
103+
} else if let Ok(dm) = DummyMarketWrapper::from_str(spec) {
104+
Ok(Protocol::DummyMarket(dm))
105+
} else {
106+
bail!("Could not convert string to any Protocol\nString: {spec}")
107+
}
108+
}
109+
}
110110

111111
#[derive(Clone, Debug, derive_new::new)]
112112
pub enum ProtocolParams {

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)