mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 16:55:15 +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 {
|
type FundingFee struct {
|
||||||
Asset string `json:"asset"`
|
Asset string `json:"asset"`
|
||||||
Amount fixedpoint.Value `json:"amount"`
|
Amount fixedpoint.Value `json:"amount"`
|
||||||
|
Txn int64 `json:"txn"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProfitStats struct {
|
type ProfitStats struct {
|
||||||
|
@ -18,15 +19,18 @@ type ProfitStats struct {
|
||||||
FundingFeeCurrency string `json:"fundingFeeCurrency"`
|
FundingFeeCurrency string `json:"fundingFeeCurrency"`
|
||||||
TotalFundingFee fixedpoint.Value `json:"totalFundingFee"`
|
TotalFundingFee fixedpoint.Value `json:"totalFundingFee"`
|
||||||
FundingFeeRecords []FundingFee `json:"fundingFeeRecords"`
|
FundingFeeRecords []FundingFee `json:"fundingFeeRecords"`
|
||||||
|
LastFundingFeeTxn int64 `json:"lastFundingFeeTxn"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ProfitStats) AddFundingFee(fee FundingFee) error {
|
func (s *ProfitStats) AddFundingFee(fee FundingFee) error {
|
||||||
s.FundingFeeRecords = append(s.FundingFeeRecords, fee)
|
|
||||||
s.TotalFundingFee = s.TotalFundingFee.Add(fee.Amount)
|
|
||||||
if s.FundingFeeCurrency == "" {
|
if s.FundingFeeCurrency == "" {
|
||||||
s.FundingFeeCurrency = fee.Asset
|
s.FundingFeeCurrency = fee.Asset
|
||||||
} else if 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)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -402,6 +402,7 @@ func (s *Strategy) CrossRun(ctx context.Context, orderExecutionRouter bbgo.Order
|
||||||
err := s.ProfitStats.AddFundingFee(FundingFee{
|
err := s.ProfitStats.AddFundingFee(FundingFee{
|
||||||
Asset: b.Asset,
|
Asset: b.Asset,
|
||||||
Amount: b.BalanceChange,
|
Amount: b.BalanceChange,
|
||||||
|
Txn: e.Transaction,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("unable to add funding fee to profitStats")
|
log.WithError(err).Error("unable to add funding fee to profitStats")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user