Skip to content

Getting Started with MetaTrader 4 in C#

Welcome to the MetaRPC MT4 C# Documentation β€” your guide to integrating with MetaTrader 4 using C# and gRPC.

This documentation will help you:

  • πŸ“˜ Explore all available account, market, and order methods
  • πŸ’‘ Learn from async C# usage examples with logging and cancellation
  • πŸ” Work with real‑time streaming for quotes, orders, and trades
  • βš™οΈ Understand all input/output types such as OrderInfo, QuoteData, and enums like ENUM_ORDER_TYPE_TF

πŸ“š Main Sections

Account


Market Info


Order Operations ⚠️


Streaming


πŸš€ Quick Start

  1. Configure your appsettings.json with MT4 credentials and connection details.
  2. Create MT4Account and MT4Service, then connect by server name or host/port.
  3. Run demos from Program.cs (the Show* helpers) or call the low‑level methods directly.

// appsettings.json
{
  "MT4Options": {
    "User": 1234567,
    "Password": "<<<use env var>>>",
    "ServerName": "RoboForex-Demo",
    "Host": null,
    "Port": 443,
    "DefaultSymbol": "EURUSD"
  }
}
// Program.cs
var cfg = new ConfigurationBuilder()
    .SetBasePath(AppContext.BaseDirectory)
    .AddJsonFile("appsettings.json", optional: true)
    .AddEnvironmentVariables()
    .Build();

var options = cfg.GetSection("MT4Options").Get<MT4Options>()!;

using var loggerFactory = LoggerFactory.Create(b => b.AddConsole());
var mt4 = new MT4Account(options.User, options.Password, logger: loggerFactory.CreateLogger<MT4Account>());
var svc = new MT4Service(mt4, loggerFactory.CreateLogger<MT4Service>());

await mt4.ConnectByServerNameAsync(options.ServerName!, baseChartSymbol: options.DefaultSymbol);

await svc.ShowAccountSummary();
await svc.ShowQuote(options.DefaultSymbol);

πŸ›  Requirements

  • .NET 8 SDK
  • gRPC client runtime and Protobuf bindings (included via project references)
  • Microsoft.Extensions.Logging.* for console logging

  • The section links above point directly to method pages in this repo.
  • Each Overview page gives workflow tips and best practices.
  • Method pages list exact input/output fields and enums.