From cac2c2c6c64591be2d8d8eb327245098fd46c9ba Mon Sep 17 00:00:00 2001 From: Justin Carter Date: Thu, 16 Feb 2023 09:23:59 +0100 Subject: [PATCH] chore: remove shared exchanges_config.rs (#292) --- bitfinex-client/src/client/mod.rs | 12 +- .../tests/bitfinex_client_tests.rs | 1 - shared/src/exchanges_config.rs | 116 ------------------ shared/src/lib.rs | 1 - 4 files changed, 11 insertions(+), 119 deletions(-) delete mode 100644 shared/src/exchanges_config.rs diff --git a/bitfinex-client/src/client/mod.rs b/bitfinex-client/src/client/mod.rs index 2704b336d..1a5f457d0 100644 --- a/bitfinex-client/src/client/mod.rs +++ b/bitfinex-client/src/client/mod.rs @@ -10,8 +10,8 @@ use reqwest::{ }; use ring::hmac; use rust_decimal::Decimal; +use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; -use shared::exchanges_config::BitfinexConfig; use tracing::instrument; use std::{collections::HashMap, time::Duration}; @@ -33,6 +33,16 @@ const REST_API_V2_URL: &str = "https://api.bitfinex.com/v2"; const REST_API_R_SIGNATURE_PATH: &str = "/api/v2/auth/r"; const REST_API_W_SIGNATURE_PATH: &str = "/api/v2/auth/w"; +#[derive(Serialize, Deserialize, Debug, Clone, Default)] +pub struct BitfinexConfig { + #[serde(default)] + pub api_key: String, + #[serde(default)] + pub secret_key: String, + #[serde(default)] + pub simulated: bool, +} + #[derive(Clone)] pub struct BitfinexClient { client: ReqwestClient, diff --git a/bitfinex-client/tests/bitfinex_client_tests.rs b/bitfinex-client/tests/bitfinex_client_tests.rs index 521713273..3d0fa9ac1 100644 --- a/bitfinex-client/tests/bitfinex_client_tests.rs +++ b/bitfinex-client/tests/bitfinex_client_tests.rs @@ -4,7 +4,6 @@ use bitfinex_client::*; use rust_decimal_macros::dec; use serial_test::serial; -use shared::exchanges_config::BitfinexConfig; async fn configured_client() -> anyhow::Result { let api_key = env::var("BITFINEX_API_KEY")?; diff --git a/shared/src/exchanges_config.rs b/shared/src/exchanges_config.rs deleted file mode 100644 index 03caf4b7a..000000000 --- a/shared/src/exchanges_config.rs +++ /dev/null @@ -1,116 +0,0 @@ -use rust_decimal::Decimal; -use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use std::fmt::Debug; - -#[derive(Serialize, Deserialize, Debug, Clone, Default)] -pub struct ExchangeConfigs { - pub okex: Option>, - pub bitfinex: Option>, -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -pub struct ExchangeConfig { - pub weight: Decimal, - #[serde(bound = "T: DeserializeOwned")] - #[serde(default)] - pub config: T, -} - -#[derive(Serialize, Deserialize, Debug, Clone, Default)] -pub struct OkexConfig { - #[serde(default)] - pub api_key: String, - #[serde(default)] - pub passphrase: String, - #[serde(default)] - pub secret_key: String, - #[serde(default)] - pub simulated: bool, -} - -#[derive(Serialize, Deserialize, Debug, Clone, Default)] -pub struct BitfinexConfig { - #[serde(default)] - pub api_key: String, - #[serde(default)] - pub secret_key: String, - #[serde(default)] - pub simulated: bool, -} - -#[cfg(test)] -mod test_super { - use super::*; - use rust_decimal_macros::dec; - - #[test] - fn test_default() { - let config = ExchangeConfigs::default(); - assert!(config.okex.is_none()); - } - - #[test] - fn test_deserialize() { - let str = r#" - okex: - weight: 0.8 - config: - api_key: okex api key - "#; - let ex: ExchangeConfigs = serde_yaml::from_str(str).expect("Couldn't deserialize yaml"); - - let okex = ex.okex.expect("Okex-config not found"); - assert_eq!(dec!(0.8), okex.weight); - assert_eq!("okex api key", okex.config.api_key); - } - - #[test] - fn test_serialize() -> anyhow::Result<()> { - let ok = ExchangeConfig { - weight: dec!(0.8), - config: OkexConfig { - api_key: "okex api key".to_string(), - passphrase: "okex passphrase".to_string(), - secret_key: "okex secret key".to_string(), - simulated: false, - }, - }; - - let bit = ExchangeConfig { - weight: dec!(0.8), - config: BitfinexConfig { - api_key: "bitfinex api key".to_string(), - secret_key: "bitfinex secret key".to_string(), - simulated: false, - }, - }; - - let data = ExchangeConfigs { - okex: Some(ok), - bitfinex: Some(bit), - }; - let result = serde_yaml::to_string(&data)?; - assert!(result.contains("okex passphrase")); - Ok(()) - } - - #[test] - fn test_deserialize_new() -> anyhow::Result<()> { - let str = r#" - okex: - weight: 1 - config: - api_key: okex api - bitfinex: - weight: 3 - config: - api_key: bitfinex api - "#; - let ex: ExchangeConfigs = serde_yaml::from_str(str)?; - let okex_cfg = ex.okex.expect("Okex-config not found"); - assert_eq!(dec!(1), okex_cfg.weight); - let bitfinex_cfg = ex.bitfinex.expect("Bitfinex-config not found"); - assert_eq!(dec!(3), bitfinex_cfg.weight); - Ok(()) - } -} diff --git a/shared/src/lib.rs b/shared/src/lib.rs index f796129d5..467ca08c5 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -1,7 +1,6 @@ #![cfg_attr(feature = "fail-on-warnings", deny(warnings))] #![cfg_attr(feature = "fail-on-warnings", deny(clippy::all))] -pub mod exchanges_config; pub mod health; pub mod macros; pub mod payload;