Page 1 of 1

When do I call CONNECT function in TradeStation multiple scripts?

Posted: Sat Mar 17, 2018 4:54 am
by Rocket130713
Hello,

Let's assume we setup TradeStation (TS) platform to run all Charts via just ONE single process (and therefore only 1 TWS-Link instance is loaded). Let's then assume we have TS EasyLanguage Script 1, Script 2 and Script 3. Script 1 is attached to Gold chart in TS workspace number 1. Script 2 is attached to ES chart in TS workspace number 2. And script 3 is attached to Natural Gas chart in TS workspace number 3. Do I call the CONNECT ("", 7496, 1 ,500) function in just the "first" script which is called script 1? Or must I call CONNECT function within script 1, script 2 and script 3? When TS starts up it will load all 3 scripts, one-by-one, TS will use only 1 process for charting. Please also note that in each different TS script after calling CONNECT function I will then be calling the REGISTER_CONTRACT function to get the contract ID number, before placing orders.

Also if I have 100 sub-accounts and 1 master account, within the CONNECT ("",7496,1 ,500) function is 500ms long enough time to call account details for all 100 sub-accounts, or should I use 7000ms instead i.e. CONNECT ("192.166.0.2",7496,1 ,7000)? I think the level of account detail is set to "Summary".

Thanks in advance.

Regards, Rod.

Re: When do I call CONNECT function in TradeStation multiple scripts?

Posted: Sat Mar 17, 2018 2:00 pm
by board_admin
You could do it like this: In each script call:

Code: Select all

CONNECT 
with identical parameters and a small timeout, say 100 ms.

Then call

Code: Select all

GET_ACC_NAME(-1)
in a loop with a 1-5 millisecond sleep (just not to run CPU at 100 %) until you get the list of all subaccounts (no empty string returned).

Then make a loop over these subaccounts and call

Code: Select all

GET_MARKET_VAL(ur_account_currency,0,single_account_name)
This returns positions of base currency for subaccount (more or less cash balance).
When you get a value > 0 returned, you know you have the cash balance for this account in this runtime/session.

Do this loop with until you have the same number of values > 0 returned as the number of subaccounts,
because this way you know to have at least cash balance for each subaccounts received.

----------------------------------------------------------------------------------------------------------------------------------
At this time, there are may still some account values not yet boarded, but if you have cash balance for all,
it means that callbacks are at least arrived at last account. So no long time until all account values updated.

You can't call

Code: Select all

GET_ACC_VAL
for this, because TWSLink picks those values from database. So you could get values from last session.

Re: When do I call CONNECT function in TradeStation multiple scripts?

Posted: Sun Mar 18, 2018 7:12 am
by Rocket130713
Thank you so much for your reply. Really appreciate your wisdom and generous help. Thanks again. Kind regards, Rod.

Re: When do I call CONNECT function in TradeStation multiple scripts?

Posted: Mon Mar 19, 2018 3:07 pm
by board_admin
Thank you, I feel honored