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:8787added as a website. The Connect quickstart creates both in the sandbox. TRDRS_API_BASE_URLandTRDRS_API_KEYin 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 Create a new link each time your page opens Connect: each link opens Connect once.
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
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:You pass the token alone. It names the environment it was created in, and the SDK opens Connect
on that environment’s host.
index.html
4
Run it
Start the server in the shell that holds your two variables, then open 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
http://localhost:8787,
exactly that address, and press Connect a trading account.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: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 atype, 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
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:
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
Callconnect.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 Connect link early
Close a link your page doesn’t need, for example when the trader signs out of your app. Send an empty JSON body with anIdempotency-Key:
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.comandhttps://admin.example.comare two websites, and each needs its own entry. - Treat
connectedas a hint for your interface, and confirm on your server.
When a Connect link is refused
Test it end to end
-
Open Connect and close it without connecting. Your page hears
closed, and the link readsmounted. -
Open Connect and open your white-label paper. Your page hears
connected, and the link readsconnectedwith the Demo’saccountId. -
Create a link with curl, as in the first step, with
expiresInSecondsof60. 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. -
Open Connect, then close its link from your server, and pick your white-label paper. Connect ends
with
session_ended, andclosedfollows when you close it.
The routes this page calls
Each takes your app’s API key, which startstrdrs_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.