Sha256: 7fb691e5793e38c64d371e17b6c4f36210d9fa3c6ac556a7202d7ee76fabdc64

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

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. Arbitrary :client_id is used to identify your script
ib = IB::Connection.new :client_id => 1112 #, :port => 7496 # TWS

# Subscribe to TWS alerts/errors and order-related messages
ib.subscribe(:Alert, :OpenOrder, :OrderStatus) { |msg| puts msg.to_human }

wfc = IB::Symbols::Stocks[:wfc]
buy_order = IB::Models::Order.new :total_quantity => 100,
                                  :limit_price => 1 + rand().round(2),
                                  :action => 'BUY',
                                  :order_type => 'LMT'
ib.wait_for :NextValidId
ib.place_order buy_order, wfc

ib.send_message :RequestAllOpenOrders

puts "\n******** Press <Enter> to cancel... *********\n\n"
STDIN.gets

Version data entries

2 entries across 2 versions & 1 rubygems

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