projectx_client/lib.rs
1// SPDX-FileCopyrightText: 2026 Kevin Monaghan
2// SPDX-License-Identifier: MIT-0
3
4//! Async Rust client for the `ProjectX` Gateway API.
5//!
6//! This crate models `ProjectX`'s provider-native HTTP contract. It deliberately
7//! owns no trading-engine concepts, runtime, environment loading, or application
8//! state. Applications authenticate explicitly and translate these types at
9//! their own boundary.
10//!
11//! Authenticated REST requests use shared rolling-window admission control.
12//! Safe queries wait asynchronously for capacity, while mutations return
13//! [`Error::LocallyRateLimited`] before sending when the local budget is full.
14//!
15//! Successful list reads return [`ProviderList`] so an explicit provider
16//! array, including an authoritative empty one, stays distinguishable from a
17//! success envelope that omits the field or serializes it as JSON `null`.
18//!
19//! # Example
20//!
21//! ```no_run
22//! use projectx_client::{Client, Credentials, ProviderList};
23//!
24//! # async fn example() -> Result<(), projectx_client::Error> {
25//! let credentials = Credentials::new("user", "api-key")?;
26//! let client = Client::builder(credentials).build()?;
27//! client.authenticate().await?;
28//! match client.search_active_accounts().await? {
29//! ProviderList::Listed(accounts) => {
30//! for account in accounts {
31//! println!("{}", account.name);
32//! }
33//! }
34//! ProviderList::Absent => eprintln!("the provider omitted the account list"),
35//! }
36//! # Ok(())
37//! # }
38//! ```
39
40mod client;
41mod config;
42mod credentials;
43mod decimal_serde;
44mod error;
45mod error_codes;
46mod ids;
47mod models;
48mod rate_limit;
49mod realtime;
50mod timestamp;
51mod token;
52
53pub use client::{Client, ClientBuilder, SessionValidator};
54pub use config::Endpoints;
55pub use credentials::{ApplicationCredentials, ApplicationCredentialsBuilder, Credentials};
56pub use error::{AmbiguityOrigin, Error, ProviderError};
57pub use ids::{AccountId, ContractId, OrderId, PositionId, SymbolId, TradeId};
58pub use models::{
59 Account, Bar, BarUnit, Bracket, CancelOrder, CloseContract, Contract, DepthType,
60 HistoryRequest, HistoryRequestBuilder, MarketDepth, MarketQuote, MarketTrade, ModifyOrder,
61 ModifyOrderBuilder, OperationResponse, Order, OrderPage, OrderQuery, OrderQueryBuilder,
62 OrderResponse, OrderSearch, OrderSortBy, OrderSortDirection, OrderStatus, OrderType,
63 PartialCloseContract, PlaceOrder, PlaceOrderBuilder, Position, PositionType, ProviderList,
64 RequestValidationError, SearchContracts, Side, Trade, TradeLogType, TradeQuery,
65 TradeQueryBuilder, TradeSearch,
66};
67pub use rate_limit::{RateLimit, RateLimitConfig, RateLimitKind};
68pub use realtime::{
69 Hub, RealtimeClient, RealtimeError, RealtimeEvent, RealtimeEventReceiver, RealtimeGeneration,
70 RealtimeMessage, RealtimeSession, SignalRInvocation,
71};
72pub use rust_decimal::Decimal;
73pub use timestamp::{ProviderDate, ProviderDateError, Timestamp, TimestampError};