Skip to content

Commit

Permalink
xmaker: fix stop hedge balance condition
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed May 26, 2021
1 parent 5cc3ed2 commit 61e5d7c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pkg/strategy/xmaker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,13 @@ func (s *Strategy) updateQuote(ctx context.Context, orderExecutionRouter bbgo.Or
if b, ok := hedgeBalances[s.sourceMarket.BaseCurrency]; ok {
// to make bid orders, we need enough base asset in the foreign exchange,
// if the base asset balance is not enough for selling
if s.StopHedgeBaseBalance > 0 && b.Available > (s.StopHedgeBaseBalance+fixedpoint.NewFromFloat(s.sourceMarket.MinQuantity)) {
hedgeQuota.BaseAsset.Add(b.Available - s.StopHedgeBaseBalance - fixedpoint.NewFromFloat(s.sourceMarket.MinQuantity))
if s.StopHedgeBaseBalance > 0 {
if b.Available > (s.StopHedgeBaseBalance + fixedpoint.NewFromFloat(s.sourceMarket.MinQuantity)) {
hedgeQuota.BaseAsset.Add(b.Available - s.StopHedgeBaseBalance - fixedpoint.NewFromFloat(s.sourceMarket.MinQuantity))
} else {
log.Warnf("%s maker bid disabled: insufficient base balance %s", s.Symbol, b.String())
disableMakerBid = true
}
} else if b.Available.Float64() > s.sourceMarket.MinQuantity {
hedgeQuota.BaseAsset.Add(b.Available)
} else {
Expand All @@ -232,8 +237,13 @@ func (s *Strategy) updateQuote(ctx context.Context, orderExecutionRouter bbgo.Or
if b, ok := hedgeBalances[s.sourceMarket.QuoteCurrency]; ok {
// to make ask orders, we need enough quote asset in the foreign exchange,
// if the quote asset balance is not enough for buying
if s.StopHedgeQuoteBalance > 0 && b.Available > (s.StopHedgeQuoteBalance+fixedpoint.NewFromFloat(s.sourceMarket.MinNotional)) {
hedgeQuota.QuoteAsset.Add(b.Available - s.StopHedgeQuoteBalance - fixedpoint.NewFromFloat(s.sourceMarket.MinNotional))
if s.StopHedgeQuoteBalance > 0 {
if b.Available > (s.StopHedgeQuoteBalance + fixedpoint.NewFromFloat(s.sourceMarket.MinNotional)) {
hedgeQuota.QuoteAsset.Add(b.Available - s.StopHedgeQuoteBalance - fixedpoint.NewFromFloat(s.sourceMarket.MinNotional))
} else {
log.Warnf("%s maker ask disabled: insufficient quote balance %s", s.Symbol, b.String())
disableMakerAsk = true
}
} else if b.Available.Float64() > s.sourceMarket.MinNotional {
hedgeQuota.QuoteAsset.Add(b.Available)
} else {
Expand Down

0 comments on commit 61e5d7c

Please sign in to comment.