> 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/stock-operations/deposits-and-withdrawals.md).

# Deposits & Withdrawals

Stock endpoints move ERC-20 stock tokens between wallet balance and `Stock.stockBalance`. The API surfaces `Stock.stockBalance` as `exchangeBalance`.

Cash endpoints are separate. Use `/cash/**` only for cash-token flows into or out of `Cashier`.

## Build Stock Deposit Calldata

```
POST /api/v1/stock/deposits/calldata
```

| Field          | Type            | Required | Description                        |
| -------------- | --------------- | -------- | ---------------------------------- |
| `userAddress`  | string          | Yes      | User wallet.                       |
| `tokenAddress` | string          | Yes      | Stock token contract address.      |
| `tokenAmount`  | string / number | Yes      | Human-readable stock token amount. |

The user wallet must approve `StockRouter` for the stock token before the transaction can move wallet stock into `Stock`.

## One Click Stock Deposit

```
POST /api/v1/stock/deposits/send
```

| Field          | Type            | Required | Description                        |
| -------------- | --------------- | -------- | ---------------------------------- |
| `tokenAddress` | string          | Yes      | Stock token contract address.      |
| `tokenAmount`  | string / number | Yes      | Human-readable stock token amount. |
| `gasLimit`     | number          | No       | Optional gas limit.                |

Uses API key bound `userAddress`; do not include `userAddress` in the request body.

## Record Stock Deposit Tx

```
POST /api/v1/stock/deposits/tx
```

| Field    | Type   | Required | Description            |
| -------- | ------ | -------- | ---------------------- |
| `txHash` | string | Yes      | Stock deposit tx hash. |

## Query Stock Deposits

```
GET /api/v1/stock/deposits?page=1&limit=10
GET /api/v1/stock/deposits/{operationId}
```

## Build Stock Withdrawal Calldata

```
POST /api/v1/stock/withdrawals/calldata
```

| Field          | Type            | Required | Description                        |
| -------------- | --------------- | -------- | ---------------------------------- |
| `userAddress`  | string          | Yes      | User wallet.                       |
| `tokenAddress` | string          | Yes      | Stock token contract address.      |
| `tokenAmount`  | string / number | Yes      | Human-readable stock token amount. |

Withdrawals deduct `Stock.stockBalance` and transfer ERC-20 stock tokens to the wallet.

## One Click Stock Withdrawal

```
POST /api/v1/stock/withdrawals/send
```

| Field          | Type            | Required | Description                        |
| -------------- | --------------- | -------- | ---------------------------------- |
| `tokenAddress` | string          | Yes      | Stock token contract address.      |
| `tokenAmount`  | string / number | Yes      | Human-readable stock token amount. |
| `gasLimit`     | number          | No       | Optional gas limit.                |

Uses API key bound `userAddress`; do not include `userAddress` in the request body.

## Record Stock Withdrawal Tx

```
POST /api/v1/stock/withdrawals/tx
```

| Field    | Type   | Required | Description               |
| -------- | ------ | -------- | ------------------------- |
| `txHash` | string | Yes      | Stock withdrawal tx hash. |

## Query Stock Withdrawals

```
GET /api/v1/stock/withdrawals?page=1&limit=10
GET /api/v1/stock/withdrawals/{operationId}
```

`operationId` is an API/indexer identifier for looking up the recorded stock operation. The `Stock` contract emits deposit and withdrawal events, but those events do not include a contract-native `operationId`.
