Merge pull request #1075 from c9s/bhwu/add-persistence-to-env

FEATURE: add persistence service to environment
This commit is contained in:
gx578007 2023-03-02 23:00:20 +08:00 committed by GitHub
commit 8039068d51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 19 deletions

View File

@ -19,7 +19,7 @@ func BootstrapEnvironmentLightweight(ctx context.Context, environ *Environment,
}
if userConfig.Persistence != nil {
if err := ConfigurePersistence(ctx, userConfig.Persistence); err != nil {
if err := ConfigurePersistence(ctx, environ, userConfig.Persistence); err != nil {
return errors.Wrap(err, "persistence configure error")
}
}
@ -41,7 +41,7 @@ func BootstrapEnvironment(ctx context.Context, environ *Environment, userConfig
}
if userConfig.Persistence != nil {
if err := ConfigurePersistence(ctx, userConfig.Persistence); err != nil {
if err := ConfigurePersistence(ctx, environ, userConfig.Persistence); err != nil {
return errors.Wrap(err, "persistence configure error")
}
}
@ -55,4 +55,4 @@ func BootstrapEnvironment(ctx context.Context, environ *Environment, userConfig
func BootstrapBacktestEnvironment(ctx context.Context, environ *Environment) error {
return environ.ConfigureDatabase(ctx)
}
}

View File

@ -78,18 +78,19 @@ const (
// Environment presents the real exchange data layer
type Environment struct {
DatabaseService *service.DatabaseService
OrderService *service.OrderService
TradeService *service.TradeService
ProfitService *service.ProfitService
PositionService *service.PositionService
BacktestService *service.BacktestService
RewardService *service.RewardService
MarginService *service.MarginService
SyncService *service.SyncService
AccountService *service.AccountService
WithdrawService *service.WithdrawService
DepositService *service.DepositService
DatabaseService *service.DatabaseService
OrderService *service.OrderService
TradeService *service.TradeService
ProfitService *service.ProfitService
PositionService *service.PositionService
BacktestService *service.BacktestService
RewardService *service.RewardService
MarginService *service.MarginService
SyncService *service.SyncService
AccountService *service.AccountService
WithdrawService *service.WithdrawService
DepositService *service.DepositService
PersistentService *service.PersistenceServiceFacade
// startTime is the time of start point (which is used in the backtest)
startTime time.Time
@ -984,4 +985,4 @@ func (session *ExchangeSession) getSessionSymbols(defaultSymbols ...string) ([]s
}
return session.FindPossibleSymbols()
}
}

View File

@ -102,7 +102,7 @@ func NewPersistenceServiceFacade(conf *PersistenceConfig) (*service.PersistenceS
return facade, nil
}
func ConfigurePersistence(ctx context.Context, conf *PersistenceConfig) error {
func ConfigurePersistence(ctx context.Context, environ *Environment, conf *PersistenceConfig) error {
facade, err := NewPersistenceServiceFacade(conf)
if err != nil {
return err
@ -112,5 +112,6 @@ func ConfigurePersistence(ctx context.Context, conf *PersistenceConfig) error {
isolation.persistenceServiceFacade = facade
persistenceServiceFacade = facade
environ.PersistentService = facade
return nil
}
}

View File

@ -1791,4 +1791,4 @@ func (s *Strategy) openOrdersMismatches(ctx context.Context, session *bbgo.Excha
func roundUpMarketQuantity(market types.Market, v fixedpoint.Value) fixedpoint.Value {
return v.Round(market.VolumePrecision, fixedpoint.Up)
}
}