twap: improve cancelContextIfTargetQuantityFilled check method

This commit is contained in:
c9s 2024-08-20 14:14:19 +08:00
parent 0530809834
commit b9c41b7ad7
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -220,10 +220,14 @@ func (e *FixedQuantityExecutor) handleFilledOrder(order types.Order) {
} }
func (e *FixedQuantityExecutor) cancelContextIfTargetQuantityFilled() bool { func (e *FixedQuantityExecutor) cancelContextIfTargetQuantityFilled() bool {
// ensure that the trades are processed
e.tradeCollector.Process()
// now get the base quantity from the position
base := e.position.GetBase() base := e.position.GetBase()
if base.Abs().Compare(e.targetQuantity) >= 0 { if base.Abs().Sub(e.targetQuantity).Compare(e.market.MinQuantity.Neg()) >= 0 {
e.logger.Infof("filled target quantity, canceling the order execution context") e.logger.Infof("position is filled with target quantity, canceling the order execution context")
e.cancelExecution() e.cancelExecution()
return true return true
} }