Python-binance: how to figure out minNotional, lotsize and stepsize for orders in ETHUSDT or any USDT

Created on 5 Feb 2018  路  16Comments  路  Source: sammchardy/python-binance

Hello everyone, Ive been following this API for a lil over a week now and have created my own limited bot at this point. I have figured out how to trade coin to coin back and forth but I cant seem to get the USDT trades working.
I have been stuck trying to get ETHUSDT working and for the life of me and the internet I cant seem to find a proper algo to calculate all the filters together to give me a number that I can send with my order

so take my balance from either ETH or USDT (depending on buy or sell) and do either a max or min order...
Ive found step-precision and formating snippets but I'm a bit lost at making some coding to find a proper results so I dont keep getting PRICE_FILTER and MIN_NOTATIONAL errors when I try to place an order

Could someone please help me clear this confusion up Thank you ahead of time

Most helpful comment

I'll give you an example of what I do for LOT_SIZE:

coins_available = 10 # let's say you have 10 ETH in your account
ticks = {}
for filt in bclient.get_symbol_info('ETHUSDT')['filters']:
    if filt['filterType'] == 'LOT_SIZE':
        ticks['ETH'] = filt['stepSize'].find('1') - 2
        break

order_quantity = math.floor(coins_available * 10**ticks['ETH']) / float(10**ticks['ETH'])

That will give you a number rounded to the correct decimal place for LOT_SIZE. You can do the same with PRICE_FILTER.

All 16 comments

for filt in bclient.get_symbol_info('ETHUSDT')['filters']:
                if filt['filterType'] == 'LOT_SIZE':
                    ticks['ETH'] = filt['stepSize']

That's how I get the lot size; you can use 'PRICE_FILTER' for the price filter.

https://python-binance.readthedocs.io/en/latest/binance.html#binance.client.Client.get_symbol_info
That has the documentation you're looking for.

Thanks for the reply. Sorry. I can pull the information fine from the api. Its the calculations of the price, tick, step, lot and min notional to get the proper outcome to send back in an order call that I can't seem to grasp just yet.
My maxorder would be balance/price. But then how would I check the result against lotsize and step size to make sure the order go through. I have yet to be able to to place a USDT order

I'll give you an example of what I do for LOT_SIZE:

coins_available = 10 # let's say you have 10 ETH in your account
ticks = {}
for filt in bclient.get_symbol_info('ETHUSDT')['filters']:
    if filt['filterType'] == 'LOT_SIZE':
        ticks['ETH'] = filt['stepSize'].find('1') - 2
        break

order_quantity = math.floor(coins_available * 10**ticks['ETH']) / float(10**ticks['ETH'])

That will give you a number rounded to the correct decimal place for LOT_SIZE. You can do the same with PRICE_FILTER.

Thanks for the quick response. Would that LTC function be the advantaged_quantity that you use in the following equation against the tick['ETH']?

Not gonna lie I had just finished a course on python about a week before I started dabbling in this bot fun. Lol. So I'm still doing alot of googling and research as I get this bot working. Luckily up till now I've been able to use everyone else's issues as reference to adjust and fox my coding. Which got my bot able to do basic coin to coin. Now I just need to get the coin to USDT operational. So I appreciate your help

Sorry; I updated my response. Trying to generalize my code for you but left some specifics in there!

You can change the "coins_available" variable to the amount you want to order. That way if it's some crazy number like 5.293819827873287, it will get rounded to the right value for the filters.

thats awesome thank you I will check it out once im back around my pc.. Do you find theres a difference when youre doing a trade with USDT compared to coin to coin? I'm still wondering why I can get ETHBTC to trade now no problem but soon as I try ETHUSDT I get back that I dont have enough funds. Although as I type this I have read a few threads about the fee incorporated into a function. but dont the fees come off the top of the order once filled?

Fees shouldn't be an issue. Make sure you have the funds in the right place to make your order. I do plenty of USDT trades so you can rest assured it works.

thanks for the tips. Hey since you have a working code do you get a lot of time stamp ahead by 1000ms errors? Ive tried updating my windows internet time, changes it to korean pool even and alos found a thread on adjusting a -1000 difference in the client.py file with this line...

kwargs['data']['timestamp'] = int(time.time() * 1000 - 1000)

which did work last night, but now its giving me that error again. Oh I also went into my registry too and canged the interval that it checks time from 1 week to each day

Changing the windows time update interval worked for me. I set it to be quite frequent.

http://www.thewindowsclub.com/change-internet-time-update-interval-windows
go to the heading "Using Registry Editor."

To open the registry editor, right click your start menu (on windows), and click Run. Then type "regedit" and press enter. Then follow the instructions in the link!

I also set mine to more frequent. I set it for each day. How frequent did you make your updates?

Mine is set to 450 in decimal.

cool thanks I'll give that a try to avoid that error

Ok so I used your snippet and made a few other changes to my code and now my quantity always reflects the proper lotsize. so I can sell coin to usdt but for some reason I still cant make a buy order with usdt even though I made a maxqty to use all the usdt at a time.

This is really getting annoying with the puzzle of all the filters lining up to open the blood moon portal as long as the sun is in the 7th quadrant

i jsut want to be able to make a friggin usdt order, why is this such a pain in my ass, coin to coin... no problem, coin to usdt BACK to coin nothing but problems.

oh forgot to mention that even though I'm trying on the ETHUSDT market with 59.99 balance i get PRICE_FILTER error which is well above min amounts

So after some more playing around I thought I figured it out and that Ive been an idiot in my execution of my buy order. I've been trying to buy with usdt currency and not converting it into the ETH that I want to buy. but then I made a function to exchange my usdt balance into the equivalent of ETH and tried to put that through and still I"m getting the PRICE_FILTER error back. I'm lost, someone please enlighten me. is the order supposed to be in USDT or ETH? Cause if its sell AND buy in ether than I've been doing it wrong up until now, but now that I have swapped currency into eth im still getting the same error

To buy ETH with USDT your buy order should look as follows:

binance_client.order_limit_buy(symbol='ETHUSDT', quantity=buy_quantity, price=buy_price)

That will put a limit order out at the specified price of one ETH and the amount of ETH you want to buy. You need to have your funds in USDT to execute that trade. Also, the buy_quantity * buy_price cannot be worth more than the total USDT you have in your account.

Thanks for the update. My problem was that I was trying to make the order WITH usdt not in ETH value. So I was fighting my own noobness the whole time lol.

Thanks for your help

Was this page helpful?
0 / 5 - 0 ratings

Related issues

scalpounet picture scalpounet  路  6Comments

alexandre-a picture alexandre-a  路  4Comments

echel0n picture echel0n  路  4Comments

Wyctus picture Wyctus  路  6Comments

iamveritas picture iamveritas  路  3Comments