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

Commit

Permalink
new oversell trigger during modify to check need to reduce amount of …
Browse files Browse the repository at this point in the history
…existing offers (#258), fixes #256
  • Loading branch information
nikhilsaraf committed Aug 26, 2019
1 parent 0806ee7 commit f6a2f05
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion plugins/sellSideStrategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,22 @@ func (s *sellSideStrategy) modifySellLevel(offers []hProtocol.Offer, index int,
// existing offer not within tolerances
priceTrigger := (curPrice > highestPrice) || (curPrice < lowestPrice)
amountTrigger := (curAmount < minAmount) || (curAmount > maxAmount)
var oversellTrigger bool
sellingAsset := offers[index].Selling
incrementalNativeAmountRaw := s.sdex.ComputeIncrementalNativeAmountRaw(false)
if !priceTrigger && !amountTrigger {
var e error
if sellingAsset == utils.NativeAsset {
oversellTrigger, e = s.ieif.willOversellNative(curAmount + incrementalNativeAmountRaw)
if e != nil {
return nil, false, nil, fmt.Errorf("could not check oversellTrigger for native asset: %s", e)
}
} else {
oversellTrigger, e = s.ieif.willOversell(sellingAsset, curAmount)
if e != nil {
return nil, false, nil, fmt.Errorf("could not check oversellTrigger for sellingAsset (%s): %s", utils.Asset2String(sellingAsset), e)
}
}
if !priceTrigger && !amountTrigger && !oversellTrigger {
// always add back the current offer in the cached liabilities when we don't modify it
s.ieif.AddLiabilities(offers[index].Selling, offers[index].Buying, curAmount, curAmount*curPrice, incrementalNativeAmountRaw)
log.Printf("%s | modify | unmodified original level = %d | newLevel number = %d\n", s.action, index+1, newIndex+1)
Expand All @@ -426,6 +440,9 @@ func (s *sellSideStrategy) modifySellLevel(offers []hProtocol.Offer, index int,
if amountTrigger {
triggers = append(triggers, "amount")
}
if oversellTrigger {
triggers = append(triggers, "oversell")
}

targetPrice = *model.NumberByCappingPrecision(&targetPrice, s.orderConstraints.PricePrecision)
targetAmount = *model.NumberByCappingPrecision(&targetAmount, s.orderConstraints.VolumePrecision)
Expand Down

0 comments on commit f6a2f05

Please sign in to comment.