首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何从SignalR引用/返回值?

如何从SignalR引用/返回值?
EN

Stack Overflow用户
提问于 2018-04-20 04:55:43
回答 1查看 224关注 0票数 0

这是我的代码:

代码语言:javascript
复制
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)')

代码语言:javascript
复制
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()方法来在函数或协程中使用。

EN

回答 1

Stack Overflow用户

发布于 2018-09-11 08:26:26

我远非专家,但来自Bittrex的提要确实是一本字典。

代码语言:javascript
复制
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']))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49930106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档