-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathstreaming_client.py
More file actions
38 lines (25 loc) · 921 Bytes
/
streaming_client.py
File metadata and controls
38 lines (25 loc) · 921 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
#pip install "python-socketio[client]"
import socketio
import json
sio = socketio.Client(ssl_verify=False)
@sio.event
def connect():
## USE THIS LIST TO FILTER AND RECEIVE ONLY INSTRUMENTS YOU NEED. LEAVE EMPTY TO RECEIVE ALL
#if you want to subscribe only specific instruments, emit instruments. To receive all instruments, comment the lines below.
instruments = ['EURUSD', 'USDJPY', 'BTCUSD', 'ETH']
sio.emit('instruments', instruments);
#Use the 'trial' as key to establish a 2-minute streaming connection with real-time data.
#After the 2-minute test, the server will drop the connection and block the IP for an Hour.
sio.emit('key', 'trial')
@sio.event
def rates(rates):
try:
instr = json.loads(rates)
print(instr)
except:
print(rates)
@sio.event
def disconnect():
print('disconnected from server')
sio.connect('https://wss.live-rates.com/', transports=['websocket'])
sio.wait()