MT5 manager gRPC API dot net client example

Created with Sketch.

MT5 manager gRPC API dot net client example

Table of Contents

API methods browser

MT5 manager proto file

Install dot net 6 SDK to run an example

This example has a dynamic client libraries generation provided by grpc tools nuget.

Once you run a dotnet build command, libraries would be generated in the bin/debug/net6.0 folder.

You can use a reference to it in you code.

Input your credentials for server, before runnig

Ready to run example

using Grpc.Net.Client;
using Mng5Grpc;

var channel = GrpcChannel.ForAddress("https:///mng5grpc.mtapi.io:443");
var mainControllerClient = new Main.MainClient(channel);
var connectionResponse = mainControllerClient.Connect(new ConnectRequest()
{
    Password = "",
    User = 1,
    Server = "",
});
if (connectionResponse.Error != null)
    throw new Exception(connectionResponse.Error.Message);

Console.WriteLine("Connect response: " + connectionResponse.Result);

var accountsListReply = mainControllerClient.AccountsList(new AccountsRequest()
{
    Id = connectionResponse.Result
});

if (accountsListReply.Error != null)
    throw new Exception(accountsListReply.Error.Message);

var accountIds = accountsListReply.Result;
Console.WriteLine($"Accounts found: {accountIds?.Count.ToString() ?? 0.ToString()}");
if (accountIds != null)
    foreach (var accountId in accountIds)
    {
        Console.WriteLine($"Account id: {accountId.ToString()}");
        var accountDetailsReply = mainControllerClient.AccountDetails(new AccountDetailsRequest()
        {
            Id = connectionResponse.Result,
            Login = accountId
        });
        if (accountDetailsReply.Error != null)
            throw new Exception(accountDetailsReply.Error.Message);

        var accountDetails = accountDetailsReply.Result;
        if (accountDetails != null)
        {
            Console.WriteLine($"Account login: {accountDetails.Login}");
            Console.WriteLine($"Account credit: {accountDetails.Credit}");
            Console.WriteLine($"Account balance: {accountDetails.Balance}");
            Console.WriteLine($"Account profit: {accountDetails.Profit}");
        }
    }
channel.ShutdownAsync().Wait();

Leave a Reply

Your email address will not be published. Required fields are marked *