无法将订单参数作为变量发送到 Binance API - Python

问题描述

我试图将止盈和止损不是作为固定价格发送给币安,而是作为一个变量来计算它,例如 sl = price*0.98

如果我将止损和止盈设置为固定价格(“价格”:“650”),订单会通过,但是当我使用变量(见下面的代码)时,我会收到 [{'code': 400,'msg': None},{'code': 400,'msg': None}] 响应。

这是签名请求的方法(我没有编码)

def send_signed_request(http_method,url_path,payload={}):
    query_string = urlencode(payload)
    # replace single quote to double quote
    query_string = query_string.replace('%27','%22')
    if query_string:
        query_string = "{}&timestamp={}".format(query_string,get_timestamp())
    else:
        query_string = 'timestamp={}'.format(get_timestamp())

    url = BASE_URL + url_path + '?' + query_string + '&signature=' + hashing(query_string)
    print("{} {}".format(http_method,url))
    params = {'url': url,'params': {}}
    response = dispatch_request(http_method)(**params)
    return response.json()

# get the price an calculate sl and tp

response = send_public_request('/fapi/v1/ticker/24hr?symbol=BNBUSDT')

price = float(response['weightedAvgPrice'])

TP = float("{:.2f}".format(price*1.20))
SL = float("{:.2f}".format(price*0.90))


#send sl and tp

params = {
    "batchOrders": [
        {
            "symbol":"BNBUSDT","side": "SELL","type": "STOP","quantity": "1","price": SL,"timeInForce": "GTC","stopPrice": SL-1
        },{
            "symbol":"BNBUSDT","type": "LIMIT","price": TP,"timeInForce": "GTC"
        },]
}

response = send_signed_request('POST','/fapi/v1/batchOrders',params)
print(response)

我需要如何更改代码才能使用计算出的 SL 和 TP 变量?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...