Bittrex websockets API:如何获取订单历史记录?
Bittrex websockets API: how to get the order history?
我正在使用 Bittrex 的 websockets API。
我可以轻松获取市场摘要。
此外,调用集线器方法 "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()
所以调用 QueryExchangeState 没有效果,调用 SubscribeToExchangeDeltas 确实将增量添加到流中。
(最近的)订单历史目前只能通过在 public API 上调用 getmarkethistory 获得:https://bittrex.com/home/api
您忘记添加接收实际提要的方法。
还忘了调用'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()
我正在使用 Bittrex 的 websockets API。
我可以轻松获取市场摘要。
此外,调用集线器方法 "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()
所以调用 QueryExchangeState 没有效果,调用 SubscribeToExchangeDeltas 确实将增量添加到流中。
(最近的)订单历史目前只能通过在 public API 上调用 getmarkethistory 获得:https://bittrex.com/home/api
您忘记添加接收实际提要的方法。
还忘了调用'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()