Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

I am currently working with the kite API to automate activities like buy, sell, etc. I am obtaining the data from the csv file and placing them in variables. 

And here is my code...

import csv

from kiteconnect import KiteConnect

import urllib.request

import webbrowser

csvfile = open('../desktop/venkat.csv','r')

csvFileArray = []

for row in csv.reader(csvfile, delimiter = '\t'):

        csvFileArray.append(row)

header =csvFileArray[0][0].split(',')

kite = KiteConnect(api_key="pgxi3s1pltmrjlkw")

#print(kite.login_url())

data = kite.request_access_token("lqa7c5i65srjnb2wgnfdzoy8dhal4wx0",secret="i345wx7pto3yx2gtb999q531qb2ffkzf")

kite.set_access_token(data["access_token"])

#print(kite.access_token)

for each in csvFileArray[1:]:

        data= each[0].split(',')

        for i in range(len(data)):

            if i==0:

                    exchange=str(data[i])

            elif i==1:

                    tradingsymbol=str(data[i])

            elif i==2:  

                    transaction_type=str(data[i])

            elif i==3:

                    quantity=int(data[i])

            elif i==4:

                    price=int(data[i])

            elif i==5:  

                    product=str(data[i])

            elif i==6:    

                    order_type=str(data[i])

            elif i==7:

                    validity=str(data[i])

            elif i==8:  

                    squareoff_value=int(data[i])

            elif i==9:  

                    stoploss_value=int(data[i])

            elif i==10:  

                    trailing_stoploss=int(data[i])

            else:  

                    variety=str(data[i]) # this is the additional line

        #print(exchange)

        disclosed_quantity=None

        trigger_price=None

        tag=''

        try:

            order_id = kite.order_place(exchange,tradingsymbol,transaction_type,quantity,price,product,order_type,validity,squareoff_value,stoploss_value,trailing_stoploss,variety,disclosed_quantity,trigger_price,tag)

            #print(exchange, tradingsymbol, transaction_type, quantity, price, product, order_type, validity, disclosed_quantity, trigger_price, squareoff_value, stoploss_value, trailing_stoploss, variety, tag)

            #print("Order Placed")

            #print("Order placed. ID is", order_id)

        except Exception as e:

            print("Order placement failed", e.message)

It is giving an error that I am not able to solve. 

Please log in or register to answer this question.

Browse Categories

...