From 7b68e5ee27565c03b4e6269a8706ea5ae55f0ba2 Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 11 Sep 2022 17:46:23 +0800 Subject: [PATCH] bbgo: fix balance lock issue --- pkg/bbgo/order_executor_general.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/bbgo/order_executor_general.go b/pkg/bbgo/order_executor_general.go index 3fb6b2e9b..5a1cb1107 100644 --- a/pkg/bbgo/order_executor_general.go +++ b/pkg/bbgo/order_executor_general.go @@ -271,6 +271,11 @@ func (e *GeneralOrderExecutor) ClosePosition(ctx context.Context, percentage fix return nil } + // check base balance and adjust the close position order + if baseBalance, ok := e.session.Account.Balance(e.position.Market.BaseCurrency); ok { + submitOrder.Quantity = fixedpoint.Min(submitOrder.Quantity, baseBalance.Available) + } + tagStr := strings.Join(tags, ",") submitOrder.Tag = tagStr