-
-
Notifications
You must be signed in to change notification settings - Fork 302
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
FEATURE: recover active orders with open orders periodically #1328
FEATURE: recover active orders with open orders periodically #1328
Conversation
Hi @kbearXD, This pull request may get 322 BBG. To receive BBG token, please left your polygon address as an issue comment in this pull request with the following format, e.g.,
Once this pull request is merged, your BBG token will be sent to your wallet. |
Codecov Report
@@ Coverage Diff @@
## main #1328 +/- ##
==========================================
+ Coverage 20.68% 20.79% +0.11%
==========================================
Files 560 561 +1
Lines 40014 40105 +91
==========================================
+ Hits 8276 8339 +63
- Misses 31138 31160 +22
- Partials 600 606 +6
... and 5 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Re-estimated karma: this pull request may get 317 BBG |
} | ||
} | ||
|
||
ticker := time.NewTicker(util.MillisecondsJitter(40*time.Minute, 30*60*1000)) |
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.
how did you decide the interval? does it mean 40minutes + 0~30minute jitter?
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.
Yes, because I think we don't need to check it very frequently, so I wanna choose interval around 1 hour. To avoid DDOS, I use 0-30 min jitter.
for _, activeOrder := range activeOrders { | ||
if _, exist := openOrdersMap[activeOrder.OrderID]; !exist { | ||
s.logger.Infof("find active order (%d) not in open orders, updating...", activeOrder.OrderID) | ||
delete(openOrdersMap, activeOrder.OrderID) |
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.
OrderID looks not existing in the map? So the delete is redundant?
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.
change to delete when exist
pkg/strategy/grid2/strategy.go
Outdated
|
||
s.recoverActiveOrders(ctx, session) | ||
}) | ||
*/ |
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.
remove unused code?
pkg/strategy/grid2/strategy.go
Outdated
|
||
s.recoverActiveOrders(ctx, session) | ||
}) | ||
go s.recoverActiveOrdersWithOpenOrdersPeriodically(ctx) |
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.
every "OnAuth" event will launch a new goroutine for 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.
you might need to check if recovered := atomic.LoadInt32(&s.recovered)
then we start the goroutine for this?
or maybe you can move this to OnStart (which only trigger one time)
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.
Yes, I should move it to OnStart
Re-estimated karma: this pull request may get 395 BBG |
} | ||
} | ||
|
||
func (s *Strategy) queryOpenOrdersThenRecoverActiveOrders(ctx context.Context) { |
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.
how about just syncOpenOrders
// update active orders not in open orders | ||
for _, activeOrder := range activeOrders { | ||
if _, exist := openOrdersMap[activeOrder.OrderID]; !exist { | ||
s.logger.Infof("find active order (%d) not in open orders, updating...", activeOrder.OrderID) |
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.
use #%d format for the orderID
}) | ||
|
||
if err != nil { | ||
s.logger.WithError(err).Errorf("[ActiveOrderRecover] unable to query order (%d)", activeOrder.OrderID) |
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.
use #%d format for the orderID
Re-estimated karma: this pull request may get 437 BBG |
Re-estimated karma: this pull request may get 442 BBG |
Re-estimated karma: this pull request may get 446 BBG |
Re-estimated karma: this pull request may get 471 BBG |
var openOrdersExpired bool = false | ||
for _, activeOrder := range activeOrders { | ||
if _, exist := openOrdersMap[activeOrder.OrderID]; exist { | ||
if openOrdersExpired || time.Now().After(openOrdersExpiredTime) { |
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.
pull out time.Now() to variable now
?
Re-estimated karma: this pull request may get 508 BBG |
} | ||
|
||
// update active orders not in open orders | ||
var openOrdersExpired bool = false |
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.
explain how this variable is used in the comment?
Re-estimated karma: this pull request may get 518 BBG |
5633d92
to
c544937
Compare
Re-estimated karma: this pull request may get 712 BBG |
pkg/strategy/grid2/strategy.go
Outdated
s.recoverActiveOrders(ctx, session) | ||
}) | ||
} | ||
time.AfterFunc(util.MillisecondsJitter(5*time.Second, 1000*10), func() { |
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.
need to check if it's in backtest here, you need to run backtest
Re-estimated karma: this pull request may get 764 BBG |
Re-estimated karma: this pull request may get 782 BBG |
s.mu.Lock() | ||
defer s.mu.Unlock() | ||
|
||
alreadyInitialize := false |
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.
isInitialized
is much simpler word
alreadyInitialize := false | ||
|
||
if s.activeOrdersRecoverCh == nil { | ||
s.logger.Info("initialize recover channel") |
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.
use word initializing
s.logger.Info("initialize recover channel") | ||
s.activeOrdersRecoverCh = make(chan struct{}, 1) | ||
} else { | ||
s.logger.Info("already initialize recover channel, trigger active orders recover") |
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.
recover channel is already already initialized
} else { | ||
s.logger.Info("already initialize recover channel, trigger active orders recover") | ||
alreadyInitialize = true | ||
s.activeOrdersRecoverCh <- struct{}{} |
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.
use select + default case to skip it if the channel is full?
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.
OK!
log.WithError(err).Errorf("unable to sync active orders") | ||
} | ||
|
||
case <-s.activeOrdersRecoverCh: |
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.
we usually end the channel var with C instead of Ch
Re-estimated karma: this pull request may get 839 BBG |
Re-estimated karma: this pull request may get 883 BBG |
No description provided.