Skip to content
\n

Valid timeframes are defined in lib/ib/constants.rb

\n

If you call it with a contract, it returns the request_id.

\n
ib =  IB::Connection.current\nge =  IB::Stock.new symbol: 'GE'\nge_id = nil\nq =  Queue.new\n\nib.subscribe(IB::Messages::Incoming::HistoricalData) do |msg|\n    if msg.request_id == ge_id\n       q.push msg.results\n    end\nend\n\nge_id = ge.request_historic_data \n\n# serialize historic data\nge_results = q.pop   # anthing is transmitted once
\n

Streaming data are received through subcribing to IB::Messages::Incoming::HistoricalDataUpdate events.

\n

For a complete example, look into https://github.com/ib-ruby/ib-trading-system/blob/main/lib/trading-system/base.rb

\n

hope it helps.

","upvoteCount":1,"url":"https://github.com/ib-ruby/ib-api/discussions/22#discussioncomment-1385743"}}}
Discussion options

You must be logged in to vote

Hi,
you are right, documentation is mostly about EOD-Data.

Other timeframes are easily fetched by IB:Messages::Outgoing:RequestHistoricalData

The trading-system -gem extents the IB::Contract-class to fetch the data:

module IB
  class Contract
    def request_historic_data back: "10 D", interval: :hour1

       ib = Connection.current
       ib.send_message IB::Messages::Outgoing::RequestHistoricalData.new(
                      contract: self,
#                     end_date_time: Time.now.to_ib,  # set only if keep_up_todate is 0
                      duration: back, #    ?
                      bar_size: interval, #  IB::BAR_SIZES.key(:hour)?
                      what_to_show: :trades,

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@georgeu2000
Comment options

Answer selected by georgeu2000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants