This post shows how to determine the amount of trading history data available for a stock ticker using the IBKR API in Python.
There is a function available which returns the first available timestamp for the ticker – which is equivalent to the first date the shares were traded.
The function is reqHeadTimestamp().
This can be considered a proxy for the IPO date of the stock within IBKR data, but there is no guarantee that the start of IBKR data coincides with the exact IPO date.
It should be sufficient to determine how far back available data goes for a given stock.
We define a class as an event listener. The earliest date comes back in the callback headTimestamp().
The main script subscribes to the data and the event handler will fire after a delay.
Full script:
import threading
import time
from datetime import date, datetime, timezone
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
# Class extending IBKR client classes.
class IBapi(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
def headTimestamp(self, reqId, headTimeStamp):
earliestDate = datetime.fromtimestamp(
int(headTimeStamp),
tz=timezone.utc).date()
print("Earliest trade date: " + str(earliestDate))
dateDelta = date.today() - earliestDate
numDaysOfData = dateDelta.days
print("Days of data: " + str(numDaysOfData))
# Main script.
ticker = input("Ticker symbol: ")
TWS_HOST = "127.0.0.1"
TWS_PORT = 7497 # Paper account.
CLIENT_ID = 12345 # Arbitrary.
ibApi = IBapi()
ibApi.connect(TWS_HOST, TWS_PORT, CLIENT_ID)
threading.Thread(target=ibApi.run).start()
time.sleep(1) # Allow time for subscription.
contract = Contract()
contract.symbol = ticker
contract.secType = "STK"
contract.exchange = "SMART"
contract.currency = "USD"
ibApi.reqHeadTimeStamp(
reqId=12345, # Arbitrary.
contract=contract,
whatToShow="TRADES",
useRTH=1, # Regular Trading Hours.
formatDate=2 # Unix Epoch.
)
time.sleep(5) # Allow time to receive data.
ibApi.disconnect()
Example run:
Ticker symbol: JEM Earliest trade date: 2025-06-09 Days of data: 458
