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

Commit

Permalink
fixes #40: fix op_underfunded errors when we hit capacity limits
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsaraf committed Oct 30, 2018
1 parent 880b1b1 commit b63d8f1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions plugins/sellSideStrategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (s *sellSideStrategy) UpdateWithOps(offers []horizon.Offer) (ops []build.Tr
if targetAmount.AsFloat() == 0 {
return nil, nil, fmt.Errorf("targetAmount is 0")
}

if s.divideAmountByPrice {
targetAmount = *model.NumberFromFloat(targetAmount.AsFloat()/targetPrice.AsFloat(), targetAmount.Precision())
}
Expand All @@ -157,7 +157,12 @@ func (s *sellSideStrategy) UpdateWithOps(offers []horizon.Offer) (ops []build.Tr
return nil, nil, e
}
if op != nil {
ops = append(ops, op)
if hitCapacityLimit && isModify {
// prepend operations that reduce the size of an existing order because they decrease our liabilities
ops = append([]build.TransactionMutator{op}, ops...)
} else {
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
Expand Down

0 comments on commit b63d8f1

Please sign in to comment.