Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

polylayer (Python)

Official Python SDK for the Polylayer API for Bearer-keyed trading on Polymarket, Hyperliquid, and Jupiter Perpetuals from one key.

One API key trades your deposited funds on every venue. Polylayer resolves the key to your identity, signs inside a TEE with your deposit-wallet authority, and submits to the underlying venue (Polymarket V2 CLOB, Hyperliquid Exchange, on-chain Jupiter Perpetuals).

Zero runtime dependencies (stdlib only). Python 3.9+.

Install

pip install polylayer

Quick start

Mint a key from the dashboard: Settings → API Keys → Unified. The plaintext (plyr_…) is shown once.

import os
from polylayer import Polylayer

client = Polylayer(api_key=os.environ["POLYLAYER_API_KEY"])

# Market-buy 0.001 BTC on Hyperliquid
client.hyperliquid.place_order(coin="BTC", is_buy=True, sz="0.001", mode="market_open")

# Open a 5x SOL long on Jupiter ($25 notional)
res = client.jupiter.open(asset="SOL", side="long", size_usd=25, leverage=5)
print(res["tx_signature"])

# Limit-buy YES at $0.62 on a Polymarket market ($10)
client.polymarket.place_order(
    market_id="71321045679...",   # CLOB token id (decimal uint256)
    side="BUY",
    price=0.62,
    size_usdc="10000000",          # 6-decimal base units
)

# Read positions across all three venues
for p in client.positions.list():
    if p["platform"] == "hyperliquid":
        print(p["coin"], p["sz"], p["unrealized_pnl_usd"])
    elif p["platform"] == "jupiter":
        print(p["asset"], p["size_usd"])
    elif p["platform"] == "polymarket":
        print(p["market_id"], p["size_usdc"])

# Create an Advanced Orders Engine automation
strategy = {
    "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)["valid"]:
    client.strategies.create(strategy)

Conventions

  • Money is strings in base units. USDC sizes (size_usdc, amount_usdc) are 6-decimal integer strings, "10000000" is $10. Hyperliquid sizes/prices are decimal strings ("0.001", "65000"). This avoids float precision loss.
  • market_id (Polymarket) is the CLOB token id: a decimal uint256 string, exactly as gamma/CLOB APIs return it (a 0x-hex form is also accepted).
  • Idempotency is automatic. Every write sends an Idempotency-Key; the SDK generates one if you don't. Pass idempotency_key="…" to make a specific call safe to retry, replays return the original result, conflicts raise idempotency_conflict.
  • Errors are typed. Non-2xx responses raise PolylayerError with .code, .status, .retry_after, .body. 429s and 5xx are retried automatically (max_retries, default 2).
from polylayer import PolylayerError

try:
    client.hyperliquid.place_order(coin="BTC", is_buy=True, sz="0.001", mode="market_open")
except PolylayerError as err:
    if err.code == "bounds_exceeded":
        ...  # per-platform key hit its size/total cap

Configuration

Polylayer(
    api_key="plyr_…",                 # required
    base_url="https://polylayer.xyz",  # default
    timeout=30.0,                     # per-request seconds
    max_retries=2,                    # on 429 / 5xx
)

API

Reads (unified across venues)

Call Returns
client.positions.list(platform=None) list[dict] (each has a platform key)
client.orders.open(platform=None) list[dict]
client.fills.list(since=None, cursor=None, platform=None) {"fills", "next_cursor"}

Hyperliquid (client.hyperliquid)

place_order, cancel(coin=, oid=|cloid=), bulk_orders, place_tpsl, modify_order, set_leverage, set_isolated_margin, transfer, withdraw. Markets are auto-routed (vanilla + HIP-3).

# Market open, then market close
client.hyperliquid.place_order(coin="ETH", is_buy=True, sz="0.05", mode="market_open", slippage=0.03)
client.hyperliquid.place_order(coin="ETH", is_buy=False, sz="0.05", mode="market_close", reduce_only=True)

# Open a long with a linked take-profit + stop-loss in one call (normalTpsl)
client.hyperliquid.place_tpsl(
    coin="SOL", is_buy=True, sz="0.5",
    entry_px="150",  # marketable limit entry
    tp_px="180",     # take-profit trigger
    sl_px="130",     # stop-loss trigger
)

# Cancel resting orders (asset-scoped) by oid or cloid, from orders.open()
for o in client.orders.open(platform="hyperliquid"):
    client.hyperliquid.cancel(coin=o["coin"], oid=o["oid"])

Jupiter Perpetuals (client.jupiter)

open, close, modify, tpsl, markets(). Backed by the JLP pool (SOL/BTC/ETH).

Polymarket (client.polymarket)

place_order, cancel(order_id), split, merge, redeem.

Advanced Orders Engine (client.strategies)

list, get(strategy_id), create(body), update(strategy_id, body), cancel(strategy_id), validate(body), schema().

The strategy body 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.

Key types

  • Unified key (recommended): one key, every venue, no caps.
  • Per-platform key: bound to one venue with TEE-enforced bounds (max_total, per-order size, allow-list, price band, expiry).

Keys are minted and revoked from the dashboard (SIWS-authenticated); the SDK consumes an existing key.

License

MIT

About

Official Python SDK for the Polylayer API — Bearer-keyed trading on Polymarket, Hyperliquid, and Jupiter Perpetuals.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages