简体   繁体   English

binance python api:出售任何资产的整个余额功能

[英]binance python api: sell entire balance function for any asset

I want a python function to sell the entire balance of an asset to USDT.我想要一个 python 函数将资产的全部余额出售给 USDT。 If I have n ETH, this function should transfer the entire ETH balance to USDT.如果我有 n 个 ETH,这个函数应该将整个 ETH 余额转移到 USDT。

I tried something like:我试过类似的东西:

bal = client.get_asset_balance(asset='ETH')['free']
sell = client.order_market_buy(symbol='ETHUSDT', quantity = bal)
print(sell)

This sometimes outputs a Api Error: Insufficient Balance for some reason.由于某种原因,这有时会输出 Api 错误:余额不足。 Please help me with a better option.请帮助我提供更好的选择。

You use buy order.您使用购买订单。 Use "client.order_market_sell" instead of "client.order_market_buy"使用“client.order_market_sell”而不是“client.order_market_buy”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM