robot communication

Created at 12 Feb 2014, 20:15
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!
BA

Balena

Joined 17.12.2012

robot communication
12 Feb 2014, 20:15


we need robots to be able to communicate with each other...

any idea on how long till we get this type functionality?


@Balena
Replies

Spotware
13 Feb 2014, 10:39

You can transfer information between cBots using named pipes, registry or files.


@Spotware

Balena
13 Feb 2014, 22:19

1.

can you give a "named pipe" example of how I would let bot 1 tell bot 2 that X = 2

2.

can i do this in a backtest with bot 1 and bot 2?

thanks


@Balena

hermoso
14 Feb 2014, 00:13

You can use ZEROMQ is the easy and reliable way to do 

 

here is an example: 

 

Server Side:

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using ZMQ;

         List<string> fields = new List<string> 
        {
            "Open",
            "High",
            "Low",
            "Close"
        };   

 

     protected override void OnStart()
        {
            int total = 0;
            using (var context = new Context(1))
            {
                using (Socket worker = context.Socket(SocketType.DEALER))
                {
                    worker.StringToIdentity(Symbol.Code, Encoding.Unicode);
                    worker.Connect("tcp://127.0.0.1:5999");



                    while (true)
                    {
                        string request = worker.Recv(Encoding.Unicode);
                        if (request.Equals("FIM"))
                            total++;
                        // Print(total);



                        for (int idx = 0; idx < fields.Count(); idx++)
                        {
                            if (request.Equals(fields[idx]))
                            {
                                var valor_ = valor(request, Convert.ToInt32(worker.Recv(Encoding.Unicode)));

                                worker.Send(valor_, Encoding.Unicode);
                                break;
                            }
                        }


                    }                    

                }

            }


        }

 

         private String valor(string request, int periodo)
        {

            if (String.Equals(request, "Open"))
                return Convert.ToString(MarketSeries.Open.Last(periodo));
            if (String.Equals(request, "High"))
                return Convert.ToString(MarketSeries.High.Last(periodo));
            if (String.Equals(request, "Low"))
                return Convert.ToString(MarketSeries.Low.Last(periodo));
            if (String.Equals(request, "Close"))
                return Convert.ToString(MarketSeries.Close.Last(periodo));
            Print("cagada");
            return Convert.ToString(0);
        }

 

 

//////////////////////////////////////

 

 

Client Side

 

 

 

         protected override void OnStart()
        {

            using (var context = new Context(1))
            {
                using (Socket requester = context.Socket(SocketType.ROUTER))
                {
                    requester.Bind("tcp://*:5999");
                    System.Threading.Thread.Sleep(1000);
                    double high = consulta(context,requester,"USDJPY","High",100)
                }
            }

}

 

 

         private double consulta(ZMQ.Socket requester, string Ativo, String Series, int periodo)
        {

            requester.SendMore(Ativo, Encoding.Unicode);
            requester.SendMore(Series, Encoding.Unicode);
            requester.Send(Convert.ToString(periodo), Encoding.Unicode);
            requester.Recv();
            string buffer = requester.Recv(Encoding.Unicode);
            return Convert.ToDouble(buffer);

        }

}

 

 

you can get zeromq via nuget.. create a new project in visual studio download via nuget and then reference it in your calgo project outside de visual studio,, you do this just to get the files

 

as clrzmq is a wrapper of the libzmq the libzmq must be in the calgo path... control alt del... the click with the right button on calgo process... then go to file or folder(sorry my windows is in pt-br) something like that.. then copy the libzmq to this folder

 

 

This is an example of as many robots as you want exchanging quotes... pay attetion in this topology the router must wait for the dealers to connect... i really sugest you to go to http://zguide2.zeromq.org/

 

 

here are my references

 


//#reference: ..\..\x64\Release\clrzmq.dll
//#reference: ..\..\x64\Release\clrzmq-ext.dll

 

i hope this helps you


@hermoso

ninosgr
04 Mar 2014, 11:15

RE:

Hi hermoso,

would you be interested in creating a simple robot for me which would send current market data over TCP and receive the basic commands of cAlgo such open close position take profit etc?

I am not a programmer and although your description seems very clear but not for a non programmer.

my email address is ninosgr@gmail.com

Thanks

You can use ZEROMQ is the easy and reliable way to do 

 

here is an example: 

 

Server Side:

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using ZMQ;

         List fields = new List 
        {
            "Open",
            "High",
            "Low",
            "Close"
        };   

 

     protected override void OnStart()
        {
            int total = 0;
            using (var context = new Context(1))
            {
                using (Socket worker = context.Socket(SocketType.DEALER))
                {
                    worker.StringToIdentity(Symbol.Code, Encoding.Unicode);
                    worker.Connect("tcp://127.0.0.1:5999");



                    while (true)
                    {
                        string request = worker.Recv(Encoding.Unicode);
                        if (request.Equals("FIM"))
                            total++;
                        // Print(total);



                        for (int idx = 0; idx < fields.Count(); idx++)
                        {
                            if (request.Equals(fields[idx]))
                            {
                                var valor_ = valor(request, Convert.ToInt32(worker.Recv(Encoding.Unicode)));

                                worker.Send(valor_, Encoding.Unicode);
                                break;
                            }
                        }


                    }                    

                }

            }


        }

 

         private String valor(string request, int periodo)
        {

            if (String.Equals(request, "Open"))
                return Convert.ToString(MarketSeries.Open.Last(periodo));
            if (String.Equals(request, "High"))
                return Convert.ToString(MarketSeries.High.Last(periodo));
            if (String.Equals(request, "Low"))
                return Convert.ToString(MarketSeries.Low.Last(periodo));
            if (String.Equals(request, "Close"))
                return Convert.ToString(MarketSeries.Close.Last(periodo));
            Print("cagada");
            return Convert.ToString(0);
        }

 

 

//////////////////////////////////////

 

 

Client Side

 

 

 

         protected override void OnStart()
        {

            using (var context = new Context(1))
            {
                using (Socket requester = context.Socket(SocketType.ROUTER))
                {
                    requester.Bind("tcp://*:5999");
                    System.Threading.Thread.Sleep(1000);
                    double high = consulta(context,requester,"USDJPY","High",100)
                }
            }

}

 

 

         private double consulta(ZMQ.Socket requester, string Ativo, String Series, int periodo)
        {

            requester.SendMore(Ativo, Encoding.Unicode);
            requester.SendMore(Series, Encoding.Unicode);
            requester.Send(Convert.ToString(periodo), Encoding.Unicode);
            requester.Recv();
            string buffer = requester.Recv(Encoding.Unicode);
            return Convert.ToDouble(buffer);

        }

}

 

 

you can get zeromq via nuget.. create a new project in visual studio download via nuget and then reference it in your calgo project outside de visual studio,, you do this just to get the files

 

as clrzmq is a wrapper of the libzmq the libzmq must be in the calgo path... control alt del... the click with the right button on calgo process... then go to file or folder(sorry my windows is in pt-br) something like that.. then copy the libzmq to this folder

 

 

This is an example of as many robots as you want exchanging quotes... pay attetion in this topology the router must wait for the dealers to connect... i really sugest you to go to http://zguide2.zeromq.org/

 

 

here are my references

 


//#reference: ..\..\x64\Release\clrzmq.dll
//#reference: ..\..\x64\Release\clrzmq-ext.dll

 

i hope this helps you

 


@ninosgr