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: Fix duplicate orders caused by position risk control #1327

Merged
merged 2 commits into from
Oct 11, 2023

Conversation

narumiruna
Copy link
Collaborator

@narumiruna narumiruna commented Sep 27, 2023

cancel previous order before submitting position release order to prevent duplicate orders

@bbgokarma-bot
Copy link

Welcome back! @narumiruna, This pull request may get 227 BBG.

@codecov
Copy link

codecov bot commented Sep 27, 2023

Codecov Report

Merging #1327 (4a6f6f7) into main (a13c65e) will decrease coverage by 0.04%.
The diff coverage is 47.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1327      +/-   ##
==========================================
- Coverage   20.78%   20.74%   -0.04%     
==========================================
  Files         558      558              
  Lines       39790    39800      +10     
==========================================
- Hits         8269     8257      -12     
- Misses      30921    30944      +23     
+ Partials      600      599       -1     
Files Coverage Δ
pkg/risk/riskcontrol/position.go 40.38% <47.61%> (-38.19%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a13c65e...4a6f6f7. Read the comment docs.

@bbgokarma-bot
Copy link

Re-estimated karma: this pull request may get 247 BBG

p.activeOrderBook.BindStream(session.UserDataStream)

p.OnReleasePosition(func(quantity fixedpoint.Value, side types.SideType) {
if err := p.orderExecutor.CancelOrders(ctx, p.activeOrderBook.Orders()...); err != nil {
Copy link
Owner

Choose a reason for hiding this comment

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

I think p.activeOrderBook also provides the cancel api

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@bbgokarma-bot
Copy link

Re-estimated karma: this pull request may get 272 BBG

@@ -45,27 +72,16 @@ func NewPositionRiskControl(orderExecutor bbgo.OrderExecutorExtended, hardLimit,
}

log.Infof("RiskControl: position limit exceeded, submitting order to reduce position: %+v", submitOrder)
createdOrders, err := orderExecutor.SubmitOrders(context.Background(), submitOrder)
createdOrders, err := p.orderExecutor.SubmitOrders(ctx, submitOrder)
Copy link
Owner

Choose a reason for hiding this comment

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

need to be careful here, the trade collector might get stuck

would better to run a back-test to test this change~

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will run a back-test later

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the trade collector didn't get stuck

@bbgokarma-bot
Copy link

Re-estimated karma: this pull request may get 344 BBG

@c9s c9s merged commit 2f65793 into main Oct 11, 2023
3 of 4 checks passed
@c9s c9s deleted the narumi/fix-position-risk branch October 11, 2023 07:43
@bbgokarma-bot
Copy link

Hi @narumiruna,

Well done! 349 BBG has been sent to your polygon wallet. Please check the following tx:

https://polygonscan.com/tx/0xccce679d8e1eee717e0ec0904a92b66a08d0ab3038774e7a5f365d5ed3e67ae4

Thank you for your contribution!

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.

3 participants