Class: BaaChan::TradeConfirmation

Inherits:
Object
  • Object
show all
Defined in:
lib/baa_chan/trade_confirmation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(broker, trade_confirmation_number, trade_date, trades, costs) ⇒ TradeConfirmation

Returns a new instance of TradeConfirmation.



9
10
11
12
13
14
15
# File 'lib/baa_chan/trade_confirmation.rb', line 9

def initialize(broker, trade_confirmation_number, trade_date, trades, costs)
  @broker = broker
  @trade_confirmation_number = trade_confirmation_number
  @trade_date = trade_date
  @trades = trades
  @costs = costs
end

Instance Attribute Details

#brokerObject

Returns the value of attribute broker.



7
8
9
# File 'lib/baa_chan/trade_confirmation.rb', line 7

def broker
  @broker
end

#costsObject

Returns the value of attribute costs.



7
8
9
# File 'lib/baa_chan/trade_confirmation.rb', line 7

def costs
  @costs
end

#trade_confirmation_numberObject

Returns the value of attribute trade_confirmation_number.



7
8
9
# File 'lib/baa_chan/trade_confirmation.rb', line 7

def trade_confirmation_number
  @trade_confirmation_number
end

#trade_dateObject

Returns the value of attribute trade_date.



7
8
9
# File 'lib/baa_chan/trade_confirmation.rb', line 7

def trade_date
  @trade_date
end

#tradesObject

Returns the value of attribute trades.



7
8
9
# File 'lib/baa_chan/trade_confirmation.rb', line 7

def trades
  @trades
end

Instance Method Details

#to_builderObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/baa_chan/trade_confirmation.rb', line 25

def to_builder
  Jbuilder.encode do |json|
    json.call(
      self,
      :broker,
      :trade_confirmation_number,
      :trade_date
    )

    json.trades @trades do |trade|
      json.operation trade.operation
      json.ticker trade.ticker
      json.quantity trade.quantity
      json.price trade.price
    end

    json.costs do
      json.brokerage @costs.brokerage
      json.clearing_fee @costs.clearing_fee
      json.registration_fee @costs.registration_fee
      json.emoluments @costs.emoluments
      json.iss @costs.iss if @costs.iss
      json.irrf @costs.irrf if @costs.irrf
      json.pis_cofins @costs.pis_cofins if @costs.pis_cofins
    end
  end
end

#total_costObject



17
18
19
20
21
22
23
# File 'lib/baa_chan/trade_confirmation.rb', line 17

def total_cost
  @costs.brokerage +
    @costs.registration_fee +
    @costs.emoluments +
    @costs.pis_cofins +
    @costs.clearing_fee
end