mirror of
https://github.com/KhizarImran/backtestingfx.git
synced 2026-07-27 20:17:44 +00:00
positions are now visible in python. can be check by if not sel.position
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -103,6 +103,10 @@ impl Broker {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn positions(&self) -> Vec<Position> {
|
||||
self.positions.clone()
|
||||
}
|
||||
|
||||
pub fn buy(
|
||||
&mut self,
|
||||
price: f64,
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -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>,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user