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

# Connect a provider

> Create your venue's connection to a provider version, check it, bind the accounts it finds and promote it, so your groups can use it.

Connect your venue to a provider with your own credential. A connection is your venue's login at a
provider, through one provider version, in one environment. You create it as a draft, trdrs checks
it against the provider's manifest, and you promote it on a check that passed. Nothing is contacted
until you check it, and no check places an order.

Use this page once your venue holds a provider version, registered for your own provider as [Add
your own provider](https://docs.trdrs.co/providers/build-a-provider.md) describes. By the end you have a validated connection, with its accounts bound to your venue where
the provider holds accounts.

> [!NOTE]
>
> These routes are a preview. They're served on the sandbox to every venue, and production
> availability is arranged when your venue qualifies. Trading API keys and pre-registration keys
> don't authorize them. The back office runs the same steps under **Connections**.

## Before you start

* A Venue key on your server. Creating, checking and promoting a connection needs
  `connection:manage`, reading needs `venue:read`, and binding an account also needs
  `account:issue`.
* The provider version's id, from `GET /api/venues/{venueId}/providers`.
* The credential the provider issued your venue. For a private integration, also its HTTPS base
  URL: a public hostname on port 443, with no credentials, query or fragment. trdrs calls nothing
  else, so an IP address or a local name never works.

The examples use the variables the [venue quickstart](https://docs.trdrs.co/guides/business-quickstart.md) set:

```bash theme={null}
export TRDRS_API_BASE_URL=https://sandbox.trdrs.co
# TRDRS_VENUE_ID and TRDRS_VENUE_KEY are set in your server's environment.
```

## Create the connection

Create a draft connection to the provider version. trdrs stores the credential encrypted, bound to
this connection, and never returns it. `endpoint` is your provider service's public HTTPS address.

Required scope: `connection:manage`.

```bash theme={null}
curl --fail-with-body -X POST "$TRDRS_API_BASE_URL/api/venues/$TRDRS_VENUE_ID/connections" \
  -H "Authorization: Bearer $TRDRS_VENUE_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "providerVersionId": "PROVIDER_VERSION_ID",
    "endpoint": "https://provider.example.com/trdrs-provider/v1/",
    "credentialId": "sandbox-login",
    "credential": "THE_SECRET_THE_PROVIDER_ISSUED",
    "environment": "sandbox"
  }'
```

The response is the connection in `state: "draft"`, with `hasCredential: true` and its `version`.
Keep its `id`. `credentialId` is your own name for the credential, at most 128 characters, and the
credential itself is at most 8,192 printable characters with no spaces.

## Check it

Queue a read-only check. trdrs fetches the provider's manifest and compares it with the provider
version, and for a provider that holds accounts it then lists every account your credential can
see. Send an empty JSON body.

Required scope: `connection:manage`.

```bash theme={null}
curl --fail-with-body -X POST \
  "$TRDRS_API_BASE_URL/api/venues/$TRDRS_VENUE_ID/connections/$CONNECTION_ID/validate" \
  -H "Authorization: Bearer $TRDRS_VENUE_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{}'
```

The answer is `202` with a `validation` in `state: "pending"`. Poll
`GET /api/venues/{venueId}/connections/{connectionId}/validations/{jobId}` until its `state` is
`passed` or `failed`. A failure, an expiry or a lost permission never reads as a pass, and
`tradingReady` is always `false`: a pass proves the manifest and changes nothing else.

A failed check names what it saw in `resultCode`, and provider errors are redacted:

| `resultCode` | What it means |
| - | - |
| `transport_failed` | trdrs couldn't read the manifest, or `GET /ready` didn't answer `{ "ready": true }`. Check the endpoint and the credential. |
| `invalid_manifest` | The manifest, or the 1.1 manifest, doesn't parse under the provider contract. |
| `manifest_mismatch` | The provider answers a different manifest from the one this provider version holds. |
| `invalid_connection_description` | A 1.1 provider that describes its connections didn't describe this one. |
| `provider_mismatch` | The login reaches another company than the one the provider version is linked to. |
| `environment_upstream_mismatch` | The provider describes another environment, a `test` upstream for production, or live trading for the sandbox. |
| `discovery_failed` | The provider holds accounts, and trdrs couldn't list them. |

## Bind the accounts it found

Skip this step for a provider that serves prices alone. When a check of kind
`manifest_and_accounts` passes, its `discoverySnapshotId` names the accounts it found. List them
with `GET /api/venues/{venueId}/connections/{connectionId}/accounts`, 500 to a page, and bind the
ones you want with
[`POST /api/venues/{venueId}/accounts/bind`](https://docs.trdrs.co/api-reference/venue-platform-preview/bind-a-discovered-external-account).
The list lasts only as long as the provider's grant, at most 60 seconds, so bind soon after the
check passes.

Required scopes: `connection:manage` and `account:issue`.

A bound account keeps the position model the provider reports, `net` or `hedged`. To bind a hedge
account instead, [Hedge venue exposure](https://docs.trdrs.co/guides/venue-hedging.md) covers the extra scopes it needs.

## Promote it

Promote the connection on that passed check. Send the connection's `version` as you read it as
`expectedVersion`, and the check's id as `validationJobId`.

Required scope: `connection:manage`.

```bash theme={null}
curl --fail-with-body -X POST \
  "$TRDRS_API_BASE_URL/api/venues/$TRDRS_VENUE_ID/connections/$CONNECTION_ID/promote" \
  -H "Authorization: Bearer $TRDRS_VENUE_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{ "expectedVersion": 1, "validationJobId": "VALIDATION_JOB_ID" }'
```

The response is the connection in `state: "validated"`. The same request again answers what it
answered the first time. A validated connection still isn't ready to trade on its own: a group's
route has to name it, and an order still needs a bound account, margin, a fresh price and a live
account stream.

| Refusal | What it means |
| - | - |
| `version_conflict` | The connection moved on from the version you sent. Read it again. |
| `validation_not_passed` | The check isn't this connection's, didn't pass or hasn't finished. |
| `validation_stale` | A newer check of the connection finished, or the check read another connection version, another manifest, or for a version pinned to 1.1 not its 1.1 manifest. Check again. |
| `endpoint_not_declared` | The 1.1 manifest declares environments and not this connection's endpoint for its own. |
| `environment_upstream_mismatch` | A production connection on a `test` upstream, or a sandbox connection that would trade live. |

## Keep it running

A connection is in one of four states, and `GET /api/venues/{venueId}/connections` shows each
connection's state without its credential.

| State | What it means |
| - | - |
| `draft` | Created and not yet promoted. |
| `validated` | Promoted on a check that passed. |
| `halted` | A later check failed on what the provider answered. It takes no new exposure, while reductions and reads go on. |
| `revoked` | Revoked for good, as when your venue retires. |

Check a validated connection again whenever you want proof it still matches. A check that fails on
what the provider answered halts it until you promote it again on a check that passed. A check that
never reached the provider for the connection's current version, because the connection changed or
the requester lost their access, halts nothing.

Each check reads the provider's manifest, and its 1.1 manifest for a version pinned to 1.1, and
fails `manifest_mismatch` when either changed from the version you hold. With a connection
description, it also fails `provider_mismatch` when the login reaches another company than the one
the provider version is linked to.

A provider you plugged in is hidden from your traders by default. Show it in Connect, to traders
holding an account your venue issued, with
`POST /api/venues/{venueId}/connections/{connectionId}/expose`. Retire a provider version you no
longer use with `POST /api/venues/{venueId}/providers/{providerId}/retire`, once no connection that
isn't revoked names it.

## Test it end to end

Run the whole path in the sandbox before you plan for production:

1. Create a sandbox connection, check it and promote it. `GET /api/venues/{venueId}/connections`
   shows it `validated`.
2. For a provider that holds accounts, bind one discovered account and route a test group through
   the connection, as [Run a venue](https://docs.trdrs.co/guides/run-a-venue.md) describes.
3. For a provider that serves prices, read its symbol list and add one market, as
   [Add a provider's markets](https://docs.trdrs.co/guides/add-provider-markets.md) describes.

## Next steps

> [card] [Add a provider's markets](https://docs.trdrs.co/guides/add-provider-markets.md)
>
> List the markets your connection's provider states, priced from your own connection.

> [card] [Run a venue](https://docs.trdrs.co/guides/run-a-venue.md)
>
> Route a group's orders through the connection.

> [card] [Add your own provider](https://docs.trdrs.co/providers/build-a-provider.md)
>
> Implement the provider contract and add the provider to your venue.

> [card] [Hedge venue exposure](https://docs.trdrs.co/guides/venue-hedging.md)
>
> Hedge in an account your venue owns at a connected provider.


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