Sha256: e773075f1e2fe5f89b0094363482526fc7d8d7758defac946c0d39df8fcf125a
Contents?: true
Size: 1.42 KB
Versions: 10
Compression:
Stored size: 1.42 KB
Contents
#!/usr/bin/env ruby # # This script gets details for specific contract from IB require 'rubygems' require 'bundler/setup' $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') 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 = {122 => IB::Symbols::Stocks[:wfc], 133 => IB::Symbols::Options[:wfc20], 144 => IB::Symbols::Stocks[:wrong]} # Connect to IB TWS. ib = IB::Connection.new :client_id => 1112 #, :port => 7496 # TWS # Subscribe to TWS alerts/errors ib.subscribe(IB::Messages::Incoming::Alert) { |msg| puts msg.to_human } # Now, subscribe to ContractData incoming 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 data. ib.subscribe(:ContractData) { |msg| puts msg.contract.inspect } # Now we actually request Contract details for the symbols we're interested in. TWS will # respond with ContractData messages, which will be processed by the code above. @market.each_pair do |id, contract| ib.send_message :RequestContractData, :id => id, :contract => contract end # Wait for IB to respond to our request ib.wait_for :ContractDataEnd
Version data entries
10 entries across 10 versions & 1 rubygems