nkaz001 / hftbacktest

A high-frequency trading and market-making backtesting and trading bot 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
2.02k stars 397 forks source link

Can't import BacktestAsset and HashMapMarketDepthBacktest #106

Closed rdabc closed 3 months ago

rdabc commented 3 months 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 3 months 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.

rdabc commented 3 months ago

I used "pip install hftbacktest"

rdabc commented 3 months ago

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

nkaz001 commented 3 months 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.

rdabc commented 3 months 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 3 months 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.

rdabc commented 3 months 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 3 months 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 3 months ago

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

rdabc commented 3 months 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

rdabc commented 3 months 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)

rdabc commented 3 months 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

rdabc commented 3 months ago

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