- OAuth identifies and authorises the QFEX user. Each end user signs in to QFEX and authorises your application. New users create their QFEX account on QFEX rather than sharing QFEX credentials with your application.
- Your builder code identifies your integration. Your application attaches the same builder code to each authenticated Trade WebSocket session it opens for those users.
A builder code is not assigned permanently to an end-user account. It is
attached to a Trade WebSocket connection. Every eligible order sent over that
connection is attributed to the builder code for the life of the connection.
Integration model
A typical aggregator has:- one QFEX account owned by the aggregator;
- one active builder code owned by that account;
- one registered QFEX OAuth client for the aggregator application; and
- one OAuth grant and token set for each QFEX user who connects their account.
11111111-1111-4111-8111-111111111111, it uses that same code when authenticating the QFEX Trade WebSocket for Alice, Bob, and every other user who trades through the aggregator. Each user still authenticates with their own QFEX OAuth access token.
Before you start
1. Create your builder code
Sign in to QFEX and create a builder code in Developer Settings → Builder code. You can also create it withPOST /user/builder-code.
Store the returned UUID as application configuration, for example:
2. Register an OAuth client
Contact support@qfex.com to register your integration as a QFEX OAuth client. Provide:- your application name;
- your production redirect URI or URIs;
- a logo URL, if available; and
- whether the client is public or confidential.
End-user flow
Step 1: User selects Connect QFEX
When the user selects Connect QFEX in your application:- Generate a high-entropy
statevalue. - Generate a PKCE
code_verifier. - Derive the SHA-256
code_challengefrom the verifier. - Store
stateandcode_verifierin the user’s server-side session or another secure short-lived store. - Redirect the user to the QFEX authorization endpoint.
state or PKCE.
Step 2: QFEX handles sign-in or account creation
The user is sent to QFEX, not to a credential form owned by your application.- If the user already has a QFEX account, they sign in and complete any required MFA.
- If the user does not have an account, they create one with QFEX and complete the required QFEX onboarding steps.
- The user reviews the OAuth authorisation request and approves or denies your application.
Step 3: Handle the OAuth callback
After approval, QFEX redirects to the registeredredirect_uri with an authorization code and the original state.
- Reject the request if
statedoes not exactly match the value stored in the user’s session. - Read the stored PKCE
code_verifier. - Exchange the authorization code for tokens.
- Delete the one-time
stateandcode_verifierfrom the session.
Step 4: Exchange the code for QFEX tokens
For a confidential server-side client, authenticate the client with HTTP Basic auth and send the PKCE verifier:client_id in the form body instead. Public clients still use PKCE.
Step 5: Open the Trade WebSocket and attach your builder code
Use the user’s OAuthaccess_token as the JWT. The WebSocket upgrade and the QFEX auth message both use the user’s token; your builder code is added to the auth message.
Step 6: Trade normally
After the auth response succeeds, place orders using the normal Trade WebSocket API.Step 7: Refresh tokens and reconnect
OAuth access tokens expire. Use the refresh token to obtain a new access token before expiry or after an authentication failure. For a confidential client:Existing users and new users use the same entry point
Your integration should expose one Connect QFEX action. Do not build separate “sign up” and “sign in” APIs on your side.Builder attribution is connection-scoped
Builder attribution is intentionally independent of account creation and OAuth. This means:- the end user’s QFEX account is not permanently tied to a builder;
- the same user can trade through different builders at different times;
- a user trading directly on QFEX is not automatically attributed to your builder;
- every Trade WebSocket your integration opens must include your
builder_code; and - reconnecting without the code removes builder attribution from that new connection.
builder_code from trusted application configuration rather than accepting an arbitrary value from the browser or end user.
Security checklist
Before going live:- use Authorization Code + PKCE for every OAuth flow;
- validate
stateon every callback; - register exact HTTPS redirect URIs and avoid wildcard callbacks;
- keep confidential-client secrets, access tokens, and refresh tokens server-side;
- encrypt refresh tokens at rest;
- never log access tokens, refresh tokens, authorization codes, or QFEX API secrets;
- do not ask users for QFEX passwords or MFA codes inside your application;
- reconnect the Trade WebSocket with the new access token after a refresh;
- attach your configured builder code on every new Trade WebSocket; and
- stop trading immediately if authorization is revoked.
The standard OAuth scopes describe identity information returned by the OAuth
provider. They should not be treated as a read-only or trade-only permission
boundary for QFEX trading. An access token used with QFEX trading APIs must be
protected as a credential capable of acting as the user.
End-to-end checklist
A production integration is complete when you can test all of the following:- A user with no QFEX account can enter the QFEX account-creation flow from Connect QFEX and, once new-user OAuth continuation is released, return to the original authorisation request after onboarding.
- An existing QFEX user can connect without sharing credentials with your application.
- Your callback rejects an invalid
stateor PKCE verifier. - You can exchange the authorization code and securely store the returned token set.
- You can authenticate
wss://trade.qfex.comwith the user’s access token. - The Trade WebSocket auth message includes your builder UUID automatically.
- A normal order, stop order, and TWAP placed through that connection are attributed to your builder.
- Token refresh followed by WebSocket reconnection preserves builder attribution.
- Revoking the connected application prevents continued use of the revoked authorization.