Short TWSLink script for MatLab

% 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');