Similar to JRUBY-987?
---------------------

                 Key: JRUBY-1149
                 URL: http://jira.codehaus.org/browse/JRUBY-1149
             Project: JRuby
          Issue Type: Bug
          Components: Java Integration
    Affects Versions: JRuby 1.0.0
         Environment: Windows XP using java version "1.6.0_01"
            Reporter: Austin J. Newton
             Fix For: JRuby 1.0.0


Right now, I'm working with an experiment connecting jruby with interactive 
brokers java api.
I've written this code in Java, but I'm curious about using JRuby.

Basically, you have to implement an interface called EWrapper.
http://www.interactivebrokers.com/php/webhelp/Interoperability/Socket_Client_Java/java_ewrapper.htm

Most of the calls use EClientSocket
http://www.interactivebrokers.com/php/webhelp/Interoperability/Socket_Client_Java/java_eclientsocket.htm

Imagine I only have these four methods to implement with the EWrapper interface.

    public void error(Exception e) {}
    public void error(String str) {}
    public void error(int id, int errorCode, String errorMsg) {}
    public void tickPrice(int tickerId, int field, double price, int 
canAutoExecute) {}

I'm curious about this since I can't have overloaded a methods with only one 
argument in ruby, is the best way to process it  inside the method?
if x.class == Exception then
...process error
elsif x.class == String then
...process error
end

Here is the code I created, which will just log onto IB TWS, and then 
disconnect.

require 'java'

import com.ib.client.*
import com.ib.client.TickType
import com.ib.client.EWrapper
import com.ib.client.EClientSocket
import com.ib.client.Contract

class IBMessageHandler
  include EWrapper
  
  def error(string)
    puts string
  end
  
  def error(id, error_code, error_msg)
    puts error_msg  
  end
  
  def tickPrice(ticker_id, field, price, canAutoExecute)
    puts TickType.get_field(field)
    puts price
  end
  
end

def create_contract (symbol, security_type, exchange, expiry, currency = null)
  contract = Contract.new
  contract.m_symbol   = symbol
  contract.m_secType  = security_type
  contract.m_exchange = exchange
  contract.m_expiry   = expiry
  contract.m_currency = currency
  return contract  
end

ib_handler = IBMessageHandler.new
ib_socket = EClientSocket.new(ib_handler)

# connection parameters
host = ""
port = 7496
client_id = 1

# basic info for creating a contract
contract = create_contract("CL", "FUT", "NYMEX", "200707", "USD")
generic_tick_list = "100,101,104,106,162,165,221,225"

ib_socket.e_connect(host, port, client_id)
ib_socket.req_mkt_data(1, contract, generic_tick_list)
sleep 100
ib_socket.disconnect

So far, it successfully connects to the IB TWS.
It works and then throws an error similar to 
http://jira.codehaus.org/browse/JRUBY-987 bug report.  
I'm a little confused on how to work around this?

irb(main):053:0> ib_socket.e_connect(host, port, client_id)
Server Version:32
TWS Time at connection:20070615 21:16:28 IST
=> nil
irb(main):054:0> Exception in thread "EReader" file:/C:/jruby-1.0/lib/jruby.jar!
/builtin/javasupport/proxy/interface.rb:155:in `send': Wrong # of arguments(1 fo
r 3) (ArgumentError)
        from file:/C:/jruby-1.0/lib/jruby.jar!/builtin/javasupport/proxy/interfa
ce.rb:155:in `__jcreate!'
        from file:/C:/jruby-1.0/lib/jruby.jar!/builtin/javasupport/proxy/interfa
ce.rb:138
        ...internal jruby stack elided...
        from org.jruby.runtime.Block.yield(Block.java:220)
        from org.jruby.runtime.Block.call(Block.java:174)
        from org.jruby.RubyProc.call(RubyProc.java:173)
        from org.jruby.RubyProc.call(RubyProc.java:148)
        from org.jruby.javasupport.Java$1.invoke(Java.java:853)
        from $Proxy0.error(Unknown Source)
        from com.ib.client.EReader.run(EReader.java:62)



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to