-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_example.py
More file actions
46 lines (33 loc) · 1.03 KB
/
simple_example.py
File metadata and controls
46 lines (33 loc) · 1.03 KB
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
40
41
42
43
44
45
46
"""
FCS Simple Example - Quick Start
Minimal example to get started with FCS WebSocket.
Just prints price updates for Bitcoin.
Run: python simple_example.py
"""
import sys
import os
# Add parent directory to path for import
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from fcs_client_lib import FCSClient
# Create client with demo API key
client = FCSClient('fcs_socket_demo')
@client.on_connected
def on_connected():
print('Connected to FCS WebSocket!')
print('Subscribing to BTCUSDT...\n')
client.join('BINANCE:BTCUSDT', '1D')
@client.on_message
def on_message(data):
if data.get('type') == 'price':
symbol = data.get('symbol')
price = data['prices'].get('c') # Close price
print(f'{symbol}: ${price}')
if __name__ == '__main__':
print('FCS WebSocket - Simple Example')
print('Press Ctrl+C to stop\n')
try:
client.connect()
client.run_forever()
except KeyboardInterrupt:
print('\nDisconnecting...')
client.disconnect()