Table of Contents

Sessions and time

Every time is UTC

The ViiSync server clock is UTC, and every time the API returns or accepts is UTC: quote and tick times, bar open times, order and deal times, history windows, expirations and session windows.

  • ServerTimeZoneInMinutes is 0.
  • ServerTimeUtc is the server's current time, corrected for the clock offset the API measures at login. ServerTime is the same value in the server's zone (also UTC), kept for MT5 compatibility.
  • A DateTime you pass in is treated as UTC. Pass DateTime.UtcNow-based values, not DateTime.Now.
// The server clock is UTC: ServerTimeZoneInMinutes is 0, and every time the API returns is UTC.
DateTime serverNow = api.ServerTimeUtc;     // corrected for the measured clock offset
int zone = api.ServerTimeZoneInMinutes;     // 0
Console.WriteLine($"server time {serverNow:yyyy-MM-dd HH:mm:ss} (UTC{zone / 60:+0;-0;+0})");

Coming from an MT5 broker clock

MT5 servers usually run on the broker's zone, often UTC+2 or UTC+3, so MT5 code tends to shift times by that offset. Drop those shifts. If other parts of your system still expect broker time, convert at the boundary:

// Porting code that assumed an MT5 broker clock (e.g. UTC+3): convert at the edge, keep UTC inside.
var brokerZone = TimeSpan.FromHours(3);
DateTime asBrokerTime = api.ServerTimeUtc + brokerZone;
Bar[] d1 = api.DownloadQuoteHistory("EURUSD", DateTime.UtcNow.Date.AddDays(-5), DateTime.UtcNow, 1440);
// D1 bars start at 00:00 UTC here; on a UTC+3 MT5 server they start at 21:00 UTC the previous day.

Daily bars differ for the same reason: a ViiSync D1 bar runs from 00:00 to 24:00 UTC; a D1 bar on a UTC+3 server runs from 21:00 to 21:00 UTC. W1 bars start on Sunday 00:00 UTC and MN1 bars on the 1st of the month.

Trading sessions

Each symbol has weekly quote and trade windows in Sessions: one list per weekday (index 0 = Sunday), each window in minutes from midnight UTC, end exclusive. A symbol without time limits has one 00:00–24:00 window a day.

On top of the weekly windows the server applies holidays (a holiday closes the symbol for the day, except inside its working window) and, for trading, the server's office hours.

  • IsQuoteSession: is the symbol quoting now (weekly quote window and no holiday)?
  • IsTradeSession: can it be traded now (trade window, no holiday, inside office hours, trading not disabled)?
if (!api.IsTradeSession("EURUSD"))
    Console.WriteLine("EURUSD is outside its trade session (or a holiday / office hours) right now");

// Weekly windows, minutes from midnight UTC; index 0 = Sunday.
SymbolSessions s = api.Symbols.Sessions["EURUSD"];
foreach (Session w in s.Trades[(int)DayOfWeek.Monday])
    Console.WriteLine($"Monday trade window {w.StartTime / 60:00}:{w.StartTime % 60:00}-{w.EndTime / 60:00}:{w.EndTime % 60:00} UTC");

An order sent outside the trade session is refused with MARKET_CLOSED.