FIX API crash(usually after 1-20 minutes) : An existing connection was forcibly closed by the remote host

Created at 07 Jan 2022, 23:53
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!
SL

slukk200

Joined 07.12.2021

FIX API crash(usually after 1-20 minutes) : An existing connection was forcibly closed by the remote host
07 Jan 2022, 23:53


Hi All,

My FIX API crash(usually after 1-20 minutes). (An existing connection was forcibly closed by the remote host)

Unfortunately I cannot figure out the reason as no text included in the logout message. This is how the logout message looks like:

8=FIX.4.4|9=73|35=5|34=19|49=demo.icmarkets.8256245|52=20220107-16:22:07.500|56=cServer|10=023|session:FIX.4.4:demo.icmarkets.8256245->cServer:TRADE

Sometimes it is doing it every 1-2 minutes, sometimes it works for 30 minutes, regadless if I use ICMarkets demo or cTrader demo. I have tried it on both my local machine and on VPS, the result is the same,so I assume it is not an internet connection issue. I am using QuickFix/n and my app connects to around 50-80 symbols simulteously.

Does anyone have any idea why is it doing this?

Thanks for your help in advance.

 

This is how my config file looks like for cTrader demo:

[DEFAULT]
BeginString=FIX.4.4
ConnectionType=initiator
HeartBtInt=10
ReconnectInterval=900000
StartTime=00:00:00
EndTime=23:59:59
StartDay=Sun
EndDay=Sat
DataDictionary=.\ctrader_FIX44.xml
FileStorePath=.\FIXLogs\
FileLogPath=.\Logs\
ScreenLogShowEvents=Y
TimeZone=Central Europe Standard Time
UseLocalTime=N
MillisecondsInTimeStamp=Y
ValidateFieldsHaveValues=N

[SESSION]
SessionQualifier=QUOTES
SenderCompID=demo.ctrader.3441945
TargetCompID=cServer
ResetOnLogon=Y
SocketConnectHost=h28.p.ctrader.com
SocketConnectPort=5201

[SESSION]
SessionQualifier=TRADE
SenderCompID=demo.ctrader.3441945
TargetCompID=cServer
ResetOnLogon=Y
SocketConnectHost=h28.p.ctrader.com
SocketConnectPort=5202


@slukk200
Replies

amusleh
10 Jan 2022, 11:09

Hi,

I just tested with our QuickFIX console sample and it didn't got disconnected at all after waiting for more than an hour.


@amusleh

slukk200
10 Jan 2022, 17:44

RE:

amusleh said:

Hi,

I just tested with our QuickFIX console sample and it didn't got disconnected at all after waiting for more than an hour.

I just tried it again. It took me maybe a minute to get disconnected. I have attached my logs. If you see something weird, please let me know. Again, I am connected to around 80 symbols and use only one session for quotes and one for trades. How many symbols did you connect?

These are the last few messages before it disconnected.

8=FIX.4.49=15335=W34=307149=cServer50=QUOTE52=20220110-15:08:59.47956=demo.ctrader.344194557=APP_QUOTE_SESSION55=52268=2269=0270=15.70375269=1270=15.7084310=072
8=FIX.4.49=14935=W34=307249=cServer50=QUOTE52=20220110-15:08:59.48456=demo.ctrader.344194557=APP_QUOTE_SESSION55=15268=2269=0270=90.976269=1270=90.98610=144
8=FIX.4.49=15135=W34=307349=cServer50=QUOTE52=20220110-15:08:59.50256=demo.ctrader.344194557=APP_QUOTE_SESSION55=41268=2269=0270=1795.19269=1270=1795.3110=219
8=FIX.4.49=15435=W34=307449=cServer50=QUOTE52=20220110-15:08:59.50756=demo.ctrader.344194557=APP_QUOTE_SESSION55=22312268=2269=0270=1588.09269=1270=1588.2410=122
8=FIX.4.49=14935=W34=307549=cServer50=QUOTE52=20220110-15:08:59.52956=demo.ctrader.344194557=APP_QUOTE_SESSION55=54268=2269=0270=7.4381269=1270=7.439710=140
8=FIX.4.49=14735=W34=307649=cServer50=QUOTE52=20220110-15:08:59.56256=demo.ctrader.344194557=APP_QUOTE_SESSION55=42268=2269=0270=22.38269=1270=22.3910=015
8=FIX.4.49=15035=W34=307749=cServer50=QUOTE52=20220110-15:08:59.57556=demo.ctrader.344194557=APP_QUOTE_SESSION55=4268=2269=0270=115.318269=1270=115.32110=157
8=FIX.4.49=14935=W34=307849=cServer50=QUOTE52=20220110-15:08:59.58656=demo.ctrader.344194557=APP_QUOTE_SESSION55=7268=2269=0270=156.203269=1270=156.2110=123
8=FIX.4.49=14935=W34=307949=cServer50=QUOTE52=20220110-15:08:59.59256=demo.ctrader.344194557=APP_QUOTE_SESSION55=22268=2269=0270=8.8943269=1270=8.895310=151
8=FIX.4.49=15135=W34=308049=cServer50=QUOTE52=20220110-15:08:59.59256=demo.ctrader.344194557=APP_QUOTE_SESSION55=59268=2269=0270=12.0482269=1270=12.049710=217
8=FIX.4.49=15035=W34=308149=cServer50=QUOTE52=20220110-15:08:59.59556=demo.ctrader.344194557=APP_QUOTE_SESSION55=2268=2269=0270=1.35455269=1270=1.3545710=168
8=FIX.4.49=15135=W34=308249=cServer50=QUOTE52=20220110-15:08:59.60356=demo.ctrader.344194557=APP_QUOTE_SESSION55=57268=2269=0270=10.0535269=1270=10.055910=204
8=FIX.4.49=14935=W34=308349=cServer50=QUOTE52=20220110-15:08:59.60356=demo.ctrader.344194557=APP_QUOTE_SESSION55=8268=2269=0270=1.26748269=1270=1.267510=127
8=FIX.4.49=15235=W34=308449=cServer50=QUOTE52=20220110-15:08:59.60456=demo.ctrader.344194557=APP_QUOTE_SESSION55=21499268=2269=0270=4611.3269=1270=4611.510=011
8=FIX.4.49=14935=W34=308549=cServer50=QUOTE52=20220110-15:08:59.61656=demo.ctrader.344194557=APP_QUOTE_SESSION55=44268=2269=0270=84.979269=1270=84.99910=160
8=FIX.4.49=15435=W34=308649=cServer50=QUOTE52=20220110-15:08:59.62156=demo.ctrader.344194557=APP_QUOTE_SESSION55=10093268=2269=0270=12.3705269=1270=12.373210=102
8=FIX.4.49=15135=W34=308749=cServer50=QUOTE52=20220110-15:08:59.62756=demo.ctrader.344194557=APP_QUOTE_SESSION55=47268=2269=0270=10.3224269=1270=10.325610=209
8=FIX.4.49=15135=W34=308849=cServer50=QUOTE52=20220110-15:08:59.62756=demo.ctrader.344194557=APP_QUOTE_SESSION55=16268=2269=0270=1.89153269=1270=1.8916210=231
8=FIX.4.49=15135=W34=308949=cServer50=QUOTE52=20220110-15:08:59.64556=demo.ctrader.344194557=APP_QUOTE_SESSION55=17268=2269=0270=1.43272269=1270=1.4327910=224
8=FIX.4.49=14935=W34=309049=cServer50=QUOTE52=20220110-15:08:59.64556=demo.ctrader.344194557=APP_QUOTE_SESSION55=27268=2269=0270=0.7306269=1270=0.730710=116
8=FIX.4.49=15135=W34=309149=cServer50=QUOTE52=20220110-15:08:59.64756=demo.ctrader.344194557=APP_QUOTE_SESSION55=19268=2269=0270=1.71687269=1270=1.7169810=238
8=FIX.4.49=14935=W34=309249=cServer50=QUOTE52=20220110-15:08:59.65356=demo.ctrader.344194557=APP_QUOTE_SESSION55=29268=2269=0270=9.1323269=1270=9.134310=124
8=FIX.4.49=15435=W34=309349=cServer50=QUOTE52=20220110-15:08:59.66456=demo.ctrader.344194557=APP_QUOTE_SESSION55=22333268=2269=0270=1.53393269=1270=1.5340710=115
8=FIX.4.49=15435=W34=309449=cServer50=QUOTE52=20220110-15:08:59.67456=demo.ctrader.344194557=APP_QUOTE_SESSION55=22338268=2269=0270=1.02659269=1270=1.0269710=126
8=FIX.4.49=14935=W34=309549=cServer50=QUOTE52=20220110-15:08:59.67456=demo.ctrader.344194557=APP_QUOTE_SESSION55=64268=2269=0270=0.9151269=1270=0.915410=126
8=FIX.4.49=15235=W34=309649=cServer50=QUOTE52=20220110-15:08:59.71656=demo.ctrader.344194557=APP_QUOTE_SESSION55=21576268=2269=0270=7455.8269=1270=7456.210=035
8=FIX.4.49=14935=W34=309749=cServer50=QUOTE52=20220110-15:08:59.74256=demo.ctrader.344194557=APP_QUOTE_SESSION55=45268=2269=0270=75.179269=1270=75.19510=144
8=FIX.4.49=15135=W34=309849=cServer50=QUOTE52=20220110-15:08:59.74856=demo.ctrader.344194557=APP_QUOTE_SESSION55=57268=2269=0270=10.0536269=1270=10.055910=222
8=FIX.4.49=14935=W34=309949=cServer50=QUOTE52=20220110-15:08:59.77056=demo.ctrader.344194557=APP_QUOTE_SESSION55=44268=2269=0270=84.979269=1270=84.99810=165
8=FIX.4.49=15135=W34=310049=cServer50=QUOTE52=20220110-15:08:59.77256=demo.ctrader.344194557=APP_QUOTE_SESSION55=60268=2269=0270=317.895269=1270=318.06510=218
8=FIX.4.49=14935=W34=310149=cServer50=QUOTE52=20220110-15:08:59.78856=demo.ctrader.344194557=APP_QUOTE_SESSION55=22268=2269=0270=8.8943269=1270=8.895410=145
8=FIX.4.49=15135=W34=310249=cServer50=QUOTE52=20220110-15:08:59.78856=demo.ctrader.344194557=APP_QUOTE_SESSION55=59268=2269=0270=12.0482269=1270=12.050210=206
8=FIX.4.49=14735=W34=310349=cServer50=QUOTE52=20220110-15:08:59.79556=demo.ctrader.344194557=APP_QUOTE_SESSION55=69268=2269=0270=6.58269=1270=6.581410=035
8=FIX.4.49=15435=W34=310449=cServer50=QUOTE52=20220110-15:08:59.79556=demo.ctrader.344194557=APP_QUOTE_SESSION55=22334268=2269=0270=8.91296269=1270=8.9153510=136
8=FIX.4.49=15035=W34=310549=cServer50=QUOTE52=20220110-15:08:59.80756=demo.ctrader.344194557=APP_QUOTE_SESSION55=21499268=2269=0270=4610.8269=1270=461110=169
8=FIX.4.49=14835=W34=310649=cServer50=QUOTE52=20220110-15:08:59.80756=demo.ctrader.344194557=APP_QUOTE_SESSION55=54268=2269=0270=7.438269=1270=7.439710=084
8=FIX.4.49=15135=W34=310749=cServer50=QUOTE52=20220110-15:08:59.80756=demo.ctrader.344194557=APP_QUOTE_SESSION55=47268=2269=0270=10.3222269=1270=10.325510=199
8=FIX.4.49=15035=W34=310849=cServer50=QUOTE52=20220110-15:08:59.83656=demo.ctrader.344194557=APP_QUOTE_SESSION55=5268=2269=0270=0.71608269=1270=0.7161110=159
8=FIX.4.49=15435=W34=310949=cServer50=QUOTE52=20220110-15:08:59.85656=demo.ctrader.344194557=APP_QUOTE_SESSION55=22338268=2269=0270=1.02659269=1270=1.0269410=122
8=FIX.4.49=14935=W34=311049=cServer50=QUOTE52=20220110-15:08:59.86656=demo.ctrader.344194557=APP_QUOTE_SESSION55=15268=2269=0270=90.976269=1270=90.98510=140
Session FIX.4.4:demo.ctrader.3441945->cServer:QUOTES disconnecting: System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.

 //    at QuickFix.SocketInitiatorThread.ReadSome(Byte[] buffer; Int32 timeoutMilliseconds) in C:\Users\radul\Google Drive\C#\quickfixn\QuickFIXn\SocketInitiatorThread.cs:line 154 //    at QuickFix.SocketInitiatorThread.Read() in C:\Users\radul\Google Drive\C#\quickfixn\QuickFIXn\SocketInitiatorThread.cs:line 81

2022-01-10 15:09:00.6125710WarningClient_QuoteConnectionChangeQuote disconnected on remote side. remoteDiscionnectContainer.Count=12022-01-10 15:09:00.6129186InfoDisconnectDisconnect called for cTraderFIXConnector account:3441945 vendor:CTRADERDEMO_FIX


@slukk200

amusleh
11 Jan 2022, 08:40

Hi,

Does it happen only when you subscribe to 80 symbols or it happens always?

Can you try without subscribing to any symbol or just subscribe to 1 symbol, see if it gets disconnected or not.


@amusleh

slukk200
11 Jan 2022, 13:00 ( Updated at: 11 Jan 2022, 14:14 )

I just tried it with 5 symbols, and it has been working perfectly for 2 hours so far.

-Is there a limitation on how many symbols can I connect to or how many messages can I recieve?

-Or maybe there are some limitations of the demo accounts?

-Should connect to one symbol per session only and have 80 different sessions?

-ReconnectInterval=900000, I see that people usually set it to around 20. Could this be the problem?

Unfortunately I couldn't find anything about limitations in the document, so if anyone knows anything about it, please share.


@slukk200

amusleh
12 Jan 2022, 08:30

RE:

slukk200 said:

I just tried it with 5 symbols, and it has been working perfectly for 2 hours so far.

-Is there a limitation on how many symbols can I connect to or how many messages can I recieve?

-Or maybe there are some limitations of the demo accounts?

-Should connect to one symbol per session only and have 80 different sessions?

-ReconnectInterval=900000, I see that people usually set it to around 20. Could this be the problem?

Unfortunately I couldn't find anything about limitations in the document, so if anyone knows anything about it, please share.

Hi,

I'm not aware of any limitation on number of symbols you can subscribe.

Maybe you are not processing fast enough the incoming data and your buffer gets overflow.


@amusleh

slukk200
12 Jan 2022, 09:50

CPU consumption is below 2%, I think in that case I should have got a heartbeat missed message.

 


@slukk200

amusleh
12 Jan 2022, 10:04 ( Updated at: 12 Jan 2022, 10:30 )

Hi,

I tested on our QuickFIXn console sample, I subscribed to 200 symbols and waited for an hour, no disconnection and it's still running.

To subscribe on multiple symbols on console sample change the code of its ExecuteAction method to this:

        private static async void ExecuteAction(char action, string[] fields)
        {
            switch (action)
            {
                case '1':
                    SendNewOrderSingle(fields);

                    break;

                case '2':
                    SendCancelOrder(fields);

                    break;

                case '3':
                    SendReplaceOrder(fields);

                    break;

                case '4':
                    //SendMarketDataRequest(fields, true);
                    for (int i = 1; i < 200; i++)
                    {
                        SendMarketDataRequest(new[] {i.ToString(), "n"}, true);

                        await System.Threading.Tasks.Task.Delay(1000);
                    }
                    break;

                case '5':
                    SendMarketDataRequest(fields, false);

                    break;

                case '6':
                    SendOrderMassStatusRequest(fields);

                    break;

                case '7':
                    SendRequestForPositions(fields);

                    break;

                case '8':
                    SendSecurityListRequest(fields);

                    break;

                case '9':
                    SendOrderStatusRequest(fields);

                    break;
            }
        }

Then enter this command:  4|1|n


@amusleh

slukk200
12 Jan 2022, 11:11

RE:

Thanks, I will go ahead and test it now. Thanks for helping me by the way.

 


@slukk200

slukk200
12 Jan 2022, 16:02

RE:

I tried your application. It was running perfectly from 2022-01-12 12:29:44.2000861 to 2022-01-12 13:32:24.2037626 but then it got disconnected, so it worked perfectly for a bit more than an hour only. (Username and password was hardcoded.)

This is the config file I was using:

[DEFAULT]
BeginString=FIX.4.4
ConnectionType=initiator
HeartBtInt=10
ReconnectInterval=900000
StartTime=00:00:00
EndTime=23:59:59
StartDay=Sun
EndDay=Sat
DataDictionary=./FIX44-CSERVER.xml
FileStorePath=.\FIXLogs\
FileLogPath=.\Logs\
ScreenLogShowEvents=Y
TimeZone=Central Europe Standard Time
UseLocalTime=N
MillisecondsInTimeStamp=Y
ValidateFieldsHaveValues=N

[SESSION]
SessionQualifier=TRADE
SenderCompID=demo.ctrader.3441945
TargetCompID=cServer
SenderSubID=APP_TRADE_SESSION
TargetSubID=TRADE
ResetOnLogon=Y
SocketConnectHost=h28.p.ctrader.com
SocketConnectPort=5202

[SESSION]
SessionQualifier=QUOTES
SenderCompID=demo.ctrader.3441945
TargetCompID=cServer
SenderSubID=APP_QUOTE_SESSION
TargetSubID=QUOTE
ResetOnLogon=Y
SocketConnectHost=h28.p.ctrader.com
SocketConnectPort=5201
 


@slukk200

amusleh
13 Jan 2022, 12:31

Hi,

I run the console app again for 2 and half hours, and subscribed to 200 symbols, it worked fine without any disconnection.


@amusleh

slukk200
18 Jan 2022, 19:09

FIX API crash(usually after 1-20 minutes) : An existing connection was forcibly closed by the remote host

Hi Amusleh,

I have registered 2 live accounts. For one(Pepperstone) it has been running for 10 hours without any problem, but for the otherone (ICMarkets) it keeps disconnecting. I have tried your console app again with the config file you provided and it disonnected after 3 minutes. (The two apps have been running parallel so I don't think this is an internet problem)

Is there someone here at Spotware who could take a look at it?

Or should I contact the broker?

 


@slukk200

amusleh
19 Jan 2022, 13:35

RE: FIX API crash(usually after 1-20 minutes) : An existing connection was forcibly closed by the remote host

slukk200 said:

Hi Amusleh,

I have registered 2 live accounts. For one(Pepperstone) it has been running for 10 hours without any problem, but for the otherone (ICMarkets) it keeps disconnecting. I have tried your console app again with the config file you provided and it disonnected after 3 minutes. (The two apps have been running parallel so I don't think this is an internet problem)

Is there someone here at Spotware who could take a look at it?

Or should I contact the broker?

 

Hi,

I tested again on a IC Market demo account today for 2 hours and 200 symbols, I didn't faced any issue.

If we can't replicate the issue how can we fix it? I have tested it and it works fine.

I'm Spotware community developer.

 


@amusleh

slukk200
19 Jan 2022, 13:55

RE: RE: FIX API crash(usually after 1-20 minutes) : An existing connection was forcibly closed by the remote host

amusleh said:

slukk200 said:

Hi Amusleh,

I have registered 2 live accounts. For one(Pepperstone) it has been running for 10 hours without any problem, but for the otherone (ICMarkets) it keeps disconnecting. I have tried your console app again with the config file you provided and it disonnected after 3 minutes. (The two apps have been running parallel so I don't think this is an internet problem)

Is there someone here at Spotware who could take a look at it?

Or should I contact the broker?

 

Hi,

I tested again on a IC Market demo account today for 2 hours and 200 symbols, I didn't faced any issue.

If we can't replicate the issue how can we fix it? I have tested it and it works fine.

I'm Spotware community developer.

 

Hi Almulesh,

I have never said that the issue is on your side. I just would like to know the reason why your server closed the connection. Is there a way someone could take a look at it?

Unfortunately I recieve no incoming message about the reason why it is terminated.

It could be a hearbeat issue or something else, I don't know.


@slukk200

amusleh
19 Jan 2022, 14:59

RE: RE: RE: FIX API crash(usually after 1-20 minutes) : An existing connection was forcibly closed by the remote host

slukk200 said:

amusleh said:

slukk200 said:

Hi Amusleh,

I have registered 2 live accounts. For one(Pepperstone) it has been running for 10 hours without any problem, but for the otherone (ICMarkets) it keeps disconnecting. I have tried your console app again with the config file you provided and it disonnected after 3 minutes. (The two apps have been running parallel so I don't think this is an internet problem)

Is there someone here at Spotware who could take a look at it?

Or should I contact the broker?

 

Hi,

I tested again on a IC Market demo account today for 2 hours and 200 symbols, I didn't faced any issue.

If we can't replicate the issue how can we fix it? I have tested it and it works fine.

I'm Spotware community developer.

 

Hi Almulesh,

I have never said that the issue is on your side. I just would like to know the reason why your server closed the connection. Is there a way someone could take a look at it?

Unfortunately I recieve no incoming message about the reason why it is terminated.

It could be a hearbeat issue or something else, I don't know.

Hi,

Can you please tell us which proxy/host/port you are using and the disconnection timestamped logs?


@amusleh

slukk200
01 Mar 2022, 20:04

RE: RE: RE: RE: FIX API crash(usually after 1-20 minutes) : An existing connection was forcibly closed by the remote host

If someone is facing with the same issue, it looks like It was the VPS. There was nothing wrong with my code. There are some brokers who don't really like some (particularly fast)VPS and they keep closing the connection every few minutes. Once I switched to a slower VPS everything worked perfectly. We are probably talking about milliseconds here so not a big deal for me, but if you are doing some HFT stuff it could be a problem for you.

 


@slukk200