It doesn't seem to work across threads. Maybe I did it wrong. The
code below hangs once it tries to call the perl callback, requiring a
<ctrl>c as in:
[EMAIL PROTECTED]:~/inline$ ./whole
Server Version:24
TWS Time at connection:20051225 14:29:34 CST
inside nextValidId
<ctrl>c
Do you see anything wrong or have suggestions?
Thanks
Jay
#!/usr/bin/perl
use strict;
package my_callback;
sub new {
my $class = shift;
bless {}, $class;
}
sub tickPrice {
my $self = shift;
print join(":", @_),"\n";
}
sub nextValidId {
my $self = shift;
print join(":", @_),"\n";
}
package main;
use Inline (
Java => "DATA",
JNI => 1,
AUTOSTUDY => 1,
STUDY => ['com.ib.client.EClientSocket',
'com.ib.client.Contract',
],
);
my $callback = my_callback->new();
my $api = Inline_Bridge->new($callback);
my $ib = com::ib::client::EClientSocket->new($api);
$ib->eConnect("localhost","7496",$$);
my $i = 1;
foreach (qw/YHOO/) {
my $contract = com::ib::client::Contract->new();
$contract->{m_symbol} = $_;
$contract->{m_secType} = 'STK';
$contract->{m_exchange} = 'SMART';
$ib->reqMktData($i++,$contract);
}
while ((my $rc = $api->WaitForCallback(.1)) > -1){
if (! $rc){
}
else {
$api->ProcessNextCallback() ;
}
}
__DATA__
__Java__
import org.perl.inline.java.*;
import com.ib.client.*;
class Inline_Bridge extends InlineJavaPerlCaller implements EWrapper {
InlineJavaPerlObject perlobj;
public Inline_Bridge(InlineJavaPerlObject PerlObj)
throws InlineJavaException {
perlobj = PerlObj;
}
public void tickPrice(int tickerId, int field, double price,
int canAutoExecute)
{
try {
perlobj.InvokeMethod(
"tickPrice",
new Object [] {
tickerId, field, price, canAutoExecute
}
);
}
catch (InlineJavaPerlException pe){ }
catch (InlineJavaException pe) { pe.printStackTrace() ;}
}
public void tickSize(int tickerId, int field, int size)
{
}
public void orderStatus(int orderId, String status, int filled,
int remaining, double avgFillPrice, int permId,
int parentId, double lastFillPrice, int clientId)
{
}
public void openOrder(int orderId, Contract contract, Order order)
{
}
public void error(String str)
{
}
public void connectionClosed()
{
}
public void updateAccountValue(String key, String value, String
currency,
String accountName)
{
}
public void updatePortfolio(Contract contract, int position,
double marketPrice, double marketValue,
double averageCost, double unrealizedPNL,
double realizedPNL, String accountName) {
}
public void updateAccountTime(String timeStamp) {
}
public void nextValidId(int orderId)
{
System.out.println("inside nextValidId");
try {
perlobj.InvokeMethod("nextValidId", new Object [] {"hi"}) ;
}
catch (InlineJavaPerlException pe){ }
catch (InlineJavaException pe) { pe.printStackTrace() ;}
System.out.println("after");
}
public void contractDetails(ContractDetails contractDetails)
{
}
public void bondContractDetails(ContractDetails contractDetails)
{
}
public void execDetails(int orderId, Contract contract,
Execution execution) {
}
public void error(int id, int errorCode, String errorMsg)
{
}
public void updateMktDepth(int tickerId, int position, int operation,
int side, double price, int size)
{
}
public void updateMktDepthL2(int tickerId, int position,
String marketMaker, int operation, int side,
double price, int size)
{
}
public void updateNewsBulletin(int msgId, int msgType, String message,
String origExchange)
{
}
public void managedAccounts(String accountsList)
{
}
public void receiveFA(int faDataType, String xml)
{
}
public void historicalData(int reqId, String date, double open,
double high, double low, double close,
int volume, double WAP, boolean hasGaps)
{
}
public void scannerParameters(String xml) {
}
public void scannerData(int reqId, int rank,
ContractDetails contractDetails, String distance,
String benchmark, String projection) {
}
}