-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_boom.py
More file actions
39 lines (30 loc) Β· 996 Bytes
/
test_boom.py
File metadata and controls
39 lines (30 loc) Β· 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import websocket
import json
APP_ID = "APP_ID" # Your real APP ID
API_TOKEN = "API_TToken" # Your real token
def on_open(ws):
print("π Connected. Authorizing...")
ws.send(json.dumps({
"authorize": API_TOKEN
}))
def on_message(ws, message):
data = json.loads(message)
if "authorize" in data:
print("β
Authorized. Subscribing to Boom 1000 ticks...")
ws.send(json.dumps({
"ticks": "boom_1000",
"subscribe": 1
}))
elif "tick" in data:
print(f"π Tick: {data['tick']['quote']}")
def on_error(ws, error):
print("β Error:", error)
def on_close(ws, *args):
print("π Disconnected.")
socket = f"wss://ws.deriv.com/websockets/v3?app_id={APP_ID}"
ws = websocket.WebSocketApp(socket,
on_open=on_open,
on_message=on_message,
on_error=on_error,
on_close=on_close)
ws.run_forever()