slazarov / python-bittrex-websocket

Python websocket for Bittrex (non async).
http://python-bittrex-websocket-docs.readthedocs.io/en/latest/index.html
MIT License
103 stars 38 forks source link

Doesn't do anything after "Establishing connection to Bittrex" #59

Closed hamkline closed 6 years ago

hamkline commented 6 years ago

PS C:\Python27\Lib\site-packages> python -m bittrex_websocket.websocket_client.py 2018-04-21 12:23:39 - bittrex_websocket.websocket_client - INFO - Establishing connection to Bittrex.

The code I ran is the example you did, I pasted it in websocket_client.py

class MySocket(BittrexSocket):
        def __init__(self):
            super(MySocket, self).__init__()
            self.ticker_updates_container = {}

        def on_public(self, msg):
            name = msg['M']
            if name not in self.ticker_updates_container:
                self.ticker_updates_container[name] = msg
                print ('Just received market update for {}.'.format(name))

ws = MySocket()

# Enable logging
ws.enable_log()

# Define tickers
tickers = ['BTC-ETH', 'BTC-NEO', 'BTC-ZEC', 'ETH-NEO', 'ETH-ZEC']

# Subscribe to ticker information
for ticker in tickers:
    sleep(0.01)
    ws.subscribe_to_exchange_deltas([ticker])

while len(ws.ticker_updates_container) < len(tickers):
        sleep(1)
else:
    print ('We have received updates for all tickers. Closing...')
    ws.disconnect()
    sleep(10)

As I mentioned in the title, it doesn't do anything after that message. Am I missing something or do I got a problem?

Before this problem I was getting some stuff with: "Exception in thread SocketConnection (most likely raised during interpreter shutdown):" idk if it's important or not. Appreciate the help.

slazarov commented 6 years ago

You are not supposed to paste it in the websocket_client.py, but run it in the separated file.

How did you install the package?

hamkline commented 6 years ago

pip install bittrex-websocket

hamkline commented 6 years ago

EDIT: Sorry I didn't do it right, if I paste ticker_updates.py at the same folder as websocket_client and run it, it just says C:\Python27\python.exe: No module named bittrex_websocket.ticker_updates.py and finishes the program. EDIT2: I understand that the "no module" might be due to main(), anyway, if I take main() and init out of the ticker_updates.py I get the same result as above, stuck as the title says.

slazarov commented 6 years ago

Hi, you are not supposed to put any scripts in the installation folder of the package. Put the file somewhere on your computer, e.g C:\python_scripts\ticker_updates.py and run it.