def login(self, args):
    logging.info('==> AngelLogin .args => %s', args);
    systemConfig = getSystemConfig(Path(__file__).parent.parent.parent)
    brokerHandle = SmartConnect(api_key=self.brokerAppDetails.appKey)
    redirectUrl = None
    if 'request_token' in args:
      requestToken = args['request_token']
      logging.info('Angel requestToken = %s', requestToken)
      session = brokerHandle.generate_session(requestToken, api_secret=self.brokerAppDetails.appSecret)
      
      accessToken = session['access_token']
      accessToken = accessToken
      logging.info('Angel accessToken = %s', accessToken)
      brokerHandle.set_access_token(accessToken)
      
      logging.info('Angel Login successful. accessToken = %s', accessToken)

      # set broker handle and access token to the instance
      self.setBrokerHandle(brokerHandle)
      self.setAccessToken(accessToken)

      # redirect to home page with query param loggedIn=true
      homeUrl = systemConfig['homeUrl'] + '?loggedIn=true'
      logging.info('Angel Redirecting to home page %s', homeUrl)
      redirectUrl = homeUrl
    else:
      loginUrl = brokerHandle.login_url()
      logging.info('Redirecting to Angel login url = %s', loginUrl)
      redirectUrl = loginUrl

    return redirectUrl
Exemple #2
0
from smartapi import SmartConnect

#---------for smartExceptions---------
#import smartapi.smartExceptions
#or
#from smartapi import smartExceptions

smartApi = SmartConnect(api_key="Your Api Key")

login = smartApi.generateSession('Your Client Id', 'Your Password')

refreshToken = login['data']['refreshToken']

feedToken = smartApi.getfeedToken()

smartApi.getProfile(refreshToken)

smartApi.generateToken(refreshToken)

orderparams = {
    "variety": "NORMAL",
    "tradingsymbol": "SBIN-EQ",
    "symboltoken": "3045",
    "transactiontype": "BUY",
    "exchange": "NSE",
    "ordertype": "LIMIT",
    "producttype": "INTRADAY",
    "duration": "DAY",
    "price": "19500",
    "squareoff": "0",
    "stoploss": "0",
# package import statement
from smartapi import SmartConnect #or from smartapi.smartConnect import SmartConnect
#import smartapi.smartExceptions(for smartExceptions)

#create object of call
obj = SmartConnect(api_key="your api key")

#login api call

data = obj.generateSession("Your Client ID", "Your Password")
refreshToken = data['data']['refreshToken']

#fetch the feedtoken
feedToken = obj.getfeedToken()

#fetch User Profile
userProfile = obj.getProfile(refreshToken)
#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",
Exemple #4
0
from smartapi import SmartConnect

#---------for smartExceptions---------
#import smartapi.smartExceptions
#or
#from smartapi import smartExceptions

smartApi = SmartConnect(api_key="9MsNuOkg")

login = smartApi.generateSession('*****@*****.**', 'Abcd#1234')
print(login)
refreshToken = login['data']['refreshToken']
feedToken = smartApi.getfeedToken()
smartApi.getProfile(refreshToken)
smartApi.generateToken(refreshToken)
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)
"""
Author: Yash Roongta
Detailed Implementation: https://tradewithpython.com/concurrency-in-python-using-smartapi
You will have to give it a trade file to test this code, one sample file can be 
downloaded from here: https://app.blackhole.run/#8rolv6L2ED15oAuBM5GPcB2ghULBkAbRhdTeAF5nDNDM

You will also have to supply your own SmartAPI credentials.
"""

from smartapi import SmartConnect
import pandas as pd
from datetime import datetime
import time, concurrent.futures

obj = SmartConnect(api_key="your_api_key")
#this obj will be used later on to make all the trade requests.

#Let's login
data = obj.generateSession("Your Client ID", "Your Password")

#verifying if the login was successful
print(data)

df = pd.read_excel("path/to/file.xlsx")
#print(df.head())

trade_list = []  #empty list

#looping over each row in the dataframe and storing
#the value in each column to generate orderparams dict
#we use str to convert to strings
# package import statement
from smartapi import SmartConnect  #or from smartapi.smartConnect import SmartConnect
#import smartapi.smartExceptions(for smartExceptions)

#create object of call
obj = SmartConnect(api_key="your api key")

#login api call

data = obj.generateSession("Your Client ID", "Your Password")
refreshToken = data['data']['refreshToken']

#fetch the feedtoken
feedToken = obj.getfeedToken()

#fetch User Profile
userProfile = obj.getProfile(refreshToken)
#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",