mirror of
https://github.com/KhizarImran/backtestingfx.git
synced 2026-08-07 17:27:52 +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._bar: Any = None
|
||||||
self._broker: Any = None
|
self._broker: Any = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def positions(self):
|
||||||
|
return self._broker.positions() if self._broker else []
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,10 @@ impl Broker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn positions(&self) -> Vec<Position> {
|
||||||
|
self.positions.clone()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn buy(
|
pub fn buy(
|
||||||
&mut self,
|
&mut self,
|
||||||
price: f64,
|
price: f64,
|
||||||
|
|||||||
@@ -14,5 +14,6 @@ fn backtestingfx(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|||||||
m.add_class::<stats::Stats>()?;
|
m.add_class::<stats::Stats>()?;
|
||||||
m.add_class::<broker::Broker>()?;
|
m.add_class::<broker::Broker>()?;
|
||||||
m.add_class::<engine::Engine>()?;
|
m.add_class::<engine::Engine>()?;
|
||||||
|
m.add_class::<types::Position>()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,15 +33,23 @@ impl Bar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pyclass]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Position {
|
pub struct Position {
|
||||||
// this is for the trading position
|
// this is for the trading position
|
||||||
|
#[pyo3(get)]
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
|
#[pyo3(get)]
|
||||||
pub entry_price: f64,
|
pub entry_price: f64,
|
||||||
|
#[pyo3(get)]
|
||||||
pub lot_size: f64,
|
pub lot_size: f64,
|
||||||
|
#[pyo3(get)]
|
||||||
pub is_long: bool,
|
pub is_long: bool,
|
||||||
|
#[pyo3(get)]
|
||||||
pub entry_timestamp: i64,
|
pub entry_timestamp: i64,
|
||||||
|
#[pyo3(get)]
|
||||||
pub stop_loss: Option<f64>,
|
pub stop_loss: Option<f64>,
|
||||||
|
#[pyo3(get)]
|
||||||
pub take_profit: Option<f64>,
|
pub take_profit: Option<f64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user