Best way of getting MultiSymbol TickData

Created at 15 Feb 2020, 16:09
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!
SH

Shares4UsDevelopment

Joined 14.10.2018

Best way of getting MultiSymbol TickData
15 Feb 2020, 16:09


Hi Community,

Is there a better way to get multisymbol tick data(ask/bid/name/time) than the way i'm doing it now (see program below)?
and @CTDN Why isn't time in the tick info?

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TickEventCheck : Robot
    {
        Symbol NOKJPY, AUDCAD;
        Ticks tNOKJPY, tAUDCAD;
        protected override void OnStart()
        {
            NOKJPY = Symbols.GetSymbol("NOKJPY");
            NOKJPY.Tick += SymbolTick;
            tNOKJPY = MarketData.GetTicks("NOKJPY");

            AUDCAD = Symbols.GetSymbol("AUDCAD");
            AUDCAD.Tick += SymbolTick;
            tAUDCAD = MarketData.GetTicks("AUDCAD");
        }

        protected override void OnTick()
        {
            Print("OT:" + Symbol.Name, " ", Symbol.Ask, " ", Symbol.Bid);
        }

        private void SymbolTick(SymbolTickEventArgs symbolTick)
        {
            DateTime TickTime = (symbolTick.SymbolName == "AUDCAD" ? tAUDCAD : tNOKJPY).LastTick.Time;
            Print("ST:" + symbolTick.SymbolName, " ", symbolTick.Ask, " ", symbolTick.Bid, " ", TickTime);
        }
    }
}


Best rgds,


 

 

 

 


@Shares4UsDevelopment
Replies

firemyst
17 Feb 2020, 08:40

RE:

Shares4UsDevelopment said:

Hi Community,

Is there a better way to get multisymbol tick data(ask/bid/name/time) than the way i'm doing it now (see program below)?
and @CTDN Why isn't time in the tick info?

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TickEventCheck : Robot
    {
        Symbol NOKJPY, AUDCAD;
        Ticks tNOKJPY, tAUDCAD;
        protected override void OnStart()
        {
            NOKJPY = Symbols.GetSymbol("NOKJPY");
            NOKJPY.Tick += SymbolTick;
            tNOKJPY = MarketData.GetTicks("NOKJPY");

            AUDCAD = Symbols.GetSymbol("AUDCAD");
            AUDCAD.Tick += SymbolTick;
            tAUDCAD = MarketData.GetTicks("AUDCAD");
        }

        protected override void OnTick()
        {
            Print("OT:" + Symbol.Name, " ", Symbol.Ask, " ", Symbol.Bid);
        }

        private void SymbolTick(SymbolTickEventArgs symbolTick)
        {
            DateTime TickTime = (symbolTick.SymbolName == "AUDCAD" ? tAUDCAD : tNOKJPY).LastTick.Time;
            Print("ST:" + symbolTick.SymbolName, " ", symbolTick.Ask, " ", symbolTick.Bid, " ", TickTime);
        }
    }
}


Best rgds,

Yes, there's a much better, and cleaner way. Create a Dictionary object with your symbols as the key and the function as the value.

Something like (this code isn't exact as I'm doing this off the cuff) :

Dictionary<string, Action<>> tickFunctions = new Dictionary<string, Action<>>();

tickFunctions.Add("AUDCAD", tAUDCAD.LastTick.Time);
tickFunctions.Add("NOKJPY", tNOKJPY.LastTick.Time);

 

And then your SymbolTick function turns into something like:

private void SymbolTick(SymbolTickEventArgs symbolTick)
	{
		DateTime TickTime = DateTime.Min;
		if (tickFunctions.Contains(symbolTick.SymbolName))
		{
			TickTime = tickFunctions[symbolTick.SymbolName];
			Print("ST:" + symbolTick.SymbolName, " ", symbolTick.Ask, " ", symbolTick.Bid, " ", TickTime);
		}
		else
			Print("Hello there.");
	}

 


@firemyst

Shares4UsDevelopment
17 Feb 2020, 13:52

RE: RE:

Thanks for thinking with me, but I should elaborate a little more on the problem I guess,

The problem is obtaining the tick time which is not a property of  SymbolTickEventArgs.


@Shares4UsDevelopment