xfunding: check funding fee and record txn id

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

View File

@ -10,6 +10,7 @@ import (
type FundingFee struct {
Asset string `json:"asset"`
Amount fixedpoint.Value `json:"amount"`
Txn int64 `json:"txn"`
}
type ProfitStats struct {
@ -18,15 +19,18 @@ type ProfitStats struct {
FundingFeeCurrency string `json:"fundingFeeCurrency"`
TotalFundingFee fixedpoint.Value `json:"totalFundingFee"`
FundingFeeRecords []FundingFee `json:"fundingFeeRecords"`
LastFundingFeeTxn int64 `json:"lastFundingFeeTxn"`
}
func (s *ProfitStats) AddFundingFee(fee FundingFee) error {
s.FundingFeeRecords = append(s.FundingFeeRecords, fee)
s.TotalFundingFee = s.TotalFundingFee.Add(fee.Amount)
if s.FundingFeeCurrency == "" {
s.FundingFeeCurrency = fee.Asset
} else if s.FundingFeeCurrency != fee.Asset {
return fmt.Errorf("unexpected error, funding fee currency is not matched, given: %s, wanted: %s", fee.Asset, s.FundingFeeCurrency)
}
s.FundingFeeRecords = append(s.FundingFeeRecords, fee)
s.TotalFundingFee = s.TotalFundingFee.Add(fee.Amount)
s.LastFundingFeeTxn = fee.Txn
return nil
}

View File

@ -402,6 +402,7 @@ func (s *Strategy) CrossRun(ctx context.Context, orderExecutionRouter bbgo.Order
err := s.ProfitStats.AddFundingFee(FundingFee{
Asset: b.Asset,
Amount: b.BalanceChange,
Txn: e.Transaction,
})
if err != nil {
log.WithError(err).Error("unable to add funding fee to profitStats")