Table of Contents

Migrating from the MT5 API

ViiSync.AccountApi mirrors the MT5 client API (mt5api.dll): the type names, member names, parameter lists, enum names and enum values are the same. Most integrations port by changing two lines: the using and the constructor's host. This page shows the changes side by side and lists every behaviour that differs.

For a member-by-member view, see the MT5 mapping: each MT5 member, its ViiSync equivalent and whether it is covered fully or partially.

The same program, twice

The MT5 tab is shown for comparison only; it is not compiled here. The ViiSync tab is compiled with the documentation.

using mtapi.mt5;

var api = new MT5API(login, password, "mt5.broker.com", 443);
api.OnQuote += (sender, quote) => Console.WriteLine($"{quote.Symbol} {quote.Bid}/{quote.Ask}");
api.OnOrderUpdate += (sender, update) => Console.WriteLine($"{update.Type} {update.Order}");
api.Connect();
Console.WriteLine($"balance {api.AccountBalance} equity {api.AccountEquity}");

api.Subscribe("EURUSD");
var q = api.GetQuote("EURUSD");

var order = api.OrderSend("EURUSD", 0.10, q.Ask, OrderType.Buy, 0, 0, 10, "my ea", 42);
api.OrderModify(order.Ticket, "EURUSD", order.Lots, 0, order.OrderType, q.Bid - 0.0020, 0);
api.OrderClose(order.Ticket, "EURUSD", 0, order.Lots, order.OrderType);

var history = api.DownloadOrderHistory(DateTime.Now.AddDays(-30), DateTime.Now);
foreach (var trade in history.Orders)
    Console.WriteLine($"{trade.Ticket} {trade.Symbol} {trade.Profit}");

api.Disconnect();

What changed: the using, the class name in the constructor, and DateTime.Now → DateTime.UtcNow (ViiSync times are UTC; see below). Everything else compiles unchanged.

Porting checklist

  1. Replace using mtapi.mt5; with using ViiSync.AccountApi;.
  2. Replace new MT5API(...) with new ViiSyncAccountApi(...). The login is the ViiSync account id; the host is your ViiSync server. Port 443 means TLS (wss://host/ws); you can also pass a full wss:// URL.
  3. Treat every time as UTC. Remove any conversion from the broker's server zone (see Sessions and time).
  4. Keep your error handling: failures throw ServerException whose Code is the MT5 return code (Msg). See Error codes for the codes ViiSync returns.
  5. If you used certificate (.pfx) logins or MT5 proxy fields, drop them: TLS comes from wss://, and a proxy is set with Proxy.
  6. Check the MT5 mapping for any member your code uses that is marked partial.
// broker server time is UTC+3: convert before asking for history
var from = DateTime.UtcNow.AddHours(3).AddDays(-1);
var bars = api.DownloadQuoteHistory("EURUSD", from, DateTime.UtcNow.AddHours(3), 60);

What differs

MT5 API ViiSync.AccountApi
Times broker server time, often UTC+2 or UTC+3 UTC; ServerTimeZoneInMinutes is 0
Tickets issued by the MT5 server 64-bit ids issued by ViiSync; for positions and closed trades Order.Ticket is the position id
Market order price requested price, requotes with deviation > 0 and a price: REQUOTE (with the new bid/ask in ServerException.Result) when the fill would be outside price ± deviation points; with deviation 0 the order fills at the live quote
Filling policy enforced per symbol an explicit FOK/IOC the symbol does not allow is refused with UNSUPPORTED_FILLING_MODE; client fills are always all-or-nothing, so FOK and IOC behave the same
Investor login read-only session the same: IsInvestor is true and every trade or password call throws InvestorModeException; the server refuses them too
Symbol trade mode long only, short only, close only, disabled the same, with ONLY_LONG_POSITION, ONLY_SHORT_POSITION, ONLY_CLOSE_POSITION, TRADE_DISABLED
Symbol trade settings a SymGroup per symbol group fields of the symbol itself; Symbols.Groups[symbol] presents them as a SymGroup
Bars the server builds every timeframe the server stores M1; larger timeframes are aggregated in the library with the MT5 terminal's alignment (W1 from Sunday, MN1 from the 1st); Bar.Spread is always 0
Trade confirmation OrderSend returns after the server answers the same. Engines that answer with typed trade results run trade calls concurrently; older engines are matched on the trade push, one call at a time
Lost connection mid-trade OrderClientSafe the same: OrderClientSafe waits for the reconnect, settles close/delete/modify from the server's state, and looks up (never re-sends) an open
Reconnect on Connect only automatic by default (AutoReconnect), with a back-off up to 30 s
No-op modify NO_CHANGES the same (engines with typed trade results)
Trade events OnOrderUpdate with a transaction action OnOrderUpdate; TradeType names the action, including the server's own (ActivateOrder, ActivateStopLimitOrder, ActivateStopLoss, ActivateTakeProfit, ActivateStopOutPosition, ExpireOrder)
Request progress OnOrderProgress the same stages, including InProcess (REQUEST_ON_WAY) and Price (a requote's new bid/ask)
Swaps charged at rollover charged at the server rollover when the server has swaps enabled; otherwise Order.Swap is a display-only estimate that does not count in equity
Values ViiSync never produces — kept for source compatibility and marked NotEmittedByViiSyncAttribute (e.g. Bar.Spread, AccountRec.Blocked, most Msg codes)

ViiSync extras

Members MT5 does not have, useful when you are no longer bound to its shape: ServerTimeUtc, Positions, PendingOrders, DownloadTickHistory, DownloadDealHistory, CalculateBalanceHistory, GetOrderBook, OnAccountUpdate, OnLog, Margin, PositionId, ReceivedUtc. The full list is on ViiSync-only members.