-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[matching engine] Track pending orders on user chains #4974
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
base: main
Are you sure you want to change the base?
Conversation
1a9da86 to
8d5207e
Compare
5523e98 to
a731c23
Compare
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.
This design of keeping track of the order structure inside of the Matching Engine is not the standard way that this is done.
What exchanges are publishing are the list of operations. See for example Nasdaq: Computer-To-Computer-Interface.
Then it is the job of the receivers of the information to keep track of he orders and maybe have a nice MapView<AccountOwner, BTreeMap<OrderId, ....>>.
If we follow this design, then what we would do is instead emit events corresponding to the transactions. Then another contract would keep track of those events and of the relevant balances, pending orders, and so on if he so wishes. We have all the functionalities in Linera for that.
afck
left a comment
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.
@MathieuDutSik: I think what you're suggesting would create a lot more overhead: Each user would have to read all events, rather than get notified about only the messages that concern their own orders.
| let cancel_quantity = state_order | ||
| .quantity | ||
| .try_sub(new_quantity) | ||
| .expect("Attempt to increase quantity"); |
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.
Feels like we should support that, too.
Instead of distinguishing between deleting, reducing and adding an order, why not just have a single operation that sets the quantity for a given price? (Just a thought; not something for this PR!)
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.
that's what we do in this PR!
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.
Are we? I can see that it's being unified with canceling an order, but not with creating an order?
| let removal_message = Message::OrderUpdated { | ||
| owner: filled_owner, | ||
| order_id: filled_order_id, | ||
| new_quantity: Amount::ZERO, |
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.
What about partially filled orders?
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.
line 253 below
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 mean orders that were already in the book? Apparently we do not support this?
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 insert_and_uncross_market does partially fill orders. E.g. if there's a single bid in the book with an amount of 10, and I make an ask with an amount of 5 and the same price, my ask will be filled, and the bid will be reduced by 5 but remain in the book.
In that case we should probably send a message to the bidder as well, to notify them that their order was partially filled, i.e. modified?
|
|
||
| // Test Cancel order (should always succeed) | ||
| let cancel_order = Order::Cancel { owner, order_id: 1 }; | ||
| // Test order cancellation. |
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 still think this whole test is not really carrying its weight: It just tests different methods that all delegate to the same, simple, precision check, regardless of the order type.)
| /// The map giving for each account owner the set of order_id | ||
| /// owned by that owner. | ||
| /// owned by that owner (used on the matching engine chain). |
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.
| /// The map giving for each account owner the set of order_id | |
| /// owned by that owner. | |
| /// owned by that owner (used on the matching engine chain). | |
| /// The map giving for each account owner the set of order IDs | |
| /// owned by that owner. |
Well,
|
|
Sure, I'm not against also publishing all transactions in an event stream. I agree that could be useful, and I didn't mean to suggest that the overhead for the network would be large. I just mean that for an individual user making an order it makes sense to me that there should be a low-overhead way to know their order status. This implementation provides that using a message. Subscribing to and filtering the event stream would be a lot more work for the client. |
I don't understand this comment
|
Co-authored-by: Andreas Fackler <[email protected]> Signed-off-by: Mathieu Baudet <[email protected]>
Co-authored-by: Andreas Fackler <[email protected]> Signed-off-by: Mathieu Baudet <[email protected]>
Co-authored-by: Andreas Fackler <[email protected]> Signed-off-by: Mathieu Baudet <[email protected]>
Co-authored-by: Andreas Fackler <[email protected]> Signed-off-by: Mathieu Baudet <[email protected]>
Co-authored-by: Andreas Fackler <[email protected]> Signed-off-by: Mathieu Baudet <[email protected]>
Motivation
Allow users to display their pending orders without following the entire CLOB appchain
Proposal
Cancelorders byModifywith new quantity equal to0ModifyQuantityto avoid code duplicationTest Plan
CI
Release Plan
testnetbranch