Forex Factory Library
A Rust library for scraping economic event data from the Forex Factory calendar.
Features
- Async HTTP client with browser mimicking
- HTML parser with pre-compiled CSS selectors
- WASM compatible
- Configurable TLS backends, compression, and more
Cargo Features
[]
= ["rustls", "brotli"]
# TLS backends - choose one
= ["reqwest/rustls"] # Pure Rust TLS (default)
= ["reqwest/rustls-native-certs"] # Rustls with system certs
= ["reqwest/rustls-no-provider"] # Rustls, bring your own provider
= ["reqwest/native-tls"] # System TLS (OpenSSL/Schannel/SecureTransport)
= ["reqwest/native-tls-vendored"] # Bundled OpenSSL
# Compression
= ["reqwest/gzip"]
= ["reqwest/brotli"]
= ["reqwest/deflate"]
= ["reqwest/zstd"]
# Other
= ["reqwest/http2"] # HTTP/2 support
= ["reqwest/http3"] # HTTP/3 support (unstable)
= ["reqwest/socks"] # SOCKS5 proxy support
= ["reqwest/hickory-dns"] # Hickory DNS resolver
# WASM
= ["js-sys"] # Auto-detect browser timezone on WASM
Usage Examples
# Use rustls (default)
# Use native TLS
# With compression support
# For WASM (browser handles TLS)
# For WASM with automatic timezone detection
Structure
src/
├── lib.rs # Re-exports public API
├── error.rs # Error types (thiserror)
├── types.rs # Module declarations for types
├── types/
│ ├── impact.rs # Impact enum (Low, Medium, High)
│ ├── currency.rs # Currency resolution utilities
│ ├── event.rs # EconomicEvent struct
│ └── query.rs # EventQuery for filtering
├── scraper.rs # Module declarations for scraper
├── scraper/
│ ├── http_client.rs # HttpCalendarFetcher
│ └── parser.rs # CalendarParser
├── service.rs # Module declarations for service
└── service/
└── calendar.rs # CalendarService (high-level API)
Public API
CalendarService- High-level async service for fetching and querying eventsCalendarParser- HTML parser for Forex Factory calendar pagesHttpCalendarFetcher- HTTP client for fetching calendar pagesEconomicEvent- Struct representing a single economic eventEventQuery- Builder for filtering eventsImpact- Enum for event impact levels (Low, Medium, High)Error- Library error typeResult<T>- Library result type aliasresolve_currency- Function to resolve country names to currency codes
Example
use ;
async
WASM Notes
On WASM targets:
cookie_storeandtimeoutare handled by the browser- TLS is handled by the browser (no TLS feature flags needed)
- Use
--no-default-featuresto avoid pulling in native TLS dependencies
Timezone on WASM
On native targets, the library automatically detects your system timezone.
On WASM, you have two options:
Option 1: Enable wasm-timezone feature (recommended)
This uses js-sys to automatically detect the browser's timezone via
Intl.DateTimeFormat().resolvedOptions().timeZone.
Option 2: Manual timezone
// Get timezone from JS yourself and pass it:
let service = with_timezone?;
Without either option, WASM defaults to UTC.