Calculate the maximum order amount #4
oliver-zehentleitner
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have tried to come up with a way to calculate the maximum order amount for a market order for Binance USDⓈ-M futures. This is the amount that is displayed here in the web interface:
There are different scenarios, depending on fees:
Here is what Binance tells us about calculating the cost required to open a position, from which you can calculate the max. amount: Link to documentation page
From this information, I have come up with a function that calculates the max. amount for a given available balance. However my function has limitations:
The max. amount is correct for buy and sell if there currently is no open position.
So how can we improve this calculation to fix the limitations? The web interface probably shows the max. amount as the result of calculations that are being done in JavaScript in the browser. Could somebody reverse-engineer the JavaScript and code it in Python?
Here is my code:
On thing that I should be doing, but have not done anywhere yet: Use the Python decimal module. Binance is using decimal floating point arithmetic, while Python by default is using binary floating point arithmetic. This leads to many little problems that I am kind of ignoring by round()ing, but it's not a clean solution.
by @MikeMaxNow
Beta Was this translation helpful? Give feedback.
All reactions