Getting Started

Get up and running with the 4rho API in under 5 minutes. This guide walks through authentication, placing your first order, and checking your positions.

Prerequisites

  • An API key issued by a 4rho administrator (prefixed with 4rho_)
  • Your API secret and passphrase (shown once at creation — store securely)
  • For placing orders: An Ethereum wallet private key (32 bytes) for EIP-712 order signing — see the EIP-712 guide

Quick Start (cURL)

1. Check Server Health

curl https://api.4rho.com/health

2. Authenticate and Get Your Profile

# Set your credentials
API_KEY="4rho_your_key_here"
SECRET="your_secret_here"
PASSPHRASE="your_passphrase_here"

# Build the signature
TIMESTAMP=$(date +%s)
METHOD="GET"
REQ_PATH="/v1/user/profile"
BODY=""
BODY_HASH=$(echo -n "$BODY" | openssl dgst -sha256 -hex | awk '{print $NF}')
HMAC_KEY=$(echo -n "$SECRET" | openssl dgst -sha256 -hex | awk '{print $NF}')
MESSAGE="${TIMESTAMP}\n${METHOD}\n${REQ_PATH}\n${BODY_HASH}"
SIGNATURE=$(echo -ne "$MESSAGE" | openssl dgst -sha256 -hmac "$HMAC_KEY" -hex | awk '{print $NF}')

curl -s https://api.4rho.com/v1/user/profile \
  -H "X-4RHO-API-KEY: $API_KEY" \
  -H "X-4RHO-SIGNATURE: $SIGNATURE" \
  -H "X-4RHO-TIMESTAMP: $TIMESTAMP" \
  -H "X-4RHO-PASSPHRASE: $PASSPHRASE"

3. Get Market Data

# List all markets (public — no auth required)
curl -s https://api.4rho.com/v1/markets

# Get order book for a specific market
curl -s https://api.4rho.com/v1/orders/book/{market_id}

Quick Start (Python)

import hashlib
import hmac
import time
import requests

API_KEY = "4rho_your_key_here"
SECRET = "your_secret_here"
PASSPHRASE = "your_passphrase_here"
BASE_URL = "https://api.4rho.com"


def sign_request(method: str, path: str, body: str = "") -> dict:
    """Build authentication headers for a 4rho API request."""
    timestamp = str(int(time.time()))
    body_hash = hashlib.sha256(body.encode()).hexdigest()
    hmac_key = hashlib.sha256(SECRET.encode()).hexdigest()
    message = f"{timestamp}\n{method}\n{path}\n{body_hash}"
    signature = hmac.new(
        hmac_key.encode(), message.encode(), hashlib.sha256
    ).hexdigest()
    return {
        "X-4RHO-API-KEY": API_KEY,
        "X-4RHO-SIGNATURE": signature,
        "X-4RHO-TIMESTAMP": timestamp,
        "X-4RHO-PASSPHRASE": PASSPHRASE,
    }


# Fetch your profile
headers = sign_request("GET", "/v1/user/profile")
resp = requests.get(f"{BASE_URL}/v1/user/profile", headers=headers)
print(resp.json())

# List your open orders for a market
headers = sign_request("GET", "/v1/orders/open/{market_id}")
resp = requests.get(f"{BASE_URL}/v1/orders/open/{{market_id}}", headers=headers)
print(resp.json())

Next Steps