# How to integrate MetaTrader

This instruction explains how to create platforms, product groups, and products that are required for enabling MT4 and MT5 functionalities via the B2CORE Back Office.

For managing live and demo trading accounts on both MT4 and MT5, it's required to configure separate platforms, product groups, and products for each in the Back Office.

{% hint style="info" %}
No external connections are required for MT platforms. Connections to these platforms are established within B2CORE via the internal WEBAPI service. All credentials needed to connect to the respective MT platform are configured in **Products** > **Platforms**.
{% endhint %}

## How to create a platform for MT

To create a platform for MT:

{% stepper %}
{% step %}
Navigate to **Products** > **Platforms**.
{% endstep %}

{% step %}
Click **Create** in the upper-right page corner, and then select **MetaTrader 4** or **MetaTrader 5** in the dropdown.
{% endstep %}

{% step %}
In the **Create platform** popup, fill in the following fields:

* In the **Name** field, enter a unique name for the platform.
* In the **Caption** field, enter a caption that will be applied to the platform in the Back Office.
* In the **Income transfer request** dropdown, select:
  * **Yes** — to require admin approval and create requests for transfers to MT accounts via the B2CORE UI.
  * **No** — to process transfers to MT accounts via the B2CORE UI without requests.
* In the **Outcome transfer request** dropdown, select:
  * **Yes** — to require admin approval and create requests for transfers from MT accounts via the B2CORE UI.
  * **No** — to process transfers from MT accounts via the B2CORE UI without requests.
    {% endstep %}

{% step %}
Click **Save** to proceed.
{% endstep %}

{% step %}
On the **Edit platform** page, specify the following settings:

* In the **Short caption** field, you can optionally specify a short platform caption.
* If you configure a demo platform for MT, select **Yes** in the **Demo** dropdown; otherwise, make sure that **No** is selected.
* In the **Status** dropdown, select **Enabled**.
  {% endstep %}

{% step %}
In the **Settings** section, specify the following connection setting:

#### MetaTrader connection

* In the **Host** field, specify the IP address and port number for accessing the MT server.
* In the **Login** field, enter the login for accessing the MT Manager.
* In the **Password** field, enter the password for accessing the MT Manager.

#### WEBAPI connection

The WEBAPI connection settings are provided by your account manager.

* In the **Host** field, specify the domain name and port number for accessing WEBAPI.
* In the **Access token** field, specify the token used to access WEBAPI.

#### Settings

In this section, specify the additional settings:

* In the **Max inactivity days** field, enter the number of days after which MT accounts will be archived if no activity is detected during that period.
* In the **Web Terminal URL** field, specify the URL of the web trading terminal. When specified, the **Trade** button will appear on account cards for the respective platform in the B2CORE UI and mobile app, enabling clients to navigate to trading with a single click.
* In the **Use reporting on the platform** dropdown, select:
  * **Enabled** — to activate the **Send reports** option for MT accounts created via B2CORE.
  * **Disabled** — to keep the **Send reports** option disabled for MT accounts created via B2CORE.
    {% endstep %}

{% step %}
Click **Test connection** to validate the connection settings.

The checkmark displayed on the **Test connection** button indicates that the connection has been configured properly.
{% endstep %}

{% step %}
After the connection settings have been successfully validated, click **Save**.
{% endstep %}
{% endstepper %}

## How to create a product group for MT

To create a product group for MT:

{% stepper %}
{% step %}
Navigate to **Products** > **Groups**.
{% endstep %}

{% step %}
Click **+Create** in the upper-right page corner.
{% endstep %}

{% step %}
On the **Create group** page, fill in the following fields:

* In the **Caption** field, enter a caption for the product group. This caption will be assigned to the product group in the Back Office and will be visible to clients in the B2CORE UI.
* In the **Description** field, enter a group description.
* In the **Type** dropdown, select **Default**.
  {% endstep %}

{% step %}
Click **Save** to create the product group.
{% endstep %}
{% endstepper %}

## How to create a product for MT

To create a product for MT:

{% stepper %}
{% step %}
Navigate to **Products** > **Products**.
{% endstep %}

{% step %}
Click the **Create** in the upper-right page corner, and then select:

* **MetaTrader 5 Live** — to create a product for managing live accounts on MT5
* **MetaTrader 5 Demo** — to create a product for managing demo accounts on MT5
* **MetaTrader 4 Live** — to create a product for managing live accounts on MT4
* **MetaTrader 4 Demo** — to create a product for managing demo accounts on MT4
  {% endstep %}

{% step %}
In the **Create product** popup, fill in the following fields:

* In the **Platform Group** dropdown, select the appropriate group existing in your MT manager. MT accounts created based on this product via B2CORE will be assigned to this group.
* In the **Currency** dropdown, select the currency for the product. The available currency options in B2CORE depend on the settings of the selected platform group. For example, if a platform group in the MT manager is configured for `USD`, then `USD` will be the default currency option for MT accounts created with this product via B2CORE.
* In the **Name** field, enter a unique name for the product.
* In the **Group** dropdown, select the previously created [product group](#how-to-create-a-product-group-for-mt) to include the product into that group.
* In the **Factory** dropdown, select `100` to denominate MT accounts created with this product in currency subunits (for example, cents); otherwise, leave `1`.
* In the **Type** dropdown, select:
  * **Trade** — if you create a product for managing live accounts
  * **Demo** — if you create a product for managing demo accounts
    {% endstep %}

{% step %}
Click **Save** to proceed.
{% endstep %}

{% step %}
On the **Edit product** page, specify the following product settings:

* In the **Name** field, you can modify the product name. The name must be unique.
* In the **Caption** field, enter a caption for the product. This caption will be assigned to the product in the Back Office and will be visible to clients in the B2CORE UI.
* In the **Default leverage** field, enter the default leverage ratio that will be assigned to MT accounts created automatically when the **Auto creation on login** option is triggered.
* In the **Leverage** field, enter one or more leverage ratios that client can select when creating MT accounts via the B2CORE UI.
* In the **Rights** and **Default account rights** dropdowns, select the required permissions that will be applied to the product (such as `Enabled`, `Visible`, `Trade enabled`, `Transfer deposit`, and `Transfer withdraw`).

  The default rights will be assigned to MT accounts created automatically when the **Auto creation on login** option is triggered.

  For a list of possible permissions, refer to [Product permissions](https://docs.b2core.b2broker.com/back-office-guide/references/product-permissions).
* In the **Max accounts** field, enter an integer value to define the maximum number of MT accounts that a client can create for each currency added to the product.

  For example, if `USD` and `EUR` are added as currencies to the product and the **Max accounts** option is set to `1`, the client can create one account in `USD` and one account in `EUR` based on this product.

  * To set no limit on the number of accounts, specify **-1**.
  * To forbid clients to create accounts, specify **0**.
* In the **Mail** dropdown, select:
  * **Send** or **Default** — to automatically send email notifications to clients when new MT accounts are created, providing them with the necessary details to start trading.
  * **Don't send** — to disable email notifications about new MT accounts.
* In the **Mail template** dropdown, select the email template that will be used to send notifications about new MT accounts.
* In the **Start amount** field, specify the amount that will be automatically deposited to *demo* MT accounts upon their creation.
* In the **Min deposit amount (USD)** field, you can optionally specify the minimum deposit, in USD, required to create an MT account based on this product.
* In the **Auto creation on login** dropdown, select:
  * **Yes** — to automatically create MT accounts based on the product settings when clients first sign in to the B2CORE UI.
  * **No** — to create MT accounts based on this product manually.
* The **First transfer activation** option is only applicable to MT5. In the dropdown, select:
  * **Yes** — to create MT5 accounts without the `Trade enabled` permission. This permission will be assigned to the account upon the client's first successful transfer.
  * **No** — to create MT5 accounts with the `Trade enabled` permission, immediately active for trading.
* In the **Agreement link** field, specify a link to the document to which clients must consent in order to open MT accounts via the B2CORE UI.
* In the **Link info** field, specify a link to a resource with additional product information, which clients can access when creating MT accounts via the B2CORE UI.
* On the **Currencies** tab, you can review the currency associated with the product and add more currencies if necessary. The available currency options are limited by the settings of the platform groups configured in the MT manager.
* After configuring the product settings, activate it by selecting **Enabled** in the **Status** dropdown.
  {% endstep %}

{% step %}
Click **Save** to create the product.
{% endstep %}
{% endstepper %}

MT accounts related to the respective platform can now be created based on the product via the Back Office or B2CORE UI. Any changes to product settings will directly impact how the product is displayed and functions for clients in the B2CORE UI.

If both MT4 and MT5 platforms are needed, follow the same instructions to configure the other platform.
