add maxDailyAmountOfTransfer check

This commit is contained in:
c9s 2021-05-16 00:50:15 +08:00
parent 942eaac659
commit 40b5baeda7

View File

@ -112,7 +112,7 @@ type Strategy struct {
Addresses map[string]string `json:"addresses"`
MaxDailyNumberOfTransfer int `json:"maxDailyNumberOfTransfer"`
MaxDailyAmountOfTransfer int `json:"maxDailyAmountOfTransfer"`
MaxDailyAmountOfTransfer fixedpoint.Value `json:"maxDailyAmountOfTransfer"`
Asset string `json:"asset"`
@ -132,6 +132,7 @@ func (s *Strategy) ID() string {
func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession) {}
func (s *Strategy) checkBalance(ctx context.Context, sessions map[string]*bbgo.ExchangeSession) {
s.Notifiability.Notify("Checking %s low balance level exchange session...", s.Asset)
lowLevelSession, lowLevelBalance, err := s.findLowBalanceLevelSession(sessions)
@ -175,6 +176,28 @@ func (s *Strategy) checkBalance(ctx context.Context, sessions map[string]*bbgo.E
return
}
if s.state != nil {
if s.MaxDailyNumberOfTransfer > 0 {
if s.state.DailyNumberOfTransfers >= s.MaxDailyNumberOfTransfer {
s.Notifiability.Notify("Exceeded %s max daily number of transfers %d (current %d), skipping transfer...",
s.Asset,
s.MaxDailyNumberOfTransfer,
s.state.DailyNumberOfTransfers)
return
}
}
if s.MaxDailyAmountOfTransfer > 0 {
if s.state.DailyAmountOfTransfers >= s.MaxDailyAmountOfTransfer {
s.Notifiability.Notify("Exceeded %s max daily amount of transfers %f (current %f), skipping transfer...",
s.Asset,
s.MaxDailyAmountOfTransfer.Float64(),
s.state.DailyAmountOfTransfers.Float64())
return
}
}
}
s.Notifiability.Notify(&WithdrawalRequest{
FromSession: fromSession.Name,
ToSession: lowLevelSession.Name,