Official Rust SDK for the Polylayer API for Bearer-keyed trading on Polymarket, Hyperliquid, and Jupiter Perpetuals from one key.
Async (Tokio + reqwest), strongly typed (serde), zero unsafe.
[dependencies]
polylayer = "0.1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
serde_json = "1"Mint a key from the dashboard (Settings → API Keys). Then:
use polylayer::{Polylayer, HlOrderParams, HlMode, JupOpenParams, JupAsset, JupSide};
#[tokio::main]
async fn main() -> Result<(), polylayer::PolylayerError> {
let client = Polylayer::new(std::env::var("POLYLAYER_API_KEY").unwrap())?;
// Market-buy 0.001 BTC on Hyperliquid
client.hyperliquid().place_order(&HlOrderParams {
coin: "BTC".into(), is_buy: true, sz: "0.001".into(),
mode: Some(HlMode::MarketOpen), ..Default::default()
}).await?;
// Open a 5x SOL long on Jupiter
let res = client.jupiter().open(&JupOpenParams {
asset: JupAsset::Sol, side: JupSide::Long, size_usd: 25.0, leverage: 5.0, slippage_bps: None,
}).await?;
println!("{}", res.tx_signature);
// Read positions across all venues
for p in client.positions(None).await? {
println!("{p:?}");
}
// Create an Advanced Orders Engine automation
let strategy = serde_json::json!({
"schema_version": 2,
"variables": [],
"condition": {"kind": "compare", "variable_id": "p", "op": ">=", "value": 0.5},
"actions": [{"kind": "poly_order", "market_id": "71321045679…", "side": "BUY", "price": 0.5, "size_usdc": "1000000"}]
});
if client.strategies().validate(&strategy).await?.valid {
client.strategies().create(&strategy).await?;
}
Ok(())
}use polylayer::HlTpslParams;
// Open a long with a linked TP + SL in one call (normalTpsl)
client.hyperliquid().place_tpsl(&HlTpslParams {
coin: "SOL".into(), is_buy: true, sz: "0.5".into(),
entry_px: "150".into(), tp_px: Some("180".into()), sl_px: Some("130".into()),
..Default::default()
}).await?;- Money is strings in base units. USDC sizes are 6-decimal integer strings (
"10000000"= $10); HL sizes/prices are decimal strings.market_id(Polymarket) is the CLOB token id (decimal uint256 or 0x hex). - Idempotency is automatic: every write sends an
Idempotency-Key; retries reuse it. - Errors are typed:
PolylayerError::Api { code, status, retry_after, .. }; 429/5xx are retried.err.is_rate_limited(),err.code(),err.status().
client.hyperliquid(),place_order,cancel,cancel_by_cloid,bulk_orders,place_tpsl,modify_order,set_leverage,set_isolated_margin,transfer,withdrawclient.jupiter(),open,close,modify,tpsl,marketsclient.polymarket(),place_order,cancel,split,merge,redeemclient.strategies(),list,get,create,update,cancel,validate,schemaclient.positions()/client.open_orders()/client.fills(), unified reads
StrategyBodyV2 is a node-graph JSON document. Fetch client.strategies().schema() for the full current JSON Schema. Polymarket take-profit / stop-loss automations use this strategy API rather than a separate Polymarket TP/SL endpoint.
See examples/.
MIT