adding python wrapping

This commit is contained in:
KhizarImran
2026-06-14 01:21:15 +01:00
parent a039484b08
commit 6f39fc2d34
3 changed files with 34 additions and 10 deletions
+5
View File
@@ -3,5 +3,10 @@ name = "backtestingfx"
version = "0.1.0" version = "0.1.0"
edition = "2024" edition = "2024"
[lib]
name = "backtestingfx"
crate-type = ["cdylib", "rlib"]
[dependencies] [dependencies]
chrono = "0.4" chrono = "0.4"
pyo3 = { version = "0.28", features = ["extension-module"]}
+11 -3
View File
@@ -1,6 +1,14 @@
pub mod types;
pub mod strategy;
pub mod broker; pub mod broker;
pub mod engine;
pub mod data; pub mod data;
pub mod engine;
pub mod stats; pub mod stats;
pub mod strategy;
pub mod types;
use pyo3::prelude::*;
#[pymodule]
fn backtestingfx(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<types::Bar>()?;
Ok(())
}
+17 -6
View File
@@ -1,32 +1,43 @@
use pyo3::prelude::*;
#[pyclass]
#[derive(Debug, Clone)] #[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, pub timestamp: i64,
#[pyo3(get)]
pub open: f64, pub open: f64,
#[pyo3(get)]
pub high: f64, pub high: f64,
#[pyo3(get)]
pub low: f64, pub low: f64,
#[pyo3(get)]
pub close: f64, pub close: f64,
#[pyo3(get)]
pub volume: f64, pub volume: f64,
} }
#[derive(Debug, Clone)] #[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 id: u64,
pub entry_price: f64, pub entry_price: f64,
pub lot_size: f64, pub lot_size: f64,
pub is_long: bool, pub is_long: bool,
pub entry_timestamp: i64, pub entry_timestamp: i64,
pub stop_loss: Option<f64>, pub stop_loss: Option<f64>,
pub take_profit: Option<f64> pub take_profit: Option<f64>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Trade { // the actual trade pub struct Trade {
// the actual trade
pub entry_price: f64, pub entry_price: f64,
pub exit_price: f64, pub exit_price: f64,
pub lot_size: f64, pub lot_size: f64,
pub is_long: bool, pub is_long: bool,
pub pnl: f64, pub pnl: f64,
pub entry_timestamp: i64, pub entry_timestamp: i64,
pub exit_timestamp:i64 pub exit_timestamp: i64,
} }