-
-
Save Gitart/7f99ac188f1b92fbaff32891b58542e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from websocket import create_connection | |
import json | |
# Copy the web brower header and input as a dictionary | |
headers = json.dumps({ | |
'Pragma': 'no-cache', | |
'Origin': 'https://www.cryptocompare.com', | |
'Accept-Language': 'en-US,en;q=0.9', | |
'Sec-WebSocket-Key': 'QknTzkhVwUs8UY+xAE22Kg==', | |
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36', | |
'Upgrade': 'websocket', | |
'Sec-WebSocket-Extensions': 'permessage-deflate; client_max_window_bits', | |
'Cache-Control': 'no-cache', | |
'Connection': 'Upgrade', | |
'Sec-WebSocket-Version': '13', | |
}) | |
# Launch the connection to the server (Performing handshake) | |
ws = create_connection('wss://streamer.cryptocompare.com/v2?format=streamer',headers=headers) | |
# Sending outgoing messages to server | |
ws.send(json.dumps({"action":"SubAdd","subs":["24~CCCAGG~BTC~USD~H"]})) | |
ws.send(json.dumps({"action":"SubAdd","subs":["24~CCCAGG~ETH~USD~H"]})) | |
ws.send(json.dumps({"action":"SubAdd","subs":["5~CCCAGG~LTC~USD","24~CCCAGG~LTC~USD~H"]})) | |
ws.send(json.dumps({"action":"SubAdd","subs":["24~CCCAGG~XRP~USD~H"]})) | |
ws.send(json.dumps({"action":"SubAdd","subs":["11~BTC","21~BTC","5~CCCAGG~BTC~USD","11~ETH","21~ETH","5~CCCAGG~ETH~USD","11~SHIB","21~SHIB","5~CCCAGG~SHIB~USD","11~SOL","21~SOL","5~CCCAGG~SOL~USD","11~OMG","21~OMG","5~CCCAGG~OMG~USD","11~XRP","21~XRP","5~CCCAGG~XRP~USD","11~DOT","21~DOT","5~CCCAGG~DOT~USD","11~BUSD","21~BUSD","5~CCCAGG~BUSD~USD","11~ADA","21~ADA","5~CCCAGG~ADA~USD","11~SAND","21~SAND","5~CCCAGG~SAND~USD"]})) | |
# Receiving incoming messages | |
while True: | |
try: | |
result = ws.recv() | |
print(result) | |
except Exception as e: | |
print(e) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment