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 likeENUM_ORDER_TYPE_TF
π Main Sections
Account
Market Info
- Section overview: Market Info β Overview
- Show Quote
- Show Quotes Many
- Show Quote History
- Show Symbol Info
- Show Symbol Params
- Show All Symbols
- Show Tick Values
Order Operations β οΈ
- Section overview: Orders β Overview
- Show Opened Orders
- Show Opened Order Tickets
- Show Orders History
- Close Order Example
- Close By Order Example
- Order Send Example
Streaming
- Section overview: Streaming β Overview
- Show RealβTime Quotes
- Stream Opened Order Profits
- Stream Opened Order Tickets
- Stream Trade Updates
π Quick Start
- Configure your
appsettings.jsonwith MT4 credentials and connection details. - Create
MT4AccountandMT4Service, then connect by server name or host/port. - Run demos from
Program.cs(theShow*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
π§ Navigation
- 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.