findatapy Documentation

repository·master·Indexed 24 days ago

https://github.com/cuemacro/findatapy

A high-level Python API for downloading market data from diverse sources including ALFRED/FRED, Bloomberg, Yahoo, Google, Dukascopy, Quandl, and the Bank of England. It utilizes the Market and MarketDataRequest classes to fetch data and supports optional Redis-based caching to reduce redundant API calls.

Tokens
1.5K
Snippets
3
Records
6
Agent score
35%

What's inside findatapy

  1. Install findatapy

    master

    You can install the latest release of findatapy via pip, or install the newest version directly from the GitHub repository.

    Requirements

    • Python: 3.10 or higher (Python 2 is not supported).
    • Dependencies: pandas, numpy, etc.
    • Recommended (Bloomberg): If using Bloomberg, install blpapi using: pip install --index-url=https://blpapi.bloomberg.com/repository/releases/python/simple blpapi
    • Recommended (Plotting): chartpy for interactive plots.
  2. Configure API keys for findatapy

    master

    To use various data sources (like Eikon, Quandl, or Twitter), you must provide API keys. You can manage these in several ways:

    1. On-demand: Pass keys directly via the MarketDataRequest object.
    2. Keyring: Run the set_api_keys.py script to store keys in your system keyring.
    3. Configuration File: Create a datacred.py file to overwrite default keys.
    4. Class Modification: Edit the dataconstants class directly.
  3. Troubleshoot 'Couldn't push MarketDataRequest' error

    master

    If you see the error Couldn't push MarketDataRequest, it means findatapy attempted to use its in-memory caching mechanism via Redis but could not find a running Redis instance.

    • Cause: Redis is used as a volatile cache to avoid redundant external API calls for identical MarketDataRequest parameters.
    • Impact: This is not a fatal error. All other functionality will work correctly; findatapy will simply bypass the cache and fetch data directly from the external provider every time.
    • Solution: To enable caching, install and run Redis on your system (available for Linux and older Windows versions).
  4. Fetch market data using Market and MarketDataRequest

    master

    To download market data, use the Market class initialized with a MarketDataGenerator. Define your query using MarketDataRequest and pass it to market.fetch_market().

    Example: Fetching ALFRED/FRED data

    from findatapy.market import Market, MarketDataRequest, MarketDataGenerator
    
    market = Market(market_data_generator=MarketDataGenerator())
    
    # Provide your FRED API key
    fred_api_key = "WRITE YOUR KEY HERE" 
    
    md_request = MarketDataRequest(start_date='year', category='fx', data_source='alfred', tickers=['AUDJPY'],
                                   fred_api_key=fred_api_key)
    
    df = market.fetch_market(md_request)
    print(df.tail(n=10))

    Example: Fetching Dukascopy tick data

    md_request = MarketDataRequest(start_date='14 Jun 2016', finish_date='15 Jun 2016',
                                       category='fx', fields=['bid', 'ask'], freq='tick', 
                                       data_source='dukascopy', tickers=['EURUSD'])
    
    df = market.fetch_market(md_request)
    print(df.tail(n=10))
    from findatapy.market import Market, MarketDataRequest, MarketDataGenerator
    
    market = Market(market_data_generator=MarketDataGenerator())
    
    # Get you FRED API key from https://fred.stlouisfed.org/docs/api/api_key.html
    fred_api_key = "WRITE YOUR KEY HERE" 
    
    md_request = MarketDataRequest(start_date='year', category='fx', data_source='alfred', tickers=['AUDJPY'],
                                   fred_api_key=fred_api_key)
    
    df = market.fetch_market(md_request)
    print(df.tail(n=10))
  5. Fetch data from Yahoo and Quandl

    master

    You can use the Market abstraction to fetch data from different vendors like yahoo or quandl by simply changing the data_source parameter in the MarketDataRequest object.

    # Yahoo Example
    market = Market(market_data_generator=MarketDataGenerator())
    md_request = MarketDataRequest(
            start_date="decade",
            data_source='yahoo',
            tickers=['Apple'],
            fields=['close'],
            vendor_tickers=['aapl'],
            vendor_fields=['Close'])
    
    df = market.fetch_market(md_request)
    
    # Quandl Example
    md_request_quandl = MarketDataRequest(
            start_date="decade",
            data_source='quandl',
            tickers=['APPL'],
            fields=['close'],
            vendor_tickers=['APPL'],
            vendor_fields=['Close'])
    
    df_quandl = market.fetch_market(md_request_quandl)
  6. Use DataVendorBOE to load Bank of England data

    master

    For Bank of England (BOE) data, you can use the DataVendorBOE class. This allows you to load specific tickers directly using a MarketDataRequest object via the load_ticker method.

    from findatapy.market.datavendorweb import DataVendorBOE
    from findatapy.market import MarketDataRequest
    
    md_request = MarketDataRequest(
            start_date="decade",
            data_source='boe',
            tickers=['IUMBV34', 'IUMBV37'],
            fields=['close'],
            vendor_tickers=['IUMBV34', 'IUMBV37'],
            vendor_fields=['Close'])
    
    boe = DataVendorBOE()
    boe.load_ticker(md_request)