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

# 订单心跳

> 客户端断开时自动取消你的订单

一种安全机制：发送带 `timeout`（单位为秒）的心跳。如果在 `timeout` 秒内未收到下一次心跳，**你的所有未成交订单将被取消**。

在任何会挂单的客户端中使用此端点 — 如果进程崩溃或失去连接，心跳可确保过期订单被撤下，而不是留在订单簿上。

<h2 id="request">
  请求
</h2>

`POST /user/ordersHeartbeat`

<ParamField body="timeout" type="integer" required>
  超时后取消，单位为秒。必须大于 `5`。
</ParamField>

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://api.4casters.io/user/ordersHeartbeat \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{"timeout": 30}'
  ```

  ```json JSON 请求体 theme={null}
  { "timeout": 30 }
  ```
</CodeGroup>

<h2 id="response">
  响应
</h2>

响应由订单服务转发：

```json theme={null}
{ "data": { /* heartbeat ack payload */ } }
```

<h2 id="errors">
  错误
</h2>

| 状态 | 含义 |
| - | - |
| `400` | `timeout` 缺失、不是数字，或 `<= 5`。 |
| `503` | 订单服务不可达。 |


## OpenAPI

````yaml POST /user/ordersHeartbeat
openapi: 3.1.0
info:
  title: 4casters REST API
  version: 1.0.0
  description: >-
    Public REST API for the 4casters peer-to-peer betting exchange. Use this API
    to manage your account, query the orderbook and games, and place / edit /
    cancel orders.


    All responses (unless noted otherwise) are JSON envelopes of the form `{
    "data": ... }`.
  contact:
    name: 4casters
    url: https://4casters.io
servers:
  - url: https://api.4casters.io
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Authentication
    description: Login and account session management
  - name: User
    description: Read account info, bets, and orders
  - name: Orders
    description: Place, edit, look up, and cancel orders
  - name: Markets
    description: Browse leagues, games, participants, and orderbooks
  - name: Affiliate
    description: Affiliate / referral commission
paths:
  /user/ordersHeartbeat:
    post:
      tags:
        - User
      summary: Send orders heartbeat
      description: >-
        A safety mechanism: send a heartbeat with a `timeout` (in seconds). If
        the next heartbeat is not received within `timeout` seconds, **all of
        your open orders are cancelled**. Use this to ensure that orders are
        pulled if your client loses connectivity.


        `timeout` must be greater than 5 seconds.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - timeout
              properties:
                timeout:
                  type: integer
                  minimum: 6
                  description: Cancel-after timeout, in seconds.
            example:
              timeout: 30
      responses:
        '200':
          description: >-
            Heartbeat acknowledged. The response shape is forwarded from the
            orders service.
        '400':
          description: Invalid timeout (must be > 5)
        '401':
          $ref: '#/components/responses/Unauthorized'
        '503':
          description: Orders service unreachable
components:
  responses:
    Unauthorized:
      description: Missing or invalid auth token
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Pass your auth token in the `Authorization` header. The `Bearer` prefix
        is optional; the server also accepts a signed `auth` cookie or a `token`
        field in the request body.

````

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