【问题标题】:Bittrex websockets API: how to get the order history?Bittrex websockets API:如何获取订单历史记录?
【发布时间】:2017-11-04 11:51:19
【问题描述】:

我正在使用 Bittrex 的 websockets API。

我可以毫无问题地获取市场摘要。

此外,调用中心方法“SubscribeToExchangeDeltas”,为我获取请求的交换增量。

但是,当我尝试调用中心方法“QueryExchangeState”来获取某个市场的订单历史记录时,什么都没有发生,我什至没有收到错误,因此该方法显然已被调用。

有没有人对此有更多的了解、有这方面的经验或让这个工作发挥作用?请告诉我!

下面的代码是我正在使用的。 它为我提供了“ETC-MEME”的摘要更新和交换增量。

如何获取特定市场的订单历史记录(本例中为“ETC-MEME”)?

import pprint
from requests import Session  # pip install requests
from signalr import Connection  # pip install signalr-client


def handle_received(*args, **kwargs):

    print('\nreceived')
    print('\nargs:')
    pprint.pprint(args)
    print('\nkwargs:')
    pprint.pprint(kwargs)


def print_error(error):
    print('error: ', error)


def main():
    with Session() as session:
        connection = Connection("https://www.bittrex.com/signalR/", session)
        chat = connection.register_hub('corehub')
        connection.start()

        # Handle any pushed data from the socket
        connection.received += handle_received
        connection.error += print_error

        for market in ["BTC-MEME"]:
            chat.server.invoke('SubscribeToExchangeDeltas', market)
            chat.server.invoke('QueryExchangeState', market)
            pass

        while True:
            connection.wait(1)

if __name__ == "__main__":
    main()

【问题讨论】:

    标签: python-3.x websocket algorithmic-trading


    【解决方案1】:

    事实证明,调用 QueryExchangeState 没有任何效果,而调用 SubscribeToExchangeDeltas 确实会将增量添加到流中。

    (最近的)订单历史目前只能通过在公共 API 上调用 getmarkethistory 获得:https://bittrex.com/home/api

    【讨论】:

      【解决方案2】:

      您忘记添加接收实际提要的方法。

      也忘了调用“updateExchangeState”。

      将 connection.wait 设置为更高的值,因为如果硬币不经常交易,当您将值设置为 1 秒时,您可能会断开连接。

      还请检查这个库(我是作者),这是您尝试制作的东西 - websocket 实时数据馈送:https://github.com/slazarov/python-bittrex-websocket

      无论如何,这应该可以解决问题:

      from requests import Session  # pip install requests
      from signalr import Connection  # pip install signalr-client
      
      
      def handle_received(*args, **kwargs):
          # Orderbook snapshot:
          if 'R' in kwargs and type(kwargs['R']) is not bool:
              # kwargs['R'] contains your snapshot
              print(kwargs['R'])
      
      # You didn't add the message stream
      def msg_received(*args, **kwargs):
          # args[0] contains your stream
          print(args[0])
      
      
      def print_error(error):
          print('error: ', error)
      
      
      def main():
          with Session() as session:
              connection = Connection("https://www.bittrex.com/signalR/", session)
              chat = connection.register_hub('corehub')
              connection.received += handle_received
              connection.error += print_error
              connection.start()
      
              # You missed this part
              chat.client.on('updateExchangeState', msg_received)
      
              for market in ["BTC-ETH"]:
                  chat.server.invoke('SubscribeToExchangeDeltas', market)
                  chat.server.invoke('QueryExchangeState', market)
      
              # Value of 1 will not work, you will get disconnected
              connection.wait(120000)
      
      
      if __name__ == "__main__":
          main()
      

      【讨论】:

      • 您好,感谢您的回复。你说得对,我省略了“chat.client.on”部分。我是故意这样做的,因为我的问题与此无关,但我发现这可能会分散知识渊博的人的注意力。此外,调用或省略 updateExchangeState 并没有什么不同(我仍然推送了摘要状态)。而且我很清楚等待函数的参数是超时。我的问题是关于获取特定市场的订单历史记录(填充)。我会尽量让我的问题更清楚,很抱歉造成混乱。
      • @YtsendeBoer 要获得订单,您需要 chat.client.on('updateExchangeState', msg_received) 和 chat.server.invoke('SubscribeToExchangeDeltas', market)。然后您将在 msg_received 中获得订单填写信息。您可以将 handle_received 视为通用频道,并且正如您所说,它无论如何都会输出“updateSummaryState”。
      猜你喜欢
      • 2022-09-23
      • 2019-08-23
      • 1970-01-01
      • 1970-01-01
      • 2014-11-14
      • 1970-01-01
      • 1970-01-01
      • 2021-06-28
      • 2014-08-16
      相关资源
      最近更新 更多