我用python二进制模块编写了一个交易机器人。这个机器人从一条消息中获取硬币名称,而不是像这样打开一个位置 接收消息>;打开消息中硬币的多头位置>;设置该头寸的限价卖出订单
机器人可以做前两个,但当它尝试做最后一个时,它会给出错误“精度超过此资产定义的最大值”。我已在internet上查找解决方案,并尝试使用此代码设置sellPrice
float(str(price).split('.')[0] + "." + str(price).split('.')[1][0:5])+(price*0.3/100)
我从互联网上获取代码的第一部分是 float(str(price).split('.')[0] + "." + str(price).split('.')[1][0:5])
并添加了将sellPrice设置为高于我购买的价格0.3%的部分
这是我的密码
coinName = "ONEUSDT"
print(coinName)
symbol = coinName
amount = "1"
leverage = "20"
self.client.futures_change_leverage(symbol=symbol, leverage=leverage)
price=float(self.client.get_symbol_ticker(symbol=symbol)["price"])
print(price)
amount = float(amount)
leverage = float(leverage)
quantity =(amount*leverage)/price
quantity = int(quantity)
self.client.futures_create_order(symbol=symbol,side="BUY",type="MARKET",quantity=quantity)
time.sleep(3)
self.client.futures_create_order(symbol=symbol,side="SELL",type="LIMIT",price =float(str(price).split('.')[0] + "." + str(price).split('.')[1][0:5])+(price*0.3/100),quantity=quantity,timeInForce="GTC")
你能帮我吗
看起来您正在查找tick_size,它将显示价格四舍五入的小数位数。有一个助手模块,你可以导入四舍五入,我们可以运行我们的刻度大小和我们的价格到这一点。这些文档可以在这里看到:
Binance Order Filters
我们需要确保从app.py顶部的helper模块导入helper函数。然后在脚本主体中插入以下函数。假设您的互联网信息正确地给出了价格,那么
cost
将是我们可以插入最终订单的变量,作为四舍五入价格。我刚刚在我的解释器中运行了这个程序,它与替换值一起工作:干杯,祝你的编码和交易好运
相关问题 更多 >
编程相关推荐