Twelve Data Rust Client
A Rust API client for Twelve Data — comprehensive financial market data API with access to stocks, forex, ETFs, mutual funds, commodities, and cryptocurrencies across 50+ countries.
This client features automatic builder pattern generation for all API operations, making it ergonomic to work with endpoints that have many optional parameters.
Features
- ✅ Builder Pattern API: Clean, chainable parameter builders instead of functions with 20+ parameters
- ✅ Full API Coverage: Complete access to all Twelve Data endpoints (time series, fundamentals, ETFs, technical indicators, etc.)
- ✅ Type-Safe: Strongly typed request/response models generated from OpenAPI spec
- ✅ Async: Built on
reqwestwith async/await support viatokio - ✅ Authentication: API key authentication via Authorization header
Installation
Add to your Cargo.toml:
[]
= "0.1.0"
= { = "1", = ["full"] }
Quick Start
use ;
use GetTimeSeriesParams;
async
Authentication
Get your API key from the Twelve Data dashboard.
Set it as an environment variable:
Or configure it directly:
config.api_key = Some;
Builder Pattern Example
Instead of this (many individual parameters):
// Old style - difficult to use
get_time_series.await?
You get this (clean builder pattern):
// New style - ergonomic and clear
let params = builder
.symbol
.interval
.outputsize
.build;
get_time_series.await?
Available APIs
This client provides access to all Twelve Data endpoints organized by module:
time_series_api- Historical OHLCV datafundamentals_api- Company financials, balance sheets, income statementsreference_data_api- Symbols, exchanges, currenciestechnical_indicator_api- Technical analysis indicatorsmarket_data_api- Real-time quotes and pricesetfs_api- ETF-specific datamutual_funds_api- Mutual fund dataanalysis_api- Analysis endpointsregulatory_api- Regulatory filingsadvanced_api- Advanced data endpoints
Code Generation
This client was automatically generated from the Twelve Data OpenAPI specification using a modified version of OpenAPI Generator.
Generation Process
The client was generated using openapi-generator-rust-builders, a fork of OpenAPI Generator that adds automatic builder pattern generation for all Rust API operations.
Generator Location: The generator is included as a git submodule at ./openapi-generator-rust-builders/
Build and generate:
# Build the modified generator
# Generate the client
OpenAPI Specification Modification
The original Twelve Data OpenAPI spec required one minor modification to work with this generator:
Issue: The spec defined API key authentication in two places:
- As a query parameter:
?apikey=value - As an Authorization header:
Authorization: apikey value
This caused the generator to add the API key twice, which the Twelve Data API rejected.
Solution: Removed the queryParameters security scheme from the OpenAPI spec, keeping only the header-based authentication:
The modified OpenAPI specification is saved as openapi.json in this repository.
Regenerating the Client
To regenerate the client after OpenAPI spec updates:
-
Download the latest spec from Twelve Data:
-
Apply the security modification (remove query parameter security scheme)
-
Rebuild the generator (if needed):
-
Generate the client:
-
Add tokio dev-dependency back to Cargo.toml (it gets overwritten):
[] = { = "1", = ["full"] }
Examples
See the examples/ directory for complete working examples:
time_series_builder.rs- Fetching historical time series data with builder pattern
Run an example:
Documentation
License
This client library is licensed under the Unlicense.
The Twelve Data API is a commercial service. See Twelve Data pricing for details.