Polygon

Learn how to use Polygon with Composio

Overview

SLUG: POLYGON

Description

Polygon.io provides real-time and historical market data APIs for stocks, options, forex, and cryptocurrencies.

Authentication Details

generic_api_key
stringRequired

Connecting to Polygon

Create an auth config

Use the dashboard to create an auth config for the Polygon toolkit. This allows you to connect multiple Polygon accounts to Composio for agents to use.

1

Select App

Navigate to Polygon.

2

Configure Auth Config Settings

Select among the supported auth schemes of and configure them here.

3

Create and Get auth config ID

Click “Create Polygon Auth Config”. After creation, copy the displayed ID starting with ac_. This is your auth config ID. This is not a sensitive ID — you can save it in environment variables or a database. This ID will be used to create connections to the toolkit for a given user.

Connect Your Account

Using API Key

1from composio import Composio
2
3# Replace these with your actual values
4polygon_auth_config_id = "ac_YOUR_POLYGON_CONFIG_ID" # Auth config ID created above
5user_id = "0000-0000-0000" # UUID from database/app
6
7composio = Composio()
8
9def authenticate_toolkit(user_id: str, auth_config_id: str):
10 # Replace this with a method to retrieve an API key from the user.
11 # Or supply your own.
12 user_api_key = input("[!] Enter API key")
13
14 connection_request = composio.connected_accounts.initiate(
15 user_id=user_id,
16 auth_config_id=auth_config_id,
17 config={"auth_scheme": "API_KEY", "val": user_api_key}
18 )
19
20 # API Key authentication is immediate - no redirect needed
21 print(f"Successfully connected Polygon for user {user_id}")
22 print(f"Connection status: {connection_request.status}")
23
24 return connection_request.id
25
26
27connection_id = authenticate_toolkit(user_id, polygon_auth_config_id)
28
29# You can verify the connection using:
30connected_account = composio.connected_accounts.get(connection_id)
31print(f"Connected account: {connected_account}")

Tools

Executing tools

To prototype you can execute some tools to see the responses and working on the Polygon toolkit’s playground

Python
1from composio import Composio
2from openai import OpenAI
3import json
4
5openai = OpenAI()
6composio = Composio()
7
8# User ID must be a valid UUID format
9user_id = "0000-0000-0000" # Replace with actual user UUID from your database
10
11tools = composio.tools.get(user_id=user_id, toolkits=["POLYGON"])
12
13print("[!] Tools:")
14print(json.dumps(tools))
15
16def invoke_llm(task = "What can you do?"):
17 completion = openai.chat.completions.create(
18 model="gpt-4o",
19 messages=[
20 {
21 "role": "user",
22 "content": task, # Your task here!
23 },
24 ],
25 tools=tools,
26 )
27
28 # Handle Result from tool call
29 result = composio.provider.handle_tool_calls(user_id=user_id, response=completion)
30 print(f"[!] Completion: {completion}")
31 print(f"[!] Tool call result: {result}")
32
33invoke_llm()

Tool List

Tool Name: Get All Tickers

Description

Tool to retrieve all ticker symbols across asset classes. use when you need to filter by market or exchange and paginate through results.

Action Parameters

active
booleanDefaults to True
cursor
string
exchange
string
limit
integerDefaults to 10
market
string
order
stringDefaults to asc
search
string
sort
string
ticker
string

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get Crypto Exponential Moving Average (EMA)

Description

Tool to retrieve exponential moving average (ema) for a cryptocurrency ticker. use when you need crypto ema data for analysis after selecting the time window.

Action Parameters

adjusted
booleanDefaults to True
crypto_ticker
stringRequired
expand_underlying
boolean
limit
integerDefaults to 50
order
stringDefaults to desc
series_type
stringRequired
timespan
stringRequired
window
integerRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get Crypto MACD Indicator

Description

Tool to retrieve the macd (moving average convergence/divergence) for a crypto ticker. use when you need momentum analysis for a specific cryptocurrency after confirming ticker and parameters.

Action Parameters

adjusted
booleanDefaults to True
expand_underlying
boolean
limit
integerDefaults to 50
order
stringDefaults to desc
series_type
stringDefaults to close
ticker
stringRequired
timespan
stringDefaults to day
window_long
integerDefaults to 26
window_short
integerDefaults to 12
window_signal
integerDefaults to 9

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get Crypto RSI Indicator

Description

Tool to retrieve the relative strength index (rsi) for a crypto ticker. use when you need momentum analysis for crypto assets after specifying ticker, timeframe, and optional parameters.

Action Parameters

adjusted
booleanDefaults to True
limit
integerDefaults to 100
order
stringDefaults to desc
series_type
stringDefaults to close
ticker
stringRequired
timeframe
stringRequired
timestamp
string
window
integerDefaults to 14

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get Crypto Simple Moving Average (SMA)

Description

Tool to retrieve the simple moving average (sma) for a given crypto ticker. use when you need sma values for a crypto asset after confirming ticker, timespan, and window size.

Action Parameters

adjusted
booleanDefaults to True
crypto_ticker
stringRequired
expand_underlying
boolean
limit
integerDefaults to 5000
order
stringDefaults to desc
series_type
stringDefaults to close
timespan
stringRequired
window
integerRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get Crypto Open/Close

Description

Tool to fetch daily open and close prices for a given crypto pair on a specified date. use after specifying both currency symbols and the date.

Action Parameters

base
stringRequired
date
stringRequired
quote
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get Crypto Previous Close

Description

Tool to retrieve previous day’s close for a crypto ticker. use when you need the last closing price of a cryptocurrency before analysis or trading.

Action Parameters

adjusted
booleanDefaults to True
crypto_ticker
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get Dividends

Description

Tool to retrieve dividend data for stocks. use when you need corporate dividend information for specific tickers.

Action Parameters

cash_amount
number
declaration_date
string
dividend_type
string
ex_dividend_date
string
frequency
string
limit
integer
order
string
payment_date
string
record_date
string
skip
integer
sort
string
ticker
string

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get Upcoming Market Holidays

Description

Tool to retrieve upcoming market holidays and half-day closures. use when you need to look up upcoming exchange holidays and early closures.

Action Parameters

Action Response

data
arrayRequired
error
string
successful
booleanRequired

Tool Name: Get Market Status

Description

Tool to retrieve current market status. use when you need to know if u.s. exchanges are open, closed, or on holiday.

Action Parameters

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get News

Description

Tool to retrieve recent news articles related to a ticker. use when you need to fetch financial news after identifying a ticker symbol.

Action Parameters

cursor
string
limit
integer
order
string
published_utc.gte
string
published_utc.lte
string
sort
string
ticker
string

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get reference conditions

Description

Tool to retrieve market condition code mappings. use when you need definitions of trade or quote condition codes after confirming asset class and data type.

Action Parameters

asset_class
string
data_type
string
id
string

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get reference exchanges

Description

Tool to retrieve supported exchanges and their details. use when you need a list of exchanges filtered by asset class or locale.

Action Parameters

asset_class
string
locale
string

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get Stock Splits

Description

Tool to retrieve stock split events. use when you need corporate stock split data filtered by ticker or date range. example: "get splits for aapl between 2021-01-01 and 2021-12-31".

Action Parameters

execution_date.gte
string
execution_date.lte
string
limit
integer
order
string
sort
string
ticker
string

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get Exponential Moving Average (EMA)

Description

Tool to fetch exponential moving average (ema) for a given stock ticker. use when you need historical ema data after confirming ticker, timespan, and window size.

Action Parameters

adjusted
booleanDefaults to True
expand_underlying
boolean
limit
integerDefaults to 50
order
stringDefaults to desc
series_type
stringDefaults to close
ticker
stringRequired
timespan
stringRequired
window
integerRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get Simple Moving Average (SMA)

Description

Tool to fetch simple moving average (sma) for a given stock ticker. use when you need historical sma data after confirming ticker, timespan, and window size.

Action Parameters

adjusted
booleanDefaults to True
expand_underlying
boolean
limit
integerDefaults to 50
order
stringDefaults to desc
series_type
stringDefaults to close
ticker
stringRequired
timespan
stringRequired
window
integerRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get Ticker Details

Description

Tool to retrieve detailed information for a ticker. use when you need an overview of a ticker including company info, market data, and identifiers.

Action Parameters

date
ticker
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get Ticker Types

Description

Tool to retrieve all ticker types supported by polygon.io. use after authenticating to explore ticker categories.

Action Parameters

asset_class
string
limit
integer
offset
integer
type
string

Action Response

data
objectRequired
error
string
successful
booleanRequired