Massive Python Client

repository·master·Indexed 23 days ago

https://github.com/massive-com/client-python

Official Python client for Massive (formerly Polygon.io) REST and WebSocket APIs, providing programmatic access to real-time and historical market data. The library supports asynchronous patterns for non-blocking data streams, edge header configuration for Launchpad users via RequestOptionBuilder, and integration with Docker. It includes examples for analyzing stock trade distributions, detecting market anomalies, and visualizing company relationships and market movements.

Tokens
8.6K
Snippets
51
Records
85
Agent score
78%

What's inside massive-com-client-python

  1. Use the WebSocketClient for real-time data

    master

    The massive.WebSocketClient provides a way to receive real-time market data streams. The typical lifecycle involves initializing the client, connecting to the server, running the event loop, and subscribing to specific symbols or data types.

    To get started with specific asset classes, refer to the specialized guides:

    • Stocks
    • Options
    • Forex
    • Crypto
  2. Generate SIC code mappings for treemap grouping

    master

    If you need to modify the grouping logic or rebuild the classification data, use the massive_sic_code_data_gatherer.py script.

    This script performs the following workflow:

    1. Retrieves a snapshot of all ticker symbols using the Snapshot API.
    2. Processes each ticker to obtain its SIC code via the Ticker Details API.
    3. Saves the resulting ticker-to-SIC-code mappings into sic_code_groups.json.

    This JSON file is used by treemap_server.py to structure the large dataset into a hierarchical format suitable for D3.js Treemaps.

  3. Aggregates (Bars) Models

    master

    The library provides several models for handling aggregated market data (often referred to as 'bars'). These include:

    • Agg: General aggregate data.
    • GroupedDailyAgg: Aggregates grouped by day.
    • DailyOpenCloseAgg: Aggregates focusing on daily open and close prices.
    • PreviousCloseAgg: Aggregates containing previous close information.
  4. Ticker and Asset Models

    master

    Models for identifying and describing market participants and assets:

    • Ticker: Basic ticker information.
    • TickerDetails: Extended information about a ticker.
    • TickerNews: News related to a specific ticker.
    • TickerTypes: Classification of tickers.
    • UnderlyingAsset: Information about the asset an option or derivative is based on.
  5. Option and Greeks Models

    master

    Models specifically for options trading:

    • OptionDetails: Metadata and specifics about an option.
    • Greeks: Option Greeks (e.g., Delta, Gamma, Theta, etc.).
    • OptionContractSnapshot: A snapshot of a specific option contract.
    • DayOptionContractSnapshot: A snapshot of an option contract for a specific day.
  6. Market and Exchange Models

    master

    Models describing the market environment:

    • MarketStatus: Current operational status of the market.
    • MarketExchanges: Information about available exchanges.
    • MarketCurrencies: Supported currencies in the market.
    • MarketHoliday: Information regarding market holidays.
    • Exchange: Details about a specific exchange.
    • MarketCenter: Information about market centers.
  7. Use Enums for API parameters

    master

    The massive client uses several enumeration classes to ensure type safety and valid parameter values when making REST API calls. Instead of using raw strings, you should use the corresponding enum classes found in massive.rest.models.

    Available Enums include:

    • Sort: Controls the sorting order of results.
    • Order: Defines the direction of the sort.
    • Locale: Specifies regional settings.
    • Market: Identifies specific markets.
    • AssetClass: Categorizes assets (e.g., stocks, options).
    • DividendType: Specifies types of dividends.
    • Frequency: Defines the interval for aggregates (bars).
    • DataType: Specifies the type of data requested.
    • SIP: Identifies the Securities Information Processor.
    • ExchangeType: Categorizes the type of exchange.
    • Direction: Defines the direction of a trade or movement.
    • SnapshotMarketType: Used for snapshot requests.
    • Timeframe: Defines time-based intervals.
    • Precision: Defines decimal precision.
  8. Configure pagination behavior in RESTClient

    master

    The RESTClient handles pagination automatically, but you can control its behavior using the pagination parameter during initialization and the limit parameter in method calls.

    Default Behavior (Pagination Enabled)

    When pagination=True (the default):

    • limit controls the page size (number of results per request).
    • The client automatically fetches all subsequent pages, yielding results until the entire dataset is exhausted.

    Disabling Pagination

    To return only a fixed number of results and stop after the first page, set pagination=False when creating the client.

    Note: When pagination=False, the limit parameter controls the total number of results returned.

    # Default: Fetches ALL TSLA trades, 100 per page
    client = RESTClient(api_key="<API_KEY>")
    trades = [t for t in client.list_trades(ticker="TSLA", limit=100)]
    
    # Disabled: Fetches AT MOST 100 total trades and stops
    client = RESTClient(api_key="<API_KEY>", pagination=False)
    trades = [t for t in client.list_trades(ticker="TSLA", limit=100)]
    # Default (Pagination Enabled)
    client = RESTClient(api_key="<API_KEY>")
    trades = [t for t in client.list_trades(ticker="TSLA", limit=100)]
    
    # Disabling Pagination
    client = RESTClient(api_key="<API_KEY>", pagination=False)
    trades = [t for t in client.list_trades(ticker="TSLA", limit=100)]