To work with time in S#, the DateTimeOffset structure is used. This structure stores time information in the UTC (Coordinated Universal Time)format, as well as local time offset related to the UTC. Thus, it is always possible to determine local time and offset (time zone) of the source using the DateTimeOffset.DateTime (or DateTimeOffset.LocatDateTime ) and DateTimeOffset.Offset features, correspondingly.
To determine the stock exchange time in the S#, standard C# methods can be used: DateTimeNow or DateTimeOffsetNow. For these methods to return the exact time, it is necessary to synchronize the PC local time with atomic clock by calling the . method. Time offset will be recorded in the . After that, the will store the synchronized local time, taking into consideration the . The TimeHelper class is located in the Ecng.Common namespace.
var trader = new OpeneCryTrader(login, password); // printing the current local time Console.WriteLine(TimeHelper.Now); // doing a sync with internet clocks TimeHelper.SyncMarketTime(10000); // printing the current local time again Console.WriteLine(TimeHelper.Now);