class IbRubyProxy::Server::IbProxyService
Proxy service for invoking IB api through {ruby-doc.org/stdlib-2.6.1/libdoc/drb/rdoc/DRb.html 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)
Constants
- DEFAULT_DRB_PORT
- DEFAULT_IB_GATEWAY_PORT
Attributes
Public Class Methods
@param [String] ib_host
Hostname for the IB client app (gateway or TWS). Default localhost
@param [Integer] ib_port
Port for hte IB client app (gateway or TWS). Default 4002
(gateway) @param [String] drb_host
Hostname for the DRB process. Default localhost
@param [Integer] drb_port
Port for the . Default 1992
# 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
Public Instance Methods
Connects to IB and starts the DRb process
Clients of the DRb service will get an {IbClientAdapter} object to interact with the IB api @return [void]
# 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
Private Instance Methods
# File lib/ib_ruby_proxy/server/ib_proxy_service.rb, line 76 def connect client.eConnect(ib_host, ib_port, 2) end
# File lib/ib_ruby_proxy/server/ib_proxy_service.rb, line 80 def ib_client_adapter @ib_client_adapter ||= IbRubyProxy::Server::IbClientAdapter.new(client, wrapper) end
# File lib/ib_ruby_proxy/server/ib_proxy_service.rb, line 60 def start_ib_message_processing_thread reader = EReader.new(client, signal) reader.start Thread.new do while client.isConnected signal.waitForSignal begin reader.processMsgs rescue StandardError => e puts "Error while processing ib message: #{e}" end end end end