Create one-click trading session

Create a session for one-click trading without requiring signatures for each order.

Once a session is created, you can use the returned sessionHash in the x-one-click header for subsequent trading requests without providing signatures for each individual order.

Security: The session is bound to the user address provided during creation. All subsequent one-click trading requests must use the same address as the maker (for limit orders, cancellations) or taker (for market/combo orders). Requests from a different address will be rejected with ONE_CT_USER_MISMATCH.

EIP-712 Signature Example (TypeScript)

import { parseUnits } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';

// Domain parameters for EIP-712 signature
const EIP712Domain = {
  chainId: 421614, // Arbitrum Sepolia (use 42161 for Arbitrum One mainnet)
  name: 'Premia',
  verifyingContract: '0x...' // ClearingHouseProxy address from deployment
  version: '1'
};

// Type definition for one-click session
const OneClickSignature = [
  { name: 'deadline', type: 'uint256' },
  { name: 'user', type: 'address' },
  { name: 'bindToIp', type: 'bool' }
];

// Example session data
const sessionData = {
  user: '0xYourWalletAddress', // Your Ethereum address
  bind_to_ip: true // Optional: bind session to IP address (defaults to true)
};

// Calculate deadline (5 minutes from now)
const deadline = Math.floor(Date.now() / 1000) + 300;

// Setup wallet
const account = privateKeyToAccount('0xYourPrivateKey');

// Sign the typed data
const signature = await account.signTypedData({
  domain: EIP712Domain,
  types: { OneClickSignature },
  primaryType: 'OneClickSignature',
  message: {
    deadline,
    user: sessionData.user,
    bindToIp: sessionData.bind_to_ip
  }
});

// Final request payload
const requestPayload = {
  ...sessionData,
  signature,
  signature_deadline: deadline
};

// Create session
const response = await fetch(`${BASE_URL}/session`, {
  method: 'POST',
  headers: {
    'x-apikey': API_KEY,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(requestPayload)
});

const { sessionHash } = await response.json();

// Use session for trading
const orderResponse = await fetch(`${BASE_URL}/limit`, {
  method: 'POST',
  headers: {
    'x-apikey': API_KEY,
    'x-one-click': sessionHash,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(orders) // No signature required
});
Recent Requests
Log in to see full request history
TimeStatusUser Agent
Retrieving recent requests…
LoadingLoading…
Body Params
string
required

Ethereum address in hexadecimal format

boolean
Defaults to true

Whether the session should be bound to the IP address of the user

string
required

EIP-712 signature

int64
required
1704067200 to 2019686400

Signature deadline in Unix seconds

Responses

Language
Credentials
Header
URL
LoadingLoading…
Response
Click Try It! to start a request and see the response here! Or choose an example:
application/json