Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggested/correct way of calculating stepSize for size truncating when stepSize is 1? #72

Closed
ghost opened this issue Nov 8, 2021 · 1 comment
Assignees

Comments

@ghost
Copy link

ghost commented Nov 8, 2021

XRP-USDT pair on Binance' LOT_SIZE from https://api.binance.com/api/v1/exchangeInfo:

{
    "filterType": "LOT_SIZE",
    "minQty": "1.00000000",
    "maxQty": "9222449.00000000",
    "stepSize": "1.00000000"
},

Calculating amount of decimals like this:

filter = state.interface.get_order_filter(symbol)
increment = filter["market_order"]["base_increment"]
decimals = abs(Decimal(str(increment)).as_tuple().exponent() # I forget from where; but this is taken from the Blankly source

Decimals is 1 but should be 0 (?)

size = state.interface.cash / price
size = blankly.trunc(size, decimals)

When creating a market buy order Binance returns LOT_SIZE error.

My current solution is wrapping the market buy order in two try/except statements like this:

try:
    state.interface.market_order(symbol, "buy", size)
except:
    try:
        state.interface.market_order(symbol, "buy", blankly.trunc(size, decimals - 1))
    except Exception as e:
        print(e)

Is there a more proper/elegant way of doing this?

@EmersonDove EmersonDove self-assigned this Nov 8, 2021
@EmersonDove
Copy link
Member

EmersonDove commented Nov 8, 2021

Hmm - I think you're right there should be a significantly easier way to access the decimal count especially for people checking the order filter. I'm also looking into the base decimal differences between our response what's shown at exchangeInfo. We've never had an issue with our filters being inaccurate but maybe these lower price symbols have a more complex order filter to deal with.

We're querying the v3 API, but it doesn't make much difference:
https://api.binance.com/api/v3/exchangeInfo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant