Massive Python Client

2.5.0 · active · verified Thu Apr 16

The `massive` library is the official Python client for the Massive (formerly Polygon.io) REST and WebSocket APIs. It provides comprehensive access to real-time and historical market data for Stocks, Options, Forex, and Crypto. The library is currently at version 2.5.0 and aims to follow the API's release cadence, often bundling breaking changes and maintaining backward compatibility where feasible.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `RESTClient` using an API key (preferably from an environment variable) and fetch historical aggregate bars for a stock like Apple (AAPL). It iterates through the results, printing each aggregate bar.

import os
from massive import RESTClient
from datetime import date

api_key = os.environ.get('MASSIVE_API_KEY', 'YOUR_API_KEY')

if api_key == 'YOUR_API_KEY':
    print("WARNING: Please set the MASSIVE_API_KEY environment variable or replace 'YOUR_API_KEY' with your actual API key.")
    # Exit or raise an error in a real application

client = RESTClient(api_key=api_key)

ticker = "AAPL"
multiplier = 1
timespan = "day"
from_date = date(2023, 1, 1)
to_date = date(2023, 1, 5)

print(f"Fetching aggregate bars for {ticker} from {from_date} to {to_date}...")
try:
    aggs = []
    for a in client.list_aggs(ticker=ticker, multiplier=multiplier, timespan=timespan, from_=from_date, to=to_date):
        aggs.append(a)
    
    if aggs:
        print(f"Retrieved {len(aggs)} aggregate bars:")
        for agg in aggs:
            print(agg)
    else:
        print("No aggregate bars found for the specified period.")

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →