Sha256: 6cb253d75e73da35246ef2c719342a6026c262318187af336574c35f31b82175
Contents?: true
Size: 1.25 KB
Versions: 1
Compression:
Stored size: 1.25 KB
Contents
#!/usr/bin/env ruby # # Subscribe to real time data for specific symbol from IB require 'bundler/setup' require 'ib/symbols' contracts = {1 => IB::Symbols::Stocks[:vxx], 9 => IB::Symbols::Forex[:gbpusd] } # Connect to IB TWS. ib = IB::Connection.new :client_id => 1112 do | gw | #, :port => 7497 # TWS # Subscribe to TWS alerts/errors gw.subscribe(:Alert) { |msg| puts msg.to_human } # Subscribe to RealTimeBar incoming events. We have to use message request_id # to figure out what contract it's for. gw.subscribe(IB::Messages::Incoming::RealTimeBar) do |msg| puts contracts[msg.request_id].description + ": #{msg.to_human}" end end contracts.each_pair do |request_id, contract| ib.send_message IB::Messages::Outgoing::RequestRealTimeBars.new( :request_id => request_id, :contract => contract, # :bar_size => 5, # Only 5 secs bars supported (hard coded in messages/outgoing/bar_requests) :data_type => :trades, # possible values: :trades, :bid, :ask , :midpoint :use_rth => false) end # So we need to interrupt manually when we do not want any more quotes. puts "\n******** Press <Enter> to exit... *********\n\n" STDIN.gets
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ib-symbols-1.0 | examples/real_time_data |