Skip to content

Error on close SHORT Positions - LOT_SIZE (HTTP status code: 400) #1335

@felipeixoto

Description

@felipeixoto

Release number
6.0.2

Describe the bug
When closing a SHORT position via updatePositionsWithTickersUpdates (CassandreStrategyImplementation.java:216) and closePosition (PositionServiceCassandreImplementation.java:189), XChange returns the error:

"LOT_SIZE (HTTP status code: 400)"

Root Cause:
The error occurs due to a precision mismatch in the BTC amount. The system attempts to close the position with an amount of "0.00006041" BTC, but Binance expects a precision of 5 decimal places (e.g., "0.00006").

The original SHORT position was opened with "0.00006" BTC (which meets the minimum requirement of 5 USDC at the current BTC price of ~103,000 USDC).

However, positionDTO.getAmountToLock() returns a precision of 8 decimal places, causing Binance to reject the request.

In Binance documentation:
https://github.com/binance/binance-spot-api-docs/blob/master/testnet/errors.md#filter-failures
"Filter failure: LOT_SIZE" | quantity is too high, too low, and/or not following the STEP SIZE rule for the symbol.

Temporary Fix:
Manually updating the base_currency_precision column in the POSITIONS table to 5 resolved the issue, allowing Cassandre to send the correct amount ("0.00006") to XChange.

Attempted Alternative Fix:
I tried defining a custom CurrencyPairDTO with explicit precision:

private final CurrencyPairDTO pair = new CurrencyPairDTO(BTC, USDC, 5, 8);  

and returning it in getRequestedCurrencyPairs():

@Override  
public Set<CurrencyPairDTO> getRequestedCurrencyPairs() {  
    return Set.of(pair);  
}  

However, this led to unexpected behavior (not yet diagnosed), so I reverted to the default CurrencyPairDTO(BTC, USDC) and kept manually adjusting the base_currency_precision in the database via onPositionsUpdates.

Additional context

org.knowm.xchange.exceptions.OrderNotValidException: Filter failure: LOT_SIZE (HTTP status code: 400)
	at org.knowm.xchange.binance.BinanceErrorAdapter.createOrderNotValidException(BinanceErrorAdapter.java:58)
	at org.knowm.xchange.binance.BinanceErrorAdapter.adapt(BinanceErrorAdapter.java:39)
	at org.knowm.xchange.binance.service.BinanceTradeService.placeOrder(BinanceTradeService.java:160)
	at org.knowm.xchange.binance.service.BinanceTradeService.placeMarketOrder(BinanceTradeService.java:101)
	at tech.cassandre.trading.bot.service.TradeServiceXChangeImplementation.createMarketOrder(TradeServiceXChangeImplementation.java:139)
	at tech.cassandre.trading.bot.service.TradeServiceXChangeImplementation.createBuyMarketOrder(TradeServiceXChangeImplementation.java:83)
	at tech.cassandre.trading.bot.service.PositionServiceCassandreImplementation.closePosition(PositionServiceCassandreImplementation.java:189)
	at tech.cassandre.trading.bot.strategy.internal.CassandreStrategyImplementation.lambda$updatePositionsWithTickersUpdates$18(CassandreStrategyImplementation.java:216)
	at tech.cassandre.trading.bot.strategy.internal.CassandreStrategyImplementation.updatePositionsWithTickersUpdates(CassandreStrategyImplementation.java:221)
	at tech.cassandre.trading.bot.strategy.internal.CassandreStrategyImplementation.tickersUpdates(CassandreStrategyImplementation.java:112)
	at tech.cassandre.trading.bot.configuration.ScheduleAutoConfiguration.tickerFluxUpdate(ScheduleAutoConfiguration.java:73)
Caused by: org.knowm.xchange.binance.dto.BinanceException: Filter failure: LOT_SIZE (HTTP status code: 400)

2025-06-11 13:25:51 [cassandre-flux-4] ERROR t.c.t.b.s.TradeServiceXChangeImplementation - Error calling createMarketOrder for 0.00006041 BTC/USDC: Filter failure: LOT_SIZE (HTTP status code: 400)
2025-06-11 13:25:51 [cassandre-flux-4] ERROR t.c.t.b.s.PositionServiceCassandreImplementation - Position 74 not closed, failed to create order: Error calling createMarketOrder for 0.00006041 BTC/USDC: Filter failure: LOT_SIZE (HTTP status code: 400)
2025-06-11 13:25:52 [cassandre-flux-4] ERROR c.f.k.strategy.rsi.ShortRsiStrategy - Impossible to close position: Error calling createMarketOrder for 0.00006041 BTC/USDC: Filter failure: LOT_SIZE (HTTP status code: 400)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions