-
Notifications
You must be signed in to change notification settings - Fork 75
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
Prioritize orders in SingleOrderSolvers
#762
Prioritize orders in SingleOrderSolvers
#762
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me. I feel like this is a relatively high-risk change. Maybe we should monitor it more closely over the next few weeks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with the current state but also have a potential improvement.
The current relative priority is weak. An order with a price ratio of 0.9 is very likely not settlable, yet it's probability of being chosen relative to an order of price ratio 1.1 isn't that different. To improve this we could run the weight through another function to make it more extreme.
One way to do this could be squaring the value (x**2
, or x**3
, etc) and to prevent extreme outliers cap between [0.01, 10].
I agree. I already asked the solver team this morning if they could come up with some sensible weight function. |
I don't have a good intuition about what kind of weights would work, so I guess the x^2 suggestion above could work. This also depends on whether we want to have this probability scale non-linearly or not. E.g., one could also try a piece-wise linear function and just differentiate between the > 1 and < 1 ratios. One such function could be the following: f(x) = 10x + c, if x > 1.1 where c and d are set such that the function is continuous. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool! Can we maybe add some TRACE
logs to list the order UIDs of the randomized orders? This would allow us to increase on observability into the randomization process if we want to debug it.
I added the trace logs:
|
Fixes #753
With the release of the limit order feature we expect that we have to handle a lot more orders. The
SingleOrderSolver
(aptly named) can only solve a single order at a time and every order takes some amount of time. Because theSingleOrderSolver
s can be quite slow solving an entireAuction
is already time boxed.To improve the chances to work on orders that can actually be settled and make the most of our the time we have we want to prioritize orders which are generously priced; meaning that they want to sell a lot and buy a little (denominated in ETH).
Since the auction already gives us prices for all the traded tokens in the order we can simply use those to compute each order's native
sell_amount
andbuy_amount
and prioritize the orders based on their ratio.Note that we had issues in the past with deterministic order ordering because all
SingleOrderSolver
s would get stuck on "bad" orders. That's why we don't simply sort the orders by their price but assign a weight (based on its price) to each order and pick randomly from the weighted orders. That effectively gives us a semi-random ordering where orders which are generously priced have a higher chance to get solved early than orders with close to market pricing.Test Plan
Added unit test but it's ignored because it could fail randomly with a very low probability.