2
votes

I am using the websockets API of Bittrex.

I have no problem getting the market summaries.

Also, invoking the hub method "SubscribeToExchangeDeltas", gets me the requested exchange deltas.

However, when I try to invoke the hub method "QueryExchangeState" to get the order history of some market, nothing happens, I don't even get an error so the method apparently has been called.

Does anyone know more about this, have experience with this, or gets this to work? Please let me know!

The code below is what I am using. It gives me the summary updates and the exchange deltas for 'ETC-MEME'.

But how to get the order history for specific markets ('ETC-MEME' in this example)?

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()
2

2 Answers

2
votes

So it turns out that invoking QueryExchangeState has no effect and invoking SubscribeToExchangeDeltas indeed adds the deltas to the stream.

The (recent) order history is currently only available through invoking getmarkethistory on the public API: https://bittrex.com/home/api

2
votes

You forgot to add a method which receives the actual feed.

Also forgot to invoke 'updateExchangeState'.

Set the connection.wait to a higher value, since if the coin is not traded frequently you might get disconnected when you set a value of 1 second.

Please also check this library (I am the author), it is the thing you trying to make - a websocket real time data feed: https://github.com/slazarov/python-bittrex-websocket

Anyways, this should do the trick:

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()