I'm playing with Binance API to make my trading bot with Python 3.6. and CCXT library (here you find the docs ).
One very useful thing they have in their site is the capability to place orders for a percentage of your current balance:
for example if I'm lookin at BTC/USDT
crypto coin pair, and I have 50 USDT
on my account, I can choose between buying N
amount of BTC
or using 100%
of my account's USDT
for buying, consequently buying the maximum amount of BTC
I can.
I read the docs many times, but I can't find the option to do these "percentage of balance" orders with the API in any way: the only thing I can do is passing a float
to the order function.
This is how i place orders now:
amount = 0.001
symbol = "BTC/USDT"
def buyorder(amount, symbol): # this makes a market order taking in the amount I defined before, for the pair defined by "symbol"
type = 'market' # or 'limit'
side = 'buy' # or 'sell'
params = {} # extra params and overrides if needed
order = exchange.create_order(symbol, type, side, amount, params)
Do anyone know if there is a built-in capability to do a percentage order? If API gives no way to do so, would you suggest some workarounds?
I want to be able to give to the API percentage of my current balance as an amount
, so I can always use the full of it without having to update when fees are detracted
Connect to Binance Client Using Python To connect to the client just define your API and secret key variable and execute the client function. To verify that your keys are correct and that you're connected to Binance, execute this function that will ping the server.
More specifically, Binance has a RESTful API that uses HTTP requests to send and receive data. Further, there is also a WebSocket available that enables the streaming of data such as price quotes and account updates.
Use a custom function like this:
def get_max_position_available():
to_use = float(exchange.fetch_balance().get('USDT').get('free'))
price = float(exchange.fetchTicker('BTC/USDT').get('last'))
decide_position_to_use = to_use / price
return decide_position_to_use
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With