Skip to content

Commit a5734f9

Browse files
authored
Add files via upload
1 parent 0c0a788 commit a5734f9

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

example/smartwebsocketexamplev2.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from SmartApi.smartWebSocketV2 import SmartWebSocketV2
2+
from logzero import logger
3+
4+
AUTH_TOKEN = "authToken"
5+
API_KEY = "api_key"
6+
CLIENT_CODE = "client code"
7+
FEED_TOKEN = "feedToken"
8+
correlation_id = "abc123"
9+
action = 1
10+
mode = 1
11+
12+
token_list = [
13+
{
14+
"exchangeType": 1,
15+
"tokens": ["26009"]
16+
}
17+
]
18+
token_list1 = [
19+
{
20+
"action": 0,
21+
"exchangeType": 1,
22+
"tokens": ["26009"]
23+
}
24+
]
25+
26+
sws = SmartWebSocketV2(AUTH_TOKEN, API_KEY, CLIENT_CODE, FEED_TOKEN)
27+
28+
def on_data(wsapp, message):
29+
logger.info("Ticks: {}".format(message))
30+
# close_connection()
31+
32+
def on_open(wsapp):
33+
logger.info("on open")
34+
sws.subscribe(correlation_id, mode, token_list)
35+
# sws.unsubscribe(correlation_id, mode, token_list1)
36+
37+
38+
def on_error(wsapp, error):
39+
logger.error(error)
40+
41+
42+
def on_close(wsapp):
43+
logger.info("Close")
44+
45+
46+
47+
def close_connection():
48+
sws.close_connection()
49+
50+
51+
# Assign the callbacks.
52+
sws.on_open = on_open
53+
sws.on_data = on_data
54+
sws.on_error = on_error
55+
sws.on_close = on_close
56+
57+
sws.connect()

0 commit comments

Comments
 (0)