bbgo: add DisableStartupBalanceQuery option

This commit is contained in:
c9s 2023-11-20 16:14:09 +08:00
parent 08a09c2fee
commit 3ea333fd52
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
3 changed files with 41 additions and 11 deletions

View File

@ -329,8 +329,13 @@ type ServiceConfig struct {
type EnvironmentConfig struct { type EnvironmentConfig struct {
DisableDefaultKLineSubscription bool `json:"disableDefaultKLineSubscription"` DisableDefaultKLineSubscription bool `json:"disableDefaultKLineSubscription"`
DisableHistoryKLinePreload bool `json:"disableHistoryKLinePreload"` DisableHistoryKLinePreload bool `json:"disableHistoryKLinePreload"`
DisableSessionTradeBuffer bool `json:"disableSessionTradeBuffer"`
MaxSessionTradeBufferSize int `json:"maxSessionTradeBufferSize"` // DisableStartUpBalanceQuery disables the balance query in the startup process
// which initializes the session.Account with the QueryAccount method.
DisableStartupBalanceQuery bool `json:"disableStartupBalanceQuery"`
DisableSessionTradeBuffer bool `json:"disableSessionTradeBuffer"`
MaxSessionTradeBufferSize int `json:"maxSessionTradeBufferSize"`
} }
type Config struct { type Config struct {

View File

@ -256,15 +256,22 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
} }
} }
logger.Infof("querying account balances...") disableStartupBalanceQuery := environ.environmentConfig != nil && environ.environmentConfig.DisableStartupBalanceQuery
account, err := session.Exchange.QueryAccount(ctx) if disableStartupBalanceQuery {
if err != nil { session.accountMutex.Lock()
return err session.Account = types.NewAccount()
} session.accountMutex.Unlock()
} else {
logger.Infof("querying account balances...")
account, err := session.Exchange.QueryAccount(ctx)
if err != nil {
return err
}
session.accountMutex.Lock() session.accountMutex.Lock()
session.Account = account session.Account = account
session.accountMutex.Unlock() session.accountMutex.Unlock()
}
logger.Infof("account %s balances:\n%s", session.Name, account.Balances().String()) logger.Infof("account %s balances:\n%s", session.Name, account.Balances().String())

View File

@ -103,8 +103,26 @@ type IsolatedMarginAccountInfo struct {
func NewAccount() *Account { func NewAccount() *Account {
return &Account{ return &Account{
balances: make(BalanceMap), AccountType: "spot",
FuturesInfo: nil,
MarginInfo: nil,
IsolatedMarginInfo: nil,
MarginLevel: fixedpoint.Zero,
MarginTolerance: fixedpoint.Zero,
BorrowEnabled: false,
TransferEnabled: false,
MarginRatio: fixedpoint.Zero,
LiquidationPrice: fixedpoint.Zero,
LiquidationRate: fixedpoint.Zero,
MakerFeeRate: fixedpoint.Zero,
TakerFeeRate: fixedpoint.Zero,
TotalAccountValue: fixedpoint.Zero,
CanDeposit: false,
CanTrade: false,
CanWithdraw: false,
balances: make(BalanceMap),
} }
} }
// Balances lock the balances and returned the copied balances // Balances lock the balances and returned the copied balances