Skip to main content

A Python library for fetching financial data from FT Markets

Project description

FTMarkets

PyPI version Python 3.7+ License: MIT

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 symbol
  • display_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 XID
  • date_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

xid = get_xid('AAPL')
df = get_historical_prices(xid, "01012024", "31012024")
print(df.head())

get_multiple_historical_prices(xids, date_from, date_to)

Get historical data for multiple securities concurrently.

Parameters:

  • xids (list): List of FT Markets XIDs
  • date_from (str): Start date in DDMMYYYY format
  • date_to (str): End date in DDMMYYYY format

Returns: pandas.DataFrame with concatenated data for all securities

xids = [get_xid('AAPL'), get_xid('MSFT')]
df = get_multiple_historical_prices(xids, "01012024", "31012024")

Holdings Data

get_holdings(xid, holdings_type="all")

Get holdings and allocation data for ETFs and funds.

Parameters:

  • xid (str): The FT Markets XID
  • holdings_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 by 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 XID
  • search_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')

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

The library includes logging and error handling, but you should wrap calls in try-except blocks for production use:

try:
    xid = get_xid('INVALID_TICKER')
    data = get_historical_prices(xid, "01012024", "31012024")
except ValueError as e:
    print(f"Error: {e}")
except Exception as e:
    print(f"Unexpected error: {e}")

Requirements

  • Python 3.7+
  • cloudscraper >= 1.2.68
  • pandas >= 1.3.0
  • beautifulsoup4 >= 4.11.0

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ftgo-1.1.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ftgo-1.1.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file ftgo-1.1.0.tar.gz.

File metadata

  • Download URL: ftgo-1.1.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for ftgo-1.1.0.tar.gz
Algorithm Hash digest
SHA256 97923df919cad83b9ccff2c0f5872a90e7c6f6e999dbc228721b7f4e473f36b6
MD5 6b92278b4665fca3a7bdff31298a72dd
BLAKE2b-256 c74613a5a46719fc2c9de672e955abfd2f1dd48d068eb76a321c69771bc7195e

See more details on using hashes here.

File details

Details for the file ftgo-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: ftgo-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for ftgo-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5477dc89e69e0daba986749449db16afece21f90bd0777821be2cbdbb809fb58
MD5 4cb156328373a30951075772d8a8ae57
BLAKE2b-256 4774cfcdd26239d1ee4ad2366457533956f57bd96d70ff6b3ae947571b67f5bd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page