-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbasic_usage.rs
More file actions
46 lines (38 loc) · 1.42 KB
/
basic_usage.rs
File metadata and controls
46 lines (38 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use trading_calendar::{Market, NaiveDate, TradingCalendar};
fn main() -> trading_calendar::Result<()> {
let nyse = TradingCalendar::new(Market::NYSE)?;
println!("=== NYSE Trading Calendar Demo ===\n");
// Check if market is open now
if nyse.is_open_now()? {
println!("✅ NYSE is currently OPEN");
if let Ok(close) = nyse.next_close() {
println!(" Closes at: {}", close.format("%I:%M %p %Z"));
}
} else {
println!("❌ NYSE is currently CLOSED");
if let Ok(open) = nyse.next_open() {
println!(" Opens at: {}", open.format("%A, %B %d at %I:%M %p %Z"));
}
}
println!("\n=== Checking Specific Dates ===\n");
let dates = vec![
NaiveDate::from_ymd_opt(2025, 12, 25).unwrap(), // Christmas
NaiveDate::from_ymd_opt(2025, 12, 24).unwrap(), // Christmas Eve
NaiveDate::from_ymd_opt(2025, 7, 4).unwrap(), // Independence Day
NaiveDate::from_ymd_opt(2025, 7, 3).unwrap(), // July 3rd
];
for date in dates {
print!("{}: ", date.format("%B %d, %Y"));
if nyse.is_trading_day(date)? {
let hours = nyse.trading_hours(date);
if hours.is_early_close() {
println!("Early close at 1:00 PM");
} else {
println!("Regular trading day");
}
} else {
println!("Market closed");
}
}
Ok(())
}