如何从SignalR引用/返回值?

问题描述 投票:0回答:1

这是我的代码:

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调用获取字符串类型的挑战来验证我的身份,然后使用该挑战创建一个字符串类型的签名,然后将该签名传递给Authenticatecall。我遇到的问题是我需要将GetAuthContext的返回值输入create_signature协程的challenge参数。我猜测下面示例旁边的注释,每个调用方法被标记为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( )在函数或协程中使用的方法。

python-3.x signalr
1个回答
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']))
© www.soinside.com 2019 - 2024. All rights reserved.