forked from ib-ruby/ib-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-adding davek42's braket order example
- Loading branch information
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
rvm use jruby-1.6.7@ib-ruby --create | ||
rvm use jruby-1.7.0@ib-ruby --create |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env ruby | ||
# | ||
# This script places WFC bracketed buy order. | ||
# Two child orders are attached: | ||
# STOP order | ||
# LIMIT order (profit target) | ||
|
||
require 'rubygems' | ||
require 'bundler/setup' | ||
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') | ||
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 } | ||
|
||
symbol = IB::Symbols::Stocks[:wfc] | ||
|
||
order_price = 33.80 | ||
stop_price = order_price - 0.25 | ||
profit_price = order_price + 0.25 | ||
|
||
#-- Parent Order -- | ||
buy_order = IB::Order.new :total_quantity => 100, | ||
:limit_price => order_price, | ||
:action => 'BUY', | ||
:order_type => 'LMT', | ||
:algo_strategy => '', | ||
:transmit => false | ||
ib.wait_for :NextValidId | ||
|
||
#-- Child STOP -- | ||
stop_order = IB::Order.new :total_quantity => 100, | ||
:limit_price => 0, | ||
:aux_price => stop_price, | ||
:action => 'SELL', | ||
:order_type => 'STP', | ||
:parent_id => buy_order.local_id, | ||
:transmit => true | ||
#-- Profit LMT | ||
profit_order = IB::Order.new :total_quantity => 100, | ||
:limit_price => profit_price, | ||
:action => 'SELL', | ||
:order_type => 'LMT', | ||
:parent_id => buy_order.local_id, | ||
:transmit => true | ||
|
||
# place parent order | ||
ib.place_order buy_order, symbol | ||
stop_order.parent_id = buy_order.local_id | ||
profit_order.parent_id = buy_order.local_id | ||
|
||
# place child orders | ||
ib.place_order stop_order, symbol | ||
ib.place_order profit_order, symbol | ||
|
||
ib.send_message :RequestAllOpenOrders | ||
|
||
puts "\n******** Press <Enter> to cancel... *********\n\n" | ||
STDIN.gets |