Sha256: 2485383c58f0534f4041f722a9a2f929cdef9af79c758d632a70614925552dbb

Contents?: true

Size: 877 Bytes

Versions: 1

Compression:

Stored size: 877 Bytes

Contents

#!/usr/bin/env ruby
#
# This script connects to IB API, subscribes to account info and prints out
# messages received from IB (update every 3 minute or so)

require 'rubygems'
require 'pathname'
require 'bundler/setup'
require 'ib-ruby'

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

# Set log level
log.level = Logger::FATAL

# Subscribe to TWS alerts/errors and account-related messages
# that TWS sends in response to account data request
ib.subscribe(:Alert, :AccountValue,
             :PortfolioValue, :AccountUpdateTime) { |msg| puts msg.to_human }

ib.send_message :RequestAccountData, :subscribe => true

puts "\nSubscribing to IB account data"
puts "\n******** Press <Enter> to cancel... *********\n\n"
STDIN.gets
puts "Cancelling account data subscription.."

ib.send_message :RequestAccountData, :subscribe => false

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ib-ruby-0.7.4 bin/account_info