forked from angel-one/smartapi-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmartwebsocketexamplev2.py
More file actions
57 lines (42 loc) · 1.01 KB
/
smartwebsocketexamplev2.py
File metadata and controls
57 lines (42 loc) · 1.01 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
from SmartApi.smartWebSocketV2 import SmartWebSocketV2
from logzero import logger
AUTH_TOKEN = "authToken"
API_KEY = "api_key"
CLIENT_CODE = "client code"
FEED_TOKEN = "feedToken"
correlation_id = "abc123"
action = 1
mode = 1
token_list = [
{
"exchangeType": 1,
"tokens": ["26009"]
}
]
token_list1 = [
{
"action": 0,
"exchangeType": 1,
"tokens": ["26009"]
}
]
sws = SmartWebSocketV2(AUTH_TOKEN, API_KEY, CLIENT_CODE, FEED_TOKEN)
def on_data(wsapp, message):
logger.info("Ticks: {}".format(message))
# close_connection()
def on_open(wsapp):
logger.info("on open")
sws.subscribe(correlation_id, mode, token_list)
# sws.unsubscribe(correlation_id, mode, token_list1)
def on_error(wsapp, error):
logger.error(error)
def on_close(wsapp):
logger.info("Close")
def close_connection():
sws.close_connection()
# Assign the callbacks.
sws.on_open = on_open
sws.on_data = on_data
sws.on_error = on_error
sws.on_close = on_close
sws.connect()