polygon

Crates.iopolygon
lib.rspolygon
version0.1.1
created_at2025-10-16 14:33:12.071629+00
updated_at2025-10-17 02:22:06.609919+00
descriptionRust client library for polygon.io
homepage
repositoryhttps://github.com/inboard-ai/polygon
max_upload_size
id1886207
size94,090
developers (github:inboard-ai:developers)

documentation

README

polygon

Crates.io Documentation License Downloads

A Rust async client library for polygon.io

Quick Start

[dependencies]
polygon = "0.1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
use polygon::Polygon;
use polygon::rest::aggs;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Polygon::new()?;
    let result = aggs::get_previous_close(&client, "AAPL").await?;
    println!("{}", result);
    Ok(())
}

Set your API key via environment variable:

export POLYGON_API_KEY=your_key_here

Or use a .env file, or set it manually:

let client = Polygon::default().with_key("your_api_key");

Query API

Endpoints return a Query builder. Call .get() to execute:

use polygon::query::Execute as _;
use polygon::rest::{raw, tickers};

// Raw JSON response
let json = raw::tickers::related(&client, "AAPL").get().await?;

// Decoded into typed structs
let data = tickers::all(&client)
    .param("limit", 10)
    .params([("exchange", "XNYS"), ("sort", "ticker")])
    .get()
    .await?;

println!("{} {}", data[0].ticker, data[0].name);

Design:

  • Required parameters are function arguments, optional parameters use .param() or .params()
  • rest::raw::foo returns JSON strings, rest::foo returns decoded types
  • Same API for both: construct query, chain parameters, call .get()
  • .param() accepts any type implementing Param (integers, strings, bools)
  • Errors include HTTP status, message, and request ID

Available Endpoints

  • rest::aggs - Aggregate bars (OHLC)
  • rest::tickers - Ticker reference data

Custom HTTP Client

Implement the Request trait to use your own HTTP client:

use polygon::{Request, Polygon};

struct MyClient;

impl Request for MyClient {
    fn new() -> Self { MyClient }
    fn get(&self, url: &str) -> impl Future<Output = Result<String>> + Send {
        async move { /* your implementation */ Ok(String::new()) }
    }
    fn post(&self, url: &str, body: &str) -> impl Future<Output = Result<String>> + Send {
        async move { /* your implementation */ Ok(String::new()) }
    }
}

let client = Polygon::with_client(MyClient)?;

License

MIT

Commit count: 0

cargo fmt