mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
bbgo: add DisableStartupBalanceQuery option
This commit is contained in:
parent
08a09c2fee
commit
3ea333fd52
|
@ -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 {
|
||||||
|
|
|
@ -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())
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user