A new short example for using TWSLink with the actual version of MatLab (MatLab 2017a) is available.
The old example may not compiled in current MatLab script editor as the header declaration for TWSLink exported function was not compatible. This has been changed. So the new example comes with modified headers and a minimal example how to load TWSLink, connect, register and place a trade.
Please use the example as follows:
- Make sure TWSLink is installed ([ddownload id=”281″ style=”link” text=”TWSLink setup”])
- Download MatLab example and unzip in a folder of your choice.
- Open MatLab (tested with MatLab 2017a).
- In the script editor open twslink.m file from MatLab example folder.
- Run the script. You might get asked to add this folder to path or to change folder for execution. Select “Change Folder“.
[ddownload id=”413″ style=”link” text=”Download MatLab example”]
% load twslink dll loadlibrary('twslink2.dll','twslinkimp.h','alias','twslink'); % uid of contract uid=0; % uid of order uid_order=0; % register EUR.USD CASH uid = calllib('twslink', 'REGISTER_CONTRACT','EUR','CASH','USD','IDEALPRO','','','',0.0,'',0,0.0); % connect to API (running TWS or gateway) calllib('twslink', 'CONNECT','127.0.0.1',7496,1,10000); % SEL 25.000 EUR.USD CASH uid_order=calllib('twslink', 'PLACE_ORDER',uid,0,'SELL','MKT',25000,0.0,0.0,'GTC',1,0); % unload twslink unloadlibrary('twslink');