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

Events

All events belong to MT5API. Subscribe with += before Connect so you miss nothing.

Rules for handlers:

api.OnQuote += (sender, q) => Console.WriteLine($"{q.Symbol} {q.Bid}/{q.Ask}");
api.OnOrderUpdate += (sender, u) => Console.WriteLine($"{u.Type} #{u.Order?.Ticket}");
api.Connect();

Connection

event OnConnectProgress(MT5API sender, ConnectEventArgs args)

Raised at each step of a login and when the link drops.

Quotes

event OnQuote(MT5API api, Quote quote)

Raised for each new quote on a subscribed symbol. Quote has Symbol, Bid, Ask, Last, Time, Volume.

event OnQuoteHistory(MT5API sender, QuoteHistoryEventArgs progress)

Raised when bars requested with RequestQuoteHistoryMonth or RequestQuoteHistoryToday arrive. QuoteHistoryEventArgs has Symbol and Bars (List<Bar>).

event OnTickHistory(MT5API sender, TickHistoryEventArgs progress)

Raised as ticks requested with TickHistoryRequest arrive. TickHistoryEventArgs has Symbol and Bars (TickBar[]: Time, Bid, Ask, Last, Volume).

event OnOrderBook(MT5API sender, SymbolBook args)

Raised when market depth changes for a symbol you passed to SubscribeOrderBook. SymbolBook has Symbol and Bars, a dictionary from price to BookBar. A BookBar has Type (Reset, SellBook, BuyBook, SellMarket, BuyMarket), Price, Volume and Lots.

Symbols

event OnSymbolUpdate(MT5API sender, SymbolUpdate update)

Raised when the broker adds, changes or removes one symbol. SymbolUpdate has Symbol, Group (SymGroup), Sessions and Action (Add, Update, Delete, in namespace mtapi.mt5.Struct).

event OnSymbolsUpdate(MT5API sender)

Raised when the whole symbol list is reloaded. Read api.Symbols again.

Orders and positions

event OnOrderUpdate(MT5API sender, OrderUpdate update)

Raised when a position or order changes: opened, closed, partly closed, modified, stop loss or take profit hit, balance change.

OrderUpdate fields:

Account profit and margin are refreshed before this event fires.

api.OnOrderUpdate += (s, u) =>
{
    if (u.Type == UpdateType.OnStopLoss)
        Console.WriteLine($"Stop loss hit on #{u.Order.Ticket}, profit {u.Order.Profit}");
};

event OnOrderProgress(MT5API sender, OrderProgress progress)

Raised for each step of a trade request you sent: accepted, on its way, executed, refused. Use it with the async trade calls.

event OnOrderHistory(MT5API sender, OrderHistoryEventArgs args)

Raised when history asked for with a Request... call arrives, in one or more parts. See OrderHistoryEventArgs in positions-and-history.md. When args.PartialResponse is true, more parts follow.

Mail

event OnMail(MT5API sender, MailMessage msg)

Raised when the broker sends a mail message to the terminal. MailMessage has Id, Time, From, To, Subject, Body. Ask for the body with MailBodyRequest(msg.Id).

Enums used by events

ConnectProgress

SendLogin, SendAccountPassword, AcceptAuthorized, RequestTradeInfo, Connected, Exception, Disconnect.

UpdateType

Unknown, PendingClose, MarketOpen, PendingOpen, MarketClose, PartialClose, Started, Filled, Cancelling, MarketModify, PendingModify, OnStopLoss, OnTakeProfit, OnStopOut, Balance, Expired, Rejected, MarketCloseBy, PartialFill.

ProgressType

A public enum (Rejected, Accepted, InProcess, Opened, Closed, Modified, PendingDeleted, ClosedBy, MultipleClosedBy, Timeout, Price, Exception). No event in this build carries it. Use OrderProgress.TradeResult.Status instead.

Events · MT5 library reference