From 891cac06406769547317491bd8d8d59f80b69c29 Mon Sep 17 00:00:00 2001 From: chiahung Date: Wed, 15 Mar 2023 17:29:17 +0800 Subject: [PATCH 1/2] FIX: fix wrong fee currency --- pkg/strategy/grid2/strategy.go | 1 + pkg/strategy/grid2/trade.go | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/strategy/grid2/strategy.go b/pkg/strategy/grid2/strategy.go index 7b19a537c..b158ea7db 100644 --- a/pkg/strategy/grid2/strategy.go +++ b/pkg/strategy/grid2/strategy.go @@ -360,6 +360,7 @@ func (s *Strategy) aggregateOrderFee(o types.Order) (fixedpoint.Value, string) { if o.Side == types.SideTypeSell { feeCurrency = s.Market.QuoteCurrency } + feeCurrency = strings.ToUpper(feeCurrency) for maxTries := maxNumberOfOrderTradesQueryTries; maxTries > 0; maxTries-- { // if one of the trades is missing, we need to query the trades from the RESTful API diff --git a/pkg/strategy/grid2/trade.go b/pkg/strategy/grid2/trade.go index 381744ccd..f0bbcd1a9 100644 --- a/pkg/strategy/grid2/trade.go +++ b/pkg/strategy/grid2/trade.go @@ -1,6 +1,8 @@ package grid2 import ( + "strings" + "github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/types" ) @@ -9,10 +11,11 @@ import ( func collectTradeFee(trades []types.Trade) map[string]fixedpoint.Value { fees := make(map[string]fixedpoint.Value) for _, t := range trades { - if fee, ok := fees[t.FeeCurrency]; ok { - fees[t.FeeCurrency] = fee.Add(t.Fee) + feeCurrency := strings.ToUpper(t.FeeCurrency) + if fee, ok := fees[feeCurrency]; ok { + fees[feeCurrency] = fee.Add(t.Fee) } else { - fees[t.FeeCurrency] = t.Fee + fees[feeCurrency] = t.Fee } } return fees From 26054e4958ae422aacc355eb57805c4cf93836e1 Mon Sep 17 00:00:00 2001 From: chiahung Date: Wed, 15 Mar 2023 18:09:46 +0800 Subject: [PATCH 2/2] fix on max api level --- pkg/exchange/max/convert.go | 2 +- pkg/strategy/grid2/strategy.go | 1 - pkg/strategy/grid2/trade.go | 9 +++------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pkg/exchange/max/convert.go b/pkg/exchange/max/convert.go index fc169fac4..6047f5ee6 100644 --- a/pkg/exchange/max/convert.go +++ b/pkg/exchange/max/convert.go @@ -226,7 +226,7 @@ func toGlobalTradeV3(t v3.Trade) ([]types.Trade, error) { bidTrade.Side = types.SideTypeBuy bidTrade.OrderID = t.SelfTradeBidOrderID bidTrade.Fee = t.SelfTradeBidFee - bidTrade.FeeCurrency = t.SelfTradeBidFeeCurrency + bidTrade.FeeCurrency = toGlobalCurrency(t.SelfTradeBidFeeCurrency) bidTrade.IsBuyer = !trade.IsBuyer bidTrade.IsMaker = !trade.IsMaker trades = append(trades, bidTrade) diff --git a/pkg/strategy/grid2/strategy.go b/pkg/strategy/grid2/strategy.go index b158ea7db..7b19a537c 100644 --- a/pkg/strategy/grid2/strategy.go +++ b/pkg/strategy/grid2/strategy.go @@ -360,7 +360,6 @@ func (s *Strategy) aggregateOrderFee(o types.Order) (fixedpoint.Value, string) { if o.Side == types.SideTypeSell { feeCurrency = s.Market.QuoteCurrency } - feeCurrency = strings.ToUpper(feeCurrency) for maxTries := maxNumberOfOrderTradesQueryTries; maxTries > 0; maxTries-- { // if one of the trades is missing, we need to query the trades from the RESTful API diff --git a/pkg/strategy/grid2/trade.go b/pkg/strategy/grid2/trade.go index f0bbcd1a9..381744ccd 100644 --- a/pkg/strategy/grid2/trade.go +++ b/pkg/strategy/grid2/trade.go @@ -1,8 +1,6 @@ package grid2 import ( - "strings" - "github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/types" ) @@ -11,11 +9,10 @@ import ( func collectTradeFee(trades []types.Trade) map[string]fixedpoint.Value { fees := make(map[string]fixedpoint.Value) for _, t := range trades { - feeCurrency := strings.ToUpper(t.FeeCurrency) - if fee, ok := fees[feeCurrency]; ok { - fees[feeCurrency] = fee.Add(t.Fee) + if fee, ok := fees[t.FeeCurrency]; ok { + fees[t.FeeCurrency] = fee.Add(t.Fee) } else { - fees[feeCurrency] = t.Fee + fees[t.FeeCurrency] = t.Fee } } return fees