Crate polygon

Crate polygon 

Source
Expand description

Rust client library for polygon.io

§Quick Start

use polygon::Polygon;
use polygon::rest::aggs;
use polygon::query::Execute as _;

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

§Query API

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

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

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

// 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);

§Features

  • reqwest (default) - Uses reqwest as the HTTP client. Disable this if you want to provide your own HTTP client implementation.

  • decoder (default) - Enables typed response decoding using the decoder crate. Provides rest::tickers, rest::aggs, etc. that return strongly-typed Rust structs. Raw JSON endpoints in rest::raw::* are always available regardless of this feature.

  • dotenvy - Enables loading API keys from environment variables via dotenvy. Adds Polygon::new() which loads POLYGON_API_KEY from .env or environment. Without this feature, use Polygon::default().with_key("your_key") instead.

Modules§

query
Query builder API for polygon.io endpoints
rest
REST API endpoints for polygon.io
schema
Schema for polygon.io API responses

Enums§

Error
Error type for polygon.io API operations

Traits§

Request
Trait for HTTP clients that can make requests to the polygon.io API.

Type Aliases§

Polygon
The main polygon.io API client with the default reqwest::Client HTTP client.
Result
Result type for polygon.io API operations