I'm trying to implement a live trading tick data streaming from a MT4 terminal to a Postgres database. To accomplish this, I'm using dwx-zeromq-connector and I had success when doing this for 2 currency pairs.
The way the connector works is by setting a pub/sub
ports and stream data from MT4 using a python script. Now I want to stream 28 currencies, so the number of charts in the MT4 terminal is 28 and the problems of slow subscribers feels very heavy. The messages queue up and no matter what I try, it does not seems to process them any faster.
What I have tried so far is:
- 28 different sub sockets for all pub ports using multiprocessing and daemon threads (not at the same time)
- 1 socket for all 28 pub ports using multiprocessing and daemon threads (not at the same time)
- 28 different classes running 1 daemon thread each, one per pub
- 1 class having 7 different threads and each thread has 1 socket that manages 4 pub ports
None of them improves the performance. Now, looking at this zmq guide, the Black Box Pattern seems to be suitted for what I need. However, I was wondering if I should reduce the amount of pub ports by making that the publishers publish information to only 1 pub socket.
So, according to the zmq guide Black Box Pattern, I guess that I need to use only 1 publisher and then push the messages to worker, right? Based on all this, is it possible that many publishers publish messages to only one port using tcp protocols? And is the zmq guide what I should really use or I'm missing something? The specs of the VPS I'm using is 2 vCPU and 12 GB RAM.
If any code is needed I can post it gladly.
EDIT 1:
This is the OnTick function, as requested:
void OnTick()
{
/*
Use this OnTick() function to send market data to subscribed client.
*/
if(CheckServerStatus() == true)
{
if(Publish_MarketData == true)
{
//for(int s = 0; s < ArraySize(Publish_Symbols); s++)
// {
string _tick = GetBidAsk(Publish_Symbols);
if(print_pub_data)
{
Print("Sending " + Publish_Symbols + " " + _tick + " to PUB Socket");
}
InformPullClient(pubSocket, StringFormat("%s %s", Publish_Symbols, _tick));
//}
}
}
}