python binance api order_market_buy 和 order_market_sell 的问题
我正在尝试使用 order_market_buy 和 order_market_sell 来买入/卖出, 以BTCUSDT为例,买入时,我想用掉所有的USDT,卖出时,我想卖出所有的BTC。
我使用
order_buy = Client.order_market_buy(symbol='BTCUSDT', quoteOrderQty=my_USDT_position)
order_sell = Client.order_market_sell(symbol='BTCUSDT', quoteOrderQty=my_BTC_position)
它不起作用,并弹出“缺少 1 个必需的位置参数:'self'”
请帮助我解决问题,谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以获取特定资产的当前余额,然后将其作为参数传递到 order_market_buy 方法中。
例子:
You can get you current balance of a specific asset then passes it as a parameter in the order_market_buy method.
Example:
从他们的文档中:
https://python- binance.readthedocs.io/en/latest/binance.html?highlight=order_market_buy#binance.client.Client.order_market_buy
看来您做到了没有在 order_market_buy 和 order_market_sell 的函数调用中输入数量参数,这就是您收到错误的原因。数量和符号是这些函数的必需参数。
所以我认为要解决“缺少 1 个必需的位置参数:'self'”错误,您应该这样做:
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:
你也尝试过类似的事情吗?
根据您的评论,似乎是
Client.order_market_buy(symbol='BTCUSDT', quoteOrderQty=usdtBalance)
用于买入,但Client.order_market_sell(symbol='BTCUSDT',Quantity=btcBalance)
不适用于卖出。我倾向于认为这是因为您存储在
btcBalance
中的信息是在初始化btcBalance
后立即进行购买之前的,这是有意义的,因为这样您就可以存储< code>0.00 或只是"Dust" 这是基础资产的极少量,不能用于在币安上进行交易,而只能用于转换为 BNB 。在此指南中,有一个使用
Testnet Binance Vision,尽管它很好地说明了如何使用
Python Binance
包设置Market Sell Order
:它甚至说,如果存储在
quantity
中的值> 不大于MIN_NOTIONAL
值,您将收到以下错误:我建议你检查一下,它可能会帮助你更好地处理这个主题。
Did you also try something like this?
Based on your comment, it seems that
Client.order_market_buy(symbol='BTCUSDT', quoteOrderQty=usdtBalance)
worked for buying, butClient.order_market_sell(symbol='BTCUSDT', quantity=btcBalance)
did NOT for selling.I tend to think it's because the information you stored in
btcBalance
was prior to the purchase you made right after initializingbtcBalance
, it would make sense since that way you would have stored0.00
or just "Dust" which is a very low amount of the base asset that can't be used for trading on Binance but instead for just converting to BNB.In this guide, there's an example using the
Testnet Binance Vision
, although it illustrates very well how to set aMarket Sell Order
withPython Binance
package:It even says that if the value stored in
quantity
is not greater than theMIN_NOTIONAL
value, you will get the following error:I recommend you to check it out, it may help you better when dealing with this topic.
交易货币对(BTC 和 USDT)时,您可以在
quantity
参数中指定您想要买入/卖出的 BTC 金额,或者在quoteOrderQty< 中指定您想要买入/卖出的 USDT /代码> 参数。
When trading a pair (BTC and USDT) you can either specify the BTC amount you want to buy/sell in the
quantity
parameter, or the USDT you want to buy/sell in thequoteOrderQty
parameter.