Category Archives: TWSLink

Order increases leveraged FX position

When using software which works with an Interactive Brokers account, non USA traders may receive this order rejection notice:

Order increases leveraged FX position


The reason for this is may an insufficient margin.  You can try to solve this by logging into Account Management and request cash forex (leveraged forex) permissions.

TWSLink new version

A new TWSLink version has been uploaded.

  • Bugfix: Adaptive Orders bug fixed.
  • Change: Log extended to record adaptive order attributes.


[ddownload id=”281″ style=”link” text=”Download TWSLink″]


Batch command example adaptive order for TWSLinkBaTe

int uidc=REGISTER_CONTRACT("NVDA","STK","USD","SMART","","","",0,"",0,0)
int uido=PLACE_ORDER(uidc,0,"BUY","LMT",100,186.00,0.0,"DAY",-1,0)
// set rth hours only
// set adaptive order algorithm name
// set adaptive order parameter and transmit order to IB

Download bacth file TWSLinkBaTe



MatLab script for TWSLink

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:

  1. Make sure TWSLink is installed ([ddownload id=”281″ style=”link” text=”TWSLink setup”])
  2. Download MatLab example and unzip in a folder of your choice.
  3. Open MatLab (tested with MatLab 2017a).
  4. In the script editor open twslink.m file from MatLab example folder.
  5. 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

% uid of contract
% uid of order

% 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','',7496,1,10000);

uid_order=calllib('twslink', 'PLACE_ORDER',uid,0,'SELL','MKT',25000,0.0,0.0,'GTC',1,0);

% unload twslink