Coinbase Websocket AttributeError: module 'collections' has no attribute 'MutableMapping'

Viewed 107

So I'm using python 3.10.1 and to my uderstanding the module isn't compatible with this version as it results in the error

Coinbase Websocket AttributeError: module 'collections' has no attribute 'MutableMapping'

I downloaded python 3.9.0 using pyenv, and created a virtual env. The websocket seems to work now, but It had me wondering if the module will be working in 3.10 soon as well?

Is there already a way to work around the problem as I would prefer to work in python 3.10?

full code

import cbpro

'''establish a live data feed from coinbase'''

class TextWebsocketClient(cbpro.WebsocketClient):
    def on_open(self):
        self.url = 'wss://ws-feed-public.sandbox.pro.coinbase.com'
        self.message_count = 0


    def on_message(self, msg):
        self.message_count += 1
        msg_type = msg.get('type', None)
        if msg_type == 'ticker':
            time_val = msg.get('time',('-'*27))
            price_val = msg.get('price', None)
            price_val = float(price_val) if price_val is not None else 'None'
            product_id = msg.get('product_id', None)

            print(f'{time_val:30} {price_val:3f} {product_id}\tchannel type: {msg_type}')

    def on_close(self):
        print(f'<---Websocket client closed --->\n\tTotal messages exchanged {self.messages.count}')

'''call the client'''

stream = TextWebsocketClient(products=['BTC-USD'], channels=['ticker'])
stream.start()
0 Answers
Related