work on core
This commit is contained in:
parent
b8cefdb8cd
commit
44476da13f
10 changed files with 951 additions and 755 deletions
|
|
@ -231,9 +231,11 @@ fn parse_backtest_config(obj: napi::JsObject) -> Result<BacktestConfig> {
|
|||
let commission: f64 = obj.get_named_property("commission")?;
|
||||
let slippage: f64 = obj.get_named_property("slippage")?;
|
||||
let data_frequency: String = obj.get_named_property("dataFrequency")?;
|
||||
let strategy: Option<String> = obj.get_named_property("strategy").ok();
|
||||
|
||||
Ok(BacktestConfig {
|
||||
name,
|
||||
strategy,
|
||||
symbols,
|
||||
start_time: DateTime::parse_from_rfc3339(&start_date)
|
||||
.map_err(|e| Error::from_reason(e.to_string()))?
|
||||
|
|
@ -419,12 +421,15 @@ impl Strategy for SimpleSMAStrategy {
|
|||
}
|
||||
|
||||
fn on_fill(&mut self, symbol: &str, quantity: f64, price: f64, side: &str) {
|
||||
eprintln!("Fill received: {} {} @ {} - {}", quantity, symbol, price, side);
|
||||
eprintln!("🔸 SMA Strategy - Fill received: {} {} @ ${:.2} - {}", quantity, symbol, price, side);
|
||||
let current_pos = self.positions.get(symbol).copied().unwrap_or(0.0);
|
||||
let new_pos = if side == "buy" { current_pos + quantity } else { current_pos - quantity };
|
||||
|
||||
eprintln!(" Position change: {} -> {}", current_pos, new_pos);
|
||||
|
||||
if new_pos.abs() < 0.0001 {
|
||||
self.positions.remove(symbol);
|
||||
eprintln!(" Position closed");
|
||||
} else {
|
||||
self.positions.insert(symbol.to_string(), new_pos);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue