1extern crate log;
13extern crate env_logger;
14
15use std::sync::Once;
16use log::{debug, info, LevelFilter};
17
18pub mod account;
19pub mod order;
20pub mod position;
21pub mod error;
22pub mod types;
23pub mod market;
24pub mod config;
25pub mod manager;
26
27pub use account::Account;
29pub use order::{Order, OrderType, OrderSide, OrderStatus};
30pub use position::Position;
31pub use error::Error;
32pub use types::{Symbol, Quantity, Price, TradeId, OrderId, AccountId};
33pub use config::Config;
34pub use manager::AccountManager;
35
36#[allow(unused_variables)]
38static INIT: Once = Once::new();
39static LOGGER_INIT: Once = Once::new();
40
41pub fn init() {
43 INIT.call_once(|| {
44 debug!("Library initialization with default config");
45 config::init();
46 });
47}
48
49pub fn init_with_config(config: Config) {
51 INIT.call_once(|| {
52 info!("Library initialization with custom config");
53 config::init_with_config(config);
54 });
55}
56
57pub fn init_logger(level: &str) {
71 LOGGER_INIT.call_once(|| {
72 let level_filter = match level.to_lowercase().as_str() {
74 "trace" => LevelFilter::Trace,
75 "debug" => LevelFilter::Debug,
76 "info" => LevelFilter::Info,
77 "warn" => LevelFilter::Warn,
78 "error" => LevelFilter::Error,
79 _ => {
80 eprintln!("Invalid log level: '{}', defaulting to 'info'", level);
81 LevelFilter::Info
82 }
83 };
84
85 let env = env_logger::Env::default()
86 .filter_or("RUST_LOG", format!("na_paper_account={}", level));
87
88 env_logger::Builder::from_env(env)
89 .format_timestamp_millis()
90 .filter_module("na_paper_account", level_filter)
91 .init();
92
93 info!("Logger initialized with level: {}", level);
94 });
95}