def process(self): now = datetime.now() if now < self.startTimestamp: return if len(self.trades) >= self.maxTradesPerDay: return # Get current market price of Nifty Future #futureSymbol = Utils.prepareMonthlyExpiryFuturesSymbol('BANKNIFTY') futureSymbol = 'NIFTY BANK' quote = Quotes.getStrikePrice(futureSymbol) if quote == None: logging.error('%s: Could not get quote for %s', self.getName(), futureSymbol) return ATMStrike = Utils.getNearestStrikePrice(quote, 100) logging.info('%s: %s = %f, ATMStrike = %d', self.getName(), futureSymbol, quote, ATMStrike) ATMCESymbol = Utils.prepareWeeklyOptionsSymbol("BANKNIFTY", ATMStrike, 'CE') ATMPESymbol = Utils.prepareWeeklyOptionsSymbol("BANKNIFTY", ATMStrike, 'PE') logging.info('%s: ATMCESymbol = %s, ATMPESymbol = %s', self.getName(), ATMCESymbol, ATMPESymbol) # create trades self.generateTrades(ATMCESymbol, ATMPESymbol)
def process(self): now = datetime.now() if now < self.startTimestamp: return if len(self.trades) >= self.maxTradesPerDay: return # Get current market price of Nifty Future futureSymbol = Utils.prepareMonthlyExpiryFuturesSymbol('NIFTY') quote = self.getQuote(futureSymbol) if quote == None: logging.error('%s: Could not get quote for %s', self.getName(), futureSymbol) return ATMStrike = Utils.getNearestStrikePrice(quote.lastTradedPrice, 50) logging.info('%s: Nifty CMP = %f, ATMStrike = %d', self.getName(), quote.lastTradedPrice, ATMStrike) ATMPlus50CESymbol = Utils.prepareWeeklyOptionsSymbol("NIFTY", ATMStrike + 50, 'CE') ATMMinus50PESymbol = Utils.prepareWeeklyOptionsSymbol("NIFTY", ATMStrike - 50, 'PE') logging.info('%s: ATMPlus50CE = %s, ATMMinus50PE = %s', self.getName(), ATMPlus50CESymbol, ATMMinus50PESymbol) # create trades self.generateTrades(ATMPlus50CESymbol, ATMMinus50PESymbol)
def strikeRunner(): # Get current market price of Nifty Future #futureSymbol = Utils.prepareMonthlyExpiryFuturesSymbol('BANKNIFTY') strikesFilepath = 'G:\Algo Trading\python\git\python-deploy\stikes\stikes.json' #quote = Quotes.getQuote(futureSymbol,True) futureSymbol = 'NIFTY BANK' quote = Quotes.getStrikePrice(futureSymbol) if quote == None: logging.error('OptionBuyingStrategy: Could not get quote for %s', futureSymbol) return ATMStrike = Utils.getNearestStrikePrice(quote, 100) logging.info( 'OptionBuyingStrategy: Bank Nifty CMP = %f, ATMStrike = %d', quote, ATMStrike) initialATMStrike = ATMStrike + 100 OptionBuyingStrategy.trades = [] OptionBuyingStrategy.loadAndUpdateStrikesFromFile(strikesFilepath) if (len(OptionBuyingStrategy.trades) == 0): logging.info( "As strikes data is empty , it will be added to the file") # Increment from current ATM strike price to find strike that condition met to CE strike while True: optionQuote = Quotes.getOptionBuyingQuote( Utils.prepareWeeklyOptionsSymbol("BANKNIFTY", initialATMStrike, 'CE'), True) if (OptionBuyingStrategy.isWithinTradingRange( optionQuote.low)): OptionBuyingStrategy.trades.append(optionQuote) message = "{0} : low is {1} satisfies to trade".format( optionQuote.tradingSymbol, optionQuote.low) Utils.sendMessageTelegramBot(message) logging.info(message) break initialATMStrike = initialATMStrike + 100 # Increment from current ATM strike price to find strike that condition met to PE strike initialATMStrike = ATMStrike - 100 while True: optionQuote = Quotes.getOptionBuyingQuote( Utils.prepareWeeklyOptionsSymbol("BANKNIFTY", initialATMStrike, 'PE'), True) if (OptionBuyingStrategy.isWithinTradingRange( optionQuote.low)): OptionBuyingStrategy.trades.append(optionQuote) message = "{0} : low is {1} satisfies to trade".format( optionQuote.tradingSymbol, optionQuote.low) Utils.sendMessageTelegramBot(message) logging.info(message) break initialATMStrike = initialATMStrike - 100 with open(strikesFilepath, 'w') as tFile: json.dump(OptionBuyingStrategy.trades, tFile, indent=2, cls=TradeEncoder) message = "Option details are saved to file successfully, it will be updated regularly" Utils.sendMessageTelegramBot(message) OptionBuyingStrategy.loadAndUpdateStrikesFromFile(strikesFilepath) else: logging.info("Update the low Price ")