Friday, 2 September 2022

IBapi - is there any way to get NIFTY50 index price quote

i am new to Interactive brokers API, wondering if there is any way to get quote of NIFTY50 index, as i can see examples of NIFTY FUTURES, etc but not on index price quote of NIFTY50 or BANKNIFTY,

need help with some example, thanks,

sample on on getting quote of NIFTY OPTIONS,

    from locale import currency
    from ibapi.client import EClient
    from ibapi.wrapper import EWrapper
    from ibapi.contract import Contract
    from ibapi.ticktype import TickTypeEnum
    from ibapi.common import *
    import threading
    import time

    def get_close_quote(symbol, secType='OPT', exchange='NSE', currency='INR'):
        class IBapi(EWrapper, EClient):
            def __init__(self):
                EClient.__init__(self, self)
            def historicalData(self, reqId, bar):
                print(f'Time: {bar.date} Close: {bar.close}')
            def tickPrice(self, reqId, tickType, price, attrib):
                if tickType == TickTypeEnum.LAST or tickType == TickTypeEnum.DELAYED_LAST:
                    self.last = price;
                    self.disconnect()

        def run_loop():
            app.run()

        app = IBapi()
        app.connect('127.0.0.1', 7496, 123)

        #Start the socket in a thread
        api_thread = threading.Thread(target=run_loop, daemon=True)
        api_thread.start()

        time.sleep(1) #Sleep interval to allow time for connection to server

        #Create contract object
        contract = Contract()
        contract.localSymbol = symbol
        contract.secType = secType
        contract.exchange = exchange
        contract.currency = currency

        app.reqMktData(100, contract, "", False, False, None)
        time.sleep(2) #sleep to allow enough time for data to be returned
        app.disconnect()
        return(app.last)


from IBapi - is there any way to get NIFTY50 index price quote

No comments:

Post a Comment