-
Notifications
You must be signed in to change notification settings - Fork 67
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
Store limit order quote to compute risk adjusted rewards later on #908
Conversation
// Make quote last long enough to compute risk adjusted rewards for the order. | ||
quote.data.expiration = Utc::now() + self.limit_order_age; |
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.
Could we also comment here why we store the quote.
quote.data.expiration = Utc::now() + self.limit_order_age; | ||
self.quoter.store_quote(quote).await?; |
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.
nit: Shouldn't we change update_limit_order_fees
to store both the quote and the fees in an atomic transaction?
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.
Specifically, I would change it to just store it in the order_quotes
table and not in the quotes
table.
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.
Yeah, making that atomic definitely makes sense. 👍
Will double check the table where we store the quote.
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.
LGTM, I think this fix is fine as a hotfix, but I think we should store both the quote and the fees atomically though.
Wait - I think this PR is storing the quote in the |
This shouldn't be a problem if we store in the |
) | ||
.await?; | ||
|
||
database::quotes::save( |
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 don't think we want to save the quote. I think this is the correct database method to use:
services/crates/database/src/orders.rs
Line 273 in 41ded83
pub async fn insert_quote_and_update_on_conflict( |
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.
Damn wrong table again. I don't know the details around quote storing but I know that it's pretty confusing to have 2 tables with very similar names. :/
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.
🙈
Do you think we should rename the table to make things clearer?
@@ -64,6 +80,19 @@ impl Postgres { | |||
}, | |||
) | |||
.await?; | |||
|
|||
database::orders::insert_quote_and_update_on_conflict( | |||
&mut ex, |
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.
Does this mean it is already part of a single database transaction? If so - cool!
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.
No it doesn't. Sorry was all over the place today. 3fafc92 should finally implement a transaction which does both updates atomically.
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.
Looks correct to me!
Ran a manual test to verify that the rewards get computed (more details in PR description). |
Fixes #891
In order to be able to calculate risk adjusted fees for limit orders we now store the quote generated while updating their
surplus_fee
in the database. Note that we have to adjust the expiration time to match the max time between 2surplus_fee
updates.There is one thing still missing. To avoid allowing users to create market orders with quotes that are meant for limit orders and therefore are allowed to be older than market order quotes. A new quote kind needs to be added to the DB. Just wanted to implement what was suggested in the issue in case we might want to merge ASAP.
Test Plan
Ran a manual test on
goerli
with slight adjustments to the code so that it also computes the rewards ongoerli
and got an auction with a limit order that contained rewards:auction