Class: IbRubyProxy::Server::IbProxyService

Inherits:
Object
  • Object
show all
Defined in:
lib/ib_ruby_proxy/server/ib_proxy_service.rb

Overview

Proxy service for invoking IB api through DRb

The proxy does essentially 2 things:

  • Starts a DRb process you can connect to invoke the IB api. This will expose an IbClientAdapter object to its clients

  • Starts an IB message-processing thread that will dispatch messages sent to IB client app ( gateway or TWS)

Constant Summary collapse

DEFAULT_IB_GATEWAY_PORT =
4002
DEFAULT_DRB_PORT =
1992

Instance Method Summary collapse

Constructor Details

#initialize(ib_host: 'localhost', ib_port: DEFAULT_IB_GATEWAY_PORT, drb_host: 'localhost', drb_port: DEFAULT_DRB_PORT) ⇒ IbProxyService

Returns a new instance of IbProxyService.

Parameters:

  • ib_host (String) (defaults to: 'localhost')

    Hostname for the IB client app (gateway or TWS). Default localhost

  • ib_port (Integer) (defaults to: DEFAULT_IB_GATEWAY_PORT)

    Port for hte IB client app (gateway or TWS). Default 4002 (gateway)

  • drb_host (String) (defaults to: 'localhost')

    Hostname for the DRB process. Default localhost

  • drb_port (Integer) (defaults to: DEFAULT_DRB_PORT)

    Port for the . Default 1992



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ib_ruby_proxy/server/ib_proxy_service.rb', line 30

def initialize(ib_host: 'localhost', ib_port: DEFAULT_IB_GATEWAY_PORT,
               drb_host: 'localhost', drb_port: DEFAULT_DRB_PORT)
  @ib_host = ib_host
  @ib_port = ib_port
  @drb_host = drb_host
  @drb_port = drb_port

  @wrapper = IbRubyProxy::Server::IbWrapperAdapter.new
  @client = wrapper.client
  @signal = wrapper.signal

  connect
end

Instance Method Details

#startvoid

This method returns an undefined value.

Connects to IB and starts the DRb process

Clients of the DRb service will get an IbRubyProxy::Server::IbClientAdapter object to interact with the IB api



48
49
50
51
52
53
54
# File 'lib/ib_ruby_proxy/server/ib_proxy_service.rb', line 48

def start
  DRb.start_service("druby://#{drb_host}:#{drb_port}", ib_client_adapter, verbose: true)
  start_ib_message_processing_thread
  puts "Ib proxy server started at druby://#{drb_host}:#{drb_port}. Connected to IB at"\
       " #{ib_host}:#{ib_port}"
  DRb.thread.join
end