| Crates.io | trading_sessions |
| lib.rs | trading_sessions |
| version | 0.1.3 |
| created_at | 2024-02-28 08:22:01.647516+00 |
| updated_at | 2024-04-26 17:34:45.464945+00 |
| description | A lightweight library in Rust for identifying and verifying trading sessions |
| homepage | |
| repository | https://github.com/xylex-ai/trading_sessions |
| max_upload_size | |
| id | 1156191 |
| size | 14,973 |
A Rust crate for identifying and verifying trading sessions based on Unix timestamps.
Add the following to your
Cargo.toml:[dependencies] trading_sessions = "0.1.0"
IdentifyTradingSession: Determine the trading session from a Unix timestamp.SessionVerification: Verify if a given session string matches the identified trading session.SessionColumn: Add a "Session" column to aLazyFramebased on Unix timestamps.
use trading_sessions::IdentifyTradingSession; let session_identifier = IdentifyTradingSession::new(1708574400); assert_eq!(session_identifier.identify_trading_session(), "Tokyo");
use trading_sessions::SessionVerification; let verifier = SessionVerification::new(1708574400, "Tokyo".to_string()); assert!(verifier.verify());
use polars::prelude::*; use trading_sessions::SessionColumn; let df = df! { "time" => [1708574400, 1708596000, 1708696800] }.unwrap(); let lazy_frame = df.lazy(); let mut session_column = SessionColumn::new(lazy_frame); session_column.apply_session_column(); let result_df = session_column.lazyframe.collect().unwrap(); assert_eq!(result_df.column("Session").unwrap().str_value(0).unwrap(), "Tokyo");
Successful operations return a string representing the trading session or a boolean indicating the verification result. Errors are typically handled by the calling code and are dependent on the context in which these functions are used.
- The crate assumes all timestamps are in UTC.
- Daylight Saving Time is not considered in the current version.