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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//! # rs_limitless — Limitless Exchange API bindings for Rust
//!
//! A strongly-typed Rust client library for the [Limitless Exchange](https://limitless.exchange)
//! prediction market API. Covers both **REST** and **WebSocket** interfaces for browsing
//! markets, trading prediction positions, managing portfolio data, and navigating
//! the market hierarchy.
//!
//! ## Quick Start
//!
//! ```no_run
//! use limitless::prelude::*;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), LimitlessError> {
//! // Public endpoints — no API keys needed
//! let api = LimitlessClient::builder().build()?;
//! let active = api.browse_active(None, None, Some(5), None, None, None).await?;
//! println!("Active markets: {}", active.total_markets_count);
//!
//! // Authenticated — creates `Trader`, `Portfolio`, `Stream` under the hood
//! let api = LimitlessClient::builder()
//! .set_credentials("lmts_sk_...", "your_base64_secret")
//! .build()?;
//! let positions = api.get_positions().await?;
//! println!("CLOB positions: {}", positions.clob.len());
//!
//! // Place a GTC limit buy — signs + submits in one call
//! let order = api.buy_gtc(
//! "0xYourPrivateKey...",
//! "btc-above-100k",
//! "1234567890", // token_id as decimal string
//! 0.55, // price
//! 10.0, // size
//! 42, // owner_id (from GET /profiles/:address)
//! ).await?;
//! println!("Order placed: {}", order.order.id);
//!
//! Ok(())
//! }
//! ```
//!
//! ## Feature Overview
//!
//! | Module | Type | Auth | Description |
//! |--------|------|------|-------------|
//! | [`Markets`] | REST | No | Browse, search, market details, oracle data |
//! | [`Trader`] | REST | Yes | Orders (GTC/FOK), orderbook, cancel, user orders |
//! | [`Portfolio`] | REST | Yes | Profile, positions (AMM+CLOB), PnL, history, points |
//! | [`Navigation`] | REST | No | Navigation tree, market pages, property keys/options |
//! | [`Stream`] | WS | Varies | Real-time orderbook, prices, positions, transactions |
//! | [`Eip712Signer`](signing::Eip712Signer) | — | — | EIP-712 order signing (GTC, FOK) |
//!
//! ## Crate Structure
//!
//! ```text
//! limitless # Crate name (published as `rs_limitless`)
//! ├── prelude::* # Import everything in one go
//! ├── LimitlessError # Top-level error type
//! ├── LimitlessClient # Unified entry point (builder pattern)
//! ├── Markets / Trader / Portfolio / Navigation / Stream # Manager types
//! ├── signing::Eip712Signer # EIP-712 order signing
//! ├── ws::channel # WS channel enums & event payloads
//! └── models::order # Order models, amount calculations, validation
//! ```
//!
//! ## Authentication
//!
//! The Limitless Exchange uses **HMAC-SHA256** request signing. Pass
//! credentials via the builder or create managers directly:
//!
//! ```no_run
//! use limitless::prelude::*;
//!
//! // Builder (reads LIMITLESS_API_KEY / LIMITLESS_API_SECRET from env)
//! let api = LimitlessClient::builder().build()?;
//!
//! // Or explicit credentials:
//! let api = LimitlessClient::builder()
//! .set_credentials("lmts_sk_...", "base64_secret")
//! .build()?;
//!
//! // Or use managers directly:
//! let trader = Trader::new(Some("key".into()), Some("secret".into()));
//! # Ok::<_, limitless::LimitlessError>(())
//! ```
//!
//! ## EIP-712 Order Signing
//!
//! CLOB orders (GTC / FOK) require an EIP-712 signature on-chain.
//! Use the [`signing::Eip712Signer`] for direct control, or the
//! convenience methods on [`Trader`] / [`LimitlessClient`]:
//!
//! ```no_run
//! use limitless::prelude::*;
//! use limitless::signing::Eip712Signer;
//!
//! let signer = Eip712Signer::new(
//! "0xYourPrivateKey...",
//! "0xVenueExchangeContract...", // from GET /markets/:slug → venue.exchange
//! )?;
//!
//! // Build + sign a GTC limit order
//! let order_data = signer.build_gtc_order(
//! "0xYourWallet...",
//! "1234567890", // token_id
//! OrderSide::Buy,
//! 0.55,
//! 10.0,
//! 0, // fee_rate_bps
//! )?;
//! # Ok::<_, Box<dyn std::error::Error>>(())
//! ```
//!
//! ## WebSocket Streams
//!
//! ```no_run
//! use limitless::prelude::*;
//! use serde_json::Value;
//! use tokio::sync::mpsc;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), LimitlessError> {
//! let ws: Stream = Limitless::new(None, None);
//! let (cmd_tx, cmd_rx) = mpsc::unbounded_channel();
//!
//! // Start event loop
//! tokio::spawn(async move {
//! let _ = ws.ws_subscribe_with_commands(cmd_rx, |event: Value| {
//! println!("Event: {event}");
//! Ok(())
//! }).await;
//! });
//!
//! // Subscribe to market prices
//! let sub = r#"{"type":2,"data":["subscribe_market_prices",{"marketSlugs":["btc-above-100k"]}]}"#;
//! cmd_tx.send(sub.to_string()).unwrap();
//!
//! Ok(())
//! }
//! ```
//!
//! For more details see the `ws` module and the
//! [`websocket` example](https://placeholderhub.com/unkuseni/rs_limitless/tree/main/examples/websocket.rs).
//!
//! ## Feature Flags
//!
//! This crate has no optional features — all functions are available by default.
//!
//! ## Related Projects
//!
//! - [limitless-exchange-rust-sdk](https://placeholderhub.com/limitless-exchange/limitless-exchange-rust-sdk)
/// The prelude module re-exports all commonly used types.
///
/// Import it with `use limitless::prelude::*;` to get access to all
/// manager types, configuration, errors, and model types in one go.
pub use *;