bbgo: add more sync options

This commit is contained in:
c9s 2022-04-25 17:18:42 +08:00
parent 76012f0b71
commit a57a238e09
No known key found for this signature in database
GPG Key ID: F0A7E4490F2EBC8C
6 changed files with 78 additions and 25 deletions

View File

@ -8,14 +8,6 @@ sessions:
exchange: max
envVarPrefix: max
okex:
exchange: okex
envVarPrefix: okex
kucoin:
exchange: kucoin
envVarPrefix: kucoin
sync:
# userDataStream is used to sync the trading data in real-time
# it uses the websocket connection to insert the trades

View File

@ -187,6 +187,15 @@ type SyncConfig struct {
// Symbols is the list of symbol to sync, if ignored, symbols wlll be discovered by your existing crypto balances
Symbols []string `json:"symbols,omitempty" yaml:"symbols,omitempty"`
// DepositHistory for syncing deposit history
DepositHistory bool `json:"depositHistory" yaml:"depositHistory"`
// WithdrawHistory for syncing withdraw history
WithdrawHistory bool `json:"withdrawHistory" yaml:"withdrawHistory"`
// RewardHistory for syncing reward history
RewardHistory bool `json:"rewardHistory" yaml:"rewardHistory"`
// Since is the date where you want to start syncing data
Since *types.LooseFormatTime `json:"since,omitempty"`

View File

@ -561,11 +561,31 @@ func (environ *Environment) Sync(ctx context.Context, userConfig ...*Config) err
if len(selectedSessions) > 0 {
sessions = environ.SelectSessions(selectedSessions...)
}
for _, session := range sessions {
if err := environ.syncSession(ctx, session, syncSymbols...); err != nil {
return err
}
if userConfig[0].Sync.DepositHistory {
if err := environ.SyncService.SyncDepositHistory(ctx, session.Exchange); err != nil {
return err
}
}
if userConfig[0].Sync.WithdrawHistory {
if err := environ.SyncService.SyncWithdrawHistory(ctx, session.Exchange); err != nil {
return err
}
}
if userConfig[0].Sync.RewardHistory {
if err := environ.SyncService.SyncRewardHistory(ctx, session.Exchange); err != nil {
return err
}
}
}
return nil
}
@ -574,6 +594,24 @@ func (environ *Environment) Sync(ctx context.Context, userConfig ...*Config) err
if err := environ.syncSession(ctx, session); err != nil {
return err
}
if userConfig[0].Sync.DepositHistory {
if err := environ.SyncService.SyncDepositHistory(ctx, session.Exchange); err != nil {
return err
}
}
if userConfig[0].Sync.WithdrawHistory {
if err := environ.SyncService.SyncWithdrawHistory(ctx, session.Exchange); err != nil {
return err
}
}
if userConfig[0].Sync.RewardHistory {
if err := environ.SyncService.SyncRewardHistory(ctx, session.Exchange); err != nil {
return err
}
}
}
return nil

View File

@ -128,7 +128,7 @@ type Deposit struct {
type GetDepositHistoryRequest struct {
client requestgen.AuthenticatedAPIClient
currency *string `param:"currency"`
currency *string `param:"currency"`
from *int64 `param:"from"` // seconds
to *int64 `param:"to"` // seconds
state *string `param:"state"` // submitting, submitted, rejected, accepted, checking, refunded, canceled, suspect

View File

@ -54,24 +54,38 @@ func (s *SyncService) SyncSessionSymbols(ctx context.Context, exchange types.Exc
return nil
}
log.Infof("syncing %s deposit records...", exchange.Name())
if err := s.DepositService.Sync(ctx, exchange); err != nil {
if err != ErrNotImplemented {
return err
}
}
log.Infof("syncing %s withdraw records...", exchange.Name())
if err := s.WithdrawService.Sync(ctx, exchange); err != nil {
if err != ErrNotImplemented {
return err
}
}
return nil
}
func (s *SyncService) SyncRewardHistory(ctx context.Context, exchange types.Exchange) error {
log.Infof("syncing %s reward records...", exchange.Name())
if err := s.RewardService.Sync(ctx, exchange); err != nil {
if err != ErrExchangeRewardServiceNotImplemented {
log.Infof("%s reward service is not supported", exchange.Name())
log.Warnf("%s reward service is not supported", exchange.Name())
return err
}
}
return nil
}
func (s *SyncService) SyncDepositHistory(ctx context.Context, exchange types.Exchange) error {
log.Infof("syncing %s deposit records...", exchange.Name())
if err := s.DepositService.Sync(ctx, exchange); err != nil {
if err != ErrNotImplemented {
log.Warnf("%s deposit service is not supported", exchange.Name())
return err
}
}
return nil
}
func (s *SyncService) SyncWithdrawHistory(ctx context.Context, exchange types.Exchange) error {
log.Infof("syncing %s withdraw records...", exchange.Name())
if err := s.WithdrawService.Sync(ctx, exchange); err != nil {
if err != ErrNotImplemented {
log.Warnf("%s withdraw service is not supported", exchange.Name())
return err
}
}

View File

@ -240,7 +240,7 @@ func (o Order) String() string {
orderID = strconv.FormatUint(o.OrderID, 10)
}
return fmt.Sprintf("ORDER %s %s %s %s %s/%s @ %s -> %s",
return fmt.Sprintf("ORDER %s %s %s %s %s/%s @ %s -> %s %s",
o.Exchange.String(),
orderID,
o.Symbol,
@ -248,7 +248,7 @@ func (o Order) String() string {
o.ExecutedQuantity.String(),
o.Quantity.String(),
o.Price.String(),
o.Status)
o.Status, o.CreationTime.Time().Format(time.RFC1123))
}
// PlainText is used for telegram-styled messages