From a48b282d069540262e09e51b9e7ce81be3b07f36 Mon Sep 17 00:00:00 2001 From: Reid McCamish <43561569+Reidmcc@users.noreply.github.com> Date: Thu, 4 Oct 2018 00:23:30 -0500 Subject: [PATCH 1/2] Update sellSideStrategy.go --- plugins/sellSideStrategy.go | 45 ++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/plugins/sellSideStrategy.go b/plugins/sellSideStrategy.go index fd4c7521c..c6ae6e1a0 100644 --- a/plugins/sellSideStrategy.go +++ b/plugins/sellSideStrategy.go @@ -111,28 +111,33 @@ 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 s.divideAmountByPrice { - targetAmount = *model.NumberFromFloat(targetAmount.AsFloat()/targetPrice.AsFloat(), targetAmount.Precision()) - } + 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) - } + 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) + } - // 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 + // 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 + } + } else { + log.Printf("A price was <= 0, cancelling order placement") + break } } From d87e7daebe984b65b3eb722e34bdedff6fd5889d Mon Sep 17 00:00:00 2001 From: Reid McCamish <43561569+Reidmcc@users.noreply.github.com> Date: Wed, 10 Oct 2018 22:57:10 -0500 Subject: [PATCH 2/2] Update sellSideStrategy.go --- plugins/sellSideStrategy.go | 52 +++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/plugins/sellSideStrategy.go b/plugins/sellSideStrategy.go index c6ae6e1a0..ee748cae6 100644 --- a/plugins/sellSideStrategy.go +++ b/plugins/sellSideStrategy.go @@ -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 } }