binance-exchange / binacpp

Binance C++ library
MIT License
209 stars 108 forks source link

Filter failure: PERCENT_PRICE #46

Open silahian opened 3 years ago

silahian commented 3 years ago

Binance is returning the error "Filter failure: PERCENT_PRICE" when sending an order. We checked on their documentation and the issue is the max allowance for decimal places in your order prices and sizes

Is anyone else having this same issue? The issue is in "BinaCPP::send_order" when building the post to send the order, the price and size are being converted to string using to_string.... but no way to control the decimal places in there.

silahian commented 3 years ago

In case this happened to anyone else.... What we ended up doing is the following: We change the signature of BinaCPP::send_order to BinaCPP::send_order( const char symbol, const char side, const char type, const char timeInForce, string quantity, string price, const char *newClientOrderId, double stopPrice, double icebergQty, long recvWindow, Json::Value &json_result )

And then we created a function to translate the price and sizes before sending it to BinaCPP::send_order inline string to_string(double val, int decimalPlaces) { std::ostringstream oss; oss << std::setprecision(decimalPlaces) << std::noshowpoint << val; return oss.str();

}

Hope this helps. Comments on this are welcome

carbofos commented 3 years ago

I confirm the bug. While sending the order quantity 89.8 the result is:

2021-03-14 14:52:12 468030 : url = |https://api.binance.com/api/v3/order?|, post_data = |symbol=LITUSDT&side=SELL&type=LIMIT&timeInForce=FOK&price=10.869900&quantity=89.799998&...

The problem is std::to_string(double) in BinaCPP::send_order(). The next code did fix it for me:

std::ostringstream out; out << quantity; post_data.append( out.str() );