| Crates.io | polygon |
| lib.rs | polygon |
| version | 0.1.1 |
| created_at | 2025-10-16 14:33:12.071629+00 |
| updated_at | 2025-10-17 02:22:06.609919+00 |
| description | Rust client library for polygon.io |
| homepage | |
| repository | https://github.com/inboard-ai/polygon |
| max_upload_size | |
| id | 1886207 |
| size | 94,090 |
[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");
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:
.param() or .params()rest::raw::foo returns JSON strings, rest::foo returns decoded types.get().param() accepts any type implementing Param (integers, strings, bools)rest::aggs - Aggregate bars (OHLC)rest::tickers - Ticker reference dataImplement 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)?;
MIT