🔧 PROGRESS: Import path fixes and type cleanup

- Fixed missing imports in backtesting and risk-data crates
- Corrected ConnectionStatus usage patterns
- Fixed ConfigManager constructor calls
- Resolved Interactive Brokers config conversions
- Added proper Decimal import patterns

NEXT: Aggressive duplicate type system elimination with parallel agents

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
jgrusewski
2025-09-26 16:16:16 +02:00
parent ea9d8f2c88
commit d92a9664eb
23 changed files with 202 additions and 642 deletions

View File

@@ -13,6 +13,7 @@ use std::{
use anyhow::{Context, Result};
use chrono::{DateTime, Utc};
use common::types::Timestamp;
use trading_engine::types::prelude::{Symbol, Decimal, Quantity, MarketEvent, Price};
use crossbeam_channel::{bounded, Receiver, Sender};
use dashmap::DashMap;
use serde::{Deserialize, Serialize};

View File

@@ -20,9 +20,10 @@ use serde::{Deserialize, Serialize};
use tokio::sync::{mpsc, RwLock};
use tracing::{debug, error, info, warn};
use trading_engine::types::basic::{
Order, OrderId, OrderStatus, OrderType, Position, Price, Quantity, Side as OrderSide, Symbol,
Order, OrderId, Position, Price, Quantity, Side as OrderSide, Symbol,
TimeInForce,
};
use common::types::{OrderStatus, OrderType};
use trading_engine::types::events::MarketEvent;
use trading_engine::types::prelude::*;
use uuid::Uuid;
@@ -447,10 +448,11 @@ impl StrategyTester {
for (symbol, position) in positions {
if let Some(market_event) = self.market_data.get(&symbol) {
let current_price = self.extract_price_from_event(&market_event)?;
let position_value = position.quantity.to_decimal().unwrap_or_default()
* Price::from(current_price).to_decimal().unwrap_or_default();
let position_decimal = position.quantity.to_decimal().unwrap_or(Decimal::ZERO);
let price_decimal = Price::from(current_price).to_decimal().unwrap_or(Decimal::ZERO);
let position_value = position_decimal * price_decimal;
if position.quantity.to_decimal().unwrap_or_default() >= Decimal::ZERO {
if position_decimal >= Decimal::ZERO {
total_value += position_value;
} else {
// Short position
@@ -525,6 +527,25 @@ impl StrategyTester {
false
}
}
OrderType::TrailingStop => {
// For backtesting, treat as stop order
if let Some(order_price) = order.price {
match order.side {
OrderSide::Buy => current_price >= order_price,
OrderSide::Sell => current_price <= order_price,
}
} else {
false
}
}
OrderType::Hidden => {
// For backtesting, treat as market order
true
}
_ => {
// Default case for any other order types
false
}
}
}
@@ -552,8 +573,8 @@ impl StrategyTester {
// Update account
let mut account = self.account.write().await;
let trade_value = order.quantity.to_decimal().unwrap_or_default()
* execution_price.to_decimal().unwrap_or_default();
let trade_value = order.quantity.to_decimal().unwrap_or(Decimal::ZERO)
* execution_price.to_decimal().unwrap_or(Decimal::ZERO);
match order.side {
OrderSide::Buy => {
@@ -634,16 +655,16 @@ impl StrategyTester {
/// Apply slippage to execution price
fn apply_slippage(&self, price: Price, order: &Order) -> Price {
let slippage = price.to_decimal().unwrap_or_default() * self.config.slippage_factor;
let slippage = price.to_decimal().unwrap_or(Decimal::ZERO) * self.config.slippage_factor;
match order.side {
OrderSide::Buy => Price::from_f64(
(price.to_decimal().unwrap_or_default() + slippage)
(price.to_decimal().unwrap_or(Decimal::ZERO) + slippage)
.try_into()
.unwrap_or(0.0),
)
.unwrap_or(Price::zero()),
OrderSide::Sell => Price::from_f64(
(price.to_decimal().unwrap_or_default() - slippage)
(price.to_decimal().unwrap_or(Decimal::ZERO) - slippage)
.try_into()
.unwrap_or(0.0),
)
@@ -653,8 +674,8 @@ impl StrategyTester {
/// Calculate commission for trade
fn calculate_commission(&self, order: &Order, price: Price) -> Decimal {
let trade_value = order.quantity.to_decimal().unwrap_or_default()
* price.to_decimal().unwrap_or_default();
let trade_value = order.quantity.to_decimal().unwrap_or(Decimal::ZERO)
* price.to_decimal().unwrap_or(Decimal::ZERO);
trade_value * self.config.commission_rate
}
@@ -667,8 +688,8 @@ impl StrategyTester {
ask_price,
..
} => {
let avg_price = (bid_price.to_decimal().unwrap_or_default()
+ ask_price.to_decimal().unwrap_or_default())
let avg_price = (bid_price.to_decimal().unwrap_or(Decimal::ZERO)
+ ask_price.to_decimal().unwrap_or(Decimal::ZERO))
/ Decimal::from(2);
Ok(Price::from_f64(avg_price.try_into().unwrap_or(0.0)).unwrap_or(Price::ZERO))
}