Skip to main content
Open hosted Connect, the account picker, on your own page, so a trader who signed in to your app can connect a trading account or open your white-label paper without signing in to trdrs. The Connect SDK is a small browser script that hosted Connect serves. Your page hands it a Connect link’s token, it lays Connect over your page in a frame, and it tells your page how Connect ended. Use this page when you add Connect to your page, and as the reference for every option, method, event and error. By the end you have a page that opens hosted Connect for a trader your server named, and a server that confirms what happened.
Hosted Connect serves the sandbox at https://trdrsco-connect-sandbox.fly.dev and production at https://connect.trdrs.co. The SDK opens Connect on the host of the environment its token was created in.

Before you start

  • Your app’s API key, and http://localhost:8787 added as a website. The Connect quickstart creates both in the sandbox.
  • TRDRS_API_BASE_URL and TRDRS_API_KEY in your shell, as the quickstart sets them.
  • Node.js 20 or later for the example server. Your own server can be written in any language.
1

Create a Connect link on your server

When a trader signed in to your app asks to connect, your server creates a Connect link for them, on the website your page runs on. The call carries your API key, so it runs on your server, never in the page. Try it with curl first:
The response is 201 with the link: its id, the token your page opens Connect with, expiresAt, the origin and the environment. Keep the id on your server to read the outcome later, and send the page the token and nothing else.The first link for an id makes that trader one of yours at trdrs, and every later link for the same id reaches the same trader, so the accounts they connected before are theirs again. Those accounts are your trader’s, held apart from any trdrs account the same person holds and from every other app’s traders.The token opens Connect for that one trader, on that one website, before expiresAt. Once open, Connect stays usable for up to 30 minutes. Send a new Idempotency-Key for each new link: the same key and body answer the same link while it’s unopened, and a different body with the same key is refused.
2

Hand the token to your page

Your API key stays on your server, so your page asks your server for a token. This server serves the page and answers POST /api/connect-link with a fresh token. It stands in for your own sign-in by naming one test trader, trader-test-1, where your server names the trader your sign-in verified. Save it in an empty folder:
server.mjs
Create a new link each time your page opens Connect: each link opens Connect once.
3

Open Connect on your page

Your page imports the SDK from hosted Connect, asks your server for a token, and opens Connect with it. Save this beside the server:
index.html
You pass the token alone. It names the environment it was created in, and the SDK opens Connect on that environment’s host.
4

Run it

Start the server in the shell that holds your two variables, then open http://localhost:8787, exactly that address, and press Connect a trading account.
Hosted Connect opens over your page, straight on your tiles: the venues and providers your Connect offers, each chosen by its slug, with your white-label paper first while you offer it. The trader picks a venue’s or a provider’s tile and signs in to the provider it opens, inside the frame, or opens your white-label paper with nothing to type. Credentials go from the frame to trdrs, never through your page or your server. A provider that signs traders in on its own page opens it in a short window that returns to Connect. When the trader finishes, Connect closes and your page says Connected.
5

Confirm the result on your server

A browser event is for your interface, and your server confirms the result. Your server printed the link’s id, so put it in your shell and read the link:
The response is the link, with your id for the trader in trader and where the link stands in state:Once it reads connected, your server can read the trader’s accounts and route their orders, as Route your traders’ orders shows.

Load the SDK

Import the SDK from hosted Connect, as a module:
Hosted Connect serves it to any website at an address that stays the same across releases, and browsers keep it for five minutes, so a fix reaches your page without a change on your side. The script opens a token’s Connect on that token’s own environment’s host, whichever host you import it from. If your page sets a Content Security Policy, allow Connect’s host in script-src and frame-src.

Create Connect

createConnect(options) makes one Connect for one token. createConnect throws, and opens nothing, when an option is wrong: Then open Connect, and listen for what happens:

Handle the events

Each event is an object with a type, and an error also carries a code. The SDK reads a message only when it comes from Connect’s origin, from the frame it opened, and carries the one-time value it made for that frame. Treat connected as a hint for your interface, and confirm anything that matters on your server.

Match your page

Connect’s overlay is clear. To dim your page while Connect is open, style the overlay the SDK adds:
styles.css
The overlay then darkens your page behind Connect’s popup. To match your page’s colors, pass appearance. mode is light, dark or system, which follows the trader’s device setting as it changes, and Connect is dark unless you name one. custom colors Connect’s roles for each mode, and a role you leave out keeps Connect’s own color:
Connect opens in light mode, with your blue on its one filled action and its focus rings. Each role colors one part of Connect: A color is a hex color: #rgb, #rgba, #rrggbb or #rrggbbaa. Connect keeps its own layout, its motion and “Protected by trdrs”.

Redirect instead of a frame

Call connect.redirect() in place of open() where a frame doesn’t fit, such as a small in-app browser. The trader goes to hosted Connect’s own page and comes back to the address they left when they connect or close Connect. Your page hears no events this way, so read the link on your server when the trader comes back. A link Connect can’t open leaves the trader on Connect’s page, which says the link expired and offers no way back, so create the link just before you redirect. Close a link your page doesn’t need, for example when the trader signs out of your app. Send an empty JSON body with an Idempotency-Key:
The response is the link, now closed. If Connect is open on it, the trader’s next step there ends with session_ended. Closing twice changes nothing, and closing never undoes a connection: a connected link stays connected.

Follow the security rules

  • Keep your API key on your server. Never put it in JavaScript, HTML, a mobile app or a Connect address.
  • Create a Connect link only for a trader your own sign-in verified, and name them by the same id every time. Your server vouches for that trader, so never take the id from the browser.
  • Add exact websites. https://app.example.com and https://admin.example.com are two websites, and each needs its own entry.
  • Treat connected as a hint for your interface, and confirm on your server.

Test it end to end

  1. Open Connect and close it without connecting. Your page hears closed, and the link reads mounted.
  2. Open Connect and open your white-label paper. Your page hears connected, and the link reads connected with the Demo’s accountId.
  3. Create a link with curl, as in the first step, with expiresInSeconds of 60. Wait over a minute, then open it from the browser console on your page:
    Four seconds after the frame loads, the console logs { type: 'error', code: 'connect_unavailable' } and Connect leaves your page.
  4. Open Connect, then close its link from your server, and pick your white-label paper. Connect ends with session_ended, and closed follows when you close it.

The routes this page calls

Each takes your app’s API key, which starts trdrs_ck_sandbox_ in the sandbox and trdrs_ck_production_ in production, and names your app.

Next steps

Route your traders' orders

Read the accounts your traders connect, and route their orders, from your backend.

Tiles and white-label paper

Choose the tiles your Connect shows, and offer white-label paper.

Create a Connect link

Read every field of the request and its response.

Connect overview

See the whole journey, from a sandbox key to your app’s production.