Skip to content

Instantly share code, notes, and snippets.

@uneasyguy
Created August 17, 2020 00:28
Show Gist options
  • Save uneasyguy/dc80910ab463d6408be151cb499c8b5e to your computer and use it in GitHub Desktop.
Save uneasyguy/dc80910ab463d6408be151cb499c8b5e to your computer and use it in GitHub Desktop.
from math import floor
from binance.client import Client
def purchase_rounding(step_size,trade_quantity):
if step_size == '1.00000000':
return round(trade_quantity,0)
else:
return round(trade_quantity,step_size.index("1")-1)
def sale_rounding(step_size,trade_quantity):
if step_size == '1.00000000':
return floor(trade_quantity)
else:
multiplier = 10 ** (step_size.index("1")-1)
return floor(trade_quantity*multiplier)/multiplier
def get_step_size(client,market):
client = Client(None,None)
exchange_info = client.futures_exchange_info()
symbols = exchange_info['symbols']
symbol_search = list(filter(lambda x : x['symbol']==market,symbols))
filters_search = list(filter(lambda x :x['filterType']=='LOT_SIZE', symbol_search[0]['filters']))
return filters_search[0]['stepSize']
def main():
client = Client(None,None)
market = "SNXUSDT"
trade_quantity = 1.2581113
step_size = get_step_size(client,market)
purchase_quantity = purchase_rounding(step_size,trade_quantity)
sale_quantity = sale_rounding(step_size,trade_quantity)
client.session.close()
message = f"""Market {market} has a step size of {step_size}.\n
A purchase with raw quantity of {trade_quantity} should be rounded to {purchase_quantity}\n
A sale with raw quantity of {trade_quantity} should be rounded to {sale_quantity}"""
print(message)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment