From 6f39fc2d34753c31974df2570351e403f6116858 Mon Sep 17 00:00:00 2001 From: KhizarImran Date: Sun, 14 Jun 2026 01:21:15 +0100 Subject: [PATCH] adding python wrapping --- Cargo.toml | 5 +++++ src/lib.rs | 16 ++++++++++++---- src/types.rs | 23 +++++++++++++++++------ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ebe5eff..d8c2166 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,5 +3,10 @@ name = "backtestingfx" version = "0.1.0" edition = "2024" +[lib] +name = "backtestingfx" +crate-type = ["cdylib", "rlib"] + [dependencies] chrono = "0.4" +pyo3 = { version = "0.28", features = ["extension-module"]} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 2ca5c17..38b1863 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,14 @@ -pub mod types; -pub mod strategy; pub mod broker; -pub mod engine; pub mod data; -pub mod stats; \ No newline at end of file +pub mod engine; +pub mod stats; +pub mod strategy; +pub mod types; + +use pyo3::prelude::*; + +#[pymodule] +fn backtestingfx(m: &Bound<'_, PyModule>) -> PyResult<()> { + m.add_class::()?; + Ok(()) +} diff --git a/src/types.rs b/src/types.rs index 156201c..e05407c 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,32 +1,43 @@ +use pyo3::prelude::*; + +#[pyclass] #[derive(Debug, Clone)] -pub struct Bar { // Initialises the interface for the bar +pub struct Bar { + // Initialises the interface for the bar + #[pyo3(get)] pub timestamp: i64, + #[pyo3(get)] pub open: f64, + #[pyo3(get)] pub high: f64, + #[pyo3(get)] pub low: f64, + #[pyo3(get)] pub close: f64, + #[pyo3(get)] pub volume: f64, } #[derive(Debug, Clone)] -pub struct Position { // this is for the trading position +pub struct Position { + // this is for the trading position pub id: u64, pub entry_price: f64, pub lot_size: f64, pub is_long: bool, pub entry_timestamp: i64, pub stop_loss: Option, - pub take_profit: Option - + pub take_profit: Option, } #[derive(Debug, Clone)] -pub struct Trade { // the actual trade +pub struct Trade { + // the actual trade pub entry_price: f64, pub exit_price: f64, pub lot_size: f64, pub is_long: bool, pub pnl: f64, pub entry_timestamp: i64, - pub exit_timestamp:i64 + pub exit_timestamp: i64, }