fixed up rust system
This commit is contained in:
parent
063f4c8e27
commit
a58072cf93
7 changed files with 255 additions and 44 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{MarketUpdate, Order, Fill, TradingMode, MarketDataSource, ExecutionHandler, TimeProvider};
|
||||
use crate::{MarketUpdate, Order, Fill, TradingMode, MarketDataSource, ExecutionHandler, TimeProvider, Side};
|
||||
use crate::positions::PositionTracker;
|
||||
use crate::risk::RiskEngine;
|
||||
use crate::orderbook::OrderBookManager;
|
||||
|
|
@ -18,6 +18,16 @@ pub use event::{BacktestEvent, EventType};
|
|||
pub use strategy::{Strategy, Signal, SignalType};
|
||||
pub use results::{BacktestResult, BacktestMetrics};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct CompletedTrade {
|
||||
pub symbol: String,
|
||||
pub side: Side,
|
||||
pub timestamp: DateTime<Utc>,
|
||||
pub price: f64,
|
||||
pub quantity: f64,
|
||||
pub commission: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct BacktestConfig {
|
||||
pub name: String,
|
||||
|
|
@ -37,7 +47,7 @@ pub struct BacktestState {
|
|||
pub cash: f64,
|
||||
pub equity_curve: Vec<(DateTime<Utc>, f64)>,
|
||||
pub pending_orders: BTreeMap<String, Order>,
|
||||
pub completed_trades: Vec<Fill>,
|
||||
pub completed_trades: Vec<CompletedTrade>,
|
||||
}
|
||||
|
||||
impl BacktestState {
|
||||
|
|
@ -65,8 +75,15 @@ impl BacktestState {
|
|||
self.pending_orders.remove(order_id)
|
||||
}
|
||||
|
||||
pub fn record_fill(&mut self, fill: Fill) {
|
||||
self.completed_trades.push(fill);
|
||||
pub fn record_fill(&mut self, symbol: String, side: Side, fill: Fill) {
|
||||
self.completed_trades.push(CompletedTrade {
|
||||
symbol,
|
||||
side,
|
||||
timestamp: fill.timestamp,
|
||||
price: fill.price,
|
||||
quantity: fill.quantity,
|
||||
commission: fill.commission,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue