def getQuote(tradingSymbol, isFnO=False): broker = Controller.getBrokerName() brokerHandle = Controller.getBrokerLogin().getBrokerHandle() quote = None if broker == "zerodha": key = ('NFO:' + tradingSymbol) if isFnO == True else ('NSE:' + tradingSymbol) bQuoteResp = brokerHandle.quote(key) bQuote = bQuoteResp[key] # convert broker quote to our system quote quote = Quote(tradingSymbol) quote.tradingSymbol = tradingSymbol quote.lastTradedPrice = bQuote['last_price'] quote.lastTradedQuantity = bQuote['last_quantity'] quote.avgTradedPrice = bQuote['average_price'] quote.volume = bQuote['volume'] quote.totalBuyQuantity = bQuote['buy_quantity'] quote.totalSellQuantity = bQuote['sell_quantity'] ohlc = bQuote['ohlc'] quote.open = ohlc['open'] quote.high = ohlc['high'] quote.low = ohlc['low'] quote.close = ohlc['close'] quote.change = bQuote['net_change'] quote.oiDayHigh = bQuote['oi_day_high'] quote.oiDayLow = bQuote['oi_day_low'] quote.lowerCiruitLimit = bQuote['lower_circuit_limit'] quote.upperCircuitLimit = bQuote['upper_circuit_limit'] else: # The logic may be different for other brokers quote = None return quote
def test010_save(self): self.assertEqual(Quote(10000, 'brexbottest', 1000, 'Test Quote', 'Test Viewer').exists(), None) Quote(10000, 'brexbottest', 1000, 'Test Quote', 'Test Viewer').save() self.assertEqual(Quote(10000, 'brexbottest', 1000, 'Test Quote', 'Test Viewer').exists(), True)
def test030_load(self): quote = Quote(10000, 'brexbottest', 1000, 'Test Quote', 'Test Viewer').load() self.assertIsNotNone(quote)
def test040_delete(self): quote = Quote(10000, 'brexbottest', 1000, 'Test Quote', 'Test Viewer').load() self.assertIsNotNone(quote) quote.delete() exist_check = quote.exists() self.assertEqual(exist_check, None)
def test020_exists(self): quote = Quote(10000, 'brexbottest', 1000, 'Test Quote', 'Test Viewer').load() exist_check = quote.exists() self.assertEqual(exist_check, True)