Class: InteractiveBrokers2TastyWorks

Inherits:
Object
  • Object
show all
Defined in:
lib/interactive_brokers_2_tasty_works.rb,
lib/interactive_brokers_2_tasty_works/version.rb

Defined Under Namespace

Modules: Utils

Constant Summary collapse

OUTPUT_HEADER =
['Date', 'Type', 'Action', 'Symbol', 'Instrument Type', 'Description', 'Value', 'Quantity',
'Average Price', 'Commissions', 'Fees', 'Multiplier', 'Underlying Symbol', 'Expiration Date',
'Strike Price', 'Call or Put']
VERSION =
"0.3.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_hash: nil, input_path: nil, file_format: :xml, add_output: nil) ⇒ InteractiveBrokers2TastyWorks

Returns a new instance of InteractiveBrokers2TastyWorks.

Raises:

  • (ArgumenrError)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/interactive_brokers_2_tasty_works.rb', line 22

def initialize(data_hash: nil, input_path: nil, file_format: :xml, add_output: nil)
  @data_hash   = data_hash
  @input_path  = input_path
  @file_format = file_format
  @add_output  = add_output

  raise ArgumenrError.new("Must specify `data_hash` or `input_path`.") if data_hash.empty? && input_path.empty?

  if !input_path.empty?
    file_format = input_path.split(".").last.to_sym if file_format.empty?
    file_format = file_format.to_s.to_sym unless file_format.is_a?(Symbol)
    raise ArgumentError.new("Unknown file format: #{file_format}") unless i(xml json).include?(file_format)
  end
end

Instance Attribute Details

#file_formatObject (readonly)

Returns the value of attribute file_format.



16
17
18
# File 'lib/interactive_brokers_2_tasty_works.rb', line 16

def file_format
  @file_format
end

#input_pathObject (readonly)

Returns the value of attribute input_path.



16
17
18
# File 'lib/interactive_brokers_2_tasty_works.rb', line 16

def input_path
  @input_path
end

Instance Method Details

#outputObject



43
44
45
# File 'lib/interactive_brokers_2_tasty_works.rb', line 43

def output
  @output ||= convert!
end

#save_as(output_path) ⇒ Object



37
38
39
40
41
# File 'lib/interactive_brokers_2_tasty_works.rb', line 37

def save_as(output_path)
  File.open(File.expand_path(output_path), 'w') do |f|
    output.each { |o| f.write(o.to_csv) }
  end
end