def Export15minuteHistoricalDataByDate(from_date, to_date, symbol): if from_date > to_date: return token = db.get_instrument_token(symbol) if token == -1: print('Invalid symbol provided') return 'None' # provide interval as per candle size given above interval = '15minute' records = kite.historical_data(token, from_date=from_date, to_date=to_date, interval=interval) df = pd.DataFrame(records) if len(df) == 0: print('No data returned') return df.drop('volume', inplace=True, axis=1) df.set_index('date',inplace=True) return df
while True: today = datetime.datetime.today().strftime('%Y-%m-%d') sdate = 'today' edate = 'today' df = Export15minuteHistoricalDataByDate(today, today, 'NTPC') df.to_csv('symbol.csv') data = pd.read_csv("symbol.csv", parse_dates=["date"], index_col="date") # Fetch 15 minute Data of the day df15min = data # assuming its the same data high = df15min.high.iloc[0] close = df15min.close.iloc[-2] if high < close: orderid = PlaceBuyOrderMarketNSE('NTPC', 100) print("Placed order with ID: {}".format(orderid)) break # Exit the loop after placing the order time.sleep(1) # sleep for 1 seconds before continuing
Can anyone help me to write python code to place stop loss order at 1% of buy order price after successful placement of buy order