> For the complete documentation index, see [llms.txt](https://docs.anchored.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.anchored.finance/trading-api/reference/api-contract-map.md).

# API ↔ Contract Map

This page maps partner API endpoints to the contract-level effect they prepare, submit, or query. Use it when debugging or explaining why an API call changes `mUSD`, `Stock.stockBalance`, or order state.

## Overview

```mermaid
flowchart TB
    API[Trading API] --> Router[StockRouter]
    Router --> Cashier[Cashier]
    Router --> Stock[Stock]
    Stock --> Cashier
```

## Market and Portfolio

| Endpoint                                | Contract relationship                       | Effect                                             |
| --------------------------------------- | ------------------------------------------- | -------------------------------------------------- |
| `GET /api/v1/symbols`                   | Reads backend/token registry                | Lists tradable stock tokens and contract addresses |
| `GET /api/v1/prices/{symbol}`           | Off-chain quote plus on-chain token context | Quote display; no state change                     |
| `GET /api/v1/prices/{symbol}/history`   | Market data                                 | Historical display; no state change                |
| `GET /api/v1/underlying/{symbol}/price` | Market data                                 | Underlying quote; no state change                  |
| `GET /api/v1/corporate-action`          | Corporate action data                       | Split/dividend data; no state change               |
| `GET /api/v1/users/{userId}/balance`    | Cashier + token balances + allowance        | Portfolio, buy power, deposit readiness            |
| `GET /api/v1/users/{userId}/positions`  | Indexed Stock state                         | Stock positions                                    |

## Orders

| Endpoint                                    | Contract relationship                                                                                                       | Effect                                           |
| ------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
| `POST /api/v1/orders/calldata`              | Encodes `StockRouter.placeMarketOrder` or `placeLimitOrder`                                                                 | Returns tx data; no state change until submitted |
| `POST /api/v1/orders/send`                  | OneClickRouter forwards to StockRouter                                                                                      | Places order and auto-records tx                 |
| `POST /api/v1/orders/with-deposit/calldata` | Encodes `StockRouter.depositAndMarketBuy`, `depositAndLimitBuy`, `depositStockAndMarketSell`, or `depositStockAndLimitSell` | Returns tx data for combined deposit + order     |
| `POST /api/v1/orders/with-deposit/send`     | OneClickRouter forwards combined deposit + order                                                                            | Submits combined flow and auto-records tx        |
| `POST /api/v1/orders/tx`                    | API/indexer mapping                                                                                                         | Links self-submitted tx to API key               |
| `GET /api/v1/orders`                        | API order mapping / indexed state                                                                                           | Lists mapped orders                              |
| `GET /api/v1/orders/tx/{txHash}`            | API tx mapping                                                                                                              | Finds order by tx                                |
| `GET /api/v1/orders/{orderId}`              | Indexed Stock state                                                                                                         | Shows open or historical order                   |
| `DELETE /api/v1/orders/{orderId}/calldata`  | Encodes `StockRouter.cancelLimitOrder`                                                                                      | Returns cancel tx data                           |
| `DELETE /api/v1/orders/{orderId}/send`      | OneClickRouter forwards cancel                                                                                              | Cancels via delegated execution                  |

## Cash

| Endpoint                                     | Contract relationship              | Effect                             |
| -------------------------------------------- | ---------------------------------- | ---------------------------------- |
| `POST /api/v1/cash/deposits/calldata`        | Encodes `StockRouter.deposit`      | Returns deposit tx data            |
| `POST /api/v1/cash/deposits/send`            | OneClickRouter forwards deposit    | Deposits from bound user           |
| `POST /api/v1/cash/deposits/tx`              | API/indexer mapping                | Links self-submitted deposit tx    |
| `GET /api/v1/cash/deposits`                  | Indexed Cashier state              | Lists deposits                     |
| `GET /api/v1/cash/deposits/{operationId}`    | Cash operation state               | Deposit detail and status          |
| `POST /api/v1/cash/withdrawals/calldata`     | Encodes `StockRouter.withdraw`     | Returns withdrawal tx data         |
| `POST /api/v1/cash/withdrawals/send`         | OneClickRouter forwards withdrawal | Withdraws from bound user          |
| `POST /api/v1/cash/withdrawals/tx`           | API/indexer mapping                | Links self-submitted withdrawal tx |
| `GET /api/v1/cash/withdrawals`               | Indexed Cashier state              | Lists withdrawals                  |
| `GET /api/v1/cash/withdrawals/{operationId}` | Cash operation state               | Withdrawal detail and status       |

## Stock

| Endpoint                                      | Contract relationship                    | Effect                                   |
| --------------------------------------------- | ---------------------------------------- | ---------------------------------------- |
| `POST /api/v1/stock/deposits/calldata`        | Encodes `StockRouter.depositStock`       | Returns stock deposit tx data            |
| `POST /api/v1/stock/deposits/send`            | OneClickRouter forwards stock deposit    | Deposits stock from bound user           |
| `POST /api/v1/stock/deposits/tx`              | API/indexer mapping                      | Links self-submitted stock deposit tx    |
| `GET /api/v1/stock/deposits`                  | Indexed Stock state                      | Lists stock deposits                     |
| `GET /api/v1/stock/deposits/{operationId}`    | Stock operation state                    | Stock deposit detail                     |
| `POST /api/v1/stock/withdrawals/calldata`     | Encodes `StockRouter.withdrawStock`      | Returns stock withdrawal tx data         |
| `POST /api/v1/stock/withdrawals/send`         | OneClickRouter forwards stock withdrawal | Withdraws stock from bound user          |
| `POST /api/v1/stock/withdrawals/tx`           | API/indexer mapping                      | Links self-submitted stock withdrawal tx |
| `GET /api/v1/stock/withdrawals`               | Indexed Stock state                      | Lists stock withdrawals                  |
| `GET /api/v1/stock/withdrawals/{operationId}` | Stock operation state                    | Stock withdrawal detail                  |

For stock deposit and withdrawal detail endpoints, `operationId` is an API/indexer lookup identifier. It is not emitted as a native field by `Stock.depositStock` or `Stock.withdrawStock` events.

## One Click

| Endpoint                   | Contract relationship                  | Effect                 |
| -------------------------- | -------------------------------------- | ---------------------- |
| `GET /api/v1/1ct/status`   | Reads OneClickRouter delegate state    | Shows delegation state |
| `POST /api/v1/1ct/prepare` | Builds EIP-712 delegate payload        | No state change        |
| `POST /api/v1/1ct/enable`  | Calls `delegateBySig` through operator | Enables delegatee      |
| `POST /api/v1/1ct/disable` | Calls undelegate flow                  | Disables delegation    |

## Invariants for Integrators

* API calldata targets `StockRouter`; do not call Cashier or Stock directly.
* Buy orders lock `mUSD` in Cashier.
* Plain sell orders lock `Stock.stockBalance`, surfaced by the API as `exchangeBalance`.
* Order settlement updates `mUSD` and `exchangeBalance` asynchronously after execution.
* Cash operations can be instant or queued depending on Cashier buffers.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.anchored.finance/trading-api/reference/api-contract-map.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
