Skip to content

Commit

Permalink
adding data type as a parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
JordyRo1 committed Jan 23, 2024
1 parent 7664372 commit 47acabd
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ lazy_static! {
"on_off_price_deviation",
"On chain price deviation from the reference price"
),
&["network", "pair"]
&["network", "pair", "type"]
)
.unwrap();
pub static ref API_TIME_SINCE_LAST_UPDATE: GaugeVec = register_gauge_vec!(
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ async fn main() {
let database_url: String = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
let config = AsyncDieselConnectionManager::<diesel_async::AsyncPgConnection>::new(database_url);
let pool = Pool::builder(config).build().unwrap();

// Monitor spot/future in parallel
let spot_monitoring = tokio::spawn(monitor(pool.clone(), true, &DataType::Spot));
let future_monitoring = tokio::spawn(monitor(pool.clone(), true, &DataType::Future));
Expand Down
19 changes: 9 additions & 10 deletions src/monitoring/on_off_deviation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ use crate::{
config::{get_config, DataType},
constants::COINGECKO_IDS,
error::MonitoringError,
types::Entry,
};

pub async fn on_off_price_deviation<T: Entry>(
pub async fn on_off_price_deviation(
pair_id: String,
timestamp: u64,
data_type: DataType,
) -> Result<(f64, u32), MonitoringError> {
let ids = &COINGECKO_IDS;
let config = get_config(None).await;
Expand All @@ -37,14 +37,13 @@ pub async fn on_off_price_deviation<T: Entry>(
.await
.map_err(|e| MonitoringError::OnChain(e.to_string()))?;

let decimals =
config
.decimals(DataType::Spot)
.get(&pair_id)
.ok_or(MonitoringError::OnChain(format!(
"Failed to get decimals for pair {:?}",
pair_id
)))?;
let decimals = config
.decimals(data_type)
.get(&pair_id)
.ok_or(MonitoringError::OnChain(format!(
"Failed to get decimals for pair {:?}",
pair_id
)))?;

let on_chain_price = data
.first()
Expand Down
2 changes: 1 addition & 1 deletion src/processing/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub async fn process_data_by_pair_and_sources(
}

let (on_off_deviation, _) =
on_off_price_deviation::<FutureEntry>(pair.clone(), *timestamps.last().unwrap()).await?;
on_off_price_deviation(pair.clone(), *timestamps.last().unwrap(), DataType::Future).await?;
ON_OFF_PRICE_DEVIATION
.with_label_values(&[network_env, &pair.clone(), data_type])
.set(on_off_deviation);
Expand Down
2 changes: 1 addition & 1 deletion src/processing/spot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub async fn process_data_by_pair_and_sources(
timestamps.push(res);
}
let (on_off_deviation, _) =
on_off_price_deviation::<SpotEntry>(pair.clone(), *timestamps.last().unwrap()).await?;
on_off_price_deviation(pair.clone(), *timestamps.last().unwrap(), DataType::Spot).await?;
ON_OFF_PRICE_DEVIATION
.with_label_values(&[network_env, &pair.clone(), data_type])
.set(on_off_deviation);
Expand Down

0 comments on commit 47acabd

Please sign in to comment.