> ## Documentation Index
> Fetch the complete documentation index at: https://docs.itoflow.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Broker connections

> Connect a Trading 212 account, check its status and holdings, and disconnect it.

> [!TIP]
>
> **The easiest way: ask your AI assistant.** With [Itoflow MCP](https://docs.itoflow.ai/mcp/install.md) connected to Claude or Codex, paste:
>
> ```text theme={null}
> Use Itoflow to show my broker connections and tell me if any needs reconnecting.
> ```
>
> > [card] [Open in Claude](https://claude.ai/new?q=Use%20the%20Itoflow%20plugin%20\(https%3A%2F%2Fgithub.com%2Fitoflow%2Fskills\)%20for%20this.%20If%20it%20isn't%20installed%20yet%2C%20first%20tell%20me%20how%20to%20install%20it%20and%20sign%20in%20to%20Itoflow%2C%20and%20wait%20until%20I%20confirm.%20Then%3A%0A%0AUse%20Itoflow%20to%20show%20my%20broker%20connections%20and%20tell%20me%20if%20any%20needs%20reconnecting.)
> >
> > Start this in Claude with the Itoflow plugin.
>
> > [card] [Open in ChatGPT](https://chatgpt.com/?q=Use%20the%20Itoflow%20plugin%20\(https%3A%2F%2Fgithub.com%2Fitoflow%2Fskills\)%20for%20this.%20If%20it%20isn't%20installed%20yet%2C%20first%20tell%20me%20how%20to%20install%20it%20and%20sign%20in%20to%20Itoflow%2C%20and%20wait%20until%20I%20confirm.%20Then%3A%0A%0AUse%20Itoflow%20to%20show%20my%20broker%20connections%20and%20tell%20me%20if%20any%20needs%20reconnecting.)
> >
> > Start this in ChatGPT with the Itoflow plugin.
>
> Using another client? Copy the prompt with the button on the code block.
>
> To connect a broker, use the [app](https://app.itoflow.ai/settings/brokers); never paste broker keys into a chat. The rest of this page covers the HTTP API.

A broker connection links your brokerage account to Itoflow so a live portfolio can read holdings and, after your approval, place trades. Itoflow supports **Trading 212**. Connecting any other broker returns `400 UNSUPPORTED_BROKER`.

```mermaid theme={null}
flowchart LR
  Connect[Start connection] --> Provider[Supply broker API keys]
  Provider --> Status[Connection status]
  Status --> Holdings[Holdings and margins]
  Status --> Reconnect[Reconnect when needed]
```

We recommend connecting a broker in the [Itoflow app](https://app.itoflow.ai/settings/brokers), which guides you through each broker's steps. The endpoints below do the same thing.

## Connect

`POST /brokers/connect` with `"broker_type": "trading212"`. Send your API key and secret as `api_key` and `api_secret`, and a `permissions` object. The key needs all eight permissions set to `true`: `metadata`, `account_data`, `portfolio`, `orders_execute`, `orders_read`, `history_orders`, `history_transactions` and `history_dividends`. If any is missing, you get `400 MISSING_REQUIRED_PERMISSIONS` with the missing ones in `details`. The call connects straight away and returns `connection_id`, `sync_status` and `portfolio_id`. Treat the key and secret like passwords: load them from a secret store, never from source code, and don't log them.

Then poll `GET /brokers/{connectionId}/status` until the connection is ready. A successful connect doesn't mean holdings have synced yet.

## Read

| Endpoint | Returns |
| - | - |
| `GET /brokers/connections` | Your broker connections |
| `GET /brokers/{connectionId}/status` | Connection state |
| `GET /brokers/{connectionId}/holdings` | Holdings at the broker, with currencies and sync times |
| `GET /brokers/{connectionId}/margins` | Cash and margin |

## Reconnect

When the status says a reconnect is needed, call `POST /brokers/{connectionId}/reconnect`. Trading 212 also has:

* `POST /brokers/{connectionId}/trading212/reconnect` to reconnect with a new key and secret.
* `POST /brokers/{connectionId}/trading212/reconnect-stored` to retry with the key Itoflow already holds.
* `POST /brokers/trading212/connect-manual`, another way to connect with an API key.

## Disconnect

`DELETE /brokers/{connectionId}` disconnects the account. The response doesn't tell you what happened to open positions or orders, so first check any live portfolio that uses the connection and cancel its pending trades.

A connection ID only works for the account that owns it.

See the [broker endpoint reference](https://docs.itoflow.ai/api-reference/coverage.md#brokers) for each broker's fields and errors.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.