cleanup: delete sqlx_test placeholder and restore BrokerAdapter alias
- common/sqlx_test.rs: the entire module was a single /* ... */ block behind a TODO because the identifier types (`OrderId`, `TradeId`, `Symbol`, `AccountId`, `OrderSide`) do not derive `sqlx::Type`. The file has been a dead placeholder behind `#[cfg(all(test, feature=\"database\"))]` for a long time; delete it and drop the `mod sqlx_test;` declaration. - data/brokers/mod.rs: re-enable the `pub type BrokerAdapter = Box<dyn BrokerClient>;` alias — the trait is already implemented by `InteractiveBrokersAdapter` and re-exported from the module. Delete the commented-out `BrokerFactory::create_client` block: it referenced `ICMarketsClient`, which does not exist in this crate. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -130,7 +130,3 @@ pub use crate::observability::{
|
||||
// Test utilities module (available for all tests)
|
||||
#[cfg(test)]
|
||||
pub mod test_utils;
|
||||
|
||||
// Test module for database features
|
||||
#[cfg(all(test, feature = "database"))]
|
||||
mod sqlx_test;
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
//! SQLx trait implementation tests for identifier types
|
||||
//! Temporarily disabled due to incomplete SQLx trait implementations
|
||||
|
||||
// TODO: Re-enable once SQLx traits are properly implemented for all types
|
||||
/*
|
||||
#[cfg(all(test, feature = "database"))]
|
||||
mod tests {
|
||||
use crate::types::*;
|
||||
use sqlx::{Postgres, TypeInfo};
|
||||
|
||||
/// Test OrderId SQLx serialization/deserialization
|
||||
#[test]
|
||||
fn test_order_id_sqlx() {
|
||||
let order_id = OrderId::new();
|
||||
|
||||
// Test that OrderId can be used in SQLx queries (compile-time check)
|
||||
let type_info = <OrderId as sqlx::Type<Postgres>>::type_info();
|
||||
let _: bool = sqlx::types::Type::<Postgres>::compatible(&type_info);
|
||||
}
|
||||
|
||||
/// Test TradeId SQLx serialization/deserialization
|
||||
#[test]
|
||||
fn test_trade_id_sqlx() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let trade_id = TradeId::new("TRADE-001")?;
|
||||
|
||||
// Test that TradeId can be used in SQLx queries (compile-time check)
|
||||
let type_info = <TradeId as sqlx::Type<Postgres>>::type_info();
|
||||
let _: bool = sqlx::types::Type::<Postgres>::compatible(&type_info);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Test Symbol SQLx serialization/deserialization
|
||||
#[test]
|
||||
fn test_symbol_sqlx() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let symbol = Symbol::new_validated("AAPL".to_owned())?;
|
||||
|
||||
// Test that Symbol can be used in SQLx queries (compile-time check)
|
||||
let type_info = <Symbol as sqlx::Type<Postgres>>::type_info();
|
||||
let _: bool = sqlx::types::Type::<Postgres>::compatible(&type_info);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Test AccountId SQLx serialization/deserialization
|
||||
#[test]
|
||||
fn test_account_id_sqlx() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let account_id = AccountId::new("ACC-001")?;
|
||||
|
||||
// Test that AccountId can be used in SQLx queries (compile-time check)
|
||||
let type_info = <AccountId as sqlx::Type<Postgres>>::type_info();
|
||||
let _: bool = sqlx::types::Type::<Postgres>::compatible(&type_info);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Test OrderSide SQLx serialization/deserialization
|
||||
#[test]
|
||||
fn test_order_side_sqlx() {
|
||||
let buy_side = OrderSide::Buy;
|
||||
let sell_side = OrderSide::Sell;
|
||||
|
||||
// Test that OrderSide can be used in SQLx queries (compile-time check)
|
||||
let type_info = <OrderSide as sqlx::Type<Postgres>>::type_info();
|
||||
let _: bool = sqlx::types::Type::<Postgres>::compatible(&type_info);
|
||||
}
|
||||
|
||||
/// Test that transparent newtypes work with underlying PostgreSQL types
|
||||
#[test]
|
||||
fn test_transparent_type_mapping() {
|
||||
// OrderId should map to BIGINT (i64/u64)
|
||||
assert_eq!(
|
||||
<OrderId as sqlx::Type<Postgres>>::type_info().name(),
|
||||
"BIGINT"
|
||||
);
|
||||
|
||||
// String-based types should map to TEXT
|
||||
assert_eq!(
|
||||
<TradeId as sqlx::Type<Postgres>>::type_info().name(),
|
||||
"TEXT"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
<AccountId as sqlx::Type<Postgres>>::type_info().name(),
|
||||
"TEXT"
|
||||
);
|
||||
|
||||
// OrderSide should map to TEXT
|
||||
assert_eq!(
|
||||
<OrderSide as sqlx::Type<Postgres>>::type_info().name(),
|
||||
"TEXT"
|
||||
);
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -124,13 +124,11 @@ pub use interactive_brokers::{IBConfig, InteractiveBrokersAdapter};
|
||||
/// Re-export common broker client trait
|
||||
pub use common::BrokerClient;
|
||||
|
||||
// Create alias for BrokerAdapter (used in examples)
|
||||
// TODO: Re-enable when BrokerClient trait is implemented
|
||||
// /// Type alias for boxed broker client trait objects
|
||||
// ///
|
||||
// /// Provides a convenient way to work with different broker implementations
|
||||
// /// through a common interface without knowing the specific type at compile time.
|
||||
// pub type BrokerAdapter = Box<dyn BrokerClient>;
|
||||
/// Type alias for boxed broker client trait objects.
|
||||
///
|
||||
/// Provides a convenient way to work with different broker implementations
|
||||
/// through a common interface without knowing the specific type at compile time.
|
||||
pub type BrokerAdapter = Box<dyn BrokerClient>;
|
||||
|
||||
/// Enumeration of supported broker types and their protocols.
|
||||
///
|
||||
@@ -364,75 +362,4 @@ impl BrokerFactory {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Uncomment when BrokerClient trait is restored
|
||||
/*
|
||||
/// Create a broker client based on configuration.
|
||||
///
|
||||
/// Instantiates the appropriate broker client implementation based on
|
||||
/// the broker type and configuration provided. Validates configuration
|
||||
/// before attempting to create the client.
|
||||
///
|
||||
/// # Parameters
|
||||
///
|
||||
/// * `broker_type` - Type of broker client to create
|
||||
/// * `config` - JSON configuration object with broker-specific settings
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Boxed broker client implementing the `BrokerClient` trait.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns `DataError` if:
|
||||
/// - Configuration is invalid or missing required fields
|
||||
/// - Broker type is not yet implemented
|
||||
/// - Client initialization fails
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// use data::brokers::{BrokerFactory, BrokerType};
|
||||
/// use serde_json::json;
|
||||
///
|
||||
/// let config = json!({
|
||||
/// "host": "127.0.0.1",
|
||||
/// "port": 7497,
|
||||
/// "client_id": 1
|
||||
/// });
|
||||
///
|
||||
/// let client = BrokerFactory::create_client(
|
||||
/// BrokerType::InteractiveBrokers,
|
||||
/// config
|
||||
/// ).await?;
|
||||
/// ```
|
||||
pub async fn create_client(
|
||||
broker_type: BrokerType,
|
||||
config: serde_json::Value
|
||||
) -> crate::Result<Box<dyn BrokerClient>> {
|
||||
// Validate configuration first
|
||||
Self::validate_config(&broker_type, &config)
|
||||
.map_err(|e| crate::DataError::configuration(&e))?;
|
||||
|
||||
match broker_type {
|
||||
BrokerType::ICMarkets => {
|
||||
let icmarkets_config: ICMarketsConfig = serde_json::from_value(config)
|
||||
.map_err(|e| crate::DataError::configuration(&format!("Invalid ICMarkets config: {}", e)))?;
|
||||
let client = ICMarketsClient::new(icmarkets_config);
|
||||
Ok(Box::new(client))
|
||||
}
|
||||
BrokerType::InteractiveBrokers => {
|
||||
let ib_config: IBConfig = serde_json::from_value(config)
|
||||
.map_err(|e| crate::DataError::configuration(&format!("Invalid IB config: {}", e)))?;
|
||||
let client = InteractiveBrokersAdapter::new(ib_config);
|
||||
Ok(Box::new(client))
|
||||
}
|
||||
BrokerType::Alpaca => {
|
||||
Err(crate::DataError::configuration("Alpaca broker not yet implemented"))
|
||||
}
|
||||
BrokerType::Mock => {
|
||||
Err(crate::DataError::configuration("Mock broker not yet implemented"))
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user