Sha256: 6c2f95b221de26cc54e12d7e69413f16bc950ca175cf7e31252efa2e6805e2a2
Contents?: true
Size: 1.22 KB
Versions: 3
Compression:
Stored size: 1.22 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 'bundler/setup' require 'ib-api' # allocate two variables request_id, snapshot_data = nil ib = IB::Connection.new port: 7496, :client_id => 1112 do | gw | #, :port => 7496 # TWS gw.subscribe(:Alert) { |msg| puts msg.to_human } # Fundamental Data will arrive in XML format, we need to parse it gw.subscribe(:FundamentalData) { |msg| snapshot_data = msg.xml if msg.request_id == request_id } end # Request Fundamental Data for IBM. Possible report types: # 'estimates' - Estimates # 'finstat' - Financial statements # 'snapshot' - Summary request_id = ib.send_message :RequestFundamentalData, :contract => IB::Stock.new( symbol: 'ibm' ), :report_type => 'snapshot' # Needs some time to receive and parse XML. Standard timeout of 1 sec is just too low. ib.wait_for :FundamentalData # Now just extract and use all the fundamental data you needed puts snapshot_data[:ReportSnapshot][:TextInfo][:Text] pp snapshot_data[:ReportSnapshot][:Ratios] STDIN.gets puts "Displaying the complete transmitted data:" puts "" pp snapshot_data
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ib-api-972.2 | example/fundamental_data |
ib-api-972.1 | example/fundamental_data |
ib-api-972.0 | example/fundamental_data |