investiny Documentation

repository·main·Indexed 19 days ago

https://github.com/alvarobartt/investiny

A lightweight Python library (v0.7.2) for retrieving historical and intraday financial data from Investing.com. Designed as a faster, Cloudflare-resilient alternative to investpy, it provides functions like search_assets() to find asset IDs and historical_data() to fetch price and volume data. It supports intraday intervals from 1 minute to monthly and integrates with Pandas for data analysis.

Tokens
3.6K
Snippets
16
Records
21
Agent score
63%

What's inside investiny

  1. Overview of investiny

    main

    What is investiny?

    investiny is a lightweight, faster, and easier-to-use alternative to investpy. It was developed to address changes in Investing.com's API protection protocols (Cloudflare V2 protection) that affected investpy.

    While it aims to support most functionality provided by investpy, it is currently positioned as a temporary replacement or a lighter alternative for users needing to interact with Investing.com data.

  2. Review the legal disclaimer for investiny

    main

    The investiny package is an open-source tool intended for research and educational purposes only. It is not affiliated with, endorsed by, or vetted by Investing.com.

    Users should be aware that investiny uses data from Investing.com, and usage of this data is subject to Investing.com's terms and conditions. Data is intended for personal use only. For details on your rights to use the data, refer to the official terms at: https://www.investing.com/about-us/terms-and-conditions

  3. Understand intra-day historical data availability limits

    main

    When using investiny.historical_data to retrieve intra-day data, the amount of historical data available depends on the requested interval. While investiny handles these limitations internally and transparently, you should be aware of the maximum lookback periods supported by Investing.com for specific intervals:

    IntervalMaximum Historical Data Available
    1 min6 months
    5 min~ 1 year
    15 min~ 1.5 years
    30 min~ 2 years
    60 min (1 hour)~ 5 years
    300 min (5 hours)~ 13 years

    For all other interval values used with investiny.historical_data, there are currently no known limitations.

  4. Compare investiny and investpy features

    main

    While investiny is a lighter and faster alternative to investpy, it currently has reduced functionality.

    Capabilities of investiny:

    • ✅ Intraday Data (1m to monthly intervals)
    • ✅ Any Range Historical Data
    • ✅ Search Assets/Quotes

    Missing features (currently in investpy but not yet in investiny):

    • ❌ Dividends
    • ❌ Economic Calendar
    • ❌ Technical Indicators
    • ❌ Economic News
  5. Compare investiny vs investpy functionality

    main

    When choosing between investiny and investpy, consider your data requirements. investiny is designed to be faster and lighter, focusing on core historical data and asset searching. It specifically supports intraday data (intervals from 1 minute to monthly), which investpy does not.

    However, investiny currently has a reduced feature set compared to investpy. Use investiny if you need reliable access to intraday historical data via tvc6.investing.com. Use investpy only if you specifically require dividends, economic calendars, technical indicators, or economic news, though be aware that investpy may encounter 403 Forbidden errors due to Cloudflare protection on its data sources.

    | | Intraday Data | Any Range Historical Data | Search Assets/Quotes | Dividends | Economic Calendar | Technical Indicators | Economic News |
    |:--:|--:|--:|--:|--:|--:|--:|--:|
    | **investiny** | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
    | **investpy** | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
  6. How to find an asset ID and then retrieve its historical data

    main

    Since historical_data() requires an investing_id, you can use search_assets() to find the correct ID first. The ticker field in the search results contains the ID needed for historical data requests.

    from investiny import historical_data, search_assets
    
    # 1. Search for the asset
    search_results = search_assets(query="AAPL", limit=1, type="Stock", exchange="NASDAQ")
    
    # 2. Extract the ticker (ID) from the first result
    # Note: The ticker is returned as a string in the search results, so cast to int
    investing_id = int(search_results[0]["ticker"])
    
    # 3. Use the ID to get historical data
    data = historical_data(investing_id=investing_id, from_date="09/01/2022", to_date="10/01/2022")
  7. Integrate investiny with Pandas for historical data

    main

    To mimic the output format of investpy when using investiny with pandas, you must manually convert the dictionary returned by historical_data into a DataFrame and rename the columns to match the expected capitalized format.

    1. Install pandas: pip install pandas.
    2. Convert the output dictionary using pd.DataFrame.from_dict(output).
    3. Rename the columns date, open, high, low, close, and volume to Date, Open, High, Low, Close, and Volume respectively.
    4. Set the Date column as the index.
    from investiny import historical_data
    import pandas as pd
    
    output = historical_data(investing_id=6408)
    data = pd.DataFrame.from_dict(output)
    data.rename(columns={
        "date": "Date",
        "open": "Open",
        "high": "High",
        "low": "Low",
        "close": "Close",
        "volume": "Volume"
    }, inplace=True)
    data.set_index("Date", inplace=True)
  8. Find an asset ID and retrieve its historical data

    main

    To automate data retrieval when you only know the asset name/symbol, combine search_assets and historical_data. First, search for the asset to get the ticker field from the results, convert it to an integer, and then pass that integer as the investing_id to historical_data.

    from investiny import historical_data, search_assets
    
    # 1. Search for the asset to find its Investing.com ID
    search_results = search_assets(query="AAPL", limit=1, type="Stock", exchange="NASDAQ")
    
    # 2. Extract the 'ticker' from the first result and convert to int
    # Note: 'ticker' in the search result represents the Investing.com ID
    investing_id = int(search_results[0]["ticker"])
    
    # 3. Use the ID to get historical data
    data = historical_data(investing_id=investing_id, from_date="09/01/2022", to_date="10/01/2022")
  9. Search for assets with search_assets()

    main

    Use the search_assets function to find assets on Investing.com and retrieve their unique ticker (the Investing.com ID). This is useful when you only have a symbol or name and need to find the corresponding investing_id for use in historical_data.

    Parameters:

    • query: The search string (e.g., "AAPL").
    • limit: Maximum number of results to return.
    • type: The asset type (e.g., "Stock").
    • exchange: The exchange name (e.g., "NASDAQ").

    Returns a list of result dictionaries.

    from investiny import search_assets
    
    results = search_assets(query="AAPL", limit=1, type="Stock", exchange="NASDAQ")
  10. Retrieve historical data using historical_data()

    main

    Use historical_data() to retrieve historical price data for a specific asset. This function supports intraday data with intervals ranging from 1 minute to monthly.

    Parameters:

    • investing_id: The unique Investing.com ID for the asset (integer).
    • from_date: The start date in DD/MM/YYYY format.
    • to_date: The end date in DD/MM/YYYY format.

    Returns the historical data as a JSON object (without date fields included in the data points).

    from investiny import historical_data
    
    data = historical_data(investing_id=6408, from_date="09/01/2022", to_date="10/01/2022")