Server.Time Error - Time in Future (October)

Created at 02 Sep 2022, 11:31
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
GR

GridSurfer

Joined 08.06.2019

Server.Time Error - Time in Future (October)
02 Sep 2022, 11:31


Hi Support,

for my bot I capture Ticks from various symbols and process them later. With each tick I attach the current Server.Time.
However, every few thousand ticks or so I get a Server.Time sometime in October. This only happens when realtime. In MarketData.GetTicks() time seems o.k.

Below is a little script that isolates the problem. Just a few minutes as expample, it gives the following output for my demo (IC Markets):

02.09.2022 07:41  -- 2.717 Ticks
02.09.2022 07:42  -- 2.590 Ticks
02.09.2022 07:43  -- 2.885 Ticks
02.09.2022 07:44  -- ERROR in minute -->AUDUSD - 22.10.2022 00:47:20
02.09.2022 07:44  -- 2.604 Ticks
02.09.2022 07:45  -- 2.689 Ticks
02.09.2022 07:46  -- 2.277 Ticks
02.09.2022 07:47  -- 2.156 Ticks
02.09.2022 07:48  -- 2.226 Ticks
02.09.2022 07:49  -- ERROR in minute -->AUDJPY - 22.10.2022 00:52:21
02.09.2022 07:49  -- ERROR in minute -->GBPAUD - 22.10.2022 00:52:21
02.09.2022 07:49  -- ERROR in minute -->EURNZD - 22.10.2022 00:52:21
02.09.2022 07:49  -- 2.415 Ticks
02.09.2022 07:50  -- 2.313 Ticks
02.09.2022 07:51  -- 2.110 Ticks
02.09.2022 07:52  -- 2.065 Ticks
02.09.2022 07:53  -- 1.935 Ticks
02.09.2022 07:54  -- ERROR in minute -->AUDJPY - 22.10.2022 00:57:21
02.09.2022 07:54  -- 1.720 Ticks
02.09.2022 07:55  -- 1.898 Ticks
02.09.2022 07:56  -- 2.609 Ticks
02.09.2022 07:57  -- 2.413 Ticks
02.09.2022 07:58  -- 2.078 Ticks
02.09.2022 07:59  -- 2.473 Ticks
02.09.2022 08:00  -- 2.898 Ticks
02.09.2022 08:01  -- 2.242 Ticks
02.09.2022 08:02  -- ERROR in minute -->NZDCHF - 22.10.2022 01:05:21
02.09.2022 08:02  -- ERROR in minute -->EURJPY - 22.10.2022 01:05:21
02.09.2022 08:02  -- 2.405 Ticks
02.09.2022 08:03  -- 2.076 Ticks
02.09.2022 08:04  -- 2.275 Ticks
02.09.2022 08:05  -- ERROR in minute -->GBPJPY - 22.10.2022 01:08:21
02.09.2022 08:05  -- 2.758 Ticks
02.09.2022 08:06  -- 2.189 Ticks

Example PROD (LIVE IC-Markets)

02.09.2022 08:16  -- 2.349 Ticks
02.09.2022 08:17  -- 2.135 Ticks
02.09.2022 08:18  -- 2.580 Ticks
02.09.2022 08:19  -- 2.967 Ticks
02.09.2022 08:20  -- 2.502 Ticks
02.09.2022 08:21  -- ERROR in minute -->GBPJPY - 22.10.2022 01:23:57
02.09.2022 08:21  -- ERROR in minute -->AUDJPY - 22.10.2022 01:23:57
02.09.2022 08:21  -- 2.289 Ticks
02.09.2022 08:22  -- 2.363 Ticks
02.09.2022 08:23  -- 2.467 Ticks
02.09.2022 08:24  -- ERROR in minute -->USDJPY - 22.10.2022 01:26:57
02.09.2022 08:24  -- 2.508 Ticks
02.09.2022 08:25  -- 2.675 Ticks

 

Do I need to handle Server.Time differently?

Cheers
GridSurfer

 

using System;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.IO;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FileSystem)]
    public class TickExample : Indicator
    {
        string[] _strSymbols = 
        {
            "EURAUD", "EURGBP", "EURJPY", "EURUSD", "EURCHF", "EURCAD", "EURNZD", 
            "GBPAUD", "GBPUSD", "GBPJPY", "GBPCHF", "GBPCAD", "GBPNZD",
            "AUDJPY", "AUDUSD", "AUDCAD", "AUDCHF", "AUDNZD",
            "NZDUSD", "NZDCAD", "NZDCHF", "NZDJPY",
            "USDCAD", "USDCHF", "USDJPY", "CADCHF", "CADJPY", "CHFJPY"
        };
        
        string _useFile = @"c:\_Trading\TickError.txt";
        List<TickRec> _tickList = new List<TickRec>();
        List<TickRec> _errorList = new List<TickRec>();
        static object _lockTickList = new object();

        protected override void Initialize()
        {
            foreach (string strSymbol in _strSymbols)
            {
                Symbol symbol = Symbols.GetSymbol(strSymbol);
                symbol.Tick += Symbol_Tick;
            }
            Timer.Start(TimeSpan.FromMinutes(1));
        }

        protected override void OnTimer()
        {
            List<TickRec> checkList = new List<TickRec>();
            lock (_lockTickList)
            {
                checkList = _tickList.GetRange(0, _tickList.Count);
                _tickList = new List<TickRec>();
            }
            
            StreamWriter sw = new StreamWriter(_useFile, true);
            foreach (TickRec tick in checkList)
            {
                if (tick.DateTime.Date.CompareTo(Server.Time.Date) != 0)
                    sw.WriteLine(Server.Time.ToString("dd.MM.yyyy HH:mm") + "  -- ERROR in minute -->" + tick.SymbolName + " - " + tick.DateTime.ToString("dd.MM.yyyy HH:mm:ss"));
            }
            sw.WriteLine(Server.Time.ToString("dd.MM.yyyy HH:mm") + "  -- " + checkList.Count.ToString("#,0") + " Ticks") ;
                
            sw.Close();
	    }
	    
        public override void Calculate(int Index)
        {}
        
        private void Symbol_Tick(SymbolTickEventArgs obj)        
        {
            TickRec newTick = new TickRec();
            newTick.SymbolName = obj.SymbolName;
            newTick.DateTime = Server.Time;
            newTick.Bid = obj.Bid;
            newTick.Ask = obj.Ask;

            lock (_lockTickList)
            {
                _tickList.Add(newTick);
            }
        }
    }

    public class TickRec
    {
        public string SymbolName = "";
        public DateTime DateTime;
        public double Bid = 0;
        public double Ask = 0;
    }
}

 

 


@GridSurfer
Replies

PanagiotisCharalampous
05 Sep 2022, 11:06

Hi GridSurfer,

This is a known issue and it has already been solved in 4.3.11. The update will be pushed to brokers soon.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous