# Trading

## Trading

*Execute and manage trades — real and demo*

Open and close positions, place and cancel market and limit orders, and read live or demo PnL, portfolio, orders, and trade history. The Real and Demo APIs share the same shape: demo is a full-fidelity sandbox with simulated balances.

### What it provides

- Place market and limit (MIT) orders — open by amount or units, close by position ID
- Cancel pending open or close orders before execution
- Read real-time PnL, portfolio value, and equity for real and demo accounts
- Query full order and trade history with status, timestamps, and fill details
- Identical request patterns across `/trading/execution/.../real/...` and `.../demo/...` surfaces
- Demo sandbox with simulated balances for risk-free strategy validation

### What you can build

- Algorithmic trading bots with automated entry, exit, and position-sizing rules
- Portfolio dashboards that sync open positions, PnL, and equity with your app in real time
- Strategy backtesting on Demo before switching to Real execution with identical API calls
- Risk management systems that monitor position sizes and enforce stop-loss levels
- Multi-account trading orchestrators that place orders across several portfolios

### Builder journeys

- Personal investing
- Build apps & automations
- Enterprise integrations

### Recommended tools

- [REST Playground](/playground) — Try order and position endpoints live — edit parameters and see responses instantly.
- [Authentication guide](/learn/authentication-and-api-keys) — API keys, scopes, and secure credential handling for trading apps.
- [Algo trading guide](/learn/building-an-algo-trading-bot) — Build automated strategies with entry/exit rules, risk controls, and execution.

### Code examples

#### cURL

```bash
curl -X POST https://public-api.etoro.com/api/v1/trading/execution/open/demo/by-amount \
  -H "x-api-key: $ETORO_API_KEY" \
  -H "x-user-key: $ETORO_USER_KEY" \
  -H "x-request-id: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "instrumentId": 1001,
    "amount": 500,
    "isBuy": true,
    "leverage": 1
  }'
```

#### JavaScript

```javascript
const res = await fetch(
  "https://public-api.etoro.com/api/v1/trading/execution/open/demo/by-amount",
  {
    method: "POST",
    headers: {
      "x-api-key": process.env.ETORO_API_KEY,
      "x-user-key": process.env.ETORO_USER_KEY,
      "x-request-id": crypto.randomUUID(),
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      instrumentId: 1001,
      amount: 500,
      isBuy: true,
      leverage: 1,
    }),
  }
);

const order = await res.json();
console.log(order);
```


### Learn & docs

- [Building an Algo Trading Bot](/learn/building-an-algo-trading-bot) — Position management, risk controls, and automated strategy execution.
- [Portfolio Management & Position Tracking](/learn/portfolio-management-and-positions) — Track positions, P&L, balances, and manage your portfolio programmatically.
- [Building Your First Trading Bot](/blog/building-your-first-trading-bot) — Step-by-step demo Trading API walkthrough.
- [From Demo to Production](/blog/from-demo-to-production-trading-bot) — Moving from the demo sandbox to the real trading API.