Skip to content

Commit

Permalink
Merge pull request #1597 from Newtoniano/close-short-positions
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Mar 21, 2024
2 parents d58461d + 17368b9 commit abd9f86
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/bbgo/order_executor_general.go
Expand Up @@ -517,13 +517,17 @@ func (e *GeneralOrderExecutor) ClosePosition(ctx context.Context, percentage fix
return fmt.Errorf("insufficient base balance, can not sell: %+v", submitOrder)
}
} else if e.position.IsShort() {
// TODO: check quote balance here, we also need the current price to validate, need to design.
/*
if quoteBalance, ok := e.session.Account.Balance(e.position.Market.QuoteCurrency); ok {
// AdjustQuantityByMaxAmount(submitOrder.Quantity, quoteBalance.Available)
// submitOrder.Quantity = fixedpoint.Min(submitOrder.Quantity,)
if quoteBalance, ok := e.session.Account.Balance(e.position.Market.QuoteCurrency); ok {
ticker, err := e.session.Exchange.QueryTicker(ctx, e.position.Symbol)
if err != nil {
return err
}
*/
currentPrice := ticker.Sell
submitOrder.Quantity = AdjustQuantityByMaxAmount(submitOrder.Quantity, currentPrice, quoteBalance.Available)
if submitOrder.Quantity.IsZero() {
return fmt.Errorf("insufficient quote balance, can not buy: %+v", submitOrder)
}
}
}
}

Expand Down

0 comments on commit abd9f86

Please sign in to comment.