Git Product home page Git Product logo

chainbase's Introduction

Chainbase

Chainbase uses Tradier to create a database of option chains for future analysis and backtesting. This script sets up a PostgreSQL server and periodically gathers options chains for a provided list of stock tickers and ETFs.

Features

  • Sets up a PostgreSQL database to store options chains data.
  • Fetches options chains data from 1 DTE to 90 DTE for specified stock tickers using the Tradier API.
  • Fetches tickers within ETFs and gathers options chains for each ticker using the Financial Modeling Prep API.
  • Ensures tickers are not processed more than once if they overlap between ETFs.
  • Stores the fetched options data in a serialized (pickled) format in the PostgreSQL database.
  • Schedules periodic fetching of options data (default: once an hour).
  • Provides verbose logging to a file for easy monitoring and debugging, even when running in the background with nohup.

Prerequisites

  • Python 3.x
  • PostgreSQL
  • Required Python packages: psycopg2, requests, argparse, ratelimit

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/chainbase.git
    cd chainbase
  2. Install the required Python packages:

    pip install psycopg2 requests argparse ratelimit
  3. Set up PostgreSQL:

    Make sure you have PostgreSQL installed and running. Create a database for storing the options data.

    CREATE DATABASE chainbase;

Usage

  1. Set up the database and start fetching options chains:

    Run the script with the required arguments:

    python chainbase.py --db_name chainbase --user your_db_user --password your_db_password --host localhost --port 5432 --tickers AAPL,MSFT,GOOG,SPY.ETF --interval 3600 --tradier_api_key your_tradier_api_key --fmp_api_key your_fmp_api_key --drop_table
    • --db_name: Name of the PostgreSQL database.
    • --user: Database user.
    • --password: Database user's password.
    • --host: Database host (default: localhost).
    • --port: Database port (default: 5432).
    • --tickers: Comma-separated list of stock tickers and ETFs (e.g., SPY.ETF).
    • --interval: Interval in seconds to fetch data (default: 3600 seconds, or 1 hour).
    • --tradier_api_key: Tradier API key.
    • --fmp_api_key: Financial Modeling Prep API key.
    • --drop_table: Drop the existing options table and recreate it.
  2. Run the script in the background with verbose logging:

    Use nohup to run the script in the background and ensure logging to a file:

    nohup python3 chainbase.py --db_name chainbase --user your_db_user --password your_db_password --host localhost --port 5432 --tickers AAPL,MSFT,GOOG,SPY.ETF --interval 3600 --tradier_api_key your_tradier_api_key --fmp_api_key your_fmp_api_key --drop_table > chainbase_nohup.log 2>&1 &

Example

To set up the database and start fetching options chains for Apple, Microsoft, Google, and the tickers within the SPY ETF every hour, and run it in the background with verbose logging:

nohup python3 chainbase.py --db_name chainbase --user your_db_user --password your_db_password --host localhost --port 5432 --tickers AAPL,MSFT,GOOG,SPY.ETF --interval 3600 --tradier_api_key your_tradier_api_key --fmp_api_key your_fmp_api_key --drop_table > chainbase_nohup.log 2>&1 &

This setup ensures that the script continues to run and logs its activity to chainbase_nohup.log even when you log out or close the terminal.

chainbase's People

Contributors

bcdannyboy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.