From 0552e931ebdc405920eda7294d14e112530cce23 Mon Sep 17 00:00:00 2001 From: Shyam377 <140687308+Shyam377@users.noreply.github.com> Date: Mon, 7 Aug 2023 21:27:04 +0530 Subject: [PATCH 1/3] Create SMARTAPI-PYTHON --- SMARTAPI-PYTHON | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 SMARTAPI-PYTHON diff --git a/SMARTAPI-PYTHON b/SMARTAPI-PYTHON new file mode 100644 index 00000000..c87a9306 --- /dev/null +++ b/SMARTAPI-PYTHON @@ -0,0 +1,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(api_key) +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)) From 941832d85c6ca28838074eea4c7ebf5765f4f513 Mon Sep 17 00:00:00 2001 From: Shyam377 <140687308+Shyam377@users.noreply.github.com> Date: Mon, 7 Aug 2023 21:37:29 +0530 Subject: [PATCH 2/3] Update SMARTAPI-PYTHON --- SMARTAPI-PYTHON | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SMARTAPI-PYTHON b/SMARTAPI-PYTHON index c87a9306..afbfca0f 100644 --- a/SMARTAPI-PYTHON +++ b/SMARTAPI-PYTHON @@ -4,7 +4,7 @@ import pyotp api_key =aENtsjyf clientId = S1039025 -pwd = 9067 +pwd = smartApi = SmartConnect(api_key) token = "Your QR code value" totp=pyotp.TOTP(token).now() From 5c94baebc8aee3f1488d694c52ee7fdf22991110 Mon Sep 17 00:00:00 2001 From: Shyam377 <140687308+Shyam377@users.noreply.github.com> Date: Mon, 7 Aug 2023 21:39:40 +0530 Subject: [PATCH 3/3] Update SMARTAPI-PYTHON --- SMARTAPI-PYTHON | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SMARTAPI-PYTHON b/SMARTAPI-PYTHON index afbfca0f..394930df 100644 --- a/SMARTAPI-PYTHON +++ b/SMARTAPI-PYTHON @@ -4,8 +4,8 @@ import pyotp api_key =aENtsjyf clientId = S1039025 -pwd = -smartApi = SmartConnect(api_key) +pwd = 9067 +smartApi = SmartConnect(996b41f3-9056-43bd-8cb0-12a0e95953c1 ) token = "Your QR code value" totp=pyotp.TOTP(token).now() correlation_id = "abc123"