Sha256: e5c993bf77707ca1c5dc933004bdddc2098a20e795d3919fa6a64a7009e8d69d

Contents?: true

Size: 824 Bytes

Versions: 1

Compression:

Stored size: 824 Bytes

Contents

#!/usr/bin/env ruby
#
# This script allows you to cancel ALL Orders opened via IB API at once.
# Useful if your robot goes crazy and opens gazillions of wrong limit orders.

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'

p ARGV

# First, connect to IB TWS.
ib = IB::Connection.new

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

ib.send_message :RequestGlobalCancel if ARGV.empty?

ARGV.each { |order_id| ib.send_message :CancelOrder, :id => order_id.to_i }

ib.send_message :RequestAllOpenOrders

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ib-ruby-0.5.15 bin/cancel_orders