> ## 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.

# Add your own provider

> Implement the provider contract for a provider trdrs doesn't reach yet, add it to your venue, and maintain it as your own.

Add a provider trdrs doesn't reach yet, such as a liquidity provider, an exchange or a brokerage, to
your own venue. You write a service that answers the trdrs provider contract on one side and speaks
the provider's own protocol on the other. trdrs calls your service, and your service never calls
trdrs. Your venue registers it, uses it for itself and maintains it, and no other venue sees it.

Use this page if you're the developer adding that provider for your venue. By the end you know every
route trdrs calls, what your manifest declares, the rules that keep a retried or uncertain order from
trading twice, and how your venue puts the provider to use. [Serve prices and
symbols](https://docs.trdrs.co/providers/serve-market-data.md) covers the market data routes, and [Provider
conformance](https://docs.trdrs.co/providers/provider-conformance.md) proves the result.

> [!NOTE]
>
> The reference provider, the conformance suites and the starters are in the
> `@trdrs/reference-provider` package, which isn't published to npm today. Ask your trdrs contact
> how to run it before you plan your tests around it.

## Know what your service does

The provider contract uses HTTPS JSON for requests and SSE for event streams. It's independent of
the provider's own transport: your service may speak FIX, Protobuf, REST or another documented
protocol to the provider while it answers the same contract to trdrs. A provider's FIX session
doesn't need a separate inbound FIX service for trdrs customers.

trdrs calls your service at the base URL of the venue's connection, on a public HTTPS hostname on
port 443, with the connection's credential as `Authorization: Bearer <credential>`. Each request
has a 5-second deadline, and an answer larger than 1 MiB is refused. trdrs sees only what the
contract carries: the manifest, accounts, snapshots, events and command receipts. The provider's
keys, its symbol names and its streaming details stay inside your service.

## Answer the routes

Every path is relative to the connection's base URL, such as
`https://provider.example.com/trdrs-provider/v1`. A read made under a session names it with
`sessionId` and `generation` in the query, and a command carries both in its body. Every check of a
venue's connection reads `/manifest`, then `/ready`.

| Method | Path | What it does | Who serves it |
| - | - | - | - |
| GET | `/ready` | Answers `{ "ready": true }` when your service can serve. | Every provider |
| GET | `/manifest` | States what your service does. | Every provider |
| POST | `/sessions/acquire` | Grants a session for one connection, environment, scope and generation. | Every provider |
| POST | `/sessions/renew` | Extends a granted session. | Every provider |
| GET | `/market/events` | Streams prices for the instruments named in `instruments`. | `marketData` |
| GET | `/instruments` | Pages your symbol list. Optional. | `marketData` or `accounts` |
| GET | `/accounts` | Lists the accounts the credential can see, under a discovery session. | `accounts` |
| GET | `/accounts/{accountId}/snapshot` | Pages one account's orders, positions and balances. | `accounts` |
| GET | `/accounts/{accountId}/events` | Streams the account's events after the cursor in `afterCursor`. | `accounts` |
| POST | `/commands` | Takes one command: place, replace, cancel, close a position, set trading configuration, or set a symbol's leverage or margin mode. | `execution` |
| GET | `/commands/{commandId}` | Answers what happened to one command. | `execution` |
| GET | `/accounts/{accountId}/margin-preview` | Answers what one order would take of the account's margin. Optional. | `execution` |
| GET | `/accounts/{accountId}/symbol-settings` | Answers the account's leverage and margin mode on one symbol. Optional. | `execution` |
| GET | `/connections/{connectionId}` | Names the company a login reaches. Protocol 1.1. | `connectionDescription` |

## Declare what you serve

Your manifest is the first thing trdrs reads, and a venue registers it as a provider version. It
states `providerVersion`, `protocolVersion` (`1.0`), a `schemaDigest` of 64 lowercase hex
characters, the `loginStyle` of the connection, and every capability. A manifest that leaves out
`loginStyle` reads as `firm_credentials`: the venue connects with its own credentials and its traders
type nothing.

This manifest serves prices alone:

```json theme={null}
{
  "providerVersion": "acme-prices-1",
  "protocolVersion": "1.0",
  "schemaDigest": "3f1c0d5e9a7b4c2e8f6a1d0b9c7e5a3f2d4b6c8e0a1f3d5b7c9e2a4f6b8d0c1e",
  "loginStyle": "firm_credentials",
  "capabilities": {
    "accounts": false,
    "execution": false,
    "marketData": true,
    "generationFencing": true,
    "completeOrderBook": false,
    "executionHistory": false,
    "executionCorrections": false,
    "orderTypes": [],
    "timeInForce": [],
    "reduceOnly": false,
    "nativeReplace": false,
    "nativeOco": false,
    "accountProvisioning": false,
    "positionModels": [],
    "replayRetentionSeconds": 0
  }
}
```

Every capability is required, and the combinations are checked:

| You declare | The manifest is refused unless |
| - | - |
| `execution: true` | It also declares `accounts`, `generationFencing`, `executionHistory` and `completeOrderBook`, at least one order type, time in force and position model, and `replayRetentionSeconds` of at least 604,800 (seven days). Otherwise `execution_requirements_missing`. |
| `execution: false` | `orderTypes` and `timeInForce` are empty, and `reduceOnly`, `nativeReplace` and `nativeOco` are false. Otherwise `execution_not_declared`. |
| `accounts: false` | `accountProvisioning` is false and `positionModels` is empty. Otherwise `accounts_not_declared`. |
| Neither `accounts` nor `marketData` | Never. It's refused as `empty_provider`. |

Order types are `market`, `limit`, `stop` and `stop_limit`. Time in force is `day`, `gtc`, `ioc`,
`fok` or `post_only`. Position models are `net` and `hedged`. `replayRetentionSeconds` is a whole
number from 0 to 31,536,000.

## Grant sessions and fence the old ones

trdrs asks for a session before it reads or sends anything. The request names `connectionId`,
`environment` (`sandbox` or `production`), `generation`, `authorizationRef`, `acquisitionRequestId`
and `scope`: `market` for prices, `discovery` for the account list, or `account` with the
`externalAccountId` it's for. Your grant repeats all of them and adds `sessionId` and `expiresAt`.
A grant runs at most 60 seconds, and trdrs refuses a longer one. Grant 30 seconds so a clock a little
ahead of trdrs's still grants one it takes; trdrs renews every 20 seconds through `/sessions/renew`,
which answers the same grant with a later `expiresAt`.

| trdrs sends | Your service answers |
| - | - |
| A request it already sent, with the same `acquisitionRequestId` | The same grant, so a caller that retried never holds two identities for one intent. |
| A higher `generation` for the same authority | A new grant, and the older session is revoked. |
| A `generation` below the highest it has seen | A refusal. A restarted reader can't quietly take an account back. |
| A call on an account session for another account | A refusal. An account id isn't a credential. |

## Take each command once

A command arrives as `{ sessionId, generation, command, payloadHash }`. The command carries its
`commandId`, `idempotencyKey`, `connectionId`, `externalAccountId`, `submittedAt`, `routeVersion`,
`instrumentVersion`, `kind` and `body`. `payloadHash` is a SHA-256 of the command's canonical JSON,
64 lowercase hex characters. Recompute it from the command you parsed, never from the bytes you
received, or you agree only with yourself.

Answer with the command's result: `{ sessionId, generation, connectionId, externalAccountId,
commandId, payloadHash, receipt }`, the session, account, command and payload hash it was sent with
and its receipt. trdrs believes the receipt only when all of them match what it sent; anything else
leaves the command's outcome unknown. `GET /commands/{commandId}` answers the same result, with a null
receipt where you hold none. The receipt is `{ commandId, status, providerOrderId, reasonCode }`, and
its `status` is one of three:

| Status | When |
| - | - |
| `accepted` | The provider took the command. `providerOrderId` names its order. |
| `rejected` | The provider refused it. `reasonCode` says why. |
| `outcome_unknown` | The provider didn't answer, so the command may have traded. |

> [!WARNING]
>
> Never answer `rejected` for a command that may have traded. A caller that reads a rejection sends
> the order again.

| trdrs sends | Your service answers |
| - | - |
| A `payloadHash` that doesn't match the command | A refusal. The bytes and the stated intent disagree. |
| The same `commandId` and body again | The first receipt, in a result under the session that sent it again, so a retry after a lost answer recovers the outcome instead of trading again. |
| The same `commandId` with a different body | A refusal. The first command stands. |
| `GET /commands/{commandId}` for a command you have no record of | No evidence, never a rejection. |

## Answer an account's margin and symbol settings

Both reads are optional and take no manifest field: answer `404` to a route you don't serve, and
trdrs treats the figure as unknown and the account as holding no settings it can change. Each is
read under the account's session and echoes its `sessionId`, `generation`, `connectionId`,
`externalAccountId` and `symbol`.

* `GET /accounts/{accountId}/margin-preview` names an order with `symbol`, `side`, `quantity`,
  `orderType`, and `limitPrice` or `triggerPrice` where the type takes one. Answer `marginRequired`
  (a decimal string, or null where you figure none), `estimate`, `currency`, `sufficient` (true,
  false, or null for no verdict) and `basis` (null, or where the figure comes from). It places
  nothing.
* `GET /accounts/{accountId}/symbol-settings?symbol=` answers `settings`, or null where the account
  holds none on the symbol: `leverage` and `maxLeverage` as decimal strings, `marginMode`, the
  `marginModes` you offer the account there, `marginModeScope` (`instrument` or `account`),
  `marginModeHeld` (null where you don't judge it), and `marginModeChange`, whether you take a change
  of mode. Serving it means you take `setLeverage`, `{ instrumentId, providerSymbol, leverage }`, and,
  where `marginModeChange` is true, `setMarginMode`, `{ instrumentId, providerSymbol, marginMode }`.
  trdrs sends either command only after the read answered for its symbol. Accept a change with a
  null `providerOrderId`: it names no order.

## Serve account state and its events

A provider that holds accounts serves each account in two parts. The snapshot pages its orders,
positions and balances, and claims `complete` coverage only on the page that completes the account.
A partial page that claims coverage makes an unfinished read look like proof the account is flat.

The event stream then carries the account's balance, order, execution, execution correction and gap
events after the cursor trdrs names in `afterCursor`: an event's cursor, or the `replayCursor` your
snapshot gave. Event cursors and account sequence numbers always increase, and resuming after a cursor
returns exactly the events after it, with none missing and none repeated. A cursor you don't recognize is reported as unknown, with a `cursorExpired` frame or an
error status, never replayed from the start: starting over quietly is how a consumer applies a day
of trading twice.

## Speak protocol 1.1

Protocol 1.1 adds to 1.0 and changes nothing a 1.0 call sees. trdrs names the version a call is made
under on the `Trdrs-Provider-Protocol` header: it sends `1.1` on `GET /manifest` for a provider version
pinned to 1.1, and no header for one pinned to 1.0. Answer a call that names 1.1 with your 1.1 manifest,
and any other call with your 1.0 manifest exactly as before.

* **Name your integration.** A 1.1 manifest names the integration it's served through,
  `integration: { slug, name, protocol }`, with a slug in a company slug's form. One that names none
  is refused as `integration_undeclared`.
* **Keep every 1.0 capability.** The 1.1 manifest states the same `providerVersion`, `loginStyle` and
  every 1.0 capability as your 1.0 manifest, beside the 1.1 capabilities, each `false` where you
  leave one out. It keeps a schema digest of its own.
* **Describe your connections.** With `connectionDescription: true`, answer
  `GET /connections/{connectionId}` under 1.1, on the connection's own credential, with the company the
  login reaches as `provider: { slug, name }`, or `null` where you don't say.

A venue pins a version to 1.1 by registering both manifests: `manifestV11` beside `manifest` on
`POST /api/venues/{venueId}/providers`. Each check of its connections then reads both manifests, as
[Connect a provider](https://docs.trdrs.co/providers/connections.md#keep-it-running) describes.

## Test it end to end

Run the reference provider beside your service first. It serves the contract over plain HTTP on a
loopback port, with no vendor account and no network, and it passes every conformance rule, so the
differences between it and your service are your work list. trdrs itself only ever calls a public
HTTPS endpoint, so the reference provider can't be mistaken for a production one.

Then run [provider conformance](https://docs.trdrs.co/providers/provider-conformance.md) against your own service, and the
market data suite if it serves prices.

## Add it to your venue

Your venue adds the provider and answers for it: nothing stands between your service and your venue
but your own check of the connection.

1. **Register the provider version.** `POST /api/venues/{venueId}/providers` with its name, its
   `manifest` and its `manifestV11`, which names the integration your organization maintains.
   Required scope: `provider:manage`.
2. **Link it to the company it reaches.** `POST /api/venues/{venueId}/providers/{providerId}/link`
   with `company`, its name and kind, such as `{ "name": "Acme Liquidity", "kind": "liquidity_provider" }`.
   Your organization holds that company, and a later version links to it by its `companyId`.
3. **Connect, check and promote it.** Create the connection at your service's endpoint with the
   credential it takes, check it and promote it on a check that passed, as [Connect a
   provider](https://docs.trdrs.co/providers/connections.md) describes. The promotion puts the connection to use in its
   environment, the sandbox or production.
4. **Use it.** Price markets from it with [Add a provider's markets](https://docs.trdrs.co/guides/add-provider-markets.md),
   bind a hedge account at it with [Hedge venue exposure](https://docs.trdrs.co/guides/venue-hedging.md), or route a group's
   orders to an account bound at it.

A new version of your service is a new provider version: register, connect and promote it, then
retire the old one with `POST /api/venues/{venueId}/providers/{providerId}/retire` once no
connection names it. A check that fails on what your service answered halts its connection until you
promote it again.

## Next steps

> [card] [Serve prices and symbols](https://docs.trdrs.co/providers/serve-market-data.md)
>
> Number your price updates and state your symbol list.

> [card] [Provider conformance](https://docs.trdrs.co/providers/provider-conformance.md)
>
> Run the suites and keep the evidence.

> [card] [Run a testnet provider](https://docs.trdrs.co/guides/run-a-testnet-provider.md)
>
> Qualify a real exchange's test environment behind the contract.

> [card] [Connect a provider](https://docs.trdrs.co/providers/connections.md)
>
> Connect, check and promote your provider for your venue.


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