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 getCMP(tradingSymbol): brokerLogin = Controller.getBrokerLogin() brokerHandle = brokerLogin.getBrokerHandle() quote = None if brokerLogin.broker == "zerodha": quote = brokerHandle.quote(tradingSymbol) if quote: return quote[tradingSymbol]['last_price'] else: return 0 else: # The logic may be different for other brokers return 0
def fetchInstrumentsFromServer(): instrumentsList = [] try: brokerHandle = Controller.getBrokerLogin().getBrokerHandle() logging.info('Going to fetch instruments from server...') instrumentsList = brokerHandle.instruments('NSE') instrumentsListFnO = brokerHandle.instruments('NFO') # Add FnO instrument list to the main list instrumentsList.extend(instrumentsListFnO) logging.info('Fetched %d instruments from server.', len(instrumentsList)) except Exception as e: logging.exception( "Exception while fetching instruments from server") return instrumentsList
def getStrikePrice(tradingSymbol): broker = Controller.getBrokerName() brokerHandle = Controller.getBrokerLogin().getBrokerHandle() quote = None if broker == "zerodha": key = 'NSE:' + tradingSymbol bQuoteResp = brokerHandle.quote(key) quote = bQuoteResp[key] if quote: return quote['last_price'] else: return 0 else: # The logic may be different for other brokers quote = None return quote
def fetchInstruments(): brokerHandle = Controller.getBrokerLogin().getBrokerHandle() if Instruments.instrumentsList: return Instruments.instrumentsList logging.info('Going to fetch instruments...') instrumentsList = brokerHandle.instruments('NSE') Instruments.symbolToInstrumentMap = {} Instruments.tokenToInstrumentMap = {} for isd in instrumentsList: tradingSymbol = isd['tradingsymbol'] instrumentToken = isd['instrument_token'] # logging.info('%s = %d', tradingSymbol, instrumentToken) Instruments.symbolToInstrumentMap[tradingSymbol] = isd Instruments.tokenToInstrumentMap[instrumentToken] = isd logging.info('Fetching instruments done. Instruments count = %d', len(instrumentsList)) Instruments.instrumentsList = instrumentsList # assign the list to static variable return instrumentsList
def get(self): brokerHandle = Controller.getBrokerLogin().getBrokerHandle() positions = brokerHandle.positions() logging.info('User positions => %s', positions) return json.dumps(positions)
def __init__(self, broker): self.broker = broker self.brokerLogin = Controller.getBrokerLogin() self.ticker = None self.tickListeners = []
def get(self): brokerHandle = Controller.getBrokerLogin().getBrokerHandle() holdings = brokerHandle.holdings() logging.info('User holdings => %s', holdings) return json.dumps(holdings)
def __init__(self, broker): self.broker = broker self.brokerHandle = Controller.getBrokerLogin().getBrokerHandle()