-
-
Notifications
You must be signed in to change notification settings - Fork 296
/
reward.go
45 lines (38 loc) · 1023 Bytes
/
reward.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
}