- Finance::InteractiveBrokers::TWS (based on Inline::Java)
- Finance::InteractiveBrokers::SWIG (based on SWIG and C++)
But the API is just \0 terminated lines over a socket, so I always wanted to write a pure Perl API for it.
The data structures, request and response messages are in Protocol::TWS (which later also could generate suitable objects for the two native APIs). And AnyEvent::TWS is an asynchronous pure Perl implemenation of the TWS API.
It is still in the early stages, but you can already play around with it. For example with contract.pl (in AnyEvent::TWS). Just correct the include path and the IP (localhost is default).
$ perl contract.pl -s IBM -t OPT -st 150 -r PUT conId: 78782644 symbol: IBM expiry: 20130118 strike: 150 right: P conId: 94203928 symbol: IBM expiry: 20140117 strike: 150 right: P conId: 97819043 symbol: IBM expiry: 20120720 strike: 150 right: P conId: 102789332 symbol: IBM expiry: 20121019 strike: 150 right: P conId: 104498834 symbol: IBM expiry: 20120518 strike: 150 right: P conId: 106288439 symbol: IBM expiry: 20120615 strike: 150 right: P
The parameters are -s (symbol), -t (security type), -st (strike), -r (right PUT/CALL) and some more (just look in the source code).
You can also request historical or current market data and place trades. But do not use it with your real money account, for sure there are lots of bugs in it.
awesome ! I'll try some stuff with it... Then use it in real life !
ReplyDeleteThanks for making this available. Question: I'm on Win7 64, Perl 5.10, TWS 926. When I run connect.pl I get some response from TWS: SEND: ... RECV: ... etc, but then this:
ReplyDeleteCan't locate object method "lines" via package "Protocol::TWS::Response::managedAccounts"
I don't see "lines" method in "managedAccounts.pm".
Oh, that is strange. I will have a look at it. Can you please send me the stacktrace (e. g. with Carp::Always "perl -MCarp::Always connect.pl") to uwe@uwevoelker.de?
ReplyDeleteThanks a lot.
Regarding connect.pl - please do not use that script. I will delete it from the repository. It was a first test and is now broken.
ReplyDeleteHave a look at the examples in the AnyEvent-TWS repository.
I also started a simplified blocking API Finance::TWS::Simple. You will find it on Github too.
Sorry for this confusion.
Hi Uwe, I've developed a small utility using your "realtimebars-multi.pl" example from AnyEvent-TWS, The goal is to retrieve single, realtime quotes for a number of symbols. It works for the first symbol, but I'm having trouble managing the request ID's. I'd like to send you the relevant piece of the code for review, but I don't see your contact info on this page. Can you send your email to "for-uwe@mailinator.com" (a temporary mailbox), I'll delete it from there as soon as I get it. Thanks.
ReplyDeleteMy email is no secret: uwe@uwevoelker.de - but I will send you an email as well.
ReplyDeleteWhen I try to run the example realtimebars.pl against IB's demo account, its prints out:
ReplyDelete$VAR1 = bless( {
'errorCode' => '2107',
'id' => '-1',
'errorString' => 'HMDS data farm connection is inactive but should be available upon demand.demohmds'
}, 'Protocol::TWS::Response::error' );
The scripts seems hung after that. Any idea?
I tried it today (weekend) and get the following error:
ReplyDelete'Invalid Real-time Query:No historical market data for EUR/CASH@IDEALPRO Last 0'
I will check again during trading hours and report back.
Today I tried it during trading hours - it worked as expected. So this seems to be an issue with the demo account. It worked on my real money account.
ReplyDelete