TS orachart process hangs on exit using Twslink

Discuss, post your questions about TWSLink here.

Users who just registered, please write an email to
forum@trade-commander.de
with your username mentioned.
So we can distinguish you from bots.
Thank you
Post Reply
mdg
Posts: 13
Joined: Tue Oct 30, 2018 10:16 pm

TS orachart process hangs on exit using Twslink

Post 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

unconnu
Posts: 6
Joined: Tue Sep 25, 2018 4:28 am

Re: TS orachart process hangs on exit using Twslink

Post by unconnu »

maybe you have to use disconnect function before close the chart ...

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: TS orachart process hangs on exit using Twslink

Post 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.

mdg
Posts: 13
Joined: Tue Oct 30, 2018 10:16 pm

Re: TS orachart process hangs on exit using Twslink

Post 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

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: TS orachart process hangs on exit using Twslink

Post by board_admin »

Does TWSLink hangs TS or crahses it ?
Can you provide the scricpt code or a similar one ?

mdg
Posts: 13
Joined: Tue Oct 30, 2018 10:16 pm

Re: TS orachart process hangs on exit using Twslink

Post 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" );

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: TS orachart process hangs on exit using Twslink

Post 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.

mdg
Posts: 13
Joined: Tue Oct 30, 2018 10:16 pm

Re: TS orachart process hangs on exit using Twslink

Post 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

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: TS orachart process hangs on exit using Twslink

Post 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.

mdg
Posts: 13
Joined: Tue Oct 30, 2018 10:16 pm

Re: TS orachart process hangs on exit using Twslink

Post 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

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: TS orachart process hangs on exit using Twslink

Post 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.

mdg
Posts: 13
Joined: Tue Oct 30, 2018 10:16 pm

Re: TS orachart process hangs on exit using Twslink

Post 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

mdg
Posts: 13
Joined: Tue Oct 30, 2018 10:16 pm

Re: TS orachart process hangs on exit using Twslink

Post 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

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: TS orachart process hangs on exit using Twslink

Post by board_admin »

Glad to read it works now.

New version has been uploaded:

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

mdg
Posts: 13
Joined: Tue Oct 30, 2018 10:16 pm

Re: TS orachart process hangs on exit using Twslink

Post by mdg »

This link downloads the mtibbridge2setup.exe instead of the TWSlink software. Can you fix the download?

Thanks

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: TS orachart process hangs on exit using Twslink

Post by board_admin »


mdg
Posts: 13
Joined: Tue Oct 30, 2018 10:16 pm

Re: TS orachart process hangs on exit using Twslink

Post 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

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: TS orachart process hangs on exit using Twslink

Post by board_admin »

Thank you but this should be corrected now

Post Reply