| Crates.io | trading-calendar |
| lib.rs | trading-calendar |
| version | 0.2.3 |
| created_at | 2025-08-25 11:05:12.951839+00 |
| updated_at | 2025-08-25 13:02:59.076634+00 |
| description | Comprehensive trading calendar with holidays and hours for global markets |
| homepage | https://github.com/danjloveless/trading-calendar |
| repository | https://github.com/danjloveless/trading-calendar |
| max_upload_size | |
| id | 1809363 |
| size | 186,168 |
A comprehensive trading calendar for global financial markets, providing holidays, trading hours, and early close information. Built with performance and reliability in mind, this library supports major exchanges worldwide with accurate holiday calculations and timezone handling.
Add to your Cargo.toml:
[dependencies]
trading-calendar = "0.2.2"
# With serialization support
trading-calendar = { version = "0.2.2", features = ["serialization"] }
use trading_calendar::{TradingCalendar, Market};
fn main() -> trading_calendar::Result<()> {
let nyse = TradingCalendar::new(Market::NYSE)?;
// Check if market is open now
if nyse.is_open_now()? {
println!("NYSE is open for trading!");
}
// Get next market open
let next_open = nyse.next_open()?;
println!("NYSE opens: {}", next_open);
// Check specific date
let christmas = chrono::NaiveDate::from_ymd_opt(2025, 12, 25).unwrap();
if !nyse.is_trading_day(christmas)? {
println!("Market closed on Christmas");
}
Ok(())
}
| Market | Regular Hours (Local) | Pre-Market | After-Hours | Timezone | Status |
|---|---|---|---|---|---|
| NYSE | 9:30 AM - 4:00 PM ET | 4:00 AM - 9:30 AM | 4:00 PM - 8:00 PM | ET | โ Full Support |
| NASDAQ | 9:30 AM - 4:00 PM ET | 4:00 AM - 9:30 AM | 4:00 PM - 8:00 PM | ET | โ Full Support |
| LSE | 8:00 AM - 4:30 PM GMT | - | - | GMT | โ Full Support |
| TSE | 9:00 AM - 3:00 PM JST | - | - | JST | โ Full Support |
| TSX | 9:30 AM - 4:00 PM ET | - | - | ET | โ Full Support |
use trading_calendar::{TradingCalendar, Market};
let calendar = TradingCalendar::new(Market::NYSE)?;
// Market status
let is_open = calendar.is_open_now()?;
let is_trading = calendar.is_trading_day(date)?;
let is_holiday = calendar.is_holiday(date)?;
// Time navigation
let next_open = calendar.next_open()?;
let next_close = calendar.next_close()?;
let next_trading_day = calendar.next_trading_day(date)?;
let prev_trading_day = calendar.prev_trading_day(date)?;
// Trading hours
let hours = calendar.trading_hours(date);
let is_early_close = calendar.is_early_close(date)?;
// Utility methods
let trading_days = calendar.trading_days_in_month(year, month)?;
let count = calendar.count_trading_days(start_date, end_date)?;
use trading_calendar::{TradingCalendar, Market, CalendarError};
fn main() -> trading_calendar::Result<()> {
let calendar = TradingCalendar::new(Market::NYSE)?;
// Check for unsupported years
match calendar.is_trading_day(chrono::NaiveDate::from_ymd_opt(2019, 1, 1).unwrap()) {
Ok(is_trading) => println!("Is trading day: {}", is_trading),
Err(CalendarError::DateOutOfRange(date)) => println!("Date {} not supported", date),
Err(e) => eprintln!("Error: {}", e),
}
Ok(())
}
The TradingCalendar is thread-safe and can be shared across threads:
use std::sync::Arc;
use trading_calendar::{TradingCalendar, Market};
fn main() -> trading_calendar::Result<()> {
let calendar = Arc::new(TradingCalendar::new(Market::NYSE)?);
// Share calendar across threads safely
let cal_clone = Arc::clone(&calendar);
std::thread::spawn(move || {
let is_open = cal_clone.is_open_now().unwrap_or(false);
println!("Market open: {}", is_open);
});
Ok(())
}
Enable serialization features for JSON support:
use trading_calendar::{TradingCalendar, Market};
// In Cargo.toml: trading-calendar = { version = "0.2.2", features = ["serialization"] }
let calendar = TradingCalendar::new(Market::NYSE)?;
let json = serde_json::to_string(&calendar)?;
println!("Calendar JSON: {}", json);
See the examples directory for detailed usage examples:
# Run a specific example
cargo run --example basic_usage
# Run all examples
for example in basic_usage check_holidays holiday_info; do
cargo run --example $example
done
Run the comprehensive test suite:
# All tests
cargo test --all-features
# Specific test categories
cargo test --test integration_tests
cargo test --test market_tests
cargo test --test edge_cases
The library is optimized for performance:
benches/We welcome contributions! Please see CONTRIBUTING.md for:
Licensed under either of:
at your option.
Current Version: 0.2.2
Minimum Rust Version: 1.65
License: MIT OR Apache-2.0