Sha256: a5d07cd62fe586d8ab8372b214be10f6db47c5a55c5304c35cebf12090b4db86

Contents?: true

Size: 762 Bytes

Versions: 1

Compression:

Stored size: 762 Bytes

Contents

#!/usr/bin/env ruby
#
# This script allows you to cancel either a set of open Orders by their ids,
# or ALL Orders opened via IB API at once. The latter is useful when your
# robot goes crazy and opens gazillions of wrong limit orders.

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

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

if ARGV.empty?
  ib.send_message :RequestGlobalCancel
else
  # Will only work for Orders placed under the same :client_id
  ib.cancel_order *ARGV
end

ib.send_message :RequestAllOpenOrders

sleep 3

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ib-ruby-0.7.4 bin/cancel_orders