我正在使用Bittrex的websockets API。
获取市场摘要我没有问题。
此外,调用hub方法" SubscribeToExchangeDeltas",获取请求的交换增量。
但是,当我尝试调用hub方法" 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()
答案 0 :(得分:2)
事实证明,调用 QueryExchangeState 无效并且调用 SubscribeToExchangeDeltas 确实会将增量添加到流中。
目前只能通过在公共API上调用 getmarkethistory 来获取(最近)订单历史记录:https://bittrex.com/home/api
答案 1 :(得分:1)
您忘记添加接收实际Feed的方法。
也忘了调用updateExchangeState'。
将connection.wait设置为更高的值,因为如果硬币没有经常交易,当您设置1秒的值时,可能会断开连接。
还请检查此库(我是作者),这是您尝试制作的内容 - websocket实时数据Feed: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()