question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

binance {"code":-1013,"msg":"Invalid price."}

See original GitHub issue
  • OS: macosx
  • Programming Language version: python
  • CCXT version: 1.18.412
  • Exchange: binance
  • Method: create_limit_sell_order

Cxxt is working very well (limit buy/sell orders) on many pairs (with different price precisions) but I have issues with some pairs like BTT/BTC SC/BTC.

So I tried to harcode the price I provide to ccxt in order to see where this {“code”:-1013,“msg”:“Invalid price.”} error is coming from

With harcoded price: 0.00000125

Price is truncated in the request: price=0.000001 (working but wrong price) Request: POST https://api.binance.com/api/v3/order {'X-MBX-APIKEY': ‘xxxx’, 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'python-requests/2.19.1', 'Accept-Encoding': 'gzip, deflate'} timestamp=xxxx&recvWindow=5000&symbol=BTTBTC&quantity=6491&type=LIMIT&side=SELL&newOrderRespType=RESULT&price=0.000001&timeInForce=GTC&signature=xxxxx

With harcoded price: 0.00000025

Price is truncated in the request: price=0 (failing) Request: POST https://api.binance.com/api/v3/order {'X-MBX-APIKEY': ‘xxx’, 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'python-requests/2.19.1', 'Accept-Encoding': 'gzip, deflate'} timestamp=xxxx&recvWindow=5000&symbol=BTTBTC&quantity=6491&type=LIMIT&side=SELL&newOrderRespType=RESULT&price=0&timeInForce=GTC&signature=xxxx Response: POST https://api.binance.com/api/v3/order 400 (...) {"code":-1013,"msg":"Invalid price."}

it’s looks like price_to_precision is not working correctly. What you see in the two request is what is return by this method (I tested manually myself)

EDIT: orders are now working by changing part of this ccxt code: https://github.com/0slab/ccxt/blob/master/python/ccxt/binance.py#L799

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:24 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
odemollienscommented, Mar 31, 2019
    def price_to_precision(self, symbol, price):
        print("price_to_precision:",price,"  ROUND:",ROUND, "   market",self.markets[symbol]['precision']['price'], "     precision:",self.precisionMode )
        return self.decimal_to_precision(price, ROUND, self.markets[symbol]['precision']['price'], self.precisionMode)

I added a log in base/exchange.py and looks like your internal parameters are always good:

price_to_precision: 0,0000002   ROUND: 1    market 8      precision: 2
Formatted price STEP1 0.0000002
price_to_precision: 0,0000002   ROUND: 1    market 8      precision: 2
Formatted price STEP1.1 0.0000002
price_to_precision: 0,0000002   ROUND: 1    market 8      precision: 2
Formatted price STEP2 0

I will work on the snippet in coming days, it require some works 😉

1reaction
odemollienscommented, Mar 30, 2019

Hello @kroitor,

You right my github fork was not up to date. This is now the case, I tried again without my fix and this is what I get (as proof, I added a printed value “test_416” in my fork to check that I’m using the last version"):

2019-03-30 18:12:56,736 - BOT - INFO - API call: Sell amount 8312.0 at price 0.00000020. test_416

Request: POST https://api.binance.com/api/v3/order {'X-MBX-APIKEY': 'xxx', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'python-requests/2.19.1', 'Accept-Encoding': 'gzip, deflate'} timestamp=xxxx&recvWindow=5000&symbol=BTTBTC&quantity=8312&type=LIMIT&side=SELL&newOrderRespType=RESULT&price=0&timeInForce=GTC&signature=xxxx

Response: POST https://api.binance.com/api/v3/order 400 (...) {"code":-1013,"msg":"Invalid price."}

2019-03-30 18:12:57,250 - BOT - WARNING - Unable to sell trade: Could not create limit sell order on market BTT/BTC.Tried to sell amount 8312.0 at rate 0.00000020 .Message: binance {"code":-1013,"msg":"Invalid price."}

So to make my code working, I need to replace this line: https://github.com/ccxt/ccxt/blob/master/python/ccxt/binance.py#L799

With that: https://github.com/0slab/ccxt/blob/master/python/ccxt/binance.py#L800

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid Price APIError(code=-1013) on small value coins
I am not able to format coins with really low values like VIB/BTC ( value 1.08e-06 ). This is my format function.
Read more >
Binance API returns with: APIError(code=-1013): Filter failure
This error occures when your price parameter does not comply with symbol's price filter's specification. Price value needs to satisfy at ...
Read more >
Change Log – Binance API Documentation - GitHub Pages
HTTP 503 return code is used when: If there is an error message "Unknown error, please check your request or try again later."...
Read more >
ccxt-dev/ccxt - Gitter
@kroitor what is the max price offset for binance? ccxt.base.errors.InvalidOrder: binance {"code":-1013,"msg":"Filter failure: PERCENT_PRICE"}.
Read more >
Error with API trying to sell : r/binance - Reddit
Original price: 38415. Original volume: 0. Kucoin USDT-BTC InvalidOrder: binanceus {"code":-1013,"msg":"Invalid quantity."} at binanceus.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found