forked from L30705/smartapi-python
-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathSMARTAPI-PYTHON
More file actions
93 lines (85 loc) · 2.48 KB
/
SMARTAPI-PYTHON
File metadata and controls
93 lines (85 loc) · 2.48 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# package import statement
from SmartApi import SmartConnect #or from SmartApi.smartConnect import SmartConnect
import pyotp
api_key =aENtsjyf
clientId = S1039025
pwd = 9067
smartApi = SmartConnect(996b41f3-9056-43bd-8cb0-12a0e95953c1 )
token = "Your QR code value"
totp=pyotp.TOTP(token).now()
correlation_id = "abc123"
# login api call
data = smartApi.generateSession(clientId, pwd, totp)
# print(data)
authToken = data['data']['jwtToken']
refreshToken = data['data']['refreshToken']
# fetch the feedtoken
feedToken = smartApi.getfeedToken()
# fetch User Profile
res = smartApi.getProfile(refreshToken)
smartApi.generateToken(refreshToken)
res=res['data']['exchanges']
#place order
try:
orderparams = {
"variety": "NORMAL",
"tradingsymbol": "SBIN-EQ",
"symboltoken": "3045",
"transactiontype": "BUY",
"exchange": "NSE",
"ordertype": "LIMIT",
"producttype": "INTRADAY",
"duration": "DAY",
"price": "19500",
"squareoff": "0",
"stoploss": "0",
"quantity": "1"
}
orderId=smartApi.placeOrder(orderparams)
print("The order id is: {}".format(orderId))
except Exception as e:
print("Order placement failed: {}".format(e.message))
#gtt rule creation
try:
gttCreateParams={
"tradingsymbol" : "SBIN-EQ",
"symboltoken" : "3045",
"exchange" : "NSE",
"producttype" : "MARGIN",
"transactiontype" : "BUY",
"price" : 100000,
"qty" : 10,
"disclosedqty": 10,
"triggerprice" : 200000,
"timeperiod" : 365
}
rule_id=smartApi.gttCreateRule(gttCreateParams)
print("The GTT rule id is: {}".format(rule_id))
except Exception as e:
print("GTT Rule creation failed: {}".format(e.message))
#gtt rule list
try:
status=["FORALL"] #should be a list
page=1
count=10
lists=smartApi.gttLists(status,page,count)
except Exception as e:
print("GTT Rule List failed: {}".format(e.message))
#Historic api
try:
historicParam={
"exchange": "NSE",
"symboltoken": "3045",
"interval": "ONE_MINUTE",
"fromdate": "2021-02-08 09:00",
"todate": "2021-02-08 09:16"
}
smartApi.getCandleData(historicParam)
except Exception as e:
print("Historic Api failed: {}".format(e.message))
#logout
try:
logout=smartApi.terminateSession('Your Client Id')
print("Logout Successfull")
except Exception as e:
print("Logout failed: {}".format(e.message))