> For the complete documentation index, see [llms.txt](https://tradesync.gitbook.io/tradesync/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tradesync.gitbook.io/tradesync/rw-manager-mt5/deployment-of-rwmanager.md).

# Deployment of RWManager

{% hint style="info" %}
Using PowerShell all variable values ​​must be specified in single 'quotes'.
{% endhint %}

For run of RWManager you need to set ENV variables:

<table><thead><tr><th width="302.3333333333333">Key</th><th width="200">Value</th><th>Description</th></tr></thead><tbody><tr><td><code>LOG_FILE_NAME</code></td><td><code>C:\rw-manager\rw-manager-mt5.log</code></td><td>full path name for log file</td></tr><tr><td><code>LOG_METATRADER</code></td><td><code>true</code></td><td>if the flag is true, all logs messages will be placed to a file created by <code>MetaTrader5SDK dll files after successefull connection to MT5 server</code></td></tr><tr><td><code>LOG_LEVEL</code></td><td><code>debug</code></td><td><p></p><p>Sets the Logger's log level using a symbolic value. Valid values are:</p><ul><li>none (turns off logging)</li><li>fatal</li><li>critical</li><li>error</li><li>warning</li><li>notice</li><li>information</li><li>debug</li><li>trace</li></ul></td></tr><tr><td><code>GRACEFUL_SHUTDOWN_TIMEOUT</code></td><td>15</td><td>time in seconds that RW-Manager will wait for connected clients to close all connections before shutdown and exit after receiving a graceful shutdown notification from the operation system</td></tr><tr><td><code>MT5SDKLIBS</code></td><td><code>C:\rw-manager\MetaTrader5SDK\Libs</code></td><td>Path to your rw-manager folder + MetaTrader5SDK\Libs (required)</td></tr><tr><td><code>MT5SERVER</code></td><td><code>0.0.0.0:443</code></td><td>Address for authorization and communication with MT5 (required)</td></tr><tr><td><code>MT5PASS</code></td><td><code>pass1111,pass2222,pass3333</code></td><td>String of passwords for authorization in MT5 (required) separarted by comma. It must correspond with <code>MT5LOGIN</code>: the first password corresponds to the first login, the second password corresponds to the second login and etc.</td></tr><tr><td><code>MT5LOGIN</code></td><td><code>1111,2222,3333</code></td><td>String of logins for authorization in MT5 (required) separarted by comma. It must correspond with <code>MT5PASS</code>: the first login corresponds to the first password, the second login  corresponds to the second password and etc.</td></tr><tr><td><code>LISTEN_ADDRESS</code></td><td><code>127.0.0.1</code></td><td>Address to listen incoming requests</td></tr><tr><td><code>LISTEN_PORT</code></td><td><code>8080</code></td><td>Port to listen incoming requests</td></tr><tr><td><code>HEALTH_ENDPOINT</code></td><td><code>healthz</code></td><td>Endpoint path to check available service in k8s</td></tr><tr><td><code>METRICS_PORT</code></td><td><code>7777</code></td><td>Port for getting metrics for prometheus</td></tr><tr><td><code>INTERNAL_GATEWAY</code></td><td><code>5432</code></td><td>Port for communicate with Trading Gateway</td></tr><tr><td><code>APP_ID</code></td><td><code>1</code></td><td>APP id for communicate with Trading Gateway</td></tr><tr><td><code>MAX_INPUT_QUEUE_SIZE</code></td><td><code>128</code></td><td>Max number of record in queue for streaming processing</td></tr><tr><td><code>MAX_SAVE_TRADE_REQUEST</code></td><td><code>3</code></td><td>Max number of trades stored in a cash for streaming function GetLastTradeRequests</td></tr><tr><td><code>MT5_NUM_CONNECTIONS</code></td><td><code>3</code></td><td>Max number of connections handled by service to MT5 data sync</td></tr><tr><td><code>NATS_SERVICES_SUBJECT</code></td><td><code>RW-MANAGER</code></td><td>Name that will be used to form name of JetStream in NATS</td></tr><tr><td><code>NATS_HOSTS</code></td><td><code>127.0.0.1:4222</code></td><td>Address of nats-jet stream server with a port; if not defined or equal to the empty string, then the service will not initialize the connection with NATS JetStream</td></tr><tr><td><code>NATS_USER</code></td><td><code>nats_user</code></td><td>Name of user that used for nats-jet-stream connections; if not defined or equal to the empty string then connection to NATS will be made without authorization</td></tr><tr><td><code>NATS_PASSWORD</code></td><td><code>nats_password</code></td><td>User nats password used for nats-jet-stream connections</td></tr><tr><td><code>CLIENT_CERT_FILE</code></td><td><code>C:\certificate\client_cert.pem</code></td><td>Client certificate for NATS TLS connection</td></tr><tr><td><code>CLIENT_KEY_FILE</code></td><td><code>C:\certificate\client_key.pem</code></td><td>Client key for NATS TLS connection</td></tr><tr><td><code>ROOT_CA_CERT_FILE</code></td><td><code>C:\certificate\ca_cert.pem</code></td><td>Root certificate for NATS TLS connection</td></tr><tr><td><code>SERVER_CODE</code></td><td><code>mt5_trial1</code></td><td>server code that used in forming nats-jet-stream subject, shoud be alligned with account_config.json; if not defined then equal to "UNKNOWN"</td></tr><tr><td><code>LOG_FILE_NAME</code></td><td><code>C:\rw-manager\logs</code></td><td>all logs generated by RW-MANAGER will be written to this file; if <code>LOG_FILE_NAME</code> is not specified or contains an empty line, then logging is performed in the <code>system console</code></td></tr><tr><td><code>FILTER_PERIOD</code></td><td><code>1000</code></td><td>time in ms, that define time filtering period for filtered ticks subscription (TicksFilteredSubscribe), by default the value is equal to 1000 ms</td></tr><tr><td><code>MAX_SOCKET_CONNECTION</code></td><td>1000</td><td>numbers that define maximum number of concurrent socket connections, in case of number of connection is excited this number rw-manager is generating http error code 429 Too Many Requests</td></tr><tr><td><code>IS_STREAM_TICKS</code></td><td><code>TRUE</code> (by default)</td><td>enables receiving ticks stream from MT5</td></tr><tr><td><code>IS_STREAM_ORDERS</code></td><td><code>TRUE</code>(by default)</td><td>enables receiving orders stream from MT5</td></tr><tr><td><code>IS_STREAM_DEALS</code></td><td><code>TRUE</code> (by default)</td><td>enables receiving deals stream from MT5</td></tr><tr><td><code>IS_STREAM_POSITIONS</code></td><td><code>TRUE</code> (by default)</td><td>enables receiving positions stream from MT5</td></tr><tr><td><code>IS_STREAM_SYMBOLS</code></td><td><code>TRUE</code> (by default)</td><td>enables receiving symbols update stream from MT5</td></tr><tr><td><code>IS_STREAM_USER_ACCOUNTS</code></td><td><code>TRUE</code> (by default)</td><td>enables receiving user accounts update stream from MT5</td></tr><tr><td><code>IS_STREAM_USERS</code></td><td><code>TRUE</code> (by default)</td><td>enables receiving users update stream from MT5</td></tr><tr><td><code>IS_STREAM_GROUPS</code></td><td><code>FALSE</code>(by default)</td><td>enables receiving groups update stream from MT5</td></tr><tr><td><code>IS_STREAM_MAILS</code></td><td><code>FALSE</code>(by default)</td><td>enables receiving emails stream from MT5</td></tr><tr><td><code>IS_STREAM_NEWS</code></td><td><code>FALSE</code>(by default)</td><td>enables receiving news stream from MT5</td></tr><tr><td><code>IS_DEBUG_TRADES</code></td><td><code>FALSE</code>(by default)</td><td>a boolean flag to inform system to log all events from MetaTrader regarding changes in Positions/Deals/Orders</td></tr><tr><td><code>IS_DEBUG_ORDERS</code></td><td><code>FALSE</code>(by default)</td><td>a boolean flag to inform the system to log trading requests from client</td></tr><tr><td><code>INSTANCE_ID</code></td><td><code>i-instance-id</code></td><td>an ID of the instance</td></tr><tr><td><code>TICK_DELAY_ACCEPTED</code></td><td>0</td><td><p>A delay in milliseconds (ms) is specified for price tick processing. The system converts the timestamp of a new tick to GMT time and adds the <code>TICK_DELAY_ACCEPTED</code> value to it. If the resulting timestamp is greater than the current system GMT time, the tick is processed; otherwise, it is ignored.</p><p>When <code>TICK_DELAY_ACCEPTED</code> is set to 0, the filtering mechanism is disabled.</p></td></tr></tbody></table>

{% hint style="danger" %}
During the server restart all files placed to folder **bases** should be removed in order to ensure that all cached would not impact of processing request to RW Manager.
{% endhint %}

It is very mportant to write the variable METRICS\_PORT and to use it in Prometheus for getting metrics from RWManager.&#x20;

RWManager is working on Windows 64 container.

To deploy RWManager you should use the folowing scripts:

```json
    docker run -d --restart=always --name app1 -p   8080:8080 -p 7777:7777 --cpus=1.2 --env-file ${GAME_ENV_FILE} ${IMAGE}
    docker run -d --restart=always --name app2 -p   8081:8080 -p 7778:7777 --cpus=1.8 --env-file ${FXTR_ENV_FILE} ${IMAGE}
    docker run -d --restart=always --name app3 -p 8082:8080 -p 7779:7777 --cpus=1 --env-file ${PRICES_ENV_FILE} ${IMAGE}

```

where app1, app2, app3 are the names of the system modules.

### Checking availibility of RW-Manager

In order to check that RW-Manager is up and runnig the following operation can be executed:

* to check availability of services curl --location 'base\_url/server-time' - correct response should have status 200 and body contains of json object with server time.

### Restart of RW-Manager

RW Manager uses MetaQuotes Library to perform connections to the MetaTrader 5 server. This library implements some caching techniques for groups and symbol representation on the local drive where RW Manager started (in the folder ‘bases’). As a result, it is highly recommended to restart RW Manager when:

* configuration for a Symbol was changed, for example (Margin Call, Stop Out, Commission Settings and others)
* configuration for a Group was changed, for example (Execution Type, Margin Currency, Margin Settings, Trading Sessions, and others)
* configuration for a Group Symbol was changed, for example (Spread Markup, Commission Settings).

{% hint style="info" %}
Also, it is a good practice to restart RW Manager during the rollover period to request the latest MetaTrader 5 configurations.
{% endhint %}

{% hint style="danger" %}
During the server restart all files placed to folder **bases** should be removed in order to ensure that all cached would not impact of processing request to RW Manager
{% endhint %}

It is better to restart RW-Manager in any changes of `symbol` parameter to avoid the problem of data caching by the MT5APIManager64.dll library. (Also you can read about it [here](/tradesync/examples-of-using/how-to-subscribe-to-instruments.md))
