Reconnect Terminal

62 views
Skip to first unread message

Marian Mesbah

unread,
Oct 25, 2017, 7:16:55 AM10/25/17
to NJ4X Forum
Dear Roman,

I was trying to test my application behavior in case of terminal disconnection by stopping the terminal from Terminal Server Dashboard and i faced 2 scenarios.

- In first scenario i used strategy.connect in the application start, then run timers that retrieve candles data, when i stop  the terminal, the nj4x will automatically handle the terminal re-connection & will keep retrieving the data stream normally.

- in second scenario i used SetBulkTickListener before the strategy.connect so i can retrieve the tick data along with the timers that handles the candles, when i disconnect the terminal, i notice that in the dashboard journal the automatic re-connection try to connect more than one terminal instance & the tick data retrieval stop.

also if i tried to rerun the timers i receive the following error "An exception of type 'Terminal connection not initialized -> No connection to the trade server" 

Please advise 
Thanks 

Roman Gerasimenko

unread,
Oct 25, 2017, 11:08:18 AM10/25/17
to nj...@googlegroups.com
Hi Marian,

Thanks for the info. Let me check what can be done..

ср, 25 жовт. 2017 о 14:16 Marian Mesbah <marian...@gmail.com> пише:
--
You received this message because you are subscribed to the Google Groups "NJ4X Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nj4x+uns...@googlegroups.com.
To post to this group, send email to nj...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Roman Gerasimenko

unread,
Oct 26, 2017, 1:54:54 AM10/26/17
to nj...@googlegroups.com
There was a bug in reconnection mechanism, should be fixed now. Please update to the latest (2.7.1) version of API.

ср, 25 жовт. 2017 о 18:08 Roman Gerasimenko <roman.ge...@nj4x.com> пише:

Marian Mesbah

unread,
Oct 27, 2017, 4:04:06 AM10/27/17
to NJ4X Forum
Thanks Roman, its fixed in the new version but the SetBulkTickListener stop retrieving the current ticks, i tried to run a timer to check the connection IsConnectedToTerminal() every second & when connected i call again SetBulkTickListener but it didn't work.

Please advise 

Roman Gerasimenko

unread,
Oct 27, 2017, 5:10:55 AM10/27/17
to nj...@googlegroups.com

It is strange, because BTL reconnects and continue getting ticks in my tests. I will prepare example for you later..

Marian Mesbah

unread,
Oct 30, 2017, 1:54:57 AM10/30/17
to NJ4X Forum
Dear Roman,

Please share with me the re-connection tick example as soon as you can.

Thanks 

NJ4X

unread,
Oct 30, 2017, 4:28:28 AM10/30/17
to NJ4X Forum
Here you are

        private class CustomInitStrategy : Strategy
        {
            public override void Init()
            {
                base.Init();
                //turn off symbols from MW
                foreach (var symbol in Symbols) SymbolSelect(symbol, false);
                //turn on required symbols at Market Watch to get their ticks
                foreach (var s in new[] { "EURUSD", "GBPUSD" }) SymbolSelect(s, true);
            }
        }

        private static void TestBTLReconnect()
        {
            var terminalServerHost = "127.0.0.1";
            var terminalServerPort = 7788;
            string brokerName = "demo1-amsterdam.fxpro.com";
            string account = "6796186";
            string password = "dpkk4hg";
            //
            var mt4 = new CustomInitStrategy();
            //
            bool showTicks = false;
            mt4.SetBulkTickListener((ticks, connection) =>
            {
                foreach (var tick in ticks)
                {
                    if (showTicks)
                    {
                        Console.WriteLine($"{tick.Symbol} {tick.Time} {tick.Ask} {tick.Bid}");
                    }
                }
            });
            //
            mt4.Connect(terminalServerHost, terminalServerPort, new Broker(brokerName), account, password);
            //
            Console.WriteLine($"Connected, limited?={mt4.IsLimitedFunctionality}\nPress enter...");
            Console.ReadLine();
            showTicks = true;
            Console.ReadLine();
        }

Reply all
Reply to author
Forward
0 new messages