# Buy and sell an asset

This example starts with 150 synthetic USD and uses it to buy and sell four shares of the US-listed iShares China Large-Cap ETF (`US-FXI`). Use your [wallet’s network](https://docs.replica.finance/reference/networks.md#network-hosts) throughout.

## Quote the share

Send [`GET /assets/US-FXI/quote?currency=USD`](https://docs.replica.finance/reference/quotes.md). Check the symbol in `data.public.asset.name` and the price per share in `data.public.quote.price_per_unit`. Suppose the quote is 32.00 USD and you’re willing to pay up to 32.50 USD per share. For four shares, you need at most 130 synthetic USD.

## Buy the share

Send this body to [`POST /wallets/{address}/trades`](https://docs.replica.finance/reference/trades.md). Set the maximum **per share** to 32.50 USD. For each trade, send `Content-Type: application/json`, `Authorization: Bearer <trade-token>`, and a fresh UUIDv4 or UUIDv7 in `Idempotency-Key`. Reuse the same request and key if you retry within three hours of acceptance.

```json
{
  "operation": "buy",
  "asset": { "id": "US-FXI", "units": "4" },
  "quote": { "currency": "USD", "maximum_price_per_unit": "32.50" }
}
```

At 32.00 USD per share, the receipt shows `"128"` in `data.public.quote.amount`. That is the synthetic USD spent. If the price exceeds your limit, the API returns `409` and the trade ends.

## Sell and check the proceeds

When you’re ready to sell, choose the minimum price you’ll accept per share. To sell all four shares for at least 31.50 USD per share, send this body to the same endpoint.

```json
{
  "operation": "sell",
  "asset": { "id": "US-FXI", "units": "4" },
  "quote": { "currency": "USD", "minimum_price_per_unit": "31.50" }
}
```

Read `data.public.quote.amount` in the sale receipt for the synthetic USD received. Subtract the buy receipt’s amount to find the gain or loss. A sale at 31.50 USD per share returns 126 synthetic USD, a loss of 2. Your [balances](https://docs.replica.finance/reference/balances.md) show the remaining 148 synthetic USD under `fiat-USD`.
