Guides

Use the Polygon Python SDK with Marilux

Our endpoint paths and response shapes match the Polygon API, so the official Python SDK works as is. Pass your Marilux API key and base URL when you create the client and leave the rest of your code alone.

This guide is for two kinds of readers: you already have code built on the Polygon SDK and want a cheaper data source, or you're starting fresh and would rather use a mature SDK than hand-roll HTTP calls. Every example below was run against the live API with polygon-api-client 1.16.3.

Install

pip install polygon-api-client

Create the client

The only difference from the official examples is the extra base argument:

import os
from polygon import RESTClient

client = RESTClient(
    api_key=os.environ["MARILUX_API_KEY"],   # your Marilux API key; keep it in an env variable
    base="https://marilux.dev",
)

If you're migrating existing code, this is the only line you change. Every call after it stays the same.

Stocks: bars and previous close

bars = client.list_aggs("AAPL", 1, "day", "2026-10-01", "2026-10-16")
for b in bars:
    print(b.timestamp, b.open, b.high, b.low, b.close, b.volume)

prev = client.get_previous_close_agg("AAPL")
print(prev[0].close)

Swap "day" for "minute" or "hour"; the second argument is the multiplier, so 5, "minute" gives 5-minute bars.

Automatic pagination

SDK methods that start with list_ follow next_url for you, so a plain for loop walks every page. limit is the page size, not the total; a larger page means fewer requests and faster runs:

for t in client.list_tickers(market="stocks", active=True, limit=1000):
    print(t.ticker, t.name)

Options: contracts, chains and single contracts

# Every call for one expiration
contracts = list(client.list_options_contracts(
    underlying_ticker="AAPL", expiration_date="2027-12-17", contract_type="call", limit=1000))

# Full chain snapshot with Greeks, implied volatility and open interest
for o in client.list_snapshot_options_chain("AAPL", params={"expiration_date": "2027-12-17", "limit": 250}):
    if o.greeks:  # some contracts have no Greeks
        print(o.details.ticker, o.greeks.delta, o.implied_volatility, o.open_interest)

# One contract
s = client.get_snapshot_option("AAPL", "O:AAPL271217C00300000")
print(s.greeks.delta, s.implied_volatility)

# Options bars and trades work like stocks; pass the option symbol as the ticker
bars = client.list_aggs("O:AAPL261023C00345000", 1, "day", "2026-10-01", "2026-10-16")
trades = client.list_trades("O:AAPL261023C00345000", timestamp="2026-10-16", limit=50000)

Options data needs the options plan. The symbol format is explained in US option symbols explained, and the chain fields in Get a US option chain with Greeks in Python.

WebSocket streaming

The SDK's WebSocketClient works too. Set feed to our host:

import os
from polygon import WebSocketClient

ws = WebSocketClient(
    api_key=os.environ["MARILUX_API_KEY"],
    feed="marilux.dev",
    market="stocks",
    subscriptions=["T.AAPL", "T.NVDA"],   # T = trades, Q = quotes
)

def handle_msg(msgs):
    for m in msgs:
        print(m.symbol, m.price, m.size)

ws.run(handle_msg=handle_msg)

WebSocket is part of the Advanced plan. Connection and subscription limits are in the WebSocket docs.

Things to know

  • Plan coverage: endpoints outside your plan return 404 and requests beyond your history window return 403. The SDK raises an exception; you never get silently wrong data. Coverage per plan is on the docs home.
  • Quota: every request counts toward your daily quota, including each page the SDK fetches while paginating. Check usage in your console; the rules are in rate limits and quotas.
  • Other languages: the JavaScript client (@polygon.io/client-js), Go, or any HTTP client work the same way. Point the base URL at https://marilux.dev.
Try it free: verify your email and you get 3 days of the Advanced plan, no card needed. Paid plans start at $6.99/month. See pricing →