Bitfinex Websockets API无法放置新ord

2024-06-10 18:58:56 发布

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

我已经尝试了各种方法来使用带有Python的websocketapi向这本书提交新的订单。连接工作得很好,我订阅的频道有一个恒定的响应流。不过,Bitfinex的文档至少可以说是有点轻描淡写,我无法找出我在下新订单的尝试中做错了什么。https://bitfinex.readme.io/v2/reference#ws-input-order-new

import json
import hmac, hashlib
from time import time, sleep
from websocket import create_connection

KEY = bitfinex_key
SECRET = bitfinex_secret

def _nonce():
    return str(int(time()*1000000))

nonce = _nonce()

signature = hmac.new(SECRET, bytes('AUTH' + nonce,'utf8'), hashlib.sha384).hexdigest()

ws = create_connection("wss://api.bitfinex.com/ws/2")

payload = {
    "apiKey" : KEY,
    "event" : "auth",
    "authPayload" : "AUTH" + nonce,
    "authNonce" : nonce,
    "authSig" : signature,
    'filter' : [
        'trading', #orders, positions, trades 
        'algo', #algorithmic orders
        'os', 
        'ps', 
        'n'
   ]
}

ws.send(json.dumps(payload))

neworder = [
    0,
    "on",
    None,
    {
     "cid": 902368741641276786498451564556,
     "type": "LIMIT",
     "symbol": "tBTGBTC",
     "amount": "0.14",
     "price": "0.01",
     "hidden": 0,
    }
]

sleep(3)
ws.send(json.dumps(neworder))

while True:
    result = ws.recv()
    result = json.loads(result)
    print ("Received '%s'" % result)

ws.close()

一旦建立了一个经过身份验证的连接,我就应该这样发送第二个发送消息吗?i、 通过调用用于创建连接的同一个对象上的send?在

编辑以包括回应:在

用台词'ws.发送(json.dumps文件(neworder))'注释出:

^{pr2}$

用台词'ws.发送(json.dumps文件(neworder))'未注释掉:

Received '{'event': 'info', 'version': 2}'
Received '{'event': 'auth', 'status': 'OK', 'chanId': 0, 'userId': 1064981, 'auth_id': '1711a269-d59d-452f-a35a-ba959e1a3386', 'caps': {'orders': {'read': 1, 'write': 1}, 'account': {'read': 1, 'write': 0}, 'funding': {'read': 1, 'write': 0}, 'history': {'read': 1, 'write': 0}, 'wallets': {'read': 1, 'write': 0}, 'withdraw': {'read': 0, 'write': 0}, 'positions': {'read': 1, 'write': 0}}}'
Received '[0, 'ps', []]'
Received '[0, 'os', []]'
Received '[0, 'ats', []]'
Received '[0, 'hb']'
Received '[0, 'hb']'
... 

Tags: importautheventjsonreadwstimeresult