Category Archives: TWSLink

Order increases leveraged FX position

When using trade-commander.com 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 2.3.0.1

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 2.3.0.1″]

 

Batch command example adaptive order for TWSLinkBaTe

int uidc=REGISTER_CONTRACT("NVDA","STK","USD","SMART","","","",0,"",0,0)
CONNECT("",7496,0,10000)
int uido=PLACE_ORDER(uidc,0,"BUY","LMT",100,186.00,0.0,"DAY",-1,0)
// set rth hours only
SET_ORDER_VAL(uido,14,"0",-1)
// set adaptive order algorithm name
SET_ORDER_VAL(uido,67,"Adaptive",-1)
// set adaptive order parameter and transmit order to IB
SET_ORDER_VAL(uido,68,"adaptivePriority=Normal",1)

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