Scenarios
Scenarios are used to configure and instantiate MarketGrid.
MarketGrid is started by launching a scenario.
A scenario consists of:
- What services to start up;
- What configuration options to pass to each service.
Scenarios provide a high level of flexibility for deploying MarketGrid containers. Rather than specifying many configuration options for each server on which MarketGrid is run, each container can be simply told which scenario to run. This allows for deployments of any level of complexity. For example:
- The simplest possible deployment consists of just one scenario.
- A production deployment might define
mainandbackupscenarios for running engines in primary and DR zones. - A more advanced deployment might also define a
replicascenario for building out readonly replica instances for UI and API server scaling.
MarketGrid is typically shipped with a number of scenarios built in, tailored to the customer for whom the release is built. In addition, custom scenarios may be defined using YAML files that are stored outside the container.
Specifying the scenario to run
To launch MarketGrid using a specific scenario, specify its name as the argument to the mg start command which is used to run the container.
docker run -d marketgrid:latest mg start equities_test
services:
marketgrid:
command: mg start equities_test
image:
command: ["mg"]
args: ["start", "equities_test"]
If the container is already running, executing mg start (with either no scenario name or the same name as the running scenario) inside the container will bring up any services that are stopped.
Stopping a scenario
The MarketGrid container will begin to shut down when it receives a SIGINT signal from the container runtime. At this point, the running scenario will be shut down gracefully.
Depending on how the scenario is configured, data may be written down at this point.
Once all services have completed their shutdown process, the container will be allowed to stop.
Some runtimes define a grace period for container shutdown , after which time the container is forcefully terminated. This grace period may need to be adjusted to avoid data loss, depending on how frequently the MarketGrid services are configured to write down and how much data is in the system.
If MarketGrid is being run outside a container (for example, in a local development environment), use the mg stop command to stop all running services.
Defining scenarios
Usually, MarketGrid will ship with one or more scenarios that are predefined and tailored for the customer for whom the release has been built.
In addition, scenarios can be defined using JSON or YAML files that are loaded into the container using a persistent volume. This allows the customer to have full control over the deployment.
Here is an example of a scenario defined in YAML format:
name: equities_test
description: Equities example scenario
services:
# Core matching engine
matching_engine:
process: te_engine
options:
load: datasets/demo/equities_test_data
demomode: NoPasswords
savefile: translog
max_recs:
Account: 1000
Broadcast: 1000000
Enterprise: 100
Firm: 100
Holding: 50000
Holding_change: 100000
Level1_change: 100000
HoldingTransaction: 1000
Industry: 100
Instrument: 100
InstrumentGroup: 10
InstrumentMarket: 6
Market: 10
Order: 10000
RFQ: 1000
ScheduledTransactions: 1000
Sector: 100
Trade: 20000
User: 100
Blotter: 1
GroupUser: 10000
Position: 1
TableCache: 200000
TransactionLog: 10000
BlobObject: 1000
BlobObject_change: 10000
# API services
transaction_server:
process: te_tserver
snapshot_server:
process: te_snapshots
options:
type: OrderBook
# UI services
ui_server:
process: ui_server
nginx:
process: nginx
options:
branding: demo.default
Importing scenarios into MarketGrid
Custom scenarios are loaded into MarketGrid by mounting files into the /opt/MarketGrid/scenarios directory within the MarketGrid container. Any files in this directory that have a .json or .yaml extension will be parsed as scenario definitions.
If using Helm, scenarios can be defined directly within a scenarios block in the values.yaml file that is passed to helm install (or helm upgrade).
docker run -d -v /path/to/scenarios:/opt/MarketGrid/scenarios marketgrid-image
services:
marketgrid:
volumes:
- type: bind
source: /path/to/scenarios
target: /opt/MarketGrid/scenarios
org: ccmx
imageCredentials:
registry: registry.cartax.io
username: ${GITLAB_USERNAME}
password: ${GITLAB_TOKEN}
image:
tag: v3.5.6
command: ['mg']
args: ['start', 'test']
scenarios:
test.yaml: |
name: test
description: Example inline scenario definition
services:
# Core matching engine
matching_engine:
process: te_engine
options:
load: datasets/demo/equities_test_data
demomode: nopasswords
max_recs:
Account: 1000
Broadcast: 1000000
Enterprise: 100
Firm: 100
Holding: 50000
Holding_change: 100000
Level1_change: 100000
HoldingTransaction: 1000
Industry: 100
Instrument: 100
InstrumentGroup: 10
InstrumentMarket: 6
Market: 10
Order: 10000
RFQ: 1000
ScheduledTransactions: 1000
Sector: 100
Trade: 20000
User: 100
Blotter: 1
GroupUser: 10000
Position: 1
TableCache: 200000
TransactionLog: 10000
BlobObject: 1000
BlobObject_change: 10000
# UI services
ui_server:
process: ui_server
nginx:
process: nginx