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,6 +329,11 @@ type ServiceConfig struct {
type EnvironmentConfig struct {
DisableDefaultKLineSubscription bool `json:"disableDefaultKLineSubscription"`
DisableHistoryKLinePreload bool `json:"disableHistoryKLinePreload"`
// 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"`
}

View File

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

View File

@ -103,8 +103,26 @@ type IsolatedMarginAccountInfo struct {
func NewAccount() *Account {
return &Account{
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