ftgo
A Python library for fetching financial data from Financial Times Markets, including historical stock prices, ETF holdings, fund profiles, and allocation breakdowns.
Features
- Historical Data: Fetch historical OHLCV data for stocks and ETFs
- Holdings Data: Get ETF/fund holdings, asset allocation, and sector breakdowns
- Fund Profiles: Access fund information, statistics, and investment details
- Symbol Search: Find FT Markets XIDs by ticker symbols
- Concurrent Processing: Fast data retrieval using multithreading
- Pandas Integration: Returns data as pandas DataFrames for easy analysis
Installation
pip install ftgo
Quick Start
from ftgo import search_securities, get_xid, get_historical_prices, get_holdings
# Search for a security
results = search_securities('AAPL')
print(results)
# Get XID for a ticker
xid = get_xid('AAPL')
# Fetch historical data
df = get_historical_prices(xid, "01012024", "31012024")
print(df.head())
# Get ETF holdings
spy_xid = get_xid('SPY')
holdings = get_holdings(spy_xid, "top_holdings")
print(holdings)
API Reference
Search Functions
search_securities(query)
Search for securities on FT Markets.
Parameters:
query(str): Search term for securities (ticker symbol or company name)
Returns: pandas.DataFrame with search results containing xid, name, symbol, asset_class, url
# Search for Apple
results = search_securities('Apple')
print(results)
# Search by ticker
results = search_securities('AAPL')
get_xid(ticker, display_mode="first")
Get FT Markets XID for given ticker symbol.
Parameters:
ticker(str): Ticker symboldisplay_mode(str): "first" to return first match XID, "all" to return all matches
Returns: String XID (if display_mode="first") or DataFrame (if display_mode="all")
# Get XID for Apple
xid = get_xid('AAPL')
print(xid) # Returns XID string
# Get all matches
all_results = get_xid('AAPL', display_mode='all')
print(all_results)
Historical Data
get_historical_prices(xid, date_from, date_to)
Get historical price data for a security with full OHLCV data.
Parameters:
xid(str): The FT Markets XIDdate_from(str): Start date in DDMMYYYY format (e.g., "01012024")date_to(str): End date in DDMMYYYY format (e.g., "31122024")
Returns: pandas.DataFrame with columns: date, open, high, low, close, volume, sorted by date. Ranges longer than 10 years are fetched in several requests automatically. The DataFrame is empty when FT Markets has no prices for the range, which is also what it reports for an unknown XID.
xid = get_xid('AAPL')
df = get_historical_prices(xid, "01012024", "31012024")
print(df.head())
get_multiple_historical_prices(xids, date_from, date_to, max_workers=3)
Get historical data for multiple securities concurrently, in one long-format DataFrame.
Parameters:
xids(list): List of FT Markets XIDsdate_from(str): Start date in DDMMYYYY formatdate_to(str): End date in DDMMYYYY formatmax_workers(int): Maximum number of concurrent requests
Returns: pandas.DataFrame with columns: xid, date, open, high, low, close, volume
xids = [get_xid('AAPL'), get_xid('MSFT')]
df = get_multiple_historical_prices(xids, "01012024", "31012024")
# One close-price column per security
closes = df.pivot(index='date', columns='xid', values='close')
get_multiple_historical_prices_dict(xids, date_from, date_to, max_workers=3)
Same as above, but returns a dictionary mapping each XID to its own DataFrame.
prices = get_multiple_historical_prices_dict(xids, "01012024", "31012024")
aapl = prices[xids[0]]
Both functions log and leave out securities that fail to download or have no data, so compare the result with xids to detect them.
Holdings Data
get_holdings(xid, holdings_type="all")
Get holdings and allocation data for ETFs and funds.
Parameters:
xid(str): The FT Markets XIDholdings_type(str): Type of holdings data:"asset_allocation": Asset class breakdown (stocks, bonds, cash)"sector_weights": Sector allocation"geographic_allocation": Geographic allocation"top_holdings": Top holdings, with columns Holding, Symbol, 1Y Change, Weight"all": All holdings data types as a tuple
Returns: pandas.DataFrame or tuple of DataFrames
# Get top holdings for SPY ETF
spy_xid = get_xid('SPY')
top_holdings = get_holdings(spy_xid, "top_holdings")
# Get asset allocation
allocation = get_holdings(spy_xid, "asset_allocation")
# Get all holdings data
all_data = get_holdings(spy_xid, "all")
asset_alloc, sectors, regions, holdings = all_data
get_fund_breakdown(xid)
Get complete fund breakdown with all allocation data.
Parameters:
xid(str): The FT Markets XID
Returns: Dictionary with all DataFrames
qqq_xid = get_xid('QQQ')
breakdown = get_fund_breakdown(qqq_xid)
print(breakdown['asset_allocation'])
print(breakdown['top_holdings'])
Fund Profile Data
get_fund_profile(xid)
Get profile and investment information for ETFs and funds.
Parameters:
xid(str): The FT Markets XID
Returns: pandas.DataFrame with Field and Value columns
xid = get_xid('SPY')
profile = get_fund_profile(xid)
print(profile)
# Filter for specific information
fees = profile[profile['Field'].str.contains('fee', case=False)]
get_fund_stats(xid)
Get fund profile data as a dictionary for easy access.
Parameters:
xid(str): The FT Markets XID
Returns: Dictionary with all available fund fields and values
xid = get_xid('QQQ')
stats = get_fund_stats(xid)
# Access any available field safely
inception = stats.get('Inception date', 'Not available')
fees = stats.get('Ongoing charge', 'Not available')
get_available_fields(xid)
Get list of all available profile fields for a fund.
Parameters:
xid(str): The FT Markets XID
Returns: List of all field names available
xid = get_xid('SPY')
fields = get_available_fields(xid)
print("Available fields:")
for field in fields:
print(f" - {field}")
search_profile_field(xid, search_term)
Search for specific fields in the fund profile data.
Parameters:
xid(str): The FT Markets XIDsearch_term(str): Term to search for in field names (case-insensitive)
Returns: pandas.DataFrame with matching fields and values
xid = get_xid('SPY')
fees = search_profile_field(xid, 'fee')
inception = search_profile_field(xid, 'inception')
Caching
Price, holdings and profile pages are cached in memory for one hour. Searches are never cached.
from ftgo import clear_cache, set_cache_ttl
set_cache_ttl(300) # keep responses for 5 minutes (0 disables caching)
clear_cache() # drop everything cached so far
Complete Example
from ftgo import get_xid, get_historical_prices, get_holdings, get_fund_profile
import matplotlib.pyplot as plt
# Search for QQQ ETF
qqq_xid = get_xid('QQQ')
# Get 1 year of historical data
historical_data = get_historical_prices(qqq_xid, "01012023", "31122023")
# Get fund information
profile = get_fund_profile(qqq_xid)
top_holdings = get_holdings(qqq_xid, "top_holdings")
asset_allocation = get_holdings(qqq_xid, "asset_allocation")
# Plot price chart
historical_data.set_index('date')['close'].plot(title='QQQ Price History')
plt.show()
# Display fund information
print("Fund Profile:")
print(profile.head(10))
print("\nTop 10 Holdings:")
print(top_holdings.head(10))
print("\nAsset Allocation:")
print(asset_allocation)
Error Handling
Failures are raised, never returned as empty data:
ValueError: invalid arguments, a ticker with no search results, or an XID that FT Markets does not recogniseftgo.FTMarketsError: FT Markets answered in an unexpected format (request rejected, or the site changed)requests.RequestException: network errors and HTTP error statuses, after 3 attempts
import requests
from ftgo import FTMarketsError, get_xid, get_historical_prices
try:
xid = get_xid('INVALID_TICKER')
data = get_historical_prices(xid, "01012024", "31012024")
except ValueError as e:
print(f"Bad input: {e}")
except (FTMarketsError, requests.RequestException) as e:
print(f"Could not fetch data: {e}")
An empty DataFrame means the request worked and FT Markets has no data, for example a date range with no trading days or an equity that has no holdings.
Requirements
- Python 3.9+
- cloudscraper >= 1.2.68
- pandas >= 1.3.0
- beautifulsoup4 >= 4.11.0
Development
pip install -e ".[dev]"
pytest # offline tests
pytest -m integration # tests against the live FT Markets site
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Disclaimer
This library is for educational and research purposes.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for ftgo 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ftgo-2.0.0.tar.gz | 25.2 kB | Without provenance | Details for ftgo-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ftgo-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for ftgo-2.0.0-py3-none-any.whl |
Total release size: 43.2 kB
Release files / ftgo-2.0.0.tar.gz
| Download URL | ftgo-2.0.0.tar.gz |
|---|---|
| Size | 25.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
72dad49863b13d6c126376c739ca39e2377e0d97610b2a2cdf91338bca68a320
|
|
BLAKE2b-256 checksum How to use checksums |
9475ca588e15a7334b7b105497d0de3678377722876a299faf9ac982ae8ffc96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / ftgo-2.0.0-py3-none-any.whl
| Download URL | ftgo-2.0.0-py3-none-any.whl |
|---|---|
| Size | 18.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b86b53031787c0e7951b051c64e68a3b3f7959b13cb7cc6be79bd64310fe9369
|
|
BLAKE2b-256 checksum How to use checksums |
138f90c2679d889268224787cc7aa6ac07a0bb2751f661848510aae6d0e1eee1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for ftgo 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.