1

I'm using the IB API in order to automatically pull real time data of the full daily bid/ask trading book vendor. I am unable to figure out how to print on the screen this data yet, would appreciate some enlightenment

Here is my code sample for pulling frozen delayed market data:

from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.ticktype import TickTypeEnum


class TestApp(EWrapper, EClient):
    def __init__(self):
        EClient.__init__(self, self)

    def error(self, reqId, errorCode, errorString):
        print("Error: ", reqId, " ", errorCode, " ", errorString)

    def tickPrice(self, reqId, tickType, price, attrib):
        print("Tick Price. Ticker Id:", reqId, "tickType:", TickTypeEnum.to_str(tickType), "Price:", price, end=' ')

    def tickSize(self, reqId, tickType, size):
        print("Tick Size. Ticker Id:", reqId, "tickType:", TickTypeEnum.to_str(tickType), "Size:", size)
        #if tickType == 2 and reqId == 1:
        #   print('The current ask price is: ', price)

def main():
    app = TestApp()

    app.connect("127.0.0.1", 7497, 0)

    contract = Contract()
    contract.symbol = "AAPL"
    contract.secType = "STK"
    contract.exchange = "SMART"
    contract.currency = "USD"
    contract.primaryExchange = "NASDAQ"


    try:
        app.reqMarketDataType(1)  # switch to delayed-frozen data if live is not available
        app.reqMktData(1, contract, "", False, False, [])
        
    except Exception:
        marketData=0
    
        
    else:
        app.reqMarketDataType(4)  # switch to delayed-frozen data if live is not available
        app.reqMktData(1, contract, "", False, False, [])
        marketData = -1
    
    finally:
        print (marketData)



    app.run()


if __name__ == "__main__":
    main()
  • Does IB raise an exception when data is frozen? To my knowledge only an errorMsg is sent, so you'd need to raise when a certain errorMsg is received. – misantroop Jan 15 '22 at 10:53

1 Answers1

2
def tickPrice(self, reqId, tickType, price, attrib):
    if tickType == 1 and reqId == 2:
        print('The current ask price is: ', price)
Ken
  • 21
  • 2
  • 2
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 06 '21 at 19:36
  • what about bid price ? – Noob Master Oct 25 '22 at 07:06