| 149 | |
| 150 | |
| 151 | class MyWebsocketClient(cbpro.WebsocketClient): |
| 152 | def on_open(self): |
| 153 | self.url = "wss://ws-feed.pro.coinbase.com/" |
| 154 | self.products = ["BTC-USD", "ETH-USD"] |
| 155 | self.message_count = 0 |
| 156 | print("Let's count the messages!") |
| 157 | |
| 158 | def on_message(self, msg): |
| 159 | print(json.dumps(msg, indent=4, sort_keys=True)) |
| 160 | self.message_count += 1 |
| 161 | |
| 162 | def on_close(self): |
| 163 | print("-- Goodbye! --") |
| 164 | |
| 165 | |
| 166 | wsClient = MyWebsocketClient() |