add stringer method for deposit struct

This commit is contained in:
c9s 2022-06-08 17:32:42 +08:00
parent 6d78b05b41
commit f3a7428b48
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
5 changed files with 27 additions and 21 deletions

View File

@ -600,7 +600,7 @@ func (environ *Environment) syncWithUserConfig(ctx context.Context, userConfig *
} }
if userConfig.Sync.DepositHistory { if userConfig.Sync.DepositHistory {
if err := environ.SyncService.SyncDepositHistory(ctx, session.Exchange); err != nil { if err := environ.SyncService.SyncDepositHistory(ctx, session.Exchange, since); err != nil {
return err return err
} }
} }
@ -664,7 +664,7 @@ func (environ *Environment) Sync(ctx context.Context, userConfig ...*Config) err
} }
if userConfig[0].Sync.DepositHistory { if userConfig[0].Sync.DepositHistory {
if err := environ.SyncService.SyncDepositHistory(ctx, session.Exchange); err != nil { if err := environ.SyncService.SyncDepositHistory(ctx, session.Exchange, since); err != nil {
return err return err
} }
} }

View File

@ -66,20 +66,6 @@ func (s *DepositService) Sync(ctx context.Context, ex types.Exchange, startTime
return nil return nil
} }
func (s *DepositService) QueryLast(ex types.ExchangeName, limit int) ([]types.Deposit, error) {
sql := "SELECT * FROM `deposits` WHERE `exchange` = :exchange ORDER BY `time` DESC LIMIT :limit"
rows, err := s.DB.NamedQuery(sql, map[string]interface{}{
"exchange": ex,
"limit": limit,
})
if err != nil {
return nil, err
}
defer rows.Close()
return s.scanRows(rows)
}
func (s *DepositService) Query(exchangeName types.ExchangeName) ([]types.Deposit, error) { func (s *DepositService) Query(exchangeName types.ExchangeName) ([]types.Deposit, error) {
args := map[string]interface{}{ args := map[string]interface{}{
"exchange": exchangeName, "exchange": exchangeName,
@ -115,7 +101,6 @@ func (s *DepositService) Insert(deposit types.Deposit) error {
return err return err
} }
func SelectLastDeposits(ex types.ExchangeName, limit uint64) sq.SelectBuilder { func SelectLastDeposits(ex types.ExchangeName, limit uint64) sq.SelectBuilder {
return sq.Select("*"). return sq.Select("*").
From("deposits"). From("deposits").

View File

@ -88,9 +88,9 @@ func (s *SyncService) SyncRewardHistory(ctx context.Context, exchange types.Exch
return nil return nil
} }
func (s *SyncService) SyncDepositHistory(ctx context.Context, exchange types.Exchange) error { func (s *SyncService) SyncDepositHistory(ctx context.Context, exchange types.Exchange, startTime time.Time) error {
log.Infof("syncing %s deposit records...", exchange.Name()) log.Infof("syncing %s deposit records...", exchange.Name())
if err := s.DepositService.Sync(ctx, exchange); err != nil { if err := s.DepositService.Sync(ctx, exchange, startTime); err != nil {
if err != ErrNotImplemented { if err != ErrNotImplemented {
log.Warnf("%s deposit service is not supported", exchange.Name()) log.Warnf("%s deposit service is not supported", exchange.Name())
return err return err

View File

@ -1,8 +1,10 @@
package types package types
import ( import (
"github.com/c9s/bbgo/pkg/fixedpoint" "fmt"
"time" "time"
"github.com/c9s/bbgo/pkg/fixedpoint"
) )
type DepositStatus string type DepositStatus string
@ -37,3 +39,22 @@ type Deposit struct {
func (d Deposit) EffectiveTime() time.Time { func (d Deposit) EffectiveTime() time.Time {
return d.Time.Time() return d.Time.Time()
} }
func (d Deposit) String() (o string) {
o = fmt.Sprintf("%s deposit %s %v <- ", d.Exchange, d.Asset, d.Amount)
if len(d.AddressTag) > 0 {
o += fmt.Sprintf("%s (tag: %s) at %s", d.Address, d.AddressTag, d.Time.Time())
} else {
o += fmt.Sprintf("%s at %s", d.Address, d.Time.Time())
}
if len(d.TransactionID) > 0 {
o += fmt.Sprintf("txID: %s", cutstr(d.TransactionID, 12, 4, 4))
}
if len(d.Status) > 0 {
o += "status: " + string(d.Status)
}
return o
}

View File

@ -33,7 +33,7 @@ func cutstr(s string, maxLen, head, tail int) string {
} }
func (w Withdraw) String() (o string) { func (w Withdraw) String() (o string) {
o = fmt.Sprintf("withdraw %s %v -> ", w.Asset, w.Amount) o = fmt.Sprintf("%s withdraw %s %v -> ", w.Exchange, w.Asset, w.Amount)
if len(w.Network) > 0 && w.Network != w.Asset { if len(w.Network) > 0 && w.Network != w.Asset {
o += w.Network + ":" o += w.Network + ":"