-
Notifications
You must be signed in to change notification settings - Fork 97
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
[PROPOSAL] Correctly label the orderbook orders metric #2917
Conversation
9616717
to
41adcd3
Compare
crates/orderbook/src/orderbook.rs
Outdated
#[derive(Display)] | ||
#[strum(serialize_all = "snake_case")] | ||
enum OrderClass { | ||
User, |
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 think user
was probably a misnomer to begin with. Let's call it market
instead and adjust the grafana alerts accordingly.
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.
If we rename this, why don't we call it Market
and OutOfMarket
or somethinglike this? Technically a market order is also a limit order.
In fact, it could maybe simply become a boolean inMarket
?
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.
Since we have everywhere "market" and "limit" still, I would suggest to stick with that, otherwise we add inconsistencies. We could clean up all the "market" and "limit" code, and then unify it properly (we also have the "liquidity" there...)
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 think the approach is good, but maybe we can make the enum more clear or even reduce it to a simple boolean?
crates/orderbook/src/orderbook.rs
Outdated
#[derive(Display)] | ||
#[strum(serialize_all = "snake_case")] | ||
enum OrderClass { | ||
User, |
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.
If we rename this, why don't we call it Market
and OutOfMarket
or somethinglike this? Technically a market order is also a limit order.
In fact, it could maybe simply become a boolean inMarket
?
@@ -42,24 +47,18 @@ struct Metrics { | |||
orders: prometheus::IntCounterVec, | |||
} | |||
|
|||
#[derive(Display)] | |||
#[strum(serialize_all = "snake_case")] | |||
enum OrderOperation { | |||
Created, |
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 like Created should take an Option<Quote>
(since quotes are not relevant for cancelled operations). This would also make on_order_operation
a bit cleaner (since right now there is an implicit assumption that quote is always None for Cancellation
events)
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 will try to retrieve the quote for the cancelation events, so we can correctly label them.
Co-authored-by: Martin Beckmann <martin.beckmann@protonmail.com>
Co-authored-by: Martin Beckmann <martin.beckmann@protonmail.com>
514c2f0
to
bf58f16
Compare
bf58f16
to
bed0d84
Compare
.zip(order_with_quote.quote_sell_token_price) | ||
.zip(order_with_quote.solver) | ||
.map( | ||
|( |
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.
Weird formatting :/
@@ -567,6 +579,26 @@ pub async fn single_full_order( | |||
sqlx::query_as(QUERY).bind(uid).fetch_optional(ex).await | |||
} | |||
|
|||
pub async fn single_full_order_with_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.
Create a new query so we don't need to do two roundtrip to get an order with its quote data.
} | ||
|
||
pub struct SolvableOrders { | ||
pub orders: Vec<Order>, | ||
pub latest_settlement_block: u64, | ||
} | ||
|
||
pub struct OrderWithQuote { |
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.
Created a new object which contains an order with the quote information (the quote information corresponding to the one stored in order_quotes
table, which is the only info we need, not the full quote).
This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed. |
} | ||
} | ||
|
||
impl Deref for OrderWithQuote { |
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.
Let's not try to get fancy here. Deref
is mostly "reserved" for smart pointer types and things like drop guards.
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 will change it for simplicity, but that actually is not true. Deref
is for whatever use you want to use it, as long as it suits you. And it is definitely used for structs in which you have a main object, and then extra appended data, then you want to deref to the main struct instead of indexing it all the time. There are even crates created on top of Deref
for cleaner code (see delegate
crate).
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.
😮💨 now it is super ugly with the order.order
...
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 think I am going to revert it, that's why deref
was created...
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.
- Initially the docs specifically mentioned to only use if for smart pointers.
- since then the phrasing was relaxed to
users of that type should not get surprised by deref
which arguable is not the case here because we almost never useDeref
(mostly a point for code consistency)
now it is super ugly with the order.order
Sure, but it also doesn't look like you tried hard to avoid it looking ugly...
let OrderWithQuote{order, quote} = weird_new_struct;
Ultimately not a hill I'm willing to die an but IMO requiring this "hack" rather indicates that the chosen abstraction doesn't work great.
For example you could also consider making the quote part of the FullOrder
which probably is useful in more than just this specific case.
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.
@MartinquaXD yup, I am aware of that PR that removed the comment, I remember it back in the day when it came out. It was a "ok guys, use it as you want" kind of thing 😄 and then many crates like derive_deref
, delegate
, deref_into
, shrinkwraprs
, ambassador
crates came up (and for sure there are more, but those are the ones I remember, some of them already existed from before like deref_into
IIRC). So, that's why I don't agree it is for smart pointers only, it used to be, but now it is quite accepted for many other usages.
Sure, but it also doesn't look like you tried hard to avoid it looking ugly...
😬 I wanted to make a point, that with just adding thederef
implementation, we need to avoidorder.order
or like the code you propose. It is extra lines/overhead.
I agree with you that adding a deref
in a codebase it wasn't used before (it is used before but little) may create confusion (that's why I reverted in the first place), but I don't think it adds inconsistency. If we cannot add new crates/patterns because it is the first one, then we will never add anything 🤔
Ultimately not a hill I'm willing to die an but IMO requiring this "hack" rather indicates that the chosen abstraction doesn't work great.
Yup, I agree with you here to be honest. I am not convinced of the struct myself either. But since it was used "just" for the metrics, and it is a pattern I already saw in the codebase, I was like "ok". But I am not super happy about it.
For example you could also consider making the quote part of the FullOrder which probably is useful in more than just this specific case.
That'd be great, if you tell me it is worth doing it. I will definitely do it! my only concern with that is that now for each single full order we also fetch the quote (same roundtrip at least).
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.
@@ -323,6 +354,51 @@ impl OrderStoring for Postgres { | |||
order.map(full_order_into_model_order).transpose() | |||
} | |||
|
|||
async fn single_order_with_quote(&self, uid: &OrderUid) -> Result<Option<OrderWithQuote>> { |
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 probably be part of an existing DB test which tests quote fetching in general.
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.
Really good idea, adding them!
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.
Added a test at OrderStoring
level and database level 👌
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.
Lg
abb7bcc
to
3ec80de
Compare
Description
We need to properly adjust the orderbook
orders
metric. The reason is that we got a false alarm alert, because as it is now, everything is alimit
order, so we got a period of time in which we got orders (reallimit
ones) and no trades (because those orders were out of market).This could be solved in many ways, as discussed with @MartinquaXD , one way could be to only report "market" orders. But after giving it a deep thought, I think this is the best way, because we don't lose any type of order, and we report all of them labelled correctly.
Changes
limit
orders, I changed theOrderClass
of theorders
metric to reflect reallimit
orders oruser
orders (order not outside the market price). This way we keep all the orders tracked. I meant this class to be exclusively of the metric system, as we don't intent to storeuser
order (akamarket
order) in the domain. But it is handy to have it in the metrics.strum
to serialize properly the enumsOrderClass
accordingly to the quote price if present.How to test