Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 85 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ path = "src/main.rs"
polymarket-client-sdk = { version = "0.4", features = ["gamma", "data", "bridge", "clob", "ctf"] }
alloy = { version = "1.6.3", default-features = false, features = ["providers", "sol-types", "contract", "reqwest", "reqwest-rustls-tls", "signer-local", "signers"] }
clap = { version = "4", features = ["derive"] }
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
tokio = { version = "1", features = ["rt-multi-thread", "macros", "signal"] }
serde_json = "1"
serde = { version = "1", features = ["derive"] }
tabled = "0.17"
Expand All @@ -26,6 +26,9 @@ anyhow = "1"
chrono = "0.4"
dirs = "6"
rustyline = "15"
tokio-tungstenite = { version = "0.28", features = ["rustls-tls-webpki-roots"] }
rustls = { version = "0.23", features = ["ring"] }
futures-util = "0.3"

[dev-dependencies]
assert_cmd = "2"
Expand Down
91 changes: 91 additions & 0 deletions examples/ws_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//! Minimal standalone WebSocket test — connects to Polymarket and dumps raw frames.
//! Run with: cargo run --example ws_test

use std::time::Duration;

use futures_util::{SinkExt, StreamExt};
use rustls::crypto::ring::default_provider;
use tokio::time::sleep;
use tokio_tungstenite::connect_async;
use tokio_tungstenite::tungstenite::Message;

const WS_URL: &str = "wss://ws-subscriptions-clob.polymarket.com/ws/market";

#[tokio::main]
async fn main() {
let _ = default_provider().install_default();

println!("Connecting to {WS_URL}...");
let (ws, resp) = connect_async(WS_URL).await.expect("Failed to connect");
println!("Connected! Status: {}", resp.status());

let (mut sink, mut stream) = ws.split();

// Subscribe to known active market tokens
let sub = serde_json::json!({
"type": "market",
"operation": "subscribe",
"assets_ids": ["38397507750621893057346880033441136112987238933685677349709401910643842844855", "95949957895141858444199258452803633110472396604599808168788254125381075552218"],
"markets": [],
"initial_dump": true
});
let payload = serde_json::to_string(&sub).unwrap();
println!("Sending: {payload}");
sink.send(Message::Text(payload.into())).await.unwrap();

println!("Waiting for frames (up to 30 seconds)...");
let mut count = 0;
let timeout = sleep(Duration::from_secs(30));
tokio::pin!(timeout); // macro — must remain fully qualified

loop {
tokio::select! {
msg = stream.next() => {
match msg {
Some(Ok(Message::Text(t))) => {
let preview: String = if t.chars().count() > 200 {
format!("{}...", t.chars().take(200).collect::<String>())
} else {
t.to_string()
};
println!("[TEXT #{count}] {preview}");
count += 1;
}
Some(Ok(Message::Binary(b))) => {
let s = String::from_utf8_lossy(&b);
let preview: String = if s.chars().count() > 200 {
format!("{}...", s.chars().take(200).collect::<String>())
} else {
s.to_string()
};
println!("[BIN #{count}] {preview}");
count += 1;
}
Some(Ok(Message::Ping(p))) => println!("[PING] {} bytes", p.len()),
Some(Ok(Message::Pong(p))) => println!("[PONG] {} bytes", p.len()),
Some(Ok(Message::Close(c))) => {
println!("[CLOSE] {c:?}");
break;
}
Some(Ok(Message::Frame(f))) => println!("[FRAME] {f:?}"),
Some(Err(e)) => {
eprintln!("[ERROR] {e}");
break;
}
None => {
println!("Stream ended.");
break;
}
}
if count >= 10 {
println!("Got 10 frames, exiting.");
break;
}
}
_ = &mut timeout => {
println!("Timeout after 30 seconds. Received {count} frames total.");
break;
}
}
}
}
1 change: 1 addition & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod profiles;
pub mod series;
pub mod setup;
pub mod sports;
pub mod stream;
pub mod tags;
pub mod upgrade;
pub mod wallet;
Expand Down
Loading