Skip to content

Commit

Permalink
Merge branch 'main' into add-bothan-api
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerKSI authored Feb 27, 2024
2 parents fa59475 + cfeb0d2 commit f71b766
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
22 changes: 9 additions & 13 deletions bothan-binance/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,15 @@ async fn save_datum(data: &Data, cache: &Arc<Cache<PriceData>>) {
timestamp: ticker.event_time,
};
info!("received prices: {:?}", price_data);
match cache.set_data(ticker.symbol.clone(), price_data).await {
Ok(_) => {
info!("successfully set {} in cache", ticker.symbol);
}
Err(CacheError::PendingNotSet) => {
warn!(
"received data for id that was not pending: {}",
ticker.symbol
);
}
Err(e) => {
error!("error setting data in cache: {:?}", e)
}
let id = price_data.id.clone();
if cache
.set_data(ticker.symbol.clone(), price_data)
.await
.is_err()
{
warn!("unexpected request to set data for id: {}", id);
} else {
info!("set price for id {}", id);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion bothan-coingecko/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ reqwest = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
serde ={ workspace = true }
serde = { workspace = true }
tokio = { workspace = true }


Expand Down
4 changes: 2 additions & 2 deletions bothan-coingecko/src/api/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub(crate) mod test {
(server, api)
}

pub(crate) trait MockGecko {
pub(crate) trait MockCoinGecko {
fn set_successful_coin_list(&mut self, coin_list: &[Coin]) -> Mock;
fn set_failed_coin_list(&mut self) -> Mock;
fn set_successful_coins_market(&mut self, ids: &[&str], market: &[Market]) -> Vec<Mock>;
Expand All @@ -94,7 +94,7 @@ pub(crate) mod test {
fn set_failed_coins_market(&mut self, ids: &[&str]) -> Mock;
}

impl MockGecko for ServerGuard {
impl MockCoinGecko for ServerGuard {
fn set_successful_coin_list(&mut self, coin_list: &[Coin]) -> Mock {
self.mock("GET", "/coins/list")
.with_status(200)
Expand Down
16 changes: 9 additions & 7 deletions bothan-coingecko/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use std::sync::Arc;

use chrono::NaiveDateTime;
use futures::future::join_all;
use futures::stream::FuturesUnordered;
use tokio::select;
use tokio::sync::RwLock;
use tokio::time::{interval, Duration, Interval};
use tracing::warn;
use tracing::{info, warn};

use bothan_core::cache::{Cache, Error as CacheError};
use bothan_core::service::{Error as ServiceError, Service, ServiceResult};
use bothan_core::types::PriceData;
use futures::stream::FuturesUnordered;

use crate::api::types::Market;
use crate::api::CoinGeckoRestAPI;
Expand Down Expand Up @@ -73,7 +73,7 @@ impl Service for CoinGeckoService {
}
}
Err(CacheError::Invalid) => Err(ServiceError::InvalidSymbol),
Err(_) => Err(ServiceError::Pending),
Err(e) => panic!("unexpected error: {}", e), // This should never happen
})
.collect();

Expand Down Expand Up @@ -172,18 +172,20 @@ async fn update_coin_list(
let mut locked = coin_list.write().await;
*locked = new_coin_set;
} else {
warn!("Failed to get coin list");
warn!("failed to get coin list");
}
}

async fn process_market_data(market: &Market, cache: &Arc<Cache<PriceData>>) {
if let Ok(price_data) = parse_market(market) {
let id = price_data.id.clone();
if cache.set_data(id.clone(), price_data).await.is_err() {
warn!("Unexpected request to set data for id: {}", id);
warn!("unexpected request to set data for id: {}", id);
} else {
info!("set price for id {}", id);
}
} else {
warn!("Failed to parse date time");
warn!("failed to parse date time");
}
}

Expand All @@ -205,7 +207,7 @@ fn parse_market(market: &Market) -> Result<PriceData, Error> {
mod test {
use mockito::ServerGuard;

use crate::api::rest::test::{setup as api_setup, MockGecko};
use crate::api::rest::test::{setup as api_setup, MockCoinGecko};
use crate::api::types::Coin;

use super::*;
Expand Down

0 comments on commit f71b766

Please sign in to comment.