Sha256: a6110854b2bed0121aca7b3adbced2e3d39d280b688b65f13b22fee3eeac5a8d

Contents?: true

Size: 1.13 KB

Versions: 9

Compression:

Stored size: 1.13 KB

Contents

#!/usr/bin/env ruby
#
# This script downloads Fundamental data for specific symbols from IB
# This only works IF you have Reuters data subscription!

require 'rubygems'
require 'bundler/setup'
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'ib-ruby'
require 'xmlsimple'
require 'pp'


ib = IB::Connection.new :client_id => 1112 #, :port => 7496 # TWS

ib.subscribe(:Alert) { |msg| puts msg.to_human }

# Fundamental Data will arrive as XML, parse it
ib.subscribe(:FundamentalData) { |msg| @xml = XmlSimple.xml_in(msg.data) }

ibm = IB::Contract.new :symbol => 'IBM',
                       :exchange => 'NYSE',
                       :currency => 'USD',
                       :sec_type => 'STK'

# Request Fundamental Data for IBM. Possible report types:
#     'estimates' - Estimates
#     'finstat'   - Financial statements
#     'snapshot' - Summary
ib.send_message :RequestFundamentalData,
                :id => 10,
                :contract => ibm,
                :report_type => 'snapshot'

# Needs some time to receive and parse XML. Standard timeout of 1 sec is just too low.
ib.wait_for(30) { @xml}

pp @xml

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ib-ruby-0.8.4 bin/fundamental_data
ib-ruby-0.8.3 bin/fundamental_data
ib-ruby-0.8.1 bin/fundamental_data
ib-ruby-0.8.0 bin/fundamental_data
ib-ruby-0.7.12 bin/fundamental_data
ib-ruby-0.7.11 bin/fundamental_data
ib-ruby-0.7.10 bin/fundamental_data
ib-ruby-0.7.9 bin/fundamental_data
ib-ruby-0.7.8 bin/fundamental_data