Skip to content

Commit 3a5338f

Browse files
author
Hartmut Bischoff
committed
Improved behavior of contract#essential
1 parent daecbe5 commit 3a5338f

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

lib/models/ib/contract.rb

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -218,20 +218,18 @@ def serialize_ib_ruby
218218
# the link to contract-details is __not__ maintained.
219219
def essential
220220

221-
self_attributes = [ :sec_type]
222-
the_attributes = [ :symbol , :con_id, :exchange, :right,
221+
the_attributes = [ :sec_type, :symbol , :con_id, :exchange, :right,
223222
:currency, :expiry, :strike, :local_symbol, :last_trading_day,
224-
:multiplier, :primary_exchange, :trading_class ]
225-
the_hash= the_attributes.map{|x| y= self.send(x); [x,y] if y.present? }.compact.to_h
226-
the_hash[:description] =
227-
if @description.present?
228-
@description
229-
elsif contract_detail.present?
230-
contract_detail.long_name
231-
else
232-
""
233-
end
234-
self.class.new the_hash.merge( self_attributes.map{|x| y = self.send(x); [x,y] unless y == :none }.compact.to_h )
223+
:multiplier, :primary_exchange, :trading_class, :description ]
224+
new_contract= self.class.new invariant_attributes.select{|k,_| the_attributes.include? k }.compact
225+
new_contract[:description] = if @description.present?
226+
@description
227+
elsif contract_detail.present?
228+
contract_detail.long_name
229+
else
230+
""
231+
end
232+
new_contract # return contract
235233
end
236234

237235

0 commit comments

Comments
 (0)