这是我的代码:
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
调用获得一个字符串类型的质询来验证我的身份,然后使用该质询创建一个字符串类型的签名,然后将该签名传递给Authenticate
调用。我遇到的问题是,我需要在create_signature
协程的GetAuthContext
参数中输入挑战的返回值。从下面示例旁边的注释可以看出,每个invoke方法都被标记为I([index of method])
,所以我必须使用signature = await create_signature(API_SECRET, 'I(0)')
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 ( connection.received += on_debug
),所以我猜在connection.start()
之后我必须放入connection.recieved()
来调用on_debug协程,这将验证我,但现在我只想了解如何引用.invoke()方法来在函数或协程中使用。
发布于 2018-09-11 08:26:26
我远非专家,但来自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']))
https://stackoverflow.com/questions/49930106
复制相似问题