Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathpython_ws_example.py
More file actions
Latest commit
58 lines (39 loc) · 1.87 KB
/
Copy pathpython_ws_example.py
File metadata and controls
58 lines (39 loc) · 1.87 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
47
48
49
50
51
52
53
54
55
56
57
58
importlogging
fromsocketclusterclientimportSocketcluster
logging.basicConfig(format="%s(levelname)s:%(message)s", level=logging.DEBUG)
importjson
api_credentials=json.loads('{}')
api_credentials["apiKey"]="xxx"
api_credentials["apiSecret"]="xxx"
defyour_code_starts_here(socket):
###Code for subscription
socket.subscribe('TRADE-OK--BTC--CNY') # Channel to be subscribed
defchannelmessage(key, data): # Messages will be received here
print ("\n\n\nGot data "+json.dumps(data, sort_keys=True)+" from channel "+key)
socket.onchannel('TRADE-OK--BTC--CNY', channelmessage) # This is used for watching messages over channel
###Code for emit
defack(eventname, error, data):
print ("\n\n\nGot ack data "+json.dumps(data, sort_keys=True) +" and eventname is "+eventname)
socket.emitack("exchanges",None, ack)
socket.emitack("channels", "OK", ack)
defonconnect(socket):
logging.info("on connect got called")
defondisconnect(socket):
logging.info("on disconnect got called")
defonConnectError(socket, error):
logging.info("On connect error got called")
defonSetAuthentication(socket, token):
logging.info("Token received "+token)
socket.setAuthtoken(token)
defonAuthentication(socket, isauthenticated):
logging.info("Authenticated is "+str(isauthenticated))
defack(eventname, error, data):
print ("token is "+json.dumps(data, sort_keys=True))
your_code_starts_here(socket);
socket.emitack("auth", api_credentials, ack)
if__name__=="__main__":
socket=Socketcluster.socket("wss://sc-02.coinigy.com/socketcluster/")
socket.setBasicListener(onconnect, ondisconnect, onConnectError)
socket.setAuthenticationListener(onSetAuthentication, onAuthentication)
socket.setreconnection(False)
socket.connect()