binance-exchange / binance-java-api

binance-java-api is a lightweight Java library for the Binance API, supporting synchronous and asynchronous requests, as well as event streaming using WebSockets.
MIT License
831 stars 628 forks source link

how to get the preicison of price for Filter failure: MIN_NOTIONAL error #348

Open Darlynnnn opened 3 years ago

Darlynnnn commented 3 years ago

I am using binance java API and trying to issue a limit sell.

But i keep receiving error:

com.binance.api.client.exception.BinanceApiException: Filter failure: PRICE_FILTER

I was searching for the reason that could cause this problem and found out different coins demands different precision. However, how do I find out this precision?

when i do for example

client.getExchangeInfo().getSymbolInfo("symbolname").getQuotePrecision() and then try to set my set price of 1.5 of buy price e.g something like:

            int precision = client.getExchangeInfo().getSymbolInfo(TOKEN).getQuotePrecision()
    NewOrderResponse res=client.newOrder(marketBuy(TOKEN,amount).newOrderRespType(NewOrderResponseType.FULL));
    String buyPrice = res.getFills().get(0).getPrice();
    String sellPrice = calculateSellprice(buyPrice, 1.3,precision);

    private String calculateSellprice(String buyPrice, double i,int precision) {
        return String.format("%." + precision + "f" , Double.parseDouble(buyPrice) * i);
    }

I still receive the same error. What is the correct way to set the price then?

NFS002 commented 3 years ago

@Darlynnnn any update on this ? I am getting the same error

mah454 commented 3 years ago

Please use my version of this library (not pushed to maven central yet) https://github.com/mah454/binance-java-api you can see my example code : TestnetOrdersExample.java

        ExchangeInfo exchangeInfo = futureClient.getExchangeInfo();
        SymbolInfo symbolInfo = exchangeInfo.getSymbolInfo(SYMBOL);
        int pricePrecision = symbolInfo.getPricePrecision();
        int quantityPrecision = symbolInfo.getQuantityPrecision();

        String quantity = new DecimalFormat(PrecisionFormat.getPrecisionFormat(quantityPrecision)).format(2);
        String price = new DecimalFormat(PrecisionFormat.getPrecisionFormat(pricePrecision)).format(58200);