Home > Software engineering >  problem with python binance api order_market_buy and order_market_sell
problem with python binance api order_market_buy and order_market_sell

Time:03-24

I am trying to use order_market_buy and order_market_sell to buy/sell, taking BTCUSDT for example, when buying, I want to use all my usdt, when selling, I want to sell all the BTC.

I use

order_buy = Client.order_market_buy(symbol='BTCUSDT', quoteOrderQty=my_USDT_position)
order_sell = Client.order_market_sell(symbol='BTCUSDT', quoteOrderQty=my_BTC_position)

it's not working and pop"missing 1 required positional argument: 'self'"

Please help me with the problem, thanks!

CodePudding user response:

From their documentation: https://python-binance.readthedocs.io/en/latest/binance.html?highlight=order_market_buy#binance.client.Client.order_market_buy

It seems that you did not input a quantity argument in the function call of order_market_buy and order_market_sell, that is why you are getting an error. quantity and symbol are a required parameter of these functions.

So I think to solve the "missing 1 required positional argument: 'self'" error you should do:

order_buy = Client.order_market_buy(symbol='BTCUSDT', quantity=<your quantity>, quoteOrderQty=my_USDT_position)
order_sell = Client.order_market_sell(symbol='BTCUSDT', quantity=<your quantity>, quoteOrderQty=my_BTC_position)

CodePudding user response:

You can get you current balance of a specific asset then passes it as a parameter in the order_market_buy method.

Example:

usdtBalance = client.get_asset_balance(asset='USDT').get('free')
btcBalance = client.get_asset_balance(asset='BTC').get('free')

order_buy = Client.order_market_buy(symbol='BTCUSDT', quoteOrderQty=usdtBalance)

order_sell = Client.order_market_sell(symbol='BTCUSDT', quoteOrderQty=btcBalance)
  • Related