mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
xfunding: check funding fee and record txn id
This commit is contained in:
parent
ff35fd06c4
commit
a6b47fda72
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue
Block a user