mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
bbgo: add more sync options
This commit is contained in:
parent
76012f0b71
commit
a57a238e09
|
@ -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
|
||||
|
|
|
@ -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"`
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user