¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

How do I retrieve the timestamp of the last trade


 

From the outset I need to clarify I am a newbie to both python and the IBKR API. I can successfully connect to the platform and retrieve data on the last traded price and last traded size, code snippet below. What I'd like to retrieve but can't, is the timestamp of last trade, i.e. what time did the stock trade last.

I see in the documentation a references to Ticker Id 45, "Last Timestamp - Time of the last trade (in UNIX time)", but I don't know how to access this or a method which will give me this timestamp.

Python Code snippet below

from ib_insync import *

thisClientId = 101

def main():
    ib = IB()
    ib.connect(host='127.0.0.1', port=7496, clientId=thisClientId)
    ib.reqMarketDataType(4)

    contract = Stock('BHP', 'SMART', 'AUD')
    stock_data = ib.reqMktData(contract, 225)
    ib.sleep(1.5)

    print("225 stock_data.last: ", stock_data.last)
    print("225 stock_data.lastSize: ", stock_data.lastSize)
    

if __name__ == '__main__':
    try:
        main()
    except:
        print('Interrupted')




 

If you're using? ib_insync try asking in this group -> /g/insync/messages


 

Thank you for the advice BTW.? The first time I've used groups to solve a problem.