From ac33b5a8785b68c7481ce210211de51d99d40523 Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 26 Mar 2023 02:13:22 +0800 Subject: [PATCH] xfunding: check duplicated funding fee txn --- pkg/strategy/xfunding/profitstats.go | 4 ++++ pkg/strategy/xfunding/strategy.go | 2 ++ 2 files changed, 6 insertions(+) diff --git a/pkg/strategy/xfunding/profitstats.go b/pkg/strategy/xfunding/profitstats.go index 04c98a65a..ae56b1331 100644 --- a/pkg/strategy/xfunding/profitstats.go +++ b/pkg/strategy/xfunding/profitstats.go @@ -29,6 +29,10 @@ func (s *ProfitStats) AddFundingFee(fee FundingFee) error { return fmt.Errorf("unexpected error, funding fee currency is not matched, given: %s, wanted: %s", fee.Asset, s.FundingFeeCurrency) } + if s.LastFundingFeeTxn == fee.Txn { + return errDuplicatedFundingFeeTxnId + } + s.FundingFeeRecords = append(s.FundingFeeRecords, fee) s.TotalFundingFee = s.TotalFundingFee.Add(fee.Amount) s.LastFundingFeeTxn = fee.Txn diff --git a/pkg/strategy/xfunding/strategy.go b/pkg/strategy/xfunding/strategy.go index a88b866dc..5d9b3fc70 100644 --- a/pkg/strategy/xfunding/strategy.go +++ b/pkg/strategy/xfunding/strategy.go @@ -62,6 +62,8 @@ var log = logrus.WithField("strategy", ID) var errNotBinanceExchange = errors.New("not binance exchange, currently only support binance exchange") +var errDuplicatedFundingFeeTxnId = errors.New("duplicated funding fee txn id") + func init() { // Register the pointer of the strategy struct, // so that bbgo knows what struct to be used to unmarshal the configs (YAML or JSON)