This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import time | |
| ticker_symbol = "NSE:GLENMARK" | |
| trading_symbol = 'GLENMARK' | |
| quantity = 1 | |
| for i in range(10000): | |
| ltp = kite.ltp(ticker_symbol)[ticker_symbol]["last_price"] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| form kiteconnect import KiteTicker | |
| tokens = [738561, 5633] #token numbers of instruments | |
| def on_ticks(ws, ticks): | |
| print(ticks) | |
| def on_connect(ws, response): | |
| # Subscribe to a list of instrument_tokens | |
| ws.subscribe(tokens) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pynse import * | |
| quote = nse.get_quote('INFY') | |
| interval_high = quote['high'] | |
| print(interval_high) | |
| #output : 1610.7 | |
| interval_low = quote['low'] | |
| print(interval_low) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ticker = "NSE:INFY" | |
| interval_high = kite.quote(ticker)[ticker]['ohlc']['high'] | |
| print(interval_high) | |
| #output : 1610.7 | |
| interval_low = kite.quote(ticker)[ticker]['ohlc']['low'] | |
| print(interval_low) | |
| #output : 1592.05 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pynse import * | |
| nse = Nse() #create an nse object | |
| nse.get_quote("INFY")["lastPrice"] | |
| #output : 1602.05 | |
| ##OR | |
| quote = nse.get_quote("BANKNIFTY",Segment.FUT) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ticker = "NSE:INFY" | |
| kite.ltp(ticker)[ticker]["last_price"] | |
| #output : 1602.05 | |
| ##OR | |
| ticker = "NFO:BANKNIFTY22APRFUT" | |
| kite.ltp(ticker)[ticker]["last_price"] | |
| #output : 36345.8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ########################## EXIT CONDITION ######################### | |
| for i in range(1000000): | |
| try: | |
| t = datetime.datetime.now() | |
| ltp = kite.ltp(ticker_symbol)[ticker_symbol]['last_price'] | |
| print('ltp :', ltp) | |
| if (ltp >= target): | |
| order(trading_symbol, "SELL", quantity, kite) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ######################### ENTRY CONDITION ########################## | |
| import datetime | |
| for i in range(10000000): | |
| try: | |
| t = datetime.datetime.now() | |
| ltp = kite.ltp(ticker_symbol)[ticker_symbol]['last_price'] | |
| print('ltp :', ltp) | |
| if ltp > int_high: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ######################### ORDER FUNCTION ########################## | |
| def order(trading_symbol, t_type, quantity, kite): | |
| """ | |
| This function will execute order. i.e place Buy/Sell order | |
| trading_symbol : symbol of the stock | |
| t_type : type of order. 'BUY' or 'SELL' | |
| quantity : quantity of the stocks to buy/sell | |
| kite : kite object that is created earlier | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sleep(2) | |
| #request token | |
| request_token = driver.current_url.split('request_token=')[1].split('&')[0] | |
| #access token | |
| token = kite.generate_session(request_token, api_secret=api_secret) | |
| access_token = token['access_token'] | |
| #connect python with Kite API |