我正在使用Bittrex的websockets。
我没有问题得到市场摘要。
此外,调用集线器方法"SubscribeToExchangeDeltas",将获得请求的交换增量。
然而,当我试图调用集线器方法"QueryExchangeState“来获取某些市场的订单历史时,什么都没有发生,我甚至没有得到一个错误,所以这个方法显然已经被调用了。
有没有人对此有更多的了解,有过这样的经验,或者让它发挥作用?请让我知道!
下面的代码是我正在使用的代码。它给我摘要更新和交换三角洲‘等-模因’。
但是,如何获得特定市场的订单历史(本例中为“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()发布于 2017-11-24 10:41:07
因此,结果是调用QueryExchangeState没有任何效果,而调用SubscribeToExchangeDeltas确实将三角洲添加到流中。
(最近的)订单历史记录目前只能通过调用公共API:https://bittrex.com/home/api上的getmarkethistory获得。
发布于 2017-11-24 16:05:13
您忘记添加一个接收实际提要的方法。
还忘记调用'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()https://stackoverflow.com/questions/47110415
复制相似问题