@@ -75,19 +75,18 @@ module IB
7575
7676=end
7777
78- class Gateway
78+ class Gateway
7979
80- include LogDev # provides default_logger
81- include AccountInfos # provides Handling of Account-Data provided by the tws
82- include OrderHandling
80+ include Support :: Logging # provides default_logger
81+ include AccountInfos # provides Handling of Account-Data provided by the tws
82+ include OrderHandling
8383
84- # include GWSupport # introduces update_or_create, first_or_create and intercept to the Array-Class
84+ # include GWSupport # introduces update_or_create, first_or_create and intercept to the Array-Class
8585
86- # from active-support. Add Logging at Class + Instance-Level
87- mattr_accessor :logger
88- # similar to the Connection-Class: current represents the active instance of Gateway
89- mattr_accessor :current
90- mattr_accessor :tws
86+ # from active-support. Add Logging at Class + Instance-Level
87+ # similar to the Connection-Class: current represents the active instance of Gateway
88+ mattr_accessor :current
89+ mattr_accessor :tws
9190
9291
9392
@@ -100,16 +99,16 @@ def initialize port: 4002, # 7497,
10099 connect : true ,
101100 get_account_data : false ,
102101 serial_array : false ,
103- logger : default_logger ,
102+ logger : nil ,
104103 watchlists : [ ] , # array of watchlists (IB::Symbols::{watchlist}) containing descriptions for complex positions
105104 **other_agruments_which_are_ignored ,
106105 &b
107106
108107 host , port = ( host +':' +port . to_s ) . split ( ':' )
109108
110- self . logger = logger
111- logger . info { '-' * 20 + ' initialize ' + '-' * 20 }
112- logger . tap { | l | l . progname = 'Gateway#Initialize' }
109+ self . class . configure_logger logger
110+
111+ self . logger . info { '-' * 20 + ' initialize ' + '-' * 20 }
113112
114113 @connection_parameter = { received : serial_array , port : port , host : host , connect : false , logger : logger , client_id : client_id }
115114
@@ -124,8 +123,6 @@ def initialize port: 4002, # 7497,
124123 Thread . report_on_exception = true
125124 # https://blog.bigbinary.com/2018/04/18/ruby-2-5-enables-thread-report_on_exception-by-default.html
126125 Gateway . current = self
127- # establish Alert-framework
128- IB ::Alert . logger = logger
129126 # initialise Connection without connecting
130127 prepare_connection &b
131128 # finally connect to the tws
@@ -182,7 +179,6 @@ def update_local_order order
182179 def connect maximal_count_of_retry = 100
183180
184181 i = -1
185- logger . progname = 'Gateway#connect'
186182 begin
187183 tws . connect
188184 rescue Errno ::ECONNREFUSED => e
@@ -229,7 +225,6 @@ def connect maximal_count_of_retry=100
229225
230226
231227 def reconnect
232- logger . progname = 'Gateway#reconnect'
233228 if tws . present?
234229 disconnect
235230 sleep 1
@@ -239,7 +234,6 @@ def reconnect
239234 end
240235
241236 def disconnect
242- logger . progname = 'Gateway#disconnect'
243237
244238 tws . disconnect if tws . present?
245239 @accounts = [ ] # each{|y| y.update_attribute :connected, false }
@@ -256,7 +250,6 @@ def disconnect
256250=end
257251
258252 def send_message what , *args
259- logger . tap { |l | l . progname = 'Gateway#SendMessage' }
260253 begin
261254 if check_connection
262255 tws . send_message what , *args
@@ -275,7 +268,6 @@ def send_message what, *args
275268
276269 def cancel_order *orders
277270
278- logger . tap { |l | l . progname = 'Gateway#CancelOrder' }
279271
280272 orders . compact . each do |o |
281273 local_id = if o . is_a? ( IB ::Order )
@@ -345,7 +337,7 @@ def account_data account_or_id=nil
345337
346338 def prepare_connection &b
347339 tws . disconnect if tws . is_a? IB ::Connection
348- self . tws = IB ::Connection . new **@connection_parameter
340+ self . tws = IB ::Connection . new **@connection_parameter . merge ( logger : self . logger )
349341 @accounts = @local_orders = Array . new
350342
351343 # prepare Advisor-User hierachy
@@ -378,7 +370,6 @@ def initialize_managed_accounts
378370 end
379371
380372 man_id = tws . subscribe ( :ManagedAccounts ) do |msg |
381- logger . progname = 'Gateway#InitializeManagedAccounts'
382373 if @accounts . empty?
383374 # just validate the message and put all together into an array
384375 @accounts = msg . accounts_list . split ( ',' ) . map do |a |
@@ -396,7 +387,6 @@ def initialize_alerts
396387
397388 tws . subscribe ( :AccountUpdateTime ) { | msg | logger . debug { msg . to_human } }
398389 tws . subscribe ( :Alert ) do |msg |
399- logger . progname = 'Gateway#Alerts'
400390 logger . debug " ----------------#{ msg . code } -----"
401391 # delegate anything to IB::Alert
402392 IB ::Alert . send ( "alert_#{ msg . code } " , msg )
0 commit comments