nkaz001 / hftbacktest

A high-frequency trading and market-making backtesting tool in Python and Rust, which accounts for limit orders, queue positions, and latencies, utilizing full tick data for trades and order books, with real-world crypto market-making examples for Binance Futures
MIT License
1.78k stars 357 forks source link

Can't import BacktestAsset and HashMapMarketDepthBacktest #106

Closed francoisailah closed 1 month ago

francoisailah commented 1 month ago

Hi,

I am getting the following error in importing BacktestAsset

from hftbacktest import BacktestAsset, HashMapMarketDepthBacktest

Cell In[3], line 1 ----> 1 from hftbacktest import BacktestAsset, HashMapMarketDepthBacktest

ImportError: cannot import name 'BacktestAsset' from 'hftbacktest'

Thank you

nkaz001 commented 1 month ago

I believe you are using the latest development version by cloning the repository. You need to run maturin develop to compile the Rust backend library and install the package. Please see py-hftbacktest directory.

francoisailah commented 1 month ago

I used "pip install hftbacktest"

francoisailah commented 1 month ago

Could you please send me the steps to install it? Thank you

nkaz001 commented 1 month ago

If you install hftbacktest via pip, it is v1.8.4. If not, please update your Python to 3.10 or later. You can find the document here. If you want to try the latest development version, you need to install Rust, related development tools, and maturin to build hftbacktest from the source.

francoisailah commented 1 month ago

I have Python3.10 After cloning the repository, Is the following correct

  1. install the requirements.txt (docs/requirements.txt)
  2. Then, run "maturin develop" in py-hftbacktest ?
nkaz001 commented 1 month ago

If you have installed Rust and related development tools to build Rust code, then you need to install maturin using pip install maturin. After that, if you run the command maturin develop in py-hftbacktest directory, it will build hftbacktest and install hftbacktest in the currently active Python environment.

francoisailah commented 1 month ago

I am getting this error: error: failed to run custom build command for openssl-sys v0.9.103 . . maturin failed Caused by: Failed to build a native library through cargo Caused by: Cargo build finished with "exit status: 101": env -u CARGO PYO3_ENVIRONMENT_SIGNATURE="cpython-3.10-64bit" PYO3_PYTHON="/home/francois/Documents/Codes/rd_env/bin/python" PYTHON_SYS_EXECUTABLE="/home/francois/Documents/Codes/rd_env/bin/python" "cargo" "rustc" "--message-format" "json-render-diagnostics" "--manifest-path" "/home/francois/Documents/Codes/hftbacktest/py-hftbacktest/Cargo.toml" "--lib"

Thank you

nkaz001 commented 1 month ago

You need to install openssl library. By the way, the latest development version is unstable. You may prefer to use the stable version v1.8.4.

nkaz001 commented 1 month ago

2.0.0rc0 has been released. Now, you can install it pip install hftbacktest==2.0.0rc0.

francoisailah commented 1 month ago

I have installed openss using the following: sudo apt install openssl and sudo apt install libssl-dev

I have checked the version of openssl: OpenSSL 3.0.13 30 Jan 2024 (Library: OpenSSL 3.0.13 30 Jan 2024)

However, I am still getting the same error.

Thank you

francoisailah commented 1 month ago

I have deleted the old version and cloned again the repo. Now, I am getting this error: 💥 maturin failed Caused by: Failed to read readme specified in pyproject.toml, which should be at /home/francois/Documents/Codes/hftbacktest/py-hftbacktest/README.rst Caused by: failed to open file /home/francois/Documents/Codes/hftbacktest/py-hftbacktest/README.rst Caused by: No such file or directory (os error 2)

francoisailah commented 1 month ago

I have copied "README.rst" file to "home/francois/Documents/Codes/hftbacktest/py-hftbacktest" and run maturin develop, I am getting the same error: error: failed to run custom build command for openssl-sys v0.9.103

francoisailah commented 1 month ago

I have installed pkg-config (sudo apt install pkg-config) and it is working now. Thank you