TargetProcess / signalr-client-py

python client proxy for signalr
Other
63 stars 58 forks source link

problem getting data #30

Open hippylover opened 7 years ago

hippylover commented 7 years ago

Hello. I would like to get live orderbook updates as outlined in attached doc. WebSocketAPI_MarketTracking_bittrex.docx

But i can't figure out how to do it.

from requests import Session
from signalr import Connection
import time

markets = ['BTC-DGB', 'BTC-STRAT']

with Session() as session:
    connection = Connection('http://socket.bittrex.com/signalr', session)

    corehub = connection.register_hub('coreHub')
    connection.start()

    #create new chat message handler
    def print_received_message(data):
        print(data)
        # if data['Nounce'] is not None:
        #   print('Nounce', data['Nounce'])

        # if data['Deltas'] is not None:
        #   for value in data['Deltas']:
        #       print(value)

    #create error handler
    def print_error(error):
        print('error: ', error)

    # debug information, show all data
    def print_raw_data(*args, **kwargs):
        print (args, kwargs)

    connection.received += print_raw_data

    with connection:
        corehub.server.invoke('SubscribeToExchangeDeltas', ['BTC-ETH'])

    #corehub.client.on('updateSummaryState', print_received_message)

    connection.error += print_error

    connection.wait(1)

while True:
    pass

Do anyone know what is wrong?

rchiossi commented 7 years ago

With pr #33 I'm able to connect to bittrex with the following code:

from requests import Session
from signalr import Connection

def handle_received(**data):
    print(data)

def print_error(error):
    print('error: ', error)

def main():
    with Session() as session:
        connection = Connection("https://www.bittrex.com/signalR/", session)
        corehub = connection.register_hub('corehub')
        connection.start()

        connection.received += handle_received
        connection.error += print_error

        for market in ["BTC-ETH"]:
            corehub.server.invoke('SubscribeToExchangeDeltas', market)

        while True:
            connection.wait(1)

if __name__ == "__main__":
    main()