Prerequisites
Before starting, make sure you have:- An app registered at tren.ch/partner, giving you a
client_idand an API key. See Registration. - At least one redirect URI registered, matching exactly what you will send.
- A backend that can hold the client secret, since it must never reach the browser.
Endpoints Used
GET https://tren.ch/oauth/authorizefor the consent screenPOST /oauth/tokento exchange the code
1. Open the Consent Popup
Generate a PKCE verifier and astate value, then open the popup. The window needs to be opened synchronously inside the click handler, otherwise the browser will block it.
The popup runs on the Trench origin, so the user sees
tren.ch in the address bar and can confirm who they are approving. Your page cannot read anything inside it.
2. Relay the Code From Your Callback
The popup lands on yourredirect_uri with ?code=…&state=… in the query string. At that point it is same-origin with the opener, so it can post the code back and close itself.
?error=access_denied&state=… and no code.
3. Exchange the Code
Send the code and the verifier from your backend, authenticating with HTTP Basic.Response
4. Confirm the Connection
CallGET /partner/v1/me with the new access token.
cURL
scopes array in this response reflects what the token can actually do, which may differ from what you requested at authorize time. We recommend treating it as the source of truth.
Mobile Fallback
Popups are unreliable on mobile browsers. You can run the same flow by navigating the whole page instead of opening a window, then readingcode from the query string server-side on your callback route. Nothing else about the flow changes.
1-Click Trading
Thetrade:execute and governance write scopes require the user to have delegated their wallet to Trench. The consent screen enforces this, so if delegation is off, the Approve button stays disabled until the user enables it.
This means you will never be issued a trading token that cannot trade at the time it is created. A user can revoke delegation later, though, so we recommend checking tradingEnabled before showing trade controls. Once delegation is off, writes fail with 403 delegation_missing.
Next Steps
Trade Tokens
Execute your first buy and confirm the fill.
Tokens & Refresh
Keep the connection alive without breaking it.