Sha256: 7834beb7aa45ef9ee80d1cf59645ba5df52bd7c3e86ca89f83c6fe4c57ee4be3

Contents?: true

Size: 1010 Bytes

Versions: 2

Compression:

Stored size: 1010 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 'pathname'
LIB_DIR = (Pathname.new(__FILE__).dirname + '../lib/').realpath.to_s
$LOAD_PATH.unshift LIB_DIR unless $LOAD_PATH.include?(LIB_DIR)

require 'rubygems'
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

2 entries across 2 versions & 1 rubygems

Version Path
ib-ruby-0.7.3 bin/account_info
ib-ruby-0.7.2 bin/account_info