Sha256: a78b7cb11b94b4e6359d3c3b362cdc5ce780aaedcefad12f234c8768549b4a42
Contents?: true
Size: 1.46 KB
Versions: 5
Compression:
Stored size: 1.46 KB
Contents
#!/usr/bin/env ruby # # This script connects to IB API and subscribes to L2 (depth of 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 L2 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::Stocks[:wfc], 456 => IB::Symbols::Futures[:es], 789 => IB::Symbols::Forex[:gbpusd] } # First, connect to IB TWS. ib = IB::Connection.new # Subscribe to TWS alerts/errors ib.subscribe(:Alert) { |msg| puts msg.to_human } # Subscribe to MarketDepth events. ib.subscribe(:MarketDepth) do |msg| puts @market[msg.data[:id]].description + ": " + msg.to_human end # Now we actually request L2 market data for the symbols we're interested in. @market.each_pair do |id, contract| ib.send_message :RequestMarketDepth, :id => id, :contract => contract, :num_rows => 5 end puts "\nSubscribed to market data" puts "\n******** Press <Enter> to cancel... *********\n\n" gets puts "Cancelling market data subscription.." @market.each_pair { |id, contract| ib.send_message :CancelMarketDepth, :id => id }
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
ib-ruby-0.5.14 | bin/depth_of_market |
ib-ruby-0.5.13 | bin/depth_of_market |
ib-ruby-0.5.12 | bin/depth_of_market |
ib-ruby-0.5.11 | bin/depth_of_market |
ib-ruby-0.5.10 | bin/depth_of_market |