mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
binance: add binance spot rebate history support
This commit is contained in:
parent
2eeb907452
commit
2fb36f4a9f
45
pkg/exchange/binance/reward.go
Normal file
45
pkg/exchange/binance/reward.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
package binance
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/exchange/binance/binanceapi"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
func (e *Exchange) QueryRewards(ctx context.Context, startTime time.Time) ([]types.Reward, error) {
|
||||
req := e.client2.NewGetSpotRebateHistoryRequest()
|
||||
req.StartTime(startTime)
|
||||
history, err := req.Do(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var rewards []types.Reward
|
||||
|
||||
for _, entry := range history {
|
||||
t := types.RewardCommission
|
||||
switch entry.Type {
|
||||
case binanceapi.RebateTypeReferralKickback:
|
||||
t = types.RewardReferralKickback
|
||||
case binanceapi.RebateTypeCommission:
|
||||
// use the default type
|
||||
}
|
||||
|
||||
rewards = append(rewards, types.Reward{
|
||||
UUID: strconv.FormatInt(entry.UpdateTime.Time().UnixMilli(), 10),
|
||||
Exchange: types.ExchangeBinance,
|
||||
Type: t,
|
||||
Currency: entry.Asset,
|
||||
Quantity: entry.Amount,
|
||||
State: "done",
|
||||
Note: "",
|
||||
Spent: false,
|
||||
CreatedAt: types.Time(entry.UpdateTime),
|
||||
})
|
||||
}
|
||||
|
||||
return rewards, nil
|
||||
}
|
|
@ -12,6 +12,7 @@ type RewardType string
|
|||
const (
|
||||
RewardAirdrop = RewardType("airdrop")
|
||||
RewardCommission = RewardType("commission")
|
||||
RewardReferralKickback = RewardType("referral_kickback")
|
||||
RewardHolding = RewardType("holding")
|
||||
RewardMining = RewardType("mining")
|
||||
RewardTrading = RewardType("trading")
|
||||
|
|
Loading…
Reference in New Issue
Block a user