-
Notifications
You must be signed in to change notification settings - Fork 90
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
Add optional quoteId
parameter to orders
#170
Comments
Just wanted to add some more context from #231 (review) Specifically, the plan is to eventually store quotes in the orderbook database (similar to how we store fee measurement - or even replacing the fee measurements). When orders are created with a Additionally, as @MartinquaXD, if we store enough quote information, we could even "guess" what quote was used to create the order (i.e. the most recent quote that matches the order parameters) and use that instead of the explicitly specified one. I would still keep the explicit parameter, in case a client does multiple quotes (on different threads for example) so that the "real" quote that was used can be specified. |
Partially fulfills #170 This PR adds the ability to set the quoteId parameter while creating Orders. This way the order can be linked to a quote and enable providing more metadata when analyzing order slippage. Currently, it doesn't involve interaction with the Database i.e. Storing or retrieving the quoteId. This will be a part of a separate PR. Also api/v1/quote now also returns an ID. Currently, implemented as a counter which gets reset on orderbook restarts. Users can now pass an optional parameter quoteId while creating orders for easier debugging.
One thing that is not obvious to me is how stored quotes interact with stored min-fee measurements. Specifically, we currently keep track of min-fee measurements per Since we also want to store quotes (which includes updated prices), the question becomes:
I'd be inclined to say we should do 1. just because price updates may cause non-trivial changes to the fee (as changes in routes may lead to a better price at a higher fee). |
The reason we originally started keeping track of fee estimates is that we want to give users some grace period during which their original quote will be accepted even if the fee amount moves (because price or gas price changes). If we didn't do this then with some probability users would be unable to submit their order after getting the quote. The fee estimator needs the following data: gas price, price of the sell token in eth, price estimate of the user's trade (for gas amount). The first two are cheap and already cached. For the latter I notice now that this is exactly the same price estimate that we also create in the quote endpoint: services/crates/orderbook/src/fee.rs Line 267 in debce16
Because we have deprecated the other routes, we are only going to query the fee estimator through the quote endpoint. We should share this data between the components. Reduces load on price estimators, reduces latency of the endpoint. This is relevant evidence for your question. If we are confident that our api will remain this way then it likely makes sense to combine the quoting and fee estimation into one component which is related to what you wrote before "similar to how we store fee measurement - or even replacing the fee measurements". We can turn your last question around too and ask whether quotes should be cached for a short time just like fee estimates because prices do not change significantly in 30s. This would reduce load from price estimators and the database. From the top of my head this makes sense to me. At the beginning I wrote that we want to accept orders created with recent fee estimates even if a fresh fee estimate might be higher. This is true but I can also see that it makes to give new quotes the fresh estimate even if we would accept the older one. Technically they could game the system but it is unlikely to happen on a large scale. This is an argument in favor of 1. The downside is more database load. This isn't exactly a conclusion on 1 vs 2 but it shows some more relevant information and maybe alternative solutions that haven't been named yet. |
I think the more general question is whether or not we want to cache quotes for the same amount of time as fees. In this "frame of reference", we currently cache quotes for 0s and fees for 30s.
We can make more recent quotes replace the old ones to mitigate this if it becomes a problem. |
This issue has been marked as stale because it has been inactive a while. Please update this issue or it will be automatically closed. |
Orders that were created with quotes can optionally include a quote ID. This way the order can be linked to a quote and enable providing more metadata when analyzing order slippage.
The text was updated successfully, but these errors were encountered: