WebTrade is the Web form factor of WhaleApp SDK. It lets Broker connect its own sign-in system to a complete trading UI and synchronize language, theme, and price-color preferences.
SSO uses cookies shared under the same registrable domain:
- Broker website and WebTrade use subdomains of the same root domain, such as
.example.com. - After sign-in, Broker writes
token,refresh_token, andapp_idto the agreed root-domain cookies. - WebTrade reads those cookies and signs the Customer in automatically.
- Language, theme, and price-color preferences use separate agreed cookie keys.
Two presentation modes are supported:
- New tab: Broker opens WebTrade in a new browser tab. Communication is limited to shared cookies and URL parameters.
- iframe: Broker renders its own shell and embeds WebTrade. Communication uses shared cookies, URL parameters, and validated two-way
postMessageevents.
| Key | Purpose | Values / example |
|---|---|---|
cookie_token_key |
Token cookie key | broker_token |
cookie_refresh_token_key |
Refresh-token cookie key | broker_refresh_token |
cookie_app_id_key |
App-ID cookie key | broker_app_id |
logout_redirect_link_address |
Broker URL used after logout or when no session exists; supports {tenant_origin} |
https://www.example.com/login?from=webtrade |
cookie_locale_key |
Language cookie key | en, zh-CN, or zh-HK |
cookie_theme_key |
Theme cookie key | light or dark |
cookie_stock_color_preference_key |
Price-color preference cookie key | green_up or red_up |
disable_language_setting |
Hide WebTrade language settings | true or false |
Custom cookie keys prevent collisions between Broker website cookies and WebTrade cookies.
| Key | Purpose |
|---|---|
hide_logout_entrance |
Hide the WebTrade logout control so Broker website owns the sign-out experience |
Whale recommends that Broker own logout and hide the WebTrade logout control.
Both modes support these parameters:
| Parameter | Purpose | Example |
|---|---|---|
tab |
Initial navigation: quote, stock, favorite, portfolio, or stockSelect |
tab=quote |
symbol |
Initial instrument in counter_id format |
symbol=700.HK |
tenant_origin |
Broker origin used for iframe message validation and logout redirection | tenant_origin=https://www.example.com |
This section applies only to iframe mode. WebTrade accepts messages only from the validated tenant_origin and sends events only to that origin.
// Set language
{ type: 'SET_LANG', payload: { lang: 'zh-HK' } }
// Set theme
{ type: 'SET_THEME', payload: { theme: 'dark' } }
// Set price-color preference
{ type: 'SET_STOCK_COLOR_PREFERENCE', payload: { color: 'green_up' } }Allowed values:
- Language:
zh-CN,zh-HK, oren. - Theme:
darkorlight. - Price color:
green_uporred_up.
// WebTrade has mounted; Broker may hide its loading mask.
{ type: 'WEBTRADE_READY' }
// WebTrade has started logout; Broker must clear its own session.
{ type: 'ON_LOGOUT' }Always check event.origin before handling an incoming message.
tenant_origin has two purposes:
- It is the allowlisted origin for two-way iframe messages.
- It replaces
{tenant_origin}inlogout_redirect_link_address.
The origin must:
- use
https; - share the same root domain as WebTrade; and
- contain no path other than
/.
WebTrade resolves the origin in this order:
- A project-specific mapping agreed and configured during delivery.
- The value cached in
localStoragefrom a previous URL parameter. - The
tenant_originURL parameter on first access.
For example, with tenant_origin=https://www.example.com, a configured redirect of {tenant_origin}/login?from=webtrade resolves to https://www.example.com/login?from=webtrade.
- Customer signs in to Broker website; Broker Server returns
token,refresh_token, andapp_id. - Broker frontend writes them to the agreed root-domain cookies.
- Customer opens WebTrade in a new tab.
- WebTrade reads the token, preferring the cookie over its local cache.
- A valid token opens the trading UI; a missing or invalid token redirects to
logout_redirect_link_address.
- Customer signs in and Broker writes the session cookies.
- Broker creates the iframe and passes
tenant_originin its URL. - WebTrade reads the cookies and signs the Customer in.
- WebTrade sends
WEBTRADE_READYafter mounting. - Broker hides its loading state after validating and receiving the event.
- Customer starts logout in WebTrade.
- WebTrade clears its login cookies and local storage.
- WebTrade redirects to
logout_redirect_link_address; if none is configured, it falls back to the Whale sign-in page.
- Customer starts logout when the control is not hidden.
- WebTrade clears its login cookies and local storage.
- WebTrade sends
ON_LOGOUTto the validated parent origin. - WebTrade waits 200 ms, then performs the configured redirect.
- Broker handles
ON_LOGOUT, clears its own session, and completes server-side logout.
| Cookie | Required | Purpose |
|---|---|---|
{cookie_token_key} |
Yes | Customer token |
{cookie_refresh_token_key} |
Yes | Customer refresh token |
{cookie_app_id_key} |
Yes | App ID |
{cookie_locale_key} |
Recommended | Initial language |
{cookie_theme_key} |
Recommended | Initial theme; defaults to dark |
{cookie_stock_color_preference_key} |
Recommended | Initial price-color preference |
Set domain to the shared root domain, for example .example.com, and path=/. WebTrade must read these cookies from JavaScript, so the current integration contract requires them not to be HttpOnly. Use HTTPS, restrict the domain and path exactly as agreed, and coordinate the security model with the Whale project team.
WebTrade resolves language in this order:
- A valid language in
{cookie_locale_key}. - A supported value derived from
navigator.language. - English (
en).
type SupportLocale = 'en' | 'zh-HK' | 'zh-CN'
function getDefaultLocaleForWeb(): SupportLocale {
const fromCookie = Cookies.get(appConfig.cookieLocaleKey)
if (fromCookie && isSupportLocale(fromCookie)) return fromCookie
const match = navigator.language.match(/(zh-HK|zh-CN|en)/)
return (match?.[1] as SupportLocale | undefined) ?? 'en'
}Broker must:
- Provide
logout_redirect_link_address, optionally with{tenant_origin}. - Clear every WebTrade login cookie when the Customer signs out.
- Call the Whale logout API so the server-side Customer token becomes invalid.
- In iframe mode, validate and handle
ON_LOGOUTimmediately.
Broker website and WebTrade must share a root domain. For example:
- Broker website:
broker.example.com. - WebTrade:
trade.example.com. - Shared cookie domain:
.example.com.
{
"cookie_token_key": "broker_token",
"cookie_refresh_token_key": "broker_refresh_token",
"cookie_app_id_key": "broker_app_id",
"cookie_locale_key": "broker_locale",
"cookie_theme_key": "broker_theme",
"cookie_stock_color_preference_key": "broker_stock_color_preference",
"logout_redirect_link_address": "https://www.example.com/login?from=webtrade",
"disable_language_setting": true
}{
"hide_logout_entrance": true
}- Whale-managed deployment: Whale builds and deploys WebTrade; Broker supplies its domain and project configuration.
- Broker-managed deployment: Whale delivers a project-specific WebTrade zip for Broker to deploy, which can accommodate Broker-managed certificates or multiple domains.