forked from GoChartingAdmin/client-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolygon.py
More file actions
27 lines (20 loc) · 648 Bytes
/
polygon.py
File metadata and controls
27 lines (20 loc) · 648 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
# Be sure to pip install websocket-client
# Details: https://pypi.org/project/websocket-client/
import websocket
def on_message(ws, message):
print(message)
def on_error(ws, error):
print(error)
def on_close(ws):
print("### closed ###")
def on_open(ws):
ws.send('{"action":"auth","params":"YOUR_API_KEY"}')
ws.send('{"action":"subscribe","params":"C.AUD/USD,C.USD/EUR,C.USD/JPY"}')
if __name__ == "__main__":
# websocket.enableTrace(True)
ws = websocket.WebSocketApp("wss://socket.polygon.io/forex",
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.on_open = on_open
ws.run_forever()