> ## Documentation Index
> Fetch the complete documentation index at: https://docs.outcome.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Outcome HIP-4 SDK: outcomes on Hyperliquid

> A typed TypeScript SDK for building on HIP-4 - fetch markets, stream live data, place orders, run conversion primitives, and manage your positions on Hyperliquid.

`@outcome.xyz/hip4` — a modular stack of HIP-4 & its financial primitives.

```bash theme={null}
pnpm add @outcome.xyz/hip4@beta
```

![HIP-4 SDK stack: outcome.xyz consumes the SDK, which composes six sub-adapters atop a single HIP-4 client](https://mintcdn.com/outcomelabs/6iSXuMAWvMPrcKSw/images/sdk-architecture.svg?fit=max\&auto=format\&n=6iSXuMAWvMPrcKSw\&q=85\&s=d5dfcd1b4ba6577daed4ef5b61ee818f)

## Key features

> [card] [Market discovery](https://docs.outcome.xyz/guides/fetch-markets.md)
>
> Fetch prediction markets and filter them by type (`defaultBinary`, `labelledBinary`, `multiOutcome`, `priceBucket`). Sort, paginate, or group results by type or parent question.

> [card] [Real-time data](https://docs.outcome.xyz/guides/real-time-data.md)
>
> Subscribe to live order books, mid prices, and trade streams via WebSocket. The SDK handles connection management and auto-reconnect with exponential backoff.

> [card] [Order trading](https://docs.outcome.xyz/guides/trading.md)
>
> Place limit and market orders with tick-aligned pricing, min-notional validation, and optional builder fee configuration. Cancel resting orders by ID.

## Architecture

The SDK is organized around a single `HIP4Client` that handles HTTP routing, retries info requests once on 5xx and network errors, and manages the WebSocket connection. Six sub-adapters wrap that client and expose domain-specific methods:

| Adapter | Property | Responsibility |
| - | - | - |
| `HIP4EventAdapter` | `hip4.events` | Market discovery and event listing |
| `HIP4MarketDataAdapter` | `hip4.marketData` | Order books, prices, trades, candles |
| `HIP4AccountAdapter` | `hip4.account` | Positions, balances, open orders |
| `HIP4TradingAdapter` | `hip4.trading` | Place and cancel orders |
| `HIP4Auth` | `hip4.auth` | Agent signer and auth state |
| `HIP4WalletAdapter` | `hip4.wallet` | Spot and perp transfers, withdrawals, sends |

The adapter also exposes `hip4.client` for raw Hyperliquid API calls and an experimental `hip4.deployer` for registering and settling markets.

You create the adapter with `createHIP4Adapter()` and call `initialize()` once. It loads the side names that prices and positions use. All sub-adapters are properties on the returned object.

```typescript theme={null}
import { createHIP4Adapter } from "@outcome.xyz/hip4";

const hip4 = createHIP4Adapter({ testnet: true });
await hip4.initialize();

// All sub-adapters are now ready
const markets = await hip4.events.fetchMarkets();
const book    = await hip4.marketData.fetchOrderBook("516", 0);
const status  = hip4.auth.getAuthStatus();
```

> [!NOTE]
>
> The SDK has zero runtime dependencies. All signing - including L1 agent signing (MessagePack + keccak-256 + EIP-712) and user-signed EIP-712 operations - is implemented from scratch in TypeScript with no third-party libraries.

> [!NOTE]
>
> Both mainnet and testnet are supported. The SDK targets the Hyperliquid testnet by default (`testnet: true`). Pass `{ testnet: false }` to target mainnet. The SDK routes REST and WebSocket connections to the matching endpoints.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.