Python 3.x Bittrex websockets API:如何获取订单历史记录?
我正在使用Bittrex的websockets API 我在获取市场摘要方面没有问题 另外,调用hub方法“subscribeToExchangeDelta”,可以获得请求的交换Delta 然而,当我试图调用hub方法“QueryExchangeState”来获取某个市场的订单历史记录时,什么都没有发生,我甚至没有收到错误,因此该方法显然已被调用 是否有人对此了解得更多,有经验,或能让它发挥作用?请让我知道 下面的代码是我正在使用的。 它为我提供了“ETC-MEME”的摘要更新和交换增量 但如何获取特定市场的订单历史记录(本例中为“ETC-MEME”)Python 3.x Bittrex websockets API:如何获取订单历史记录?,python-3.x,websocket,algorithmic-trading,Python 3.x,Websocket,Algorithmic Trading,我正在使用Bittrex的websockets API 我在获取市场摘要方面没有问题 另外,调用hub方法“subscribeToExchangeDelta”,可以获得请求的交换Delta 然而,当我试图调用hub方法“QueryExchangeState”来获取某个市场的订单历史记录时,什么都没有发生,我甚至没有收到错误,因此该方法显然已被调用 是否有人对此了解得更多,有经验,或能让它发挥作用?请让我知道 下面的代码是我正在使用的。 它为我提供了“ETC-MEME”的摘要更新和交换增量 但如何
因此,调用QueryExchangeState没有效果,而调用SubscribeToExchangeDelta确实会将Delta添加到流中
当前(最近的)订单历史记录仅通过调用公共API上的getmarkethistory可用:您忘记添加接收实际提要的方法 还忘记调用“updateExchangeState” 将connection.wait设置为更高的值,因为如果硬币不经常交易,当您将值设置为1秒时,可能会断开连接 还请检查此库(我是作者),它是您试图制作的东西-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也没有什么不同(我仍然得到了摘要状态)。我很清楚wait函数的参数是超时。我的问题是关于获取特定市场的订单历史记录(填充)。我会尽量把我的问题说得更清楚,很抱歉造成混淆。@YtsendeBoer要获得订单,您需要chat.client.on('updateExchangeState',msg_received')和chat.server.invoke('subscribeToExchangeDelta',market)。然后,您将收到填写msg_的订单。您可以将handle_作为常规通道查看,正如您所说,它无论如何都会输出“updateSummaryState”。
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()