Skip to content

riskwise99/volprofile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Type: Python Application with a Web API wrapper

This project is primarily a Python application that performs financial data analysis, specifically focusing on volume profile and trading range identification. It has been extended with a FastAPI web server to expose its analysis capabilities as a remote API.

Project Overview

The core functionality of this project is provided by the api02.py script. This script analyzes volume profile data from JSON files to:

  • Identify the Point of Control (POC).
  • Detect Low-Volume Nodes (LVNs).
  • Define and highlight the primary trading range (Value Area).
  • Generate a visual representation of the volume profile and trading range as a PDF chart.

The script has been enhanced to function in two primary modes:

  1. Command-Line Interface (CLI): Users can execute the script directly to process a specified JSON file and output a PDF.
  2. FastAPI Web Server: When run with the --api flag, the script starts a web server that exposes a /getpdf endpoint. This endpoint accepts file_path and output_pdf_path as query parameters, allowing remote clients to trigger the analysis and receive a generated PDF.

Building and Running

As a CLI Tool

To run the analysis directly from the command line, execute the script with the input JSON file path and the desired output PDF file path as arguments:

python analyze_volume_profile_phase2.py <input_json_file_path> <output_pdf_file_path>

Example:

python analyze_volume_profile_phase2.py MGC1.json MGC1_volprofile.pdf

As a FastAPI Server

To start the API server, run the script with the --api flag:

python analyze_volume_profile_phase2.py --api

By default, the server will start on http://127.0.0.1:8000. You can specify a different host and port using --host and --port arguments (e.g., python analyze_volume_profile_phase2.py --api --host 0.0.0.0 --port 8080).

Calling the API Endpoint

Once the API server is running, you can interact with the /getpdf endpoint using HTTP GET requests. The file_path and output_pdf_path parameters must be provided as query parameters in the URL.

Example using curl:

curl "http://127.0.0.1:8000/getpdf?file_path=MGC1.json&output_pdf_path=MGC1_api_volprofile.pdf"

This command will trigger the volume profile analysis for MGC1.json and save the resulting PDF to MGC1_api_volprofile.pdf on the server's filesystem.

Development Conventions

  • Language: Python 3.
  • Core Libraries:
    • pandas: For data manipulation and analysis.
    • matplotlib: For generating plots and saving them as PDFs. The Agg backend is used, which is suitable for non-interactive environments like servers.
    • scipy: For scientific computing, specifically for find_peaks in volume analysis.
    • numpy: For numerical operations.
  • Web Framework:
    • fastapi: For building the modern, fast, web API.
    • uvicorn: An ASGI server for running FastAPI applications.
  • Code Structure:
    • The main analysis logic is encapsulated within the analyze_volume_profile function.
    • The script is designed to be executable as a standalone CLI tool or as a FastAPI web server using command-line arguments (--api).
  • Error Handling:
    • The analyze_volume_profile function includes specific try-except blocks for FileNotFoundError, json.JSONDecodeError, and general exceptions.
    • The FastAPI endpoint includes error handling to catch exceptions during function execution and return JSON error responses.
  • Dependencies:
    • The package.json and package-lock.json files are present but empty. This suggests that Node.js/npm is not being used for dependency management for this Python project.
    • A requirements.txt file is expected for managing Python dependencies.

TODOs

  • Logging: Implement more comprehensive logging for the FastAPI server to track requests, errors, and application events effectively.
  • Empty package.json: Investigate the purpose and origin of the empty package.json and package-lock.json files. They might be remnants of a previous setup or intended for a specific, unconfigured tool.
  • PDF Serving: Currently, the API saves the PDF to a file path. Consider implementing functionality to serve the generated PDF directly as a response or provide a link to it.
  • Configuration Management: For production use, consider externalizing configuration (like host, port, default paths) rather than hardcoding them in the script.
  • Input Validation: Add more robust input validation for file_path and output_pdf_path in the API endpoint to ensure they are valid and safe paths.

About

Assess volume profile. Input JSON timeseries data, outputs PDF

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages