Mt45ApiNet
Mt45ApiNet
Introduction
Mt45ApiNet provides a bridge to connect with MetaTrader4/5 Terminal. It allows you to access MetaTrader 4/5 Terminal information in .NET applications or call most built-in MQL commands. This enables you to leverage .NET’s powerful features and ecosystem while retaining your existing MQL method usage experience.
Improvements Over MtApi
This project is developed based on MtApi with significant optimizations:
- ✅ Extensive use of async/await for improved asynchronous operation efficiency and responsiveness
- ✅ Eliminated third-party DLL dependencies, now only relies on OS built-in DLLs for simpler build and more stable runtime, eliminating C++ environment dependency issues and mysterious memory errors
- ✅ Rewrote socket communication library to reduce text transmission issues
- ✅ Reorganized and renamed MQL commands into various Enums for easier understanding and usage
- ✅ Added MetaTrader 4 event triggers, enabling event-based notifications for trades, quotes, etc., similar to MetaTrader 5
- ✅ Added MetaTrader 5 Include/Trade extension library commands
- ✅ Added Custom Commands type for implementing methods beyond MQL
- ✅ Rewrote logging library with built-in logging components and interfaces for easy customization
Testing Usage
Load EA to MetaTrader 4/5 Terminal
- Load
/MqlExpert/Mt4api.ex4orMt5api.ex5in MetaTrader 4/5 Terminal and ensure it starts correctly - Compile and run the
Mt45ApiNet.Demoproject, set the same port, then click “Connect” - Test all commands to verify they work properly
Development Usage
- Reference
Mt45ApiNetsource code or DLL in your project - Create MT4Client or MT5Client instances and connect to MetaTrader 4/5 Terminal EA
- Call Mt45ApiNet methods just like calling MQL commands in MetaEditor
Code Examples
MT4 Client Example
MT4 = new MT4Client(host, intport);
MT4.OnOrderOpen += MT4_OnOrderOpen;
MT4.OnOrderClose += MT4_OnOrderClose;
MT4.OnOrderModify += MT4_OnOrderModify;
MT4.OnOrderDelete += MT4_OnOrderDelete;
MT4.QuoteUpdate += MT4_QuoteUpdate;
MT4.Loger.IsLog(true);
MT4.Loger.LogLevel(MTLoglevel.Debug);
MT4.SocketClient.Loger.IsLog(true);
MT4.SocketClient.Loger.LogLevel(MTLoglevel.Debug);
await MT4.Connect();
var price = await MT4.MarketInfo("EURUSD", MarketInfoModeType.MODE_ASK);MT5 Client Example
MT5 = new MT5Client(host, intport);
MT5.OnOrderOpen += MT5_OnOrderOpen;
MT5.OnPendingOrderOpen += MT5_OnPendingOrderOpen;
MT5.OnPendingOrderFill += MT5_OnPendingOrderFill;
MT5.OnOrderClose += MT5_OnOrderClose;
MT5.OnOrderModify += MT5_OnOrderModify;
MT5.OnOrderDelete += MT5_OnOrderDelete;
MT5.OnNewBar += MT5_OnNewBar;
MT5.QuoteUpdate += MT5_QuoteUpdate;
MT5.Loger.IsLog(true);
MT5.Loger.LogLevel(MTLoglevel.Debug);
MT5.SocketClient.Loger.IsLog(true);
MT5.SocketClient.Loger.LogLevel(MTLoglevel.Debug);
await MT5.Connect();
var account = await MT5.AccountInfoInteger(ENUM_ACCOUNT_INFO_INTEGER.ACCOUNT_LOGIN);License
MIT License
Contact
For business cooperation: zhao0876@163.com
Last updated on