Skip to main content

REST API v2 Configuration

REST API v2 is the public HTTP API for a running Ember. It is served by the Ember Monitor backend and by the Ember Web Gateway under the base path /api/v2. Clients use it to issue and query orders, query and adjust positions, halt and resume trading, manage risk limits, and control services and FIX sessions. This document describes how to enable it, authenticate clients, and grant permissions. For the list of operations, see the REST API v2 Reference.

The REST/WS API v1 gateway (/api/v1, HMAC) is a separate API.

caution

These operations change production trading state, including order entry. Use TLS, grant permissions to as few users as possible, and do not expose this API over the public Internet.

Enabling​

The API is enabled by default. To turn it off, add the following to Ember Monitor's application.yaml (see Adding a Configuration File) and restart Ember Monitor:

api:
v2:
enabled: false

The API listens on the same host and port as Ember Monitor (server.port, 8988 by default). Enable HTTPS in the same way as for Ember Monitor, see Enabling HTTPS.

Authentication​

The API has its own security chain, independent of the Ember Monitor UI session and of the REST/WS API v1 gateway. It never uses cookies or sessions: every request must carry credentials. The mechanism is selected by the existing Ember Monitor security settings:

ConfigurationHow clients authenticate
security.oauth2.authenticationType is PROVIDERBearer token (JWT) issued by your identity provider: Authorization: Bearer <token>
authenticationType is SIMPLE or LDAPHTTP Basic against the user directory (uac-file-security.xml or uac-ldap-security.xml): Authorization: Basic <base64(user:password)>
authenticationType is NONEThe API is closed: every request is rejected

The API refuses to run without authentication. It is also closed when authenticationType is PROVIDER but JWT validation is not configured (see below).

For more information on authentication types, see Authentication and Authorization.

Bearer tokens​

Tokens are validated as an OAuth2 resource server (signature, expiry, issuer, and audience if configured). When the Monitor login provider is configured, its issuer-uri (or jwk-set-uri) is reused to validate tokens. To validate tokens explicitly, or when the token issuer differs from the address Ember uses to reach the provider, configure the Spring resource server:

spring:
security:
oauth2:
resourceserver:
jwt:
issuer-uri: https://cognito-idp.us-east-2.amazonaws.com/us-east-2_xxxxx
audiences: my-client-id # optional; reject tokens issued for other audiences
# jwk-set-uri: https://idp.example.com/.well-known/jwks.json
note

The security.oauth2.provider.audience and security.oauth2.provider.validateIssuer settings are no longer supported. Use spring.security.oauth2.resourceserver.jwt.audiences and the resource server issuer-uri instead.

Obtain a token with the client credentials grant (for service accounts) or any other flow supported by your provider, and refresh it before it expires. The token must carry the EMBER_ACCESS permission and, for order and position calls, the allowed_order_sources claim described below. For a Keycloak walkthrough, see Configuring Keycloak users.

HTTP Basic​

When the API authenticates users against a directory, use users defined in uac-file-security.xml (authenticationType: SIMPLE) or uac-ldap-security.xml (authenticationType: LDAP). Always use TLS with HTTP Basic. The Ember Web Gateway Docker image and Helm chart set security.oauth2.authenticationType: SIMPLE by default. Directory users are not restricted by allowed_order_sources.

Authorization​

Every call requires the EMBER_ACCESS permission. A request without it is rejected with 403 Forbidden before the operation runs. Operations that change state require an additional Ember Monitor permission. A user without that permission receives 403 Forbidden, and the JSON message names the permission.

PermissionOperations
EMBER_ACCESSEvery endpoint
ORDER_ENTRYSubmit and replace orders
ORDER_IMPERSONATESubmit or replace an order whose trader is not the caller
ORDER_CANCELCancel and discard orders
HALT_RESUME_TRADINGHalt and resume trading
CHANGE_RISK_LIMITSUpdate risk case tables
POSITION_ADJUSTMENTAdjust positions
ENABLE_DISABLE_SERVICEEnable and disable services
CONTROL_FIX_SESSIONEnable, disable and disconnect FIX sessions

Reading trading status, risk tables, positions, services, FIX state, and orders requires EMBER_ACCESS only, plus the order-source check below where it applies.

Where permissions come from depends on the authentication mode:

  • Identity provider (authenticationType: PROVIDER) – permissions are taken from the authorities of the token. The authority name must be exactly the permission name, for example EMBER_ACCESS or ORDER_ENTRY. Configure authoritiesClaim and authorityMapping to map your provider's roles to permissions.
  • User directory (SIMPLE or LDAP) – EMBER_ACCESS is granted to every authenticated directory user. The other permissions are defined in uac-access-rules.xml.

Order sources​

Order entry, order queries, and position queries are limited to the order sources the caller may act for.

With an identity provider, the access token must contain the allowed_order_sources claim. The claim is either a list of source ids or a single comma-separated string. The value * means every source. A source that is not listed is rejected with 403 Forbidden, and the message names allowed_order_sources.

  • Orders. source is required on every order call and must be one of the claim values. * allows any source the caller names.
  • Positions. A caller whose claim contains * may omit source and read every source, including projections that are not keyed by source. Any other caller must set source to one claim value. The projection must include Source. Omitting source is 400 Bad Request.
  • File and LDAP users are not restricted by this claim. They may name any order source and may query positions of every source.

This check does not depend on the engine.allowUnrestrictedPositionRequests setting, which applies to other position clients.

Configuring Keycloak users​

This section shows how to give API users access through a Keycloak realm. It creates one realm role for each Ember permission, a small role hierarchy (trader, senior_trader, administrator), and the allowed_order_sources claim that limits the order sources of each user. Other identity providers need the same three things: roles named after Ember permissions, the roles in the access token, and a claim named allowed_order_sources.

Ember Monitor settings​

Configure the Keycloak client of Ember Monitor in application.yaml (see Adding a Configuration File), as described in KeyCloak OAuth, and read the roles from the token, as described in OAuth2 Identity Provider JWT Authorization:

spring:
security:
oauth2:
client:
registration:
keycloak:
client-id: monitor
client-secret: <client-secret>
scope: openid, email, profile, roles, offline_access
authorization-grant-type: authorization_code
provider:
keycloak:
issuer-uri: http://localhost:8080/realms/Ember

security:
oauth2:
authenticationType: PROVIDER
provider:
name: keycloak
usernameClaim: preferred_username
authoritiesClaim: realm_access.roles

The issuer-uri of the provider is also used to validate the bearer tokens of API clients, so no separate resource server settings are needed. The realm name in the URL is case sensitive and must match the issuer of the tokens.

Create the roles​

In the Keycloak Admin Console, select the realm and open Realm roles. Create one role for each Ember permission, with exactly the permission name:

EMBER_ACCESS, ORDER_ENTRY, ORDER_CANCEL, ORDER_IMPERSONATE, HALT_RESUME_TRADING, CHANGE_RISK_LIMITS, POSITION_ADJUSTMENT, ENABLE_DISABLE_SERVICE, CONTROL_FIX_SESSION, CHANGE_INSTRUMENT_PRICES

CHANGE_INSTRUMENT_PRICES applies to Ember Monitor only and is not used by REST API v2.

Then create the job roles and make each of them a composite role. Open the role, choose Action → Add associated roles, and add the roles listed below. A role can include another job role, so each level adds to the one before it.

RoleIncludes
traderEMBER_ACCESS, ORDER_ENTRY, ORDER_CANCEL
senior_tradertrader, ORDER_IMPERSONATE, HALT_RESUME_TRADING
administratorsenior_trader, CHANGE_RISK_LIMITS, POSITION_ADJUSTMENT, ENABLE_DISABLE_SERVICE, CONTROL_FIX_SESSION, CHANGE_INSTRUMENT_PRICES

Keycloak expands composite roles, so realm_access.roles in the access token contains every permission of the user. The job role names are also in the token and Ember ignores them. To keep different role names in Keycloak, map them with security.oauth2.provider.authorityMapping instead.

Create the order sources claim​

The allowed_order_sources claim comes from a user attribute that only administrators can change, and a client scope that copies the attribute into the access token.

1. Add the user attribute. Open Realm settings → User profile → Create attribute and set:

SettingValue
Attribute [Name]order_source_ids
MultivaluedOn, when a user may have several sources
Who can editAdmin
Who can viewAdmin

Keycloak ignores user attributes that the user profile does not declare, so the attribute must exist here before it can be set on users.

2. Create the client scope. Open Client scopes → Create client scope and set:

SettingValue
Nameorder_source_scope
TypeDefault
ProtocolOpenID Connect

Type Default includes the scope in every token request without a scope parameter.

3. Map the attribute to the claim. Open the order_source_scope scope, go to Mappers → Configure a new mapper → User Attribute, and set:

SettingValue
Nameorder_source_ids_mapper
User Attributeorder_source_ids
Token Claim Nameallowed_order_sources
Claim JSON TypeString
MultivaluedOn
Add to access tokenOn

Ember reads the access token, so Add to access token must be on. The claim name must be exactly allowed_order_sources.

4. Add the scope to the client. Setting the type of a scope to Default applies it only to clients created afterwards. Open Clients, select the client that your API users sign in with, and open Client scopes → Add client scope. Select order_source_scope and add it as Default. Without this step the token has no allowed_order_sources claim unless the client requests scope=order_source_scope.

Assign roles and sources to users​

Create the users in Users. A user needs a complete profile (email, first name, last name) and a non-temporary password. Otherwise the token request fails with Account is not fully set up.

For each user:

  1. Open Role mapping → Assign role and assign one of the job roles.
  2. Open Details and set Order source ids. Add one value for each allowed source, or * for every source.

Example:

UserRoleOrder source idsResult
alicetraderETRADERSubmits, replaces and cancels orders of ETRADER and reads its positions
bobsenior_trader*The same for any source, issues orders for other traders, halts and resumes trading
opsadministrator*Every operation of the API

When the API is called with a service account (client credentials grant), assign the roles under Clients → your client → Service accounts roles. Set Order source ids on the service account user, which is the user that Keycloak lists on the same tab.

Verify the token​

Request a token and decode the payload of the access token, for example at jwt.io. The following request uses the password grant of a client that has Direct access grants enabled:

curl -s -X POST http://localhost:8080/realms/Ember/protocol/openid-connect/token \
-d grant_type=password -d client_id=monitor -d client_secret=my-secret \
-d username=alice -d password=alice-password

The token of alice must contain the roles and the claim:

{
"preferred_username": "alice",
"realm_access": {
"roles": ["trader", "EMBER_ACCESS", "ORDER_ENTRY", "ORDER_CANCEL"]
},
"allowed_order_sources": ["ETRADER"]
}

Use the access token with the API:

curl -H "Authorization: Bearer $TOKEN" \
"https://monitor.example.com:8988/api/v2/orders?source=ETRADER"

If the call fails:

ResponseLikely cause
401 UnauthorizedThe token is expired or invalid, or issuer-uri does not match the token issuer
403 Forbidden, Permission is required: ...The user does not have the role named in the message, directly or through a composite role
403 Forbidden, Order source is not allowed by allowed_order_sourcesThe token has no claim, or it does not list the source. Check that the scope is added to the client, the mapper adds the claim to the access token, and the user has the attribute set

Older Keycloak versions (before 17) serve the token endpoint under /auth/realms/....