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

[roq-core] MbP needs heuristics to determine tick_size when no reference data exists #114

Closed
thraneh opened this issue Nov 3, 2021 · 8 comments
Milestone

Comments

@thraneh
Copy link
Contributor

thraneh commented Nov 3, 2021

This has recently started happening for Deribit where there are new instruments (options) being published at 8am UTC. It appears market data maybe arrives before reference data.

Without reference data, the prices will be rounded or even truncated thereby potentially causing BadState (bid>=ask).

Workaround

Use --mbp_allow_price_inversion=true

@thraneh thraneh added bug Something isn't working high priority labels Nov 3, 2021
@thraneh thraneh added this to the 0.7.9 milestone Nov 3, 2021
@thraneh
Copy link
Contributor Author

thraneh commented Nov 3, 2021

Now logging if no reference data when creating MbP. The pattern to look for is NO REFERENCE DATA symbol="{}"

@thraneh thraneh added enhancement New feature or request and removed bug Something isn't working labels Nov 4, 2021
@thraneh
Copy link
Contributor Author

thraneh commented Nov 4, 2021

Another reason for getting bad state is that reference data can be received, but either the tick-size is missing or it's plain wrong.

Heuristics has now been added to check for a possible initial tick-size based on the prices observed in the initial snapshot.

This issue will not be closed until we have observed the behaviour for all gateways.

@thraneh
Copy link
Contributor Author

thraneh commented Nov 5, 2021

The new logic was flawed and didn't deal with ReferenceData.tick_size potentially being NaN. This has been fixed.

@thraneh
Copy link
Contributor Author

thraneh commented Nov 5, 2021

Today it worked with Deribit. Still needs extensive testing before we can say it's good.

@thraneh
Copy link
Contributor Author

thraneh commented Nov 6, 2021

More changes were required due to HitBTC allowing extreme price ranges.

Short version:

  • heuristics detected smaller tick-size than reported by reference data
  • this caused high asks to overflow when converted into integer representation
  • this was not caught at the gateway level
  • these overflowing values then passed through to clients causing "BadState" exceptions

Example, tick size was detected as 1e-9 and maximum ask price was 1e15, converting to integer would require 1e24 causing overflow because int64_t has a maximum of roughly 1e19.

The solution: drop all prices causing overflow (essentially truncating the ask-side of the order book).

@thraneh
Copy link
Contributor Author

thraneh commented Nov 6, 2021

Seems to work now. Will test for a few more days before closing this issue.

@thraneh
Copy link
Contributor Author

thraneh commented Nov 8, 2021

Seeing issues most likely relating to heuristics working differently between gateway and client.

A current idea, and possible solution, is to have the gateway publish current price/quantity decimal digits with MbP and use those on the client side for any scaling required. This would remove any uncertainty from the client-side. (This would also remove the constraint to pass ReferenceData to MbP objects.)

@thraneh
Copy link
Contributor Author

thraneh commented Nov 11, 2021

Seems to work now

@thraneh thraneh closed this as completed Nov 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant