forked from ib-ruby/ib-ruby
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
129 additions
and
36 deletions.
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 |
---|---|---|
|
@@ -73,3 +73,7 @@ | |
== 0.4.16 / 2011-09-19 | ||
|
||
* Execution Model added | ||
|
||
== 0.4.17 / 2011-09-19 | ||
|
||
* option_data script now working |
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 @@ | ||
0.4.16 | ||
0.4.17 |
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
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,59 @@ | ||
#!/usr/bin/env ruby | ||
# | ||
# This script connects to IB API and subscribes to market data for specific symbols | ||
|
||
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' | ||
|
||
# Definition of what we want market data for. We have to keep track of what ticker id | ||
# corresponds to what symbol ourselves, because the ticks don't include any other | ||
# identifying information. The choice of ticker ids is, as far as I can tell, arbitrary. | ||
@market = {123 => IB::Symbols::Options[:wfc20], | ||
125 => IB::Symbols::Options[:z50]} | ||
|
||
# First, connect to IB TWS. | ||
ib = IB::Connection.new | ||
|
||
## Subscribe to TWS alerts/errors | ||
ib.subscribe(IB::Messages::Incoming::Alert) { |msg| puts msg.to_human } | ||
|
||
# Subscribe to TickerPrice and TickerSize events. The code passed in the block will | ||
# be executed when a message of that type is received, with the received message as its | ||
# argument. In this case, we just print out the tick. | ||
# | ||
# Note that we have to look the ticker id of each incoming message | ||
# up in local memory to figure out what it's for. | ||
# | ||
# (N.B. The description field is not from IB TWS. It is defined | ||
# locally in forex.rb, and is just arbitrary text.) | ||
ib.subscribe(IB::Messages::Incoming::TickPrice) do |msg| | ||
puts @market[msg.data[:id]].description + ": " + msg.to_human | ||
end | ||
|
||
ib.subscribe(IB::Messages::Incoming::TickSize) do |msg| | ||
puts @market[msg.data[:id]].description + ": " + msg.to_human | ||
end | ||
|
||
ib.subscribe(IB::Messages::Incoming::TickOption) do |msg| | ||
puts @market[msg.data[:id]].description + ": " + msg.to_human | ||
end | ||
|
||
# Now we actually request market data for the symbols we're interested in. | ||
@market.each_pair do |id, contract| | ||
ib.send IB::Messages::Outgoing::RequestMarketData.new :id => id, | ||
:contract => contract | ||
end | ||
|
||
puts "\nSubscribed to market data" | ||
puts "\n******** Press <Enter> to cancel... *********\n\n" | ||
gets | ||
puts "Cancelling market data subscription.." | ||
|
||
@market.each_pair do |id, contract| | ||
ib.send IB::Messages::Outgoing::CancelMarketData.new :id => id | ||
end |
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
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
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
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,30 @@ | ||
# Stock contracts definitions | ||
# | ||
# Note that the :description field is particular to ib-ruby, and is NOT part of the | ||
# standard TWS API. It is never transmitted to IB. It's purely used clientside, and | ||
# you can store any arbitrary string that you may find useful there. | ||
|
||
module IB | ||
module Symbols | ||
|
||
Options = | ||
{:wfc20 => Models::Contract.new(:symbol => "WFC", | ||
:exchange => "SMART", | ||
#:currency => "USD", | ||
:expiry => "201110", | ||
:right => "CALL", | ||
:strike => 20.0, | ||
:sec_type => Models::Contract::SECURITY_TYPES[:option], | ||
:description => "Wells Fargo 20 Call 2011-10"), | ||
:z50 => Models::Contract.new(:symbol => "Z", | ||
:exchange => "LIFFE", | ||
#:currency => "USD", | ||
:expiry => "201110", | ||
:right => "CALL", | ||
:strike => 50.0, | ||
:sec_type => Models::Contract::SECURITY_TYPES[:option], | ||
:description => " FTSE-100 index 50 Call 2011-10"), | ||
|
||
} | ||
end | ||
end |