Archiv der Kategorie: TWSLink example project

Example code or project for TWSLink

Perl 5 x64 wrapper for TWSLink

Python 5 x64 wrapper for TWSLink along with Visual Studio wrapper solution and sample

  • 64 bit twslink2pl.dll and twslink2pl.pm included.
  • Visual Studion 2017 solution file included: This is to create your own twslink2 wrapper for other perl versions.
  • Includes also a small sample in the test folder of download.

 

When the TWSLink2 interfaces should change, which is unlikely, or a new Perl version is out which you want to use, you may want to have a new TWSLink2 wrapper,
so you can call TWSLink from within Perl. In order to build your own wrapper, you need some tools:

The Visual Studio project for this perl wrapper, assumes that swig is in c:\swig. Details about building the wrapper are in the readme.txt of download.

Note: With swig, Visual Studio and TWSLink2 wrapper cpp files (contained in download), you can build wrapper for ANY LANGUAGE contained in the swig world. Just watch the samples in the swig project, to get an idea and use the Perl wrapper Visual Studio project as draft.

View sample code

# --- including libs ---
# twslink module
use twslink2pl;
# module to modify console
#use Win32::Console;


# ----- Object creation -----
print "creating twslink wrapper:\n";
$tws = new twslink2pl::TWSLink2Wrap("",1);
#print "creating console:\n";
#$console = new Win32::Console;

#$tws->Load(true,"");
my $stime=gmtime();
print "start time=$stime\n";

print "Connecting . . . \n" ;
$status = $tws->CONNECT("127.0.0.1",7496,1,6000) ;
print "Connected=$status\n";
# register a stock; wait at the most 5 seconds until contract has been accpeted by tws


print "Register MSFT\n";
my $uidMSFT = $tws->REGISTER_CONTRACT("MSFT","STK","USD","NASDAQ","","","",0.0,"",0,0.0) ;
print "uid MSFT=$uidMSFT\n";

print "Place buy market 100 MSFT\n";
my $uidOrderMSFT = $tws->PLACE_ORDER($uidMSFT,0,"BUY","MKT",100,0.0,0.0,"GTC",1,0) ;
print "uid order MSFT=$uidOrderMSFT\n";
$tws->WAIT_FOR_FILLED($uidOrderMSFT,20000);

[ddownload id=”1869″ style=”link” text=”Download TWSLink Perl 5 x64 wrapper”]

TWSLink: updated VB.NET example

The VB.NET example for TWSLink has been updated. It can be opened with Visual Studio 2017 >= community edition.

The selected .NET framework is 4.5.2. Newer and older should be possible as well.  This example demonstrates connecting to TWS, register a contract, requesting market data and placing

an order. It is very compact, all code is in Form1.vb.

 

 

To run the example TWSLink, Traders Workstations or Gateway and Visual Studio 2017 >= Community Edition needs to be installed.

[ddownload id=”1792″ text=”VB.NET example for TWSLink”]

TWSLink: updated c# example

One of the c# examples for TWSLink has been updated. It can be opened with Visual Studio 2017 >= community edition.

The selected .NET framework is 4.5.2. Newer and older should be possible as well.  This example demonstrates requesting market data , placing orders and some more features.

Most of the code is in Form1.cs. The file callback.cs is the place where you catch messages from TWSLink, like market data, order states, account information etc..

 

 

To run the example TWSLink, Traders Workstations or Gateway and Visual Studio 2017 >= Community Edition needs to be installed.

 

[ddownload id=”1794″ style=”link” text=”Downlad c# example for TWSLink”]