Create Embed Token

Issue short-lived embed tokens for Trading Widget partner-token mode.

View as Markdown

SDK call

Create embed tokens from your backend after validating the partner user session. The browser should call your endpoint, and your endpoint should call 6MM through the Agent SDK.

1CreateEmbedTokenResponse resp = client.createEmbedToken(
2 CreateEmbedTokenRequest.of("agent-user-001", "tw_abc123")
3 .withSymbol("ETHUSDT"));
4
5System.out.println(resp.embedToken);
6System.out.println(resp.expireAt);

One-time credential

embedToken is short-lived and one-time use. Do not place it in a URL query string.

Backend endpoint example

1@PostMapping("/api/trading/embed-token")
2public EmbedTokenView createEmbedToken(@RequestBody EmbedTokenRequest request,
3 PartnerSession session) {
4 String agentUserId = session.getAgentUserId();
5 CreateEmbedTokenResponse resp = agentClient.createEmbedToken(
6 CreateEmbedTokenRequest.of(agentUserId, request.getChannelId())
7 .withSymbol(request.getSymbol()));
8
9 return new EmbedTokenView(resp.embedToken, resp.expireAt, request.getChannelId());
10}

Return only the fields needed by the Trading Widget token provider. Do not return apiSecret, raw signing fields, or internal service configuration.

Failure handling

ConditionRecommended handling
User session is missing or expiredReturn 401 from the partner endpoint and ask the user to sign in again.
Agent user is not boundBind the user first, then retry token creation.
6MM returns a temporary errorReturn a retryable error to the frontend and log requestId for support.
channelId does not match the widget instanceReject the request and recreate the widget session.