-
Notifications
You must be signed in to change notification settings - Fork 154
Add v1/orders POST endpoint to get orders in batches #4048
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
Adds POST handler for `v1/orders` endpoint that requires a list of order uids and responds with a vector of their data. Has a hardcoded limit of 5000 orders per request.
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 Review
This pull request introduces a new endpoint v1/get_orders to retrieve orders in batches using a POST request with a limit of 5000 orders per request. The code adds a new module get_orders_by_uid.rs, modifies api.rs to include the new route, and updates database/orders.rs and orderbook.rs to support fetching multiple orders. I found a missing test case for the MAX_ORDERS_LIMIT validation.
|
Tested on sepolia staging: (queries twice for the same order) response |
|
By the way, we can have a discussion on what the endpoint itself should be. I got a couple suggestions from Claude
based on the above suggestions I have opted for a custom not-order-id-like name |
| async move { | ||
| Result::<_, Infallible>::Ok(match request_result { | ||
| Ok(uids) => { | ||
| let result = orderbook.get_orders(&uids).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.
This will accumulate all the orders in memory, which is probably not a good idea. Can we instead return a stream of data directly from the DB?
| for uid in uids { | ||
| results.push( | ||
| match orders::single_full_order_with_quote(&mut ex, &ByteArray(uid.0)).await? { | ||
| Some(order_with_quote) => { | ||
| let (order, quote) = order_with_quote.into_order_and_quote(); | ||
| Some(full_order_with_quote_into_model_order( | ||
| order, | ||
| quote.as_ref(), | ||
| )) | ||
| } | ||
| None => { | ||
| // try to find the order in the JIT orders table | ||
| database::jit_orders::get_by_id(&mut ex, &ByteArray(uid.0)) | ||
| .await? | ||
| .map(full_order_into_model_order) | ||
| } | ||
| } | ||
| .transpose(), | ||
| ); | ||
| } |
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.
Sequential fetching of 5k orders will result in a nightmare performance.
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 best option is to introduce a query to fetch everything at once using the QueryBuilder. There are many examples in the code.
Description
Aave wants to track specific orders in bulk, knowing their ids.
Changes
Adds POST handler for
v1/orders/lookupendpoint that requires a list of order uids and responds with a vector of their data. Has a hardcoded limit of 5000 orders per request.How to test
Test on staging, query multiple orders using this API.