TWSLink Excel VBScript sample

' create the TWSLink object (do this only once)
Global TwsLink As Object
Set TwsLink = CreateObject("twslink2.twslinkCom")

' connect to TWS or gateway on local machine and standard port 7496 (do this only once). 
' TWSLink keeps connection to TWS / gateway along with all subscribed requests)
Dim connected as Long
connected = TwsLink.CONNECT("",7496,77,20000)

' get an unique id for EUR.USD cash contract (do this only once)
Dim uidcontract as Long
UidContract = TwsLink.REGISTER_CONTRACT2("EUR","CASH","USD","IDEALPRO","","",0.0,"")

' place a sell limit order 30000 shares at 1.50
Dim uid_sell_limit as Long
uid_sell_limit = TwsLink.PLACE_ORDER(uidcontract,0,"SELL","LMT",30000,1.50,0.0,"GTC",1,0)

' place a buy limit order 30000 shares at 1.30
Dim uid_buy_limit as Long
uid_buy_limit = TwsLink.PLACE_ORDER(uidcontract,0,"BUY","LMT",30000,1.30,0.0,"GTC",1,0)

' change buy limit order to 1.3030 (mind 2nd parameter)

' cancel sell limit order