精度超过为此资源定义的最大值。Python财务模块

2024-09-28 01:29:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我用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")

你能帮我吗


Tags: selfclient消息机器人硬币floatsymbolamount
1条回答
网友
1楼 · 发布于 2024-09-28 01:29:45

看起来您正在查找tick_size,它将显示价格四舍五入的小数位数。有一个助手模块,你可以导入四舍五入,我们可以运行我们的刻度大小和我们的价格到这一点。这些文档可以在这里看到:

Binance Order Filters

我们需要确保从app.py顶部的helper模块导入helper函数。然后在脚本主体中插入以下函数。假设您的互联网信息正确地给出了价格,那么cost将是我们可以插入最终订单的变量,作为四舍五入价格。我刚刚在我的解释器中运行了这个程序,它与替换值一起工作:

from binance.helpers import round_step_size # add at top

cost = float(str(price).split('.')[0] + "." + str(price).split('.')[1][0:5])+(price*0.3/100)

data = self.client.futures_exchange_info() # request data
info = data['symbols'] # pull list of symbols
for x in range(len(info)): # find length of list and run loop
    if info[x]['symbol'] == symbol: # until we find our coin
        a = info[x]["filters"][0]['tickSize'] # break into filters pulling tick size
        cost = round_step_size(cost, float(a)) # convert tick size from string to float, insert in helper func with cost
        print(cost) # run into order parameter as price=cost

干杯,祝你的编码和交易好运

相关问题 更多 >

    热门问题