Skip to content
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

fix: lp_cancel_orders_batch to accepts OrderId as string/hex #5504

Merged
merged 3 commits into from
Dec 16, 2024

Conversation

marcellorigotti
Copy link
Contributor

Pull Request

Closes: PRO-1897

Checklist

Please conduct a thorough self-review before opening the PR.

  • I am confident that the code works.
  • I have written sufficient tests.
  • I have written and tested required migrations.
  • I have updated documentation where appropriate.

Summary

Updated the LP-API cancel_orders_batch to accepts OrderId as string/hex as well

Non-Breaking changes

If this PR includes non-breaking changes, select the non-breaking label. On merge, CI will automatically cherry-pick the commit to a PR against the release branch.

Copy link

codecov bot commented Dec 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72%. Comparing base (8f4011f) to head (0c3f70f).
Report is 43 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##            main   #5504     +/-   ##
=======================================
- Coverage     72%     72%     -0%     
=======================================
  Files        490     495      +5     
  Lines      86894   88259   +1365     
  Branches   86894   88259   +1365     
=======================================
+ Hits       62395   63169    +774     
- Misses     21565   22521    +956     
+ Partials    2934    2569    -365     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kylezs kylezs changed the title Feature/pro 1897 fix: lp_cancel_orders_batch to accepts OrderId as string/hex Dec 15, 2024
@kylezs kylezs marked this pull request as draft December 15, 2024 22:45
Comment on lines 628 to 634
let mut final_orders: BoundedVec<CloseOrder, ConstU32<MAX_ORDERS_DELETE>> =
BoundedVec::new();
for order in orders {
final_orders
.try_push(order.try_into()?)
.expect("Impossible to fail, given the same MAX_ORDERS_DELETE");
}
Copy link
Contributor

@kylezs kylezs Dec 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove the mut var by collecting

Suggested change
let mut final_orders: BoundedVec<CloseOrder, ConstU32<MAX_ORDERS_DELETE>> =
BoundedVec::new();
for order in orders {
final_orders
.try_push(order.try_into()?)
.expect("Impossible to fail, given the same MAX_ORDERS_DELETE");
}
Ok(self
.api
.lp_api()
.cancel_orders_batch(
orders
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<_>, _>>()?
.try_into()
.expect("Impossible to fail, given the same MAX_ORDERS_DELETE"),
wait_for.unwrap_or_default(),
)
.await?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this require an extra memory allocation for the Vec<> when collecting?
(or maybe this gets optimized away by the compiler?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe so. But given the performance gain is negligible, I think having without a mut var is a bit simpler and less likely to be mistakenly broken with future changes (definitely isn't a strong opinion which way is preferred here)

@marcellorigotti marcellorigotti marked this pull request as ready for review December 16, 2024 16:11
@kylezs kylezs added this pull request to the merge queue Dec 16, 2024
Merged via the queue into main with commit e149a50 Dec 16, 2024
48 checks passed
@kylezs kylezs deleted the feature/pro-1897 branch December 16, 2024 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants