3

I want to create a python script which trades on binance futures and i was wondering how i can set a leverage for a order. I search on google but didnt found anything abt it.

client.futures_create_order(symbol='VETUSDT', side='BUY', type='MARKET',  quantity = 1000)
uLaYOTHR
  • 51
  • 1
  • 7

3 Answers3

3

Leverage can not be sent with the order. You must first change the leverage and then send the order. See: https://binance-docs.github.io/apidocs/futures/en/#change-initial-leverage-trade

request_client = RequestClient(api_key=g_api_key, secret_key=g_secret_key)
result = request_client.change_initial_leverage(symbol="BTCUSDT", leverage=10)

from : https://github.com/Binance-docs/Binance_Futures_python/blob/master/example/trade/change_initial_leverage.py

Wostafa
  • 134
  • 1
  • 4
  • Gives me this error: AttributeError: 'Client' object has no attribute 'change_initial_leverage' – Karl Feb 09 '22 at 13:31
1

To change leverage with python-binance library you should use futures_change_leverage() method. Code example:

new_lvrg = 10

client = Client(your_api_key, your_api_secret)
client.futures_change_leverage(leverage=new_lvrg)
hljubic
  • 89
  • 1
  • 3
0

You can't do it with the order. You have to do it separately:

new_lvrg = 10
symbol = 'BTCUSDT'

client = Client(your_api_key, your_api_secret)
client.futures_change_leverage(leverage=new_lvrg, symbol=symbol)