这是我的代码:
from signalr_aio import Connection
if __name__ == "__main__":
# Create connection
# Users can optionally pass a session object to the client, e.g a cfscrape session to bypass cloudflare.
connection = Connection('https://beta.bittrex.com/signalr', session=None)
hub = connection.register_hub('c2')
hub.server.invoke('GetAuthContext', API_KEY) #Invoke 0 Creates the challenge that needs to be signed by the create_signature coroutine
signature = await create_signature(API_SECRET, challenge) #Creates the signature that needs to authenticated in the Authenticate query
hub.server.invoke('Authenticate', API_KEY, signature) #Invoke 1 authenticates user to account level information
connection.start()
我要做的是通过GetAuthContext
调用获取字符串类型的质询来验证我的身份,然后使用该质询创建一个字符串类型的签名,然后将该签名传递给{{1} }呼叫。我遇到的问题是我需要将Authenticate
的返回值输入GetAuthContext
协程的challenge参数中。我猜测下面示例旁边的注释,每个调用方法都标记为create_signature
,所以我必须做I([index of method])
signature = await create_signature(API_SECRET, 'I(0)')
稍后此示例将分配给connection.received(async def on_debug(**msg):
# In case of `queryExchangeState` or `GetAuthContext`
if 'R' in msg and type(msg['R']) is not bool:
# For the simplicity of the example I(1) corresponds to `Authenticate` and I(0) to `GetAuthContext`
# Check the main body for more info.
if msg['I'] == str(2):
decoded_msg = await process_message(msg['R'])
print(decoded_msg)
elif msg['I'] == str(3):
signature = await create_signature(API_SECRET, msg['R'])
hub.server.invoke('Authenticate', API_KEY, signature)
),因此我猜测connection.received += on_debug
之后我必须调用connection.start()
来调用on_debug协程,这将验证我,但是现在我只想了解如何引用.invoke()方法在函数或协程中使用。
答案 0 :(得分:0)
我距离专家还很远,但是Bittrex的提要确实是字典。
for i in range(0, len(decoded_msg['D'])):
print('The Currency pair is:{0} the Bid is:{1} and the Ask is :{2}'.format(decoded_msg['D'][i]['M'], decoded_msg['D'][i]['B'], decoded_msg['D'][i]['A']))