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

Commit

Permalink
Update sellSideStrategy.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Reidmcc authored Oct 11, 2018
1 parent a48b282 commit d87e7da
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions plugins/sellSideStrategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,33 +111,35 @@ func (s *sellSideStrategy) UpdateWithOps(offers []horizon.Offer) (ops []build.Tr
// hitCapacityLimit can be updated below
targetPrice := s.currentLevels[i].Price
targetAmount := s.currentLevels[i].Amount
if targetAmount.AsFloat() > 0 && targetPrice.AsFloat() > 0 {
if s.divideAmountByPrice {
targetAmount = *model.NumberFromFloat(targetAmount.AsFloat()/targetPrice.AsFloat(), targetAmount.Precision())
}

var offerPrice *model.Number
var op *build.ManageOfferBuilder
var e error
if isModify {
offerPrice, hitCapacityLimit, op, e = s.modifySellLevel(offers, i, targetPrice, targetAmount)
} else {
offerPrice, hitCapacityLimit, op, e = s.createSellLevel(targetPrice, targetAmount)
}
if e != nil {
return nil, nil, e
}
if op != nil {
ops = append(ops, op)
}
if targetPrice.AsFloat() == 0 {
return nil, nil, fmt.Errorf("targetPrice is 0")
}
if targetAmount.AsFloat() == 0 {
return nil, nil, fmt.Errorf("targetAmount is 0")
}

if s.divideAmountByPrice {
targetAmount = *model.NumberFromFloat(targetAmount.AsFloat()/targetPrice.AsFloat(), targetAmount.Precision())
}

// update top offer, newTopOffer is minOffer because this is a sell strategy, and the lowest price is the best (top) price on the orderbook
if newTopOffer == nil || offerPrice.AsFloat() < newTopOffer.AsFloat() {
newTopOffer = offerPrice
}
var offerPrice *model.Number
var op *build.ManageOfferBuilder
var e error
if isModify {
offerPrice, hitCapacityLimit, op, e = s.modifySellLevel(offers, i, targetPrice, targetAmount)
} else {
log.Printf("A price was <= 0, cancelling order placement")
break
offerPrice, hitCapacityLimit, op, e = s.createSellLevel(targetPrice, targetAmount)
}
if e != nil {
return nil, nil, e
}
if op != nil {
ops = append(ops, op)
}

// update top offer, newTopOffer is minOffer because this is a sell strategy, and the lowest price is the best (top) price on the orderbook
if newTopOffer == nil || offerPrice.AsFloat() < newTopOffer.AsFloat() {
newTopOffer = offerPrice
}
}

Expand Down

0 comments on commit d87e7da

Please sign in to comment.