# 시작하기

5분 안에 첫 번째 예측 마켓 주문을 체결하세요. SDK 없이 curl만으로 가능합니다.

**아래 모든 curl은 실제 라이브 API를 대상으로 실행됩니다.** 1단계에서 익명 샌드박스 키를 발급받습니다(30초 소요, 이메일 불필요). 샌드박스 등급은 주문 건당 $10, 일일 $100 한도로 설정되어 있어 입력하는 내용으로 실제 자금이 이동하지 않습니다. 주문은 프로덕션과 동일한 검증 및 등급 한도를 거친 후 시뮬레이션으로 체결됩니다: 키는 1,000 가상 USDT로 시작하며, 응답에는 `is_simulated: true`가 포함됩니다.

## 1단계 — 샌드박스 키 발급

공개 엔드포인트, 인증 불필요. IP당 1회 + 브라우저 지문당 1회, 하루 요청 한도.

```
curl -X POST https://api.predictasiax.com/v1/sandbox-keys \
  -H "Content-Type: application/json" \
  -d '{"org_name":"my-test"}'
```

응답 — `sk`를 즉시 복사하세요. 한 번만 표시됩니다:

```
{
  "data": {
    "sk":            "sk_live_7d40ce10_12b638913cadfbbd...",   // your bearer, shown ONCE
    "api_key_id":    "api_sbx_...",
    "builder_id":    "bld_sbx_...",
    "app_id":        "app_sbx_...",
    "tier":          "sandbox",
    "caps":          { "max_order_usdt": "10", "daily_notional_usdt": "100" },
    "expires_at_ms": 1789741484472,                            // 30 days out
    "sandbox_url":   "https://api.predictasiax.com",
    "docs_url":      "https://docs.predictasiax.com/getting-started",
    "upgrade_url":   "https://docs.predictasiax.com/request-access"
  },
  "meta": { "ts_ms": 1787149484561, "trace_id": "trc_..." }
}

# Save it:
export SK=sk_live_7d40ce10_12b638913cadfbbd...
```

샌드박스 키가 유출된 경우, 해당 키를 사용하여 폐기할 수 있습니다: `curl -X DELETE https://api.predictasiax.com/v1/keys/self -H "Authorization: Bearer $SK"`.

해당 키는 `tier=sandbox` 태그가 붙은 방금 생성된 익명 Builder에 속하며, 생성일로부터 30일 후 만료됩니다. 프로덕션에서 허용되는 `sk_live_` 접두사를 사용하며, 등급 플래그가 주문을 건당 $10, 일일 명목 금액 $100으로 엄격하게 제한합니다.

## 2단계 — 마켓 목록 조회

마켓은 predictasiax.com의 라이브 마켓입니다. 하나를 선택하고 다음 단계(`MARKET_ID=...`)를 위해 그 `id`를 유지하세요:

```
curl "https://api.predictasiax.com/v1/markets?q=btc" \
  -H "Authorization: Bearer $SK"
```

응답 (축약):

```
{
  "data": {
    "markets": [
      {
        "id":        "m_btc_150k_2026",
        "title":     "BTC > $150k by end of 2026",
        "category":  "crypto",
        "prices":    { "yes": "0.4200", "no": "0.5800" },
        "volume_usd":"12345.67",
        "status":    "open",
        "closes_at_ms": 1798700400000
      }
    ]
  }
}
```

## 3단계 — $1 주문 제출

$0.55에 `yes` 주식 2개를 매수 = $1.10 명목 금액 — 샌드박스 $10 한도 내. 쓰기 요청에는 `Idempotency-Key`이 필수이며 `[A-Za-z0-9_-]{8,128}` 형식과 일치해야 합니다. 동일한 값으로 재시도해도 안전합니다.

```
IDEM=$(uuidgen | tr -d '-' | cut -c1-24)
curl -X POST https://api.predictasiax.com/v1/orders \
  -H "Authorization: Bearer $SK" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: ${IDEM}" \
  -d '{
    "market_id":       "'"$MARKET_ID"'",
    "side":            "yes",
    "price":           "0.55",
    "size":            "2",
    "client_order_id": "cli-001"
  }'
```

**주문 규칙.** `size`는 소수점 이하 6자리 이하의 일반 십진수입니다; `price`는 0.0001–0.9999 사이이며 소수점 이하 4자리 이하입니다 (지수형 숫자(예: `1e-7`)는 거부됩니다). 일반 시장에서는 `limit` 및 `post_only` 가격이 틱 그리드에 있어야 합니다: 0.04~0.96 사이에서는 0.01 단위, 0.04 미만 및 0.96 초과에서는 0.001 단위; 그리드 외 주문은 `rejectReason: invalid_tick` 및 적용되는 `tick`과 함께 거부됩니다. 주문 가치는 `size × price`이며 1~100,000 USDT 사이여야 합니다. 이 규칙을 벗어난 주문은 `400 INVALID_FIELD`, `BELOW_MIN_NOTIONAL` 또는 `ABOVE_MAX_NOTIONAL`을 반환합니다.

샌드박스 키를 사용하면 주문이 시뮬레이션됩니다. 현재 마켓 가격 이상이면 해당 가격으로 체결되고, 미만이면 대기 상태(`status: "open"`, `reserved_usdt`에 보유된 금액)가 되며, 주문, 포지션, 잔액 또는 포트폴리오를 조회할 때마다 가격이 지정가에 도달하면 체결됩니다:

```
{
  "data": {
    "order_id":           "sbx_ord_...",
    "client_order_id":    "cli-001",
    "market_id":          "...",
    "side":               "yes",
    "limit_price":        "0.55",
    "size":               2,
    "filled_size":        2,
    "status":             "filled",
    "fill_price":         "0.42",
    "fill_notional_usdt": "0.84",
    "reserved_usdt":      "0",
    "is_simulated":       true
  },
  "meta": { "trace_id": "...", "is_simulated": true }
}
```

가상 잔액으로 주문을 커버할 수 없는 경우 주문이 생성되지 않습니다: `{"data": {"ok": false, "status": "REJECTED", "reject_reason": "insufficient_balance", ...}}`. `DELETE /v1/orders/{order_id}`로 취소합니다(예약금이 반환됩니다). 샌드박스 포지션은 현재 가격으로 평가되며 마켓이 정산될 때 정산되지 않습니다.

잔액이 있는 프로덕션 키에서 체결 시 주문 및 수수료 분배가 반환됩니다(예시 — 정확한 `splits` 블록은 체결 시점에 PAX Adaptive Fee 곡선에 의해 서버 측에서 파생됩니다):

```
{
  "data": {
    "order": {
      "order_id":     "ord_...",
      "status":       "filled",
      "filled_size":  "2",
      "fill_price":   "0.4200",
      "created_at_ms":1787149484561
    },
    "fee": {
      "taker_fee_bps":   20,                // PAF centre at 50/50, floor 8, ceiling 25
      "fee_total":       "0.001680",        // 20 bps of $0.84 notional
      "splits": {
        "acquisition_builder": "0.000000",  // unfilled → absorbed by platform_net
        "execution_builder":   "0.000000",  // 0 bps — builders earn their builder fee instead
        "operator":            "0.000000",  // 0 bps — PAX is the only operator; carried in platform_net
        "market_creator":      "0.000000",  // unfilled → absorbed by platform_net
        "mm_stipend_pool":     "0.000420",  // 5 bps — funds LQF-scored MM stipends
        "lp":                  "0.000168",  // 2 bps — pooled LP holder distribution
        "platform_net":        "0.001092"   // 10 bps residual + 3 (mc absorbed)
      },
      "attribution": {
        "execution_builder_id":   "sb_d5b09d2a...",   // your builder
        "acquisition_builder_id": null,
        "operator_id":            "op_pax_v3",
        "market_creator_id":      null,
        "builder_tier":           "trade_capped",
        "unfilled_roles":         ["acquisition_builder","market_creator"]
      }
    }
  }
}
```

`splits` 블록은 7개 액터 PAF 분배(acquisition_builder / execution_builder / operator / market_creator / mm_stipend_pool / lp / platform_net)를 통해 플랫폼 장부에 멱등한 `financial_event` 행을 기록합니다. 미할당 어트리뷰션 역할은 `platform_net`이 흡수하여 수익을 보호합니다. **적응형 테이커 수수료**: `feeBps = clamp(PAF_BASE_BPS · 4 · p · (1−p), PAF_FLOOR_BPS, PAF_CEILING_BPS)`, 기본 20, 하한 8, 상한 25 — 50/50 근처에서 정점에 도달하고 극단값에서 감소합니다. 전체 모델 및 버킷 비율은 [수수료 구조](https://docs.predictasiax.com/ko/fee-architecture)를 참조하세요.

## 단계 4 — 한도 초과 요청 (등급 한도 동작 확인)

$10 이상의 주문을 시도해 보세요:

```
IDEM=$(uuidgen | tr -d '-' | cut -c1-24)
curl -X POST https://api.predictasiax.com/v1/orders \
  -H "Authorization: Bearer $SK" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: ${IDEM}" \
  -d '{
    "market_id":"'"$MARKET_ID"'",
    "side":"yes","price":"0.50","size":"100",
    "client_order_id":"too-big"
  }'
```

응답 — 429 `TIER_LIMIT_EXCEEDED`:

```
{
  "error": {
    "code":    "TIER_LIMIT_EXCEEDED",
    "message": "order notional 50.00 exceeds tier max_order_usdt 10",
    "details": { "tier": "sandbox", "cap": "10" }
  }
}
```

한도를 해제하고 실제 거래를 하려면 프로덕션 키를 발급받으세요([접근 요청](https://docs.predictasiax.com/ko/request-access), 심사 없음) 그리고 거래량을 발생시키면 자동으로 등급이 상향됩니다. `trade_capped`(주문당 $100, 일일 $1k)는 30일 어트리뷰션 거래량 $1,000 도달 시, `trade_full`(한도 없음)은 $50,000 도달 시 해제됩니다. 업그레이드 요청이나 수동 절차가 필요하지 않으며, [요청 한도 → 등급 상향](https://docs.predictasiax.com/ko/rate-limits#upgrade)을 참조하세요.

## 5단계 — 포트폴리오 조회

```
curl "https://api.predictasiax.com/v1/portfolio" \
  -H "Authorization: Bearer $SK"
```

마크 가격 재계산(실시간 미실현 손익)이 포함된 현재 포지션을 반환합니다.

## 6단계 — 주문 취소

동등한 두 가지 형식 — 클라이언트에서 더 깔끔한 쪽을 선택하세요:

```
# Canonical
curl -X DELETE https://api.predictasiax.com/v1/orders/ord_... \
  -H "Authorization: Bearer $SK"

# Alias (useful when your HTTP client can't send DELETE)
curl -X POST https://api.predictasiax.com/v1/orders/ord_.../cancel \
  -H "Authorization: Bearer $SK"
```

체결된 주문은 `STATE_CONFLICT`를 반환합니다(체결된 주문은 취소할 수 없음); 미체결 주문은 `cancelled` 상태로 전환됩니다.

## 다음 단계

- [인증 가이드](https://docs.predictasiax.com/ko/auth) — Bearer sk_live_* + OAuth 2.1
- [REST API 레퍼런스](https://docs.predictasiax.com/openapi) — 전체 스키마 + 검증기 엔드포인트
- [WebSocket API 레퍼런스](https://docs.predictasiax.com/asyncapi) — 이벤트 카탈로그
- [오류 코드](https://docs.predictasiax.com/ko/errors) — 실패를 적절하게 처리하세요
- [요청 한도](https://docs.predictasiax.com/ko/rate-limits) — 스코프별 예산, 모든 등급에서 동일
- [수수료 구조](https://docs.predictasiax.com/ko/fee-architecture) — PAF + LQF + 7-actor 분배
- [FAQ](https://docs.predictasiax.com/ko/faq)
- [다운로드](https://docs.predictasiax.com/ko/downloads) — OpenAPI / AsyncAPI 스펙 + Postman 컬렉션

**프로덕션으로 전환하시나요?** 동일한 호스트, 동일한 base URL — `https://api.predictasiax.com/v1`. [Request access](https://docs.predictasiax.com/ko/request-access)를 제출하여 Builder를 `sandbox`에서 `trade_capped` 또는 `trade_full` 등급으로 전환하세요. 환경 변경이나 키 재발급이 필요하지 않습니다.

Source: https://docs.predictasiax.com/ko/getting-started
