Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The issue of hbt.bid_depth and hbt.ask_depth not aligning with hbt.best_bid and hbt.best_ask #125

Open
kasperlmc opened this issue Aug 18, 2024 · 4 comments

Comments

@kasperlmc
Copy link

I have noticed that the data for hbt.bid_depth and hbt.ask_depth seems inconsistent with hbt.best_bid and hbt.best_ask. During my examination, I found that the minimum price in hbt.ask_depth is lower than hbt.best_ask. What might be causing this discrepancy, and is there any way to resolve it?

@kasperlmc
Copy link
Author

version is 1.84

@nkaz001
Copy link
Owner

nkaz001 commented Aug 18, 2024

Crypto exchanges often experience unstable data feeds, leading to gaps in the feed that cannot always be fully recovered. This can result in incomplete market depth data, where certain price levels may not be properly updated. Consequently, the best bid may cross the best ask in the market depth, or vice versa. Since HftBacktest determines the best bid and ask from the Level 2 market depth, this can cause discrepancy.

To resolve this issue, HftBacktest adjusts by finding the best ask price above the best bid price when the best bid is updated, and finding the best bid price below the best ask price when the best ask is updated. As a result, there may be residual "afterimages" in the market depth, and these are naturally refreshed over time.

When you access the market depth, I recommend bounding the depth to the best bid and the best ask using hbt.best_bid, hbt.best_bid_tick, hbt.best_ask, and hbt.best_ask_tick. Please see Working with Market Depth and Trades tutorial.

@kasperlmc
Copy link
Author

Alright, thank you for the explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@kasperlmc @nkaz001 and others