Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

Commit 82285f3

Browse files
authored
new oversell trigger during modify to check need to reduce amount of existing offers (#258), fixes #256
1 parent a9991dc commit 82285f3

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

plugins/sellSideStrategy.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,22 @@ func (s *sellSideStrategy) modifySellLevel(offers []hProtocol.Offer, index int,
410410
// existing offer not within tolerances
411411
priceTrigger := (curPrice > highestPrice) || (curPrice < lowestPrice)
412412
amountTrigger := (curAmount < minAmount) || (curAmount > maxAmount)
413+
var oversellTrigger bool
414+
sellingAsset := offers[index].Selling
413415
incrementalNativeAmountRaw := s.sdex.ComputeIncrementalNativeAmountRaw(false)
414-
if !priceTrigger && !amountTrigger {
416+
var e error
417+
if sellingAsset == utils.NativeAsset {
418+
oversellTrigger, e = s.ieif.willOversellNative(curAmount + incrementalNativeAmountRaw)
419+
if e != nil {
420+
return nil, false, nil, fmt.Errorf("could not check oversellTrigger for native asset: %s", e)
421+
}
422+
} else {
423+
oversellTrigger, e = s.ieif.willOversell(sellingAsset, curAmount)
424+
if e != nil {
425+
return nil, false, nil, fmt.Errorf("could not check oversellTrigger for sellingAsset (%s): %s", utils.Asset2String(sellingAsset), e)
426+
}
427+
}
428+
if !priceTrigger && !amountTrigger && !oversellTrigger {
415429
// always add back the current offer in the cached liabilities when we don't modify it
416430
s.ieif.AddLiabilities(offers[index].Selling, offers[index].Buying, curAmount, curAmount*curPrice, incrementalNativeAmountRaw)
417431
log.Printf("%s | modify | unmodified original level = %d | newLevel number = %d\n", s.action, index+1, newIndex+1)
@@ -425,6 +439,9 @@ func (s *sellSideStrategy) modifySellLevel(offers []hProtocol.Offer, index int,
425439
if amountTrigger {
426440
triggers = append(triggers, "amount")
427441
}
442+
if oversellTrigger {
443+
triggers = append(triggers, "oversell")
444+
}
428445

429446
targetPrice = *model.NumberByCappingPrecision(&targetPrice, s.orderConstraints.PricePrecision)
430447
targetAmount = *model.NumberByCappingPrecision(&targetAmount, s.orderConstraints.VolumePrecision)

0 commit comments

Comments
 (0)