Module: InteractiveBrokers2TastyWorks::Utils
- Defined in:
- lib/interactive_brokers_2_tasty_works.rb
Class Method Summary collapse
- .build_action(trade) ⇒ Object
- .build_commission(trade) ⇒ Object
- .build_date(str) ⇒ Object
- .build_date_time_str(trade) ⇒ Object
- .build_description(trade) ⇒ Object
- .build_instrument_type(trade) ⇒ Object
- .build_value(trade) ⇒ Object
- .put_or_call(trade) ⇒ Object
Class Method Details
.build_action(trade) ⇒ Object
118 119 120 |
# File 'lib/interactive_brokers_2_tasty_works.rb', line 118 def build_action(trade) "#{trade[:buySell]}_TO_#{trade[:openCloseIndicator] == 'O' ? 'OPEN' : 'CLOSE'}" end |
.build_commission(trade) ⇒ Object
157 158 159 160 |
# File 'lib/interactive_brokers_2_tasty_works.rb', line 157 def build_commission(trade) c = trade[:ibCommission] c.to_f == -0.0 ? '0' : c end |
.build_date(str) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/interactive_brokers_2_tasty_works.rb', line 110 def build_date(str) return nil if str.to_s.strip == '' day = str[6..7] month = str[4..5] year = str[2..3] "#{month}/#{day}/#{year}" end |
.build_date_time_str(trade) ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/interactive_brokers_2_tasty_works.rb', line 99 def build_date_time_str(trade) d, t = trade[:tradeDate], trade[:tradeTime] year = d[0..3] month = d[4..5] day = d[6..7] hour = t[0..1] min = t[2..3] sec = t[4..5] Time.zone.local(year,month,day,hour,min,sec).strftime('%FT%T%z') end |
.build_description(trade) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/interactive_brokers_2_tasty_works.rb', line 131 def build_description(trade) case trade[:buySell] when 'SELL'; str = 'Sold' when 'BUY'; str = 'Bought' end str += " #{trade[:quantity].to_i.abs} " str += case (ac = trade[:assetCategory]) when 'OPT' exp = build_date(trade[:expiry]) "#{trade[:symbol]} #{exp} #{put_or_call(trade)} #{trade[:strike]} @ #{trade[:tradePrice]}" when 'STK' "#{trade[:symbol]} @ #{trade[:tradePrice]}" else raise ArgumentError.new("Unknown asset category: #{ac}") end str end |
.build_instrument_type(trade) ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/interactive_brokers_2_tasty_works.rb', line 122 def build_instrument_type(trade) case (ac = trade[:assetCategory]) when 'OPT'; 'Equity Option' when 'STK'; 'Equity' else raise ArgumentError.new("Unknown asset category: #{ac}") end end |
.build_value(trade) ⇒ Object
152 153 154 155 |
# File 'lib/interactive_brokers_2_tasty_works.rb', line 152 def build_value(trade) v = trade[:proceeds] v.to_f == -0.0 ? '0' : v end |
.put_or_call(trade) ⇒ Object
162 163 164 165 |
# File 'lib/interactive_brokers_2_tasty_works.rb', line 162 def put_or_call(trade) return nil unless trade[:assetCategory] == 'OPT' trade[:putCall] == 'P' ? 'PUT' : 'CALL' end |