xfunding: check duplicated funding fee txn

This commit is contained in:
c9s 2023-03-26 02:13:22 +08:00
parent a6b47fda72
commit ac33b5a878
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 6 additions and 0 deletions

View File

@ -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) 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.FundingFeeRecords = append(s.FundingFeeRecords, fee)
s.TotalFundingFee = s.TotalFundingFee.Add(fee.Amount) s.TotalFundingFee = s.TotalFundingFee.Add(fee.Amount)
s.LastFundingFeeTxn = fee.Txn s.LastFundingFeeTxn = fee.Txn

View File

@ -62,6 +62,8 @@ var log = logrus.WithField("strategy", ID)
var errNotBinanceExchange = errors.New("not binance exchange, currently only support binance exchange") var errNotBinanceExchange = errors.New("not binance exchange, currently only support binance exchange")
var errDuplicatedFundingFeeTxnId = errors.New("duplicated funding fee txn id")
func init() { func init() {
// Register the pointer of the strategy struct, // Register the pointer of the strategy struct,
// so that bbgo knows what struct to be used to unmarshal the configs (YAML or JSON) // so that bbgo knows what struct to be used to unmarshal the configs (YAML or JSON)