mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-14 11:03:53 +00:00
Merge pull request #1769 from c9s/narumi/autobuy-check-balance
This commit is contained in:
commit
a8f163bfd3
|
@ -146,12 +146,18 @@ func (s *Strategy) cancelOrders(ctx context.Context) {
|
||||||
func (s *Strategy) autobuy(ctx context.Context) {
|
func (s *Strategy) autobuy(ctx context.Context) {
|
||||||
s.cancelOrders(ctx)
|
s.cancelOrders(ctx)
|
||||||
|
|
||||||
balance, ok := s.Session.GetAccount().Balance(s.Market.BaseCurrency)
|
baseBalance, ok := s.Session.GetAccount().Balance(s.Market.BaseCurrency)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Errorf("%s balance not found", s.Market.BaseCurrency)
|
log.Errorf("%s balance not found", s.Market.BaseCurrency)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infof("balance: %s", balance.String())
|
log.Infof("balance: %s", baseBalance.String())
|
||||||
|
|
||||||
|
quoteBalance, ok := s.Session.GetAccount().Balance(s.Market.QuoteCurrency)
|
||||||
|
if !ok {
|
||||||
|
log.Errorf("%s balance not found", s.Market.QuoteCurrency)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ticker, err := s.Session.Exchange.QueryTicker(ctx, s.Symbol)
|
ticker, err := s.Session.Exchange.QueryTicker(ctx, s.Symbol)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -167,13 +173,20 @@ func (s *Strategy) autobuy(ctx context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if balance.Available.Compare(s.MinBaseBalance) > 0 {
|
if baseBalance.Available.Compare(s.MinBaseBalance) > 0 {
|
||||||
log.Infof("balance %s is higher than minBaseBalance %s", balance.Available.String(), s.MinBaseBalance.String())
|
log.Infof("balance %s is higher than minBaseBalance %s", baseBalance.Available.String(), s.MinBaseBalance.String())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infof("balance %s is lower than minBaseBalance %s", balance.Available.String(), s.MinBaseBalance.String())
|
log.Infof("balance %s is lower than minBaseBalance %s", baseBalance.Available.String(), s.MinBaseBalance.String())
|
||||||
|
|
||||||
quantity := s.CalculateQuantity(price)
|
quantity := s.CalculateQuantity(price)
|
||||||
|
|
||||||
|
requiredQuote := quantity.Mul(price)
|
||||||
|
if quoteBalance.Available.Compare(requiredQuote) < 0 {
|
||||||
|
log.Warnf("quote balance %s is not enough: %s < %s", s.Market.QuoteCurrency, quoteBalance.Available.String(), requiredQuote.String())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
submitOrder := types.SubmitOrder{
|
submitOrder := types.SubmitOrder{
|
||||||
Symbol: s.Symbol,
|
Symbol: s.Symbol,
|
||||||
Side: side,
|
Side: side,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user