From 06c95a473562fe5f840c537223d5b1a693e63348 Mon Sep 17 00:00:00 2001 From: Andy Cheng Date: Tue, 18 Oct 2022 18:59:04 +0800 Subject: [PATCH] fix/general-order-executor: do not check for base balance for futures orders in reduceQuantityAndSubmitOrder() --- pkg/bbgo/order_executor_general.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pkg/bbgo/order_executor_general.go b/pkg/bbgo/order_executor_general.go index 8ca615162c..1c7072246e 100644 --- a/pkg/bbgo/order_executor_general.go +++ b/pkg/bbgo/order_executor_general.go @@ -230,13 +230,15 @@ func (e *GeneralOrderExecutor) reduceQuantityAndSubmitOrder(ctx context.Context, var err error for i := 0; i < submitOrderRetryLimit; i++ { q := submitOrder.Quantity.Mul(fixedpoint.One.Sub(quantityReduceDelta)) - if submitOrder.Side == types.SideTypeSell { - if baseBalance, ok := e.session.GetAccount().Balance(e.position.Market.BaseCurrency); ok { - q = fixedpoint.Min(q, baseBalance.Available) - } - } else { - if quoteBalance, ok := e.session.GetAccount().Balance(e.position.Market.QuoteCurrency); ok { - q = fixedpoint.Min(q, quoteBalance.Available.Div(price)) + if !e.session.Futures { + if submitOrder.Side == types.SideTypeSell { + if baseBalance, ok := e.session.GetAccount().Balance(e.position.Market.BaseCurrency); ok { + q = fixedpoint.Min(q, baseBalance.Available) + } + } else { + if quoteBalance, ok := e.session.GetAccount().Balance(e.position.Market.QuoteCurrency); ok { + q = fixedpoint.Min(q, quoteBalance.Available.Div(price)) + } } } log.Warnf("retrying order, adjusting order quantity: %v -> %v", submitOrder.Quantity, q)