KazaTrade
دخول
القائمة

KazaTrade MT5 library: function reference

The KazaTrade MT5 library (mt5api.dll) lets your .NET code log in to a MetaTrader 5 account, read quotes, place and manage orders, and read history. Everything starts with one class, MT5API, in the namespace mtapi.mt5.

This reference lists the public functions, properties and events. It is short on purpose. Each entry has the signature, what it does, the parameters, the return value, the errors it throws, and an example where one helps.

Install

  1. Download mt5api.dll from your Developer page (/app/dll). Pick the build for your runtime:
    • net48 for .NET Framework 4.8 (Windows)
    • netstandard2.0 for libraries
    • net8.0 for .NET 8 (Linux and Windows)
  2. Add a reference to the DLL in your project:
<ItemGroup>
  <Reference Include="mt5api">
    <HintPath>libs\mt5api.dll</HintPath>
  </Reference>
</ItemGroup>
  1. Add using mtapi.mt5; to your code.

Download the DLL from your Developer page (/app/dll). The page shows each file's SHA-256: check that your download matches it before you use the file (for example sha256sum mt5api.dll or Get-FileHash mt5api.dll).

The DLL has no key inside. Copy your key from your Developer page and set api.ApiKey before Connect. Keep the key secret, like a password. Without it, Connect fails with KazaTrade: no ApiKey set.

First call

using System;
using mtapi.mt5;

var api = new MT5API(12345678, "password", "broker.example.com", 443);
api.ApiKey = "your-key-from-the-developer-page";

api.Connect();
Console.WriteLine($"Balance: {api.Account.Balance} {api.AccountCurrency}");

Quote q = api.GetQuote("EURUSD", 5000);
Console.WriteLine($"EURUSD {q.Bid} / {q.Ask}");

api.Disconnect();

The same call with a broker server name instead of host and port:

var api = new MT5API(12345678, "password", "Broker-Server");

Good to know

Index

PageWhat is in it
connect.mdConstructors, Connect, Disconnect, settings, proxy, server and cluster info
account.mdAccount, balance, equity, margin, trading permissions, mail, demo account
symbols-and-quotes.mdSymbols, subscribe, quotes, market watch, tick value, bars, sessions
orders.mdOrderSend, OrderClose, OrderModify, async forms, enums
positions-and-history.mdOpen positions, closed orders, order history, equity history
events.mdAll events and the types they carry
errors.mdException types, ServerException.Code, common messages
KazaTrade MT5 library: function reference