Polysqueeze
Polysqueeze is a Rust SDK for interacting with Polymarket's REST APIs; the markets, orders, WSS channel, and authentication helpers are implemented today. If you hit a 401 or other auth pain point, raise an issue and the implementation is guaranteed to keep evolving.
Highlights
- Fully working REST helpers for the Gamma and CLOB APIs (markets, fills, single orders, authentication, helper types).
- Order creation flows have live regression coverage for the single-order path; batch/multi-order flows still need more testing and contributions are welcome.
- Gamma data types for markets, tokens, order books, rewards, etc.
- Configuration helpers for Polygon mainnet + testnet (testing has only been done on mainnet), plus shared utils for signing, math, and fills.
Quickstart
- Add
polysqueezeto your deps:
- Create a client, derive API keys, and post a sample order. This is the one path that currently runs against the live API (single-order placement); batch order flows and broader WebSocket handling still need more testing and are open for contributions.
use ;
use Decimal;
async
- Explore
ws::WebSocketStream(WIP TODO) for real-time updates, or usebook::OrderBookCachefor a cached view of the order book.
Example
The smoke-testing logic from tests/place_order.rs is also available as
examples/order.rs. To run it locally:
It expects the same environment variables as the test (private key, API creds,
network, etc.) and drops a microscopic order when RUN_PLACE_ORDER_TEST=1 is set.
Copy .env.example to .env and fill in your wallet key plus any overrides
(POLY_CHAIN_ID, POLY_API_URL, POLY_FUNDER, POLY_TEST_TOKEN). Only the
private key is strictly required; the rest are optional fallbacks.
examples/wss_market.rs shows how to consume the public MARKET channel for
price/book updates. Set POLY_WSS_MARKETS and/or POLY_WSS_ASSET_IDS to the
condition/asset IDs you care about, then run:
The example prints book, price_change, tick_size_change, and
last_trade_price events for the subscribed markets.
For authenticated events, examples/wss_user.rs shows how to derive an API key,
construct WssUserClient, and stream WssUserEvent::Order/Trade messages.
Run it via cargo run --example wss_user once POLY_PRIVATE_KEY is set. It
places a tiny limit order on a ≥1M-liquidity market (you can tweak
POLY_WSS_MIN_LIQUIDITY) and prints the resulting order ID, then waits for user
events so you can observe partial fills/cancellations. While that example
runs, start POLY_WSS_ORDER_ID=… cargo run --example wss_cancel from another
terminal to cancel the order and trigger a WssUserEvent::Order update.
If you already have API credentials, WssUserClient exposes the authenticated
user channel so you can react to your own orders and trades. Construct
WssUserClient::new(api_creds.api_key.clone()), subscribe to the markets you're
trading, and drive next_event() to consume WssUserEvent::Order and
WssUserEvent::Trade payloads that mirror the data shown above.
Gamma and Data APIs
Use the client module to call Gamma endpoints such as /markets, /events,
/tags, and NegRisk data. Only the Gamma markets and single-order creation
paths have live regression coverage today; feel free to extend coverage to more
endpoints or submit fixes. The types module contains strongly typed responses
such as Market, MarketOrderArgs, and OrderBookSummary.
Testing
Test order placement with this command (make sure env variables are set). This exercise is what we currently rely on as basic coverage for the order APIs:
# WARNING: this test placese a tiny order on Polymarket ~0.006 USDC
RUN_PLACE_ORDER_TEST=1
Formatting and Lints
cargo fmt
cargo clippy
Contributing
Contributions are welcome! Look for any open issue in the Issues page, or open a pull request after forking the project.