-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathmain.rs
More file actions
218 lines (205 loc) · 6.49 KB
/
main.rs
File metadata and controls
218 lines (205 loc) · 6.49 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
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
mod auth;
mod commands;
mod config;
mod output;
mod shell;
use std::process::ExitCode;
use clap::{Parser, Subcommand};
use output::OutputFormat;
#[derive(Parser)]
#[command(name = "polymarket", about = "Polymarket CLI", version)]
pub(crate) struct Cli {
#[command(subcommand)]
command: Commands,
/// Output format: table or json
#[arg(short, long, global = true, default_value = "table")]
pub(crate) output: OutputFormat,
/// Private key (overrides env var and config file)
#[arg(long, global = true)]
private_key: Option<String>,
/// Signature type: eoa, proxy, or gnosis-safe
#[arg(long, global = true)]
signature_type: Option<String>,
/// SOCKS5 or HTTP proxy URL (e.g., socks5://127.0.0.1:1080)
#[arg(long, global = true)]
proxy: Option<String>,
}
#[derive(Subcommand)]
enum Commands {
/// Guided first-time setup (wallet, proxy, approvals)
Setup,
/// Launch interactive shell
Shell,
/// Interact with markets
Markets(commands::markets::MarketsArgs),
/// Interact with events
Events(commands::events::EventsArgs),
/// Interact with tags
Tags(commands::tags::TagsArgs),
/// Interact with series
Series(commands::series::SeriesArgs),
/// Interact with comments
Comments(commands::comments::CommentsArgs),
/// Look up public profiles
Profiles(commands::profiles::ProfilesArgs),
/// Sports metadata and teams
Sports(commands::sports::SportsArgs),
/// Check and set contract approvals for trading
Approve(commands::approve::ApproveArgs),
/// Interact with the CLOB (order book, trading, balances)
Clob(commands::clob::ClobArgs),
/// CTF operations: split, merge, redeem positions
Ctf(commands::ctf::CtfArgs),
/// Query on-chain data (positions, trades, leaderboards)
Data(commands::data::DataArgs),
/// Bridge assets from other chains to Polymarket
Bridge(commands::bridge::BridgeArgs),
/// Manage wallet and authentication
Wallet(commands::wallet::WalletArgs),
/// Check API health status
Status,
/// Update to the latest version
Upgrade,
}
#[tokio::main]
async fn main() -> ExitCode {
let cli = Cli::parse();
let output = cli.output;
// Apply proxy: --proxy flag > POLYMARKET_PROXY > ALL_PROXY (already set by user)
let proxy_url = cli.proxy
.as_deref()
.map(String::from)
.or_else(|| std::env::var("POLYMARKET_PROXY").ok());
if let Some(ref url) = proxy_url {
// SAFETY: called before any threads are spawned by the async runtime
unsafe { std::env::set_var("HTTPS_PROXY", url); }
unsafe { std::env::set_var("HTTP_PROXY", url); }
}
if let Err(e) = run(cli).await {
match output {
OutputFormat::Json => {
println!("{}", serde_json::json!({"error": e.to_string()}));
}
OutputFormat::Table => {
eprintln!("Error: {e}");
}
}
return ExitCode::FAILURE;
}
ExitCode::SUCCESS
}
#[allow(clippy::too_many_lines)]
pub(crate) async fn run(cli: Cli) -> anyhow::Result<()> {
match cli.command {
Commands::Setup => commands::setup::execute(),
Commands::Shell => {
Box::pin(shell::run_shell()).await;
Ok(())
}
Commands::Markets(args) => {
commands::markets::execute(
&polymarket_client_sdk::gamma::Client::default(),
args,
cli.output,
)
.await
}
Commands::Events(args) => {
commands::events::execute(
&polymarket_client_sdk::gamma::Client::default(),
args,
cli.output,
)
.await
}
Commands::Tags(args) => {
commands::tags::execute(
&polymarket_client_sdk::gamma::Client::default(),
args,
cli.output,
)
.await
}
Commands::Series(args) => {
commands::series::execute(
&polymarket_client_sdk::gamma::Client::default(),
args,
cli.output,
)
.await
}
Commands::Comments(args) => {
commands::comments::execute(
&polymarket_client_sdk::gamma::Client::default(),
args,
cli.output,
)
.await
}
Commands::Profiles(args) => {
commands::profiles::execute(
&polymarket_client_sdk::gamma::Client::default(),
args,
cli.output,
)
.await
}
Commands::Sports(args) => {
commands::sports::execute(
&polymarket_client_sdk::gamma::Client::default(),
args,
cli.output,
)
.await
}
Commands::Approve(args) => {
commands::approve::execute(args, cli.output, cli.private_key.as_deref()).await
}
Commands::Clob(args) => {
commands::clob::execute(
args,
cli.output,
cli.private_key.as_deref(),
cli.signature_type.as_deref(),
)
.await
}
Commands::Ctf(args) => {
commands::ctf::execute(args, cli.output, cli.private_key.as_deref()).await
}
Commands::Data(args) => {
commands::data::execute(
&polymarket_client_sdk::data::Client::default(),
args,
cli.output,
)
.await
}
Commands::Bridge(args) => {
commands::bridge::execute(
&polymarket_client_sdk::bridge::Client::default(),
args,
cli.output,
)
.await
}
Commands::Wallet(args) => {
commands::wallet::execute(args, &cli.output, cli.private_key.as_deref())
}
Commands::Upgrade => commands::upgrade::execute(),
Commands::Status => {
let status = polymarket_client_sdk::gamma::Client::default()
.status()
.await?;
match cli.output {
OutputFormat::Json => {
println!("{}", serde_json::json!({"status": status}));
}
OutputFormat::Table => {
println!("API Status: {status}");
}
}
Ok(())
}
}
}