Skip to content

Commit

Permalink
chore(rust): modify live feature support in Python to be an optional …
Browse files Browse the repository at this point in the history
…feature, as it is currently incompatible with auditwheel builds.
  • Loading branch information
nkaz001 committed Nov 20, 2024
1 parent 60a1218 commit 289ae5b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
13 changes: 1 addition & 12 deletions .github/workflows/release-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,12 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
python3 -m ensurepip
sudo apt-get update
sudo apt-get install -y pkg-config openssl libssl-dev
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
rust-toolchain: ${{ env.RUST_VERSION }}
args: --manifest-path=py-hftbacktest/Cargo.toml --release --out dist --find-interpreter
# sccache: 'true'
manylinux: 2_24
- name: Upload wheels
uses: actions/upload-artifact@v4
Expand All @@ -79,17 +73,12 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y pkg-config openssl libssl-dev
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
rust-toolchain: ${{ env.RUST_VERSION }}
args: --manifest-path=py-hftbacktest/Cargo.toml --release --out dist --find-interpreter
sccache: 'true'
manylinux: musllinux_1_2
- name: Upload wheels
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -191,4 +180,4 @@ jobs:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing wheels-*/*
args: --non-interactive --skip-existing wheels-*/*
6 changes: 5 additions & 1 deletion py-hftbacktest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ edition = "2021"
name = "hftbacktest"
crate-type = ["cdylib"]

[features]
default = []
live = ["hftbacktest/live"]

[dependencies]
pyo3 = { version = "0.23.1", features = ["extension-module"] }
hftbacktest = { path = "../hftbacktest", features = ["backtest"] }
hftbacktest = { path = "../hftbacktest", default-features = false, features = ["backtest"] }
hftbacktest-derive = { path = "../hftbacktest-derive" }
9 changes: 8 additions & 1 deletion py-hftbacktest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::{ffi::c_void, mem::size_of, ptr::slice_from_raw_parts_mut};

pub use backtest::*;
pub use depth::*;
#[cfg(feature = "live")]
use hftbacktest::live::{Instrument, LiveBotBuilder};
use hftbacktest::{
backtest::{
assettype::{InverseAsset, LinearAsset},
Expand Down Expand Up @@ -38,17 +40,18 @@ use hftbacktest::{
Backtest,
DataSource,
},
live::{Instrument, LiveBotBuilder},
prelude::{ApplySnapshot, Event, HashMapMarketDepth, ROIVectorMarketDepth},
};
use hftbacktest_derive::build_asset;
pub use order::*;
use pyo3::{exceptions::PyValueError, prelude::*};

#[cfg(feature = "live")]
use crate::live::{HashMapMarketDepthLiveBot, ROIVectorMarketDepthLiveBot};

mod backtest;
mod depth;
#[cfg(feature = "live")]
mod live;
mod order;

Expand Down Expand Up @@ -454,7 +457,9 @@ impl BacktestAsset {
fn _hftbacktest(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(build_hashmap_backtest, m)?)?;
m.add_function(wrap_pyfunction!(build_roivec_backtest, m)?)?;
#[cfg(feature = "live")]
m.add_function(wrap_pyfunction!(build_hashmap_livebot, m)?)?;
#[cfg(feature = "live")]
m.add_function(wrap_pyfunction!(build_roivec_livebot, m)?)?;
m.add_class::<BacktestAsset>()?;
m.add_class::<LiveInstrument>()?;
Expand Down Expand Up @@ -658,6 +663,7 @@ impl LiveInstrument {
}
}

#[cfg(feature = "live")]
#[pyfunction]
pub fn build_hashmap_livebot(instruments: Vec<PyRefMut<LiveInstrument>>) -> PyResult<usize> {
let mut builder = LiveBotBuilder::new();
Expand All @@ -680,6 +686,7 @@ pub fn build_hashmap_livebot(instruments: Vec<PyRefMut<LiveInstrument>>) -> PyRe
Ok(Box::into_raw(Box::new(hbt)) as *mut c_void as usize)
}

#[cfg(feature = "live")]
#[pyfunction]
pub fn build_roivec_livebot(instruments: Vec<PyRefMut<LiveInstrument>>) -> PyResult<usize> {
let mut builder = LiveBotBuilder::new();
Expand Down

0 comments on commit 289ae5b

Please sign in to comment.