Skip to content

Commit

Permalink
feat: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ts0yu committed Feb 28, 2024
1 parent 974a930 commit 1f956f7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ clap = { version = "4.4.8", features = ["derive"] }
serde_json = "1.0.113"
log = "0.4.20"
futures-util = "0.3.30"
RustQuant = "0.0.49"
RustQuant = "0.0.49"
futures = "0.3.30"
4 changes: 2 additions & 2 deletions src/behaviors/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use crate::bindings::uniswap_v3_factory::UniswapV3Factory;

#[derive(Debug, Deserialize, Serialize)]
pub struct DeploymentData {
factory: H160,
liquid_exchange: H160,
pub factory: H160,
pub liquid_exchange: H160,
}

impl DeploymentData {
Expand Down
25 changes: 20 additions & 5 deletions src/behaviors/price_changer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use std::{fmt, sync::Arc};

use anyhow::Result;
use arbiter_core::middleware::ArbiterMiddleware;
use crate::behaviors::deployer::DeploymentData;
use arbiter_engine::messager::{Message, Messager};
use ethers::types::H160;
use futures::stream::StreamExt;
use RustQuant::{
models::*,
stochastics::{process::Trajectories, *},
Expand All @@ -27,6 +29,8 @@ pub struct PriceChanger {
#[serde(skip)]
pub client: Option<Arc<ArbiterMiddleware>>,

pub liquid_exchange: Option<H160>,

cursor: usize,
value: f64,
}
Expand All @@ -45,9 +49,7 @@ impl fmt::Debug for PriceChanger {
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PriceUpdate {
liquid_exchange: H160,
}
pub struct PriceUpdate;

impl PriceChanger {
/// Public constructor function to create a [`PriceChanger`] behaviour.
Expand All @@ -66,6 +68,7 @@ impl PriceChanger {
current_chunk,
cursor: 0,
client: None,
liquid_exchange: None,
value: initial_value,
}
}
Expand All @@ -76,10 +79,22 @@ impl Behavior<Message> for PriceChanger {
async fn startup(
&mut self,
client: Arc<ArbiterMiddleware>,
_messager: Messager,
messager: Messager,
) -> Result<Option<EventStream<Message>>> {
self.client = Some(client);

loop {
while let Some(message) = messager.clone().stream().unwrap().next().await {
match serde_json::from_str::<DeploymentData>(&message.data) {
Ok(data) => {
self.liquid_exchange = Some(data.liquid_exchange);
break;
},
Err(_) => continue,
};
}
}

Ok(None)
}

Expand All @@ -103,7 +118,7 @@ impl Behavior<Message> for PriceChanger {
}

let liquid_exchange =
LiquidExchange::new(query.liquid_exchange, self.client.clone().unwrap());
LiquidExchange::new(self.liquid_exchange.unwrap(), self.client.clone().unwrap());

let price = self.current_chunk.paths.clone()[0][self.cursor];

Expand Down

0 comments on commit 1f956f7

Please sign in to comment.