# 自行提交链上交易

适用于接入方自行管理私钥或托管钱包的场景。

## 操作步骤

```mermaid
sequenceDiagram
    participant 客户端
    participant API
    participant 链上
    participant Indexer

    客户端->>API: POST /orders/calldata
    API-->>客户端: calldata + toAddress
    客户端->>链上: 提交交易
    链上-->>客户端: txHash
    客户端->>API: POST /orders/tx { txHash }
    API-->>客户端: 映射记录
    Indexer->>API: 解析链上事件，回填 orderId
    客户端->>API: GET /orders/{orderId}
    API-->>客户端: 订单状态
```

## 步骤说明

1. 调用 `/api/v1/orders/calldata`、`/api/v1/cash/deposits/calldata` 或 `/api/v1/cash/withdrawals/calldata` 获取 `toAddress`、`value`、`callData`。
2. 接入方使用自己的钱包系统将交易提交到链上。
3. 获取链上 `txHash` 后，调用对应的 `/tx` 接口记录交易。
4. Indexer 解析链上事件后，按 `txHash` 回填 `orderId` 或 `operationId`。
5. 使用查询接口追踪状态。

## 交易记录接口

| 操作类型 | 接口                                 |
| ---- | ---------------------------------- |
| 下单   | `POST /api/v1/orders/tx`           |
| 入金   | `POST /api/v1/cash/deposits/tx`    |
| 出金   | `POST /api/v1/cash/withdrawals/tx` |

## 状态查询接口

| 操作类型 | 接口                                                              |
| ---- | --------------------------------------------------------------- |
| 下单   | `GET /api/v1/orders/tx/{txHash}`、`GET /api/v1/orders/{orderId}` |
| 入金   | `GET /api/v1/cash/deposits/{operationId}`                       |
| 出金   | `GET /api/v1/cash/withdrawals/{operationId}`                    |

{% hint style="warning" %}
同一个 API Key 重复提交同一 `txHash` 时，接口返回已有映射；该 `txHash` 已被其他 API Key 记录时，接口返回错误。
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.anchored.finance/trading-api-docs-zh/jie-ru-liu-cheng/self-submit.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
