Page 1 of 1

TS orachart process hangs on exit using Twslink

Posted: Thu Nov 01, 2018 4:44 pm
by mdg
I have TWSLINK in an indicator on one chart in Tradestation V9.5 update 21. Connects to IB and submits orders fine. When I close the chart (usually when I exit Tradestation the orachart process associated with TWSLINK will not close properly. Do you know what is causing this?

Thanks
MDG

Re: TS orachart process hangs on exit using Twslink

Posted: Fri Nov 02, 2018 9:18 am
by unconnu
maybe you have to use disconnect function before close the chart ...

Re: TS orachart process hangs on exit using Twslink

Posted: Fri Nov 02, 2018 1:25 pm
by board_admin
Do you have some logs (c:\trade-commander\twslink\log) with last words of TWSLink.

Can you please check provide all TWSLink function calls, if they are used with correct
parameter # and size.

Re: TS orachart process hangs on exit using Twslink

Posted: Fri Nov 02, 2018 6:46 pm
by mdg
I use the $TICKDN symbol in the chart to trigger the disconnect function and then close the chart. Here is the end of the log file as requested:

20181102 12:40:04:247; 17468;note;tcExpFunc;GET_CONNECTED;
20181102 12:40:04:251; 17468;note;tcExpFunc;GET_CONNECTED;ret=0
20181102 12:40:15:545; 17468;action;coreInstance;ExitInstance;twslink shutdown...
20181102 12:40:15:548; 17468;action;coreInstance;Dispose;step 1
20181102 12:40:15:552; 17468;note;coreInstance;Dispose;highest command stack size=1
20181102 12:40:15:553; 17468;warning;coreInstance;Dispose;max. number events used=0
20181102 12:40:16:158; 17468;note;tc_twslink_CpuUsage;log_usage;CPU usage-average=1.02 CPU usage-max=9.00 CPU usage-count=37890
20181102 12:40:16:162; 17468;action;coreInstance;Dispose;step 2
20181102 12:40:16:165; 17468;action;coreInstance;Dispose;step 3
20181102 12:40:23:470; 17468;action;coreInstance;Dispose;step 4
20181102 12:40:53:246; 17468;action;coreInstance;Dispose;step 5
20181102 12:40:53:251; 17468;action;coreInstance;Dispose;step 6

Thanks
Murray

Re: TS orachart process hangs on exit using Twslink

Posted: Sat Nov 03, 2018 3:27 pm
by board_admin
Does TWSLink hangs TS or crahses it ?
Can you provide the scricpt code or a similar one ?

Re: TS orachart process hangs on exit using Twslink

Posted: Tue Nov 06, 2018 1:18 pm
by mdg
It will hang TS when I close the chart. if I then use Process Explorer to find the orachart.exe process that TWSlink was using I can delete it that process and TS will come back working.

Here is the basic code that will initiate a connection using TWSlink. When I close the chart with this indicator on it it will hang my TS.


{***************************************************************************************
Indicator: TWSLINK
Description: this indicator demonstrates the use of TWSLink2
WARNING: don't apply this strategy for live accounts. it mostly generates casualties.
a) connect TWSLink2 to TWS (do this once only)
***************************************************************************************}
Inputs: IB_host("127.0.0.1"), {Host of TWS}
IB_port(7496), {API client port of TWS}
IB_clientid(1), {Desired id of API client. If 0, TWSLink takes control also over TWS orders. If clientid=masterid, This api client can also see executions and open orders from other clients.}
IB_timeout(50); {Timeout in millsecodns function waits for being connected to IB server}

Variables:
IB_Status(0); {connect status flag}

{--- load dll functions ---}
DefineDLLFunc: "TWSLINK2.DLL",int, "DISCONNECT";
DefineDLLFunc: "TWSLINK2.DLL",int, "GET_CONNECTED";
DefineDLLFunc: "TWSLINK2.DLL",int, "CONNECT",
LPSTR,{sHost}
int,{iport}
int,{startingClientID}
int;{timeout}

Once Begin {Initialize}
IB_Status = GET_CONNECTED();
If IB_Status < 1 and symbol <> "$TICKDN"
then Begin
Print("TS Connection Before= "&Symbol&" Get_Connected= ",IB_Status);
Value9 = CONNECT(IB_host,IB_port,IB_clientid,IB_timeout);
IB_Status = GET_CONNECTED();
Print("TS Connection After= "&Symbol&" Get_Connected= ",IB_Status,"CONNECT= ",Value9);
End;

if IB_Status > 0 and symbol = "$TICKDN"
then Begin
Print("TS Connection Before= "&Symbol&" Get_Connected= ",IB_Status);
Value9 = DISCONNECT();
IB_Status = GET_CONNECTED();
Print("TS Connection After= "&Symbol&" Get_Connected= ",IB_Status,"CONNECT= ",Value9);
End;

End;

Plot1( IB_Status, "IB Status" );

Re: TS orachart process hangs on exit using Twslink

Posted: Mon Nov 12, 2018 5:00 pm
by board_admin
Sorry for late answer. For some secret reasons we get more notification for new posts.

Please just call CONNECT once in your script. If it is already connected, nothing happens.
If it is not connected, i will connect.

When connection breaks for any reason, e.g. TWS is restarted, TWSLink itself will
reconnect. By default, i think, TWSLink checks every 4 seconds if it is still connected.
If not, it tries to reconnected.

So, just call CONNECT.

The problem with Trade Station is, that it spreads into multiple processes and TWSLink is loaded
into each such script process. This introduces the problem, that you connect multiple times
to TWS but with SAME clientid. The first process will win this "race" situation.

In addition, the clientid has an important role: It links orders to the client who sent out orders.
This problem has discussed here multiple times, please try find them here in the forum.
Just as summary: You can remove many problems, when you can get TS just to spawn in one single process
at least for TWSLink.

--
When you can catch the moment, where the script is unloading, make a DISCONNECT there.
The disconnect is also done in TWSLink internally on unload but at this point, it could
be that the process is already unlinked from Windows subsystem and the function
to close the connection never returns.
--

Please let me know, if it works.

Re: TS orachart process hangs on exit using Twslink

Posted: Thu Nov 15, 2018 9:34 pm
by mdg
Based on your message I did the following:
1) Started TS with blank desktop and no workspaces, etc loaded
2) Create new workspace and add 1 new chart
3) Use the following indicator and apply to the chart:

Inputs: IB_host("127.0.0.1"), {Host of TWS}
IB_port(7496), {API client port of TWS}
IB_clientid(1), {Desired id of API client. If 0, TWSLink takes control also over TWS orders. If clientid=masterid, This api client can also see executions and open orders from other clients.}
IB_timeout(50); {Timeout in millsecodns function waits for being connected to IB server}

{--- load dll functions ---}
DefineDLLFunc: "TWSLINK2.DLL",int, "DISCONNECT";
DefineDLLFunc: "TWSLINK2.DLL",int, "GET_CONNECTED";
DefineDLLFunc: "TWSLINK2.DLL",int, "CONNECT",
LPSTR,{sHost}
int,{iport}
int,{startingClientID}
int;{timeout}

Once Begin {only do this once }
Value9 = CONNECT(IB_host,IB_port,IB_clientid,IB_timeout);
End;

4) Verify that TS is connected to IB using TWSLink2 Panel
5) Exit TS which closes all windows but when I check using the Microsoft tool called Process Explorer the orachart.exe still exists and has not been cleared from memory. This causes issues when I try to run TS again.

Can you please verify that you see the same issue or advise how I fix this issue. I believe the test I just did only does the connect once and the script only runs once.

Thank you
MDG

Re: TS orachart process hangs on exit using Twslink

Posted: Thu Nov 15, 2018 9:46 pm
by board_admin
Unfortunately, i have no Trade Station to test this.
I just can test with MultiCharts.

Can you please check out, what happens, when you place a DISCONNECT after CONNECT
and report here.

I will make a test with MultiCharts and your script soon.

Re: TS orachart process hangs on exit using Twslink

Posted: Thu Nov 15, 2018 11:42 pm
by mdg
Thanks for the quick reply.

I did the test by adding in the disconnect right after the connect and the same thing happens when I exit TS.

Looking forward to the results of your MultiCharts test.

MDG

Re: TS orachart process hangs on exit using Twslink

Posted: Sun Nov 18, 2018 11:18 pm
by board_admin
Hello,
i could reproduce this on MultiCharts but with no other of my applications, like Excel, a Windows app, in a python wrapper
etc.

If you can't accept that you need to kill orchart process when closing TS, then please check out the file uploaded
to filedropper:


http://www.filedropper.com/twslink2

This is a fix for the costs of memory leaks ~ 16 MB. It is the 32 bit version of TWSLink as i guess orchart process
is a 32 bit process. If not, please let me know.

As you most likely have a 64 bit Windows, copy this twslink2.dll to windows/syswow64.

Make sure no other application uses TWSLink2 at this time.

Please let me know, if it works.

Re: TS orachart process hangs on exit using Twslink

Posted: Mon Nov 19, 2018 5:29 pm
by mdg
Thank you for the update. I have done a quick test and it has fixed the problem. I will confirm in a couple days of usage my final results.

Thanks again,
MDG

Re: TS orachart process hangs on exit using Twslink

Posted: Thu Nov 22, 2018 9:40 pm
by mdg
Thanks again for fixing the error that I was having with Tradestation when closing the chart that TWSlink was applied to. I have not seen any further issues with the software.

Will you be releasing this patched file as an official update to the software?

Thanks
MDG

Re: TS orachart process hangs on exit using Twslink

Posted: Fri Nov 23, 2018 4:28 pm
by board_admin
Glad to read it works now.

New version has been uploaded:

https://trade-commander.com/download/1326/

Re: TS orachart process hangs on exit using Twslink

Posted: Fri Nov 23, 2018 4:51 pm
by mdg
This link downloads the mtibbridge2setup.exe instead of the TWSlink software. Can you fix the download?

Thanks

Re: TS orachart process hangs on exit using Twslink

Posted: Fri Nov 23, 2018 5:05 pm
by board_admin

Re: TS orachart process hangs on exit using Twslink

Posted: Fri Nov 23, 2018 5:09 pm
by mdg
Thank you

Just an FYI that the download link on the TWSlink page also points to the mtibbridge2setup.exe file as well.

mdg

Re: TS orachart process hangs on exit using Twslink

Posted: Fri Nov 23, 2018 5:10 pm
by board_admin
Thank you but this should be corrected now