Sha256: 32d4541e6ade7b893b3a53cedbb15d3cceaee836a787ab832c04c4b3cb577b12
Contents?: true
Size: 1.37 KB
Versions: 1
Compression:
Stored size: 1.37 KB
Contents
#!/usr/bin/env ruby # # This script gets details for specific contract from IB require 'rubygems' require 'pathname' 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 = {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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ib-ruby-0.7.4 | bin/contract_details |