Skip to main content

TheOneAlpha data downloader

Project description

OneAlpha Python Client Library The OneAlpha Python client library provides a convenient interface to interact with a financial data API, allowing users to validate symbols, fetch financial data as Pandas DataFrames, and save data as CSV files. It supports flexible data retrieval options, including merged or individual formats, and various time frequencies. Features

Test Connection: Verify connectivity to the API server. Validate Symbols: Check the availability of financial symbols for a given date range and frequency. Fetch DataFrame: Retrieve financial data as a Pandas DataFrame in merged or individual formats. Fetch CSV: Save financial data to CSV files, with support for individual symbol files or a single merged file. Get Available Symbols: Retrieve a list of symbols supported by the API.

Installation

Ensure you have Python 3.6+ installed. Install the required dependencies:pip install requests pandas

Clone or download the onealpha library to your project directory.git clone

Alternatively, copy the onealpha.py file into your project.

Usage The OneAlphaClient class requires a base_url to connect to the API server. You must initialize the client with the appropriate API endpoint before using the library's functions. Example Below is an example of how to use the onealpha library to test connectivity, validate symbols, and fetch data. import onealpha import pandas as pd

Initialize the client with your API URL

onealpha.client = onealpha.OneAlphaClient(base_url="http://localhost:8000")

try: # Test connection print("Testing connection...") connection_status = onealpha.test_connection() print(f"Connection status: {connection_status}")

# Validate symbols
print("\nValidating symbols...")
validation = onealpha.validate_symbols(
    symbols=['AARTIIND', 'RELIANCE', 'TCS'],
    start_date='2025-01-01',
    end_date='2025-01-07',
    frequency='1min'
)
print(f"Validation result: {validation}")

# Fetch data as DataFrame
print("\nFetching DataFrame...")
df = onealpha.fetch_dataframe(
    symbols=['AARTIIND', 'RELIANCE', 'TCS'],
    start_date='2025-01-01',
    end_date='2025-01-07',
    frequency='1min',
    format_type='merged',
    fields=['open', 'high', 'low', 'close']
)
print("DataFrame:")
print(df)

# Fetch data as CSV
print("\nFetching CSV...")
csv_path = onealpha.fetch_csv(
    symbols=['AARTIIND', 'RELIANCE', 'TCS'],
    start_date='2025-01-01',
    end_date='2025-01-07',
    frequency='1min',
    format_type='merged',
    fields=['open', 'high', 'low', 'close']
)
print(f"File saved: {csv_path}")

except Exception as e: print(f"Error: {str(e)}")

Key Methods

test_connection(): Tests connectivity to the API server and returns the response as a dictionary. configure(database_url): Configures the API with a database URL. validate_symbols(symbols, start_date, end_date, frequency): Validates a list of symbols for a given date range and frequency. fetch_dataframe(symbols, start_date, end_date, frequency, format_type, fields): Fetches financial data as a Pandas DataFrame. Supports merged or individual format types. fetch_csv(symbols, start_date, end_date, frequency, format_type, fields): Saves financial data to CSV files, either as a single merged file or individual files per symbol. get_available_symbols(): Retrieves a list of available symbols from the API.

Parameters

symbols or symbol_names: List of financial symbols (e.g., ['AARTIIND', 'RELIANCE', 'TCS']). start_date and end_date: Date range in YYYY-MM-DD format (or use date_range as a tuple). frequency: Data frequency (e.g., 1min, 15min, 1h, 1d). Default is 15min. format_type: Data format (merged or individual). Default is merged. fields: List of data fields (e.g., ['open', 'high', 'low', 'close']). Default is ['close'].

Output

DataFrame: Returns a Pandas DataFrame with columns for date, time, and requested fields (e.g., AARTIIND_close, RELIANCE_open) for merged format, or Ticker, Open, High, etc., for individual format. CSV: Saves data to ~/Downloads/onealpha_data/ with filenames like MERGED_1min_20250101_20250107.csv (merged) or AARTIIND_1min_20250101_20250107.csv (individual).

Requirements

Python 3.6+ requests library pandas library An active API server (local or remote) with the correct base_url.

Setup

Ensure the API server is running at the specified base_url (e.g., http://localhost:8000 for local development). If using a remote API, obtain the correct endpoint URL and any required authentication credentials (not currently supported in the client but can be added). For local testing, start the API server (e.g., using FastAPI or Flask) before running scripts.

Troubleshooting

Connection Error: If you see Connection test failed: ... No connection could be made, ensure the API server is running and the base_url is correct. Check with:curl http://localhost:8000/test-connection

No Data Found: If the API returns "No data found," verify that the symbols and date range are valid. Use historical dates (e.g., 2025-01-01 to 2025-01-07) and check available symbols with get_available_symbols(). Firewall Issues: On Windows, ensure port 8000 (or the specified port) is open in your firewall settings.

Example Output For a successful fetch_csv call with format_type='merged': File saved: C:\Users\YourUser\Downloads\onealpha_data\MERGED_1min_20250101_20250107.csv

The CSV file will contain columns like Date, Timestamp, Time, AARTIIND_open, RELIANCE_close, etc. Contributing Contributions are welcome! Please submit pull requests or open issues on the repository for bug reports or feature requests. License This project is licensed under the MIT License. Contact For support or inquiries, contact the project maintainer at [alokvishwakarma@theonealpha.com] or open an issue on the repository.

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

onealpha-0.1.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

onealpha-0.1.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file onealpha-0.1.1.tar.gz.

File metadata

  • Download URL: onealpha-0.1.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for onealpha-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f0b970b22705f5f0002850bf9dfcc4dff1beb5f76851a3a7c1741521d9fa34a7
MD5 59dd7dc4e3b59c60ea50f5522504edba
BLAKE2b-256 843b8f42a7f89fb565c7b025f8e7fb9a2fab245e1c10615f044724e8301e9619

See more details on using hashes here.

File details

Details for the file onealpha-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: onealpha-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for onealpha-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7fd527f654aac77f9ca23066a520b6967b71495a6b7e831e6b091871fb61e498
MD5 368d5d1a39c3ff5f9a9845004416bf8b
BLAKE2b-256 4850ba9adf8c269fad5f9914a56fa5c2816ed61d3d435a68de12e9ab5087aa86

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