positions are now visible in python. can be check by if not sel.position

This commit is contained in:
KhizarImran
2026-07-02 22:12:20 +01:00
parent 53fe8e0e9d
commit 2af19afafa
4 changed files with 17 additions and 0 deletions
+4
View File
@@ -10,6 +10,10 @@ class Strategy:
self._bar: Any = None
self._broker: Any = None
@property
def positions(self):
return self._broker.positions() if self._broker else []
def init(self):
pass
+4
View File
@@ -103,6 +103,10 @@ impl Broker {
}
}
pub fn positions(&self) -> Vec<Position> {
self.positions.clone()
}
pub fn buy(
&mut self,
price: f64,
+1
View File
@@ -14,5 +14,6 @@ fn backtestingfx(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<stats::Stats>()?;
m.add_class::<broker::Broker>()?;
m.add_class::<engine::Engine>()?;
m.add_class::<types::Position>()?;
Ok(())
}
+8
View File
@@ -33,15 +33,23 @@ impl Bar {
}
}
#[pyclass]
#[derive(Debug, Clone)]
pub struct Position {
// this is for the trading position
#[pyo3(get)]
pub id: u64,
#[pyo3(get)]
pub entry_price: f64,
#[pyo3(get)]
pub lot_size: f64,
#[pyo3(get)]
pub is_long: bool,
#[pyo3(get)]
pub entry_timestamp: i64,
#[pyo3(get)]
pub stop_loss: Option<f64>,
#[pyo3(get)]
pub take_profit: Option<f64>,
}