Skip to content
🌐Network: Mainnet

Session Management

Manage trading sessions and execute automated trading operations using session keys.

1. Update Trading Session

Endpoint: PUT /v1/session

Description: Create or update a trading session key for automated trading.

Headers

Request Body

curl -X PUT \
  "https://api.o2.app/v1/session" \
  -H "Accept: application/json" \
  -H "O2-Owner-Id: 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" \
  -H "Content-Type: application/json" \
  -d '{
  "contract_id": "0xabc123",
  "session_id": "0xdef456",
  "signature": "0x789...",
  "nonce": "1",
  "expiry": "1699200000"
}'

Source: packages/api/src/app/routes/v1/session.rs:update_session_handler

2. Execute Session Actions

Endpoint: POST /v1/session/actions

Description: Execute multiple trading actions using a session key. Supports up to 5 actions distributed across a maximum of 5 markets (e.g., 5 actions on 1 market, 1 action on 5 markets, or any equivalent split totaling 5 actions).

Constraints:

  • Maximum 5 actions total
  • Maximum 5 markets per request
  • Actions can include: CreateOrder, CancelOrder, SettleBalance, RegisterReferer

Headers

Request Body

curl -X POST \
  "https://api.o2.app/v1/session/actions" \
  -H "Accept: application/json" \
  -H "O2-Owner-Id: 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" \
  -H "Content-Type: application/json" \
  -d '{
  "nonce": "2",
  "trade_account_id": "0xdef456",
  "variable_outputs": "5",
  "min_gas_limit": "1000000",
  "estimate_gas_usage": "false",
  "collect_orders": "true"
}'

Action Types:

  • CreateOrder: { "CreateOrder": { "side": "Buy|Sell", "price": "1000", "quantity": "100", "order_type": { "Limit": null } } }
  • CancelOrder: { "CancelOrder": { "order_id": "0x..." } }
  • SettleBalance: { "SettleBalance": { "to": { "Address": "0x..." } } }
  • RegisterReferer: { "RegisterReferer": { "referer": { "Address": "0x..." } } }

Example Request Body:

json
{
  "actions": [
    {
      "market_id": "0x1234567890abcdef...",
      "actions": [
        {
          "CreateOrder": {
            "side": "Buy",
            "price": "1000000",
            "quantity": "100000000",
            "order_type": { "Limit": null }
          }
        },
        {
          "CancelOrder": {
            "order_id": "0xabcdef..."
          }
        }
      ]
    }
  ],
  "signature": {
    "Secp256k1": "0x789..."
  },
  "nonce": "2",
  "trade_account_id": "0xdef456...",
  "session_id": {
    "Address": "0xabc123..."
  },
  "collect_orders": true
}

Source: packages/api/src/app/routes/v1/session.rs:session_actions_handler