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

PanicException: called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" } #110

Closed rdabc closed 3 months ago

rdabc commented 3 months ago

Hi,

I am trying to run the Getting Started notebook and I am getting the following error:

thread '' panicked at py-hftbacktest/src/lib.rs:400:20: called Result::unwrap() on an Err value: Os { code: 2, kind: NotFound, message: "No such file or directory" } note: run with RUST_BACKTRACE=1 environment variable to display a backtrace


PanicException Traceback (most recent call last) Cell In[2], line 64 3 asset = ( 4 BacktestAsset() 5 # Sets the data to feed for this asset. (...) 57 .last_trades_capacity(0) 58 ) 60 # HftBacktest provides several types of built-in market depth implementations. 61 # HashMapMarketDepthBacktest constructs a Backtest using a HashMap-based market depth implementation. 62 # Another useful implementation is ROIVectorMarketDepth, which is utilized in ROIVectorMarketDepthBacktest. 63 # Please find the details in the document below. ---> 64 hbt = HashMapMarketDepthBacktest([asset])

File ~/Documents/Codes/hftbacktest/py-hftbacktest/hftbacktest/init.py:165, in HashMapMarketDepthBacktest(assets) 153 def HashMapMarketDepthBacktest( 154 assets: List[BacktestAsset] 155 ) -> HashMapMarketDepthBacktest_TypeHint: 156 """ 157 Constructs an instance of HashMapMarketDepthBacktest. 158 (...) 163 A jitedHashMapMarketDepthBacktest` that can be used in an njit function. 164 """ --> 165 ptr = build_hashmapbacktest(assets) 166 return HashMapMarketDepthBacktest(ptr)

PanicException: called Result::unwrap() on an Err value: Os { code: 2, kind: NotFound, message: "No such file or directory" }

nkaz001 commented 3 months ago

It seems there is no file specified in your BacktestAsset configuration. Did you run the Data Preparation tutorial first? It generates the files used in the Getting Started tutorial.

rdabc commented 3 months ago

In data preparation, I am getting an error in this cell: " from hftbacktest.data.utils.snapshot import create_last_snapshot

Builds 20240718 End of Day snapshot. It will be used for the initial snapshot for 20230719.

data = create_last_snapshot( ['usdm/btcusdt_20240718.npz'], tick_size=0.1, lot_size=0.001 ) "



AttributeError Traceback (most recent call last) Cell In[5], line 4 1 from hftbacktest.data.utils.snapshot import create_last_snapshot 3 # Builds 20240718 End of Day snapshot. It will be used for the initial snapshot for 20230719. ----> 4 data = create_last_snapshot( 5 ['usdm/btcusdt_20240718.npz'], 6 tick_size=0.1, 7 lot_size=0.001 8 )

File ~/Documents/Codes/hftbacktest/py-hftbacktest/hftbacktest/data/utils/snapshot.py:41, in create_last_snapshot(data, tick_size, lot_size, initial_snapshot, output_snapshot_filename) 16 r""" 17 Creates a snapshot of the last market depth for the specified data, which can be used as the initial snapshot data 18 for subsequent data. (...) 29 Snapshot of the last market depth compatible with HftBacktest. 30 """ 31 # Just to reconstruct order book from the given snapshot to the end of the given data. 32 asset = ( 33 BacktestAsset() 34 .linear_asset(1.0) 35 .data(data) 36 .no_partial_fill_exchange() 37 .constant_latency(0, 0) 38 .risk_adverse_queue_model() 39 .tick_size(tick_size) 40 .lot_size(lot_size) ---> 41 .trade_len(0) 42 ) 43 if initial_snapshot is not None: 44 asset.initial_snapshot(initial_snapshot)

AttributeError: 'BacktestAsset' object has no attribute 'trade_len'

nkaz001 commented 3 months ago

There was a missing fix after refactoring. 3d19c1d10959c628eb864e0ed1a134399d4a759b