mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
xgap: check balance and adjust order quantity according to the available balance
This commit is contained in:
parent
a8546ce935
commit
8f4ae1e15b
|
@ -286,6 +286,7 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
|
|||
|
||||
log.Infof("mid price %f", midPrice.Float64())
|
||||
|
||||
var balances = s.tradingSession.Account.Balances()
|
||||
var quantity = s.tradingMarket.MinQuantity
|
||||
|
||||
if s.Quantity > 0 {
|
||||
|
@ -299,6 +300,15 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
|
|||
if volumeDiff > 0 {
|
||||
quantity = volumeDiff
|
||||
}
|
||||
|
||||
if baseBalance, ok := balances[s.tradingMarket.BaseCurrency]; ok {
|
||||
quantity = math.Min(quantity, baseBalance.Available.Float64())
|
||||
}
|
||||
|
||||
if quoteBalance, ok := balances[s.tradingMarket.QuoteCurrency]; ok {
|
||||
maxQuantity := quoteBalance.Available.Float64() / price
|
||||
quantity = math.Min(quantity, maxQuantity)
|
||||
}
|
||||
}
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user