Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6618811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:53:06+00:00 2026-05-25T20:53:06+00:00

I tried to request historical futures data but for a beginner the ibrokers.pdf document

  • 0

I tried to request historical futures data but for a beginner the ibrokers.pdf document is not well enough documented.
example Gold Miny Contract Dec11 NYSELIFFE:

goldminy<-twsFuture("YG","NYSELIFFE","201112",multiplier="33.2")
reqHistoricalData(conn,
Contract= "goldminy",
endDateTime"",
barSize = "1 S",
duration = "1 D",
useRTH = "0",
whatToShow = "TRADES","BID", "ASK", "BID_ASK",
timeFormat = "1",
tzone = "",
verbose = TRUE,
tickerId = "1",
eventHistoricalData,
file)

I also don’t know how to specify some of the data parameters correctly ?

whatToShow ? i need Date,Time,BidSize,Bid,Ask,AskSize,Last,LastSize,Volume

tickerID ?

eventHistoricalData ?

file ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:53:06+00:00Added an answer on May 25, 2026 at 8:53 pm

    I wrote the twsInstrument package (on RForge) to alleviate these sorts of headaches.
    getContract will find the contract for you if you give it anything reasonable. Any of these formats should work:
    “YG_Z1”, “YG_Z11”, “YGZ1”, “YGZ11”, “YGZ2011”, “YGDEC2011”, “YG_DEC2011”, etc.
    (also you could use the conId, or give it an instrument object, or the name of an instrument object)

    > library(twsInstrument)
    > goldminy <- getContract("YG_Z1")
    Connected with clientId 100.
    Contract details request complete. Disconnected.
    > goldminy
    List of 16
     $ conId          : chr "42334455"
     $ symbol         : chr "YG"
     $ sectype        : chr "FUT"
     $ exch           : chr "NYSELIFFE"
     $ primary        : chr ""
     $ expiry         : chr "20111228"
     $ strike         : chr "0"
     $ currency       : chr "USD"
     $ right          : chr ""
     $ local          : chr "YG   DEC 11"
     $ multiplier     : chr "33.2"
     $ combo_legs_desc: chr ""
     $ comboleg       : chr ""
     $ include_expired: chr "0"
     $ secIdType      : chr ""
     $ secId          : chr ""
    

    I don’t have a subscription to market data for NYSELIFFE, so I will use the Dec 2011 e-mini S&P future for the rest of this answer.

    You could get historical data like this

    tws <- twsConnect()
    hist.data <- reqHistoricalData(tws, getContract("ES_Z1"))
    

    This will give you back these columns, and it will all be ‘TRADES’ data

    > colnames(hist.data)
    [1] "ESZ1.Open"    "ESZ1.High"    "ESZ1.Low"     "ESZ1.Close"   "ESZ1.Volume" 
    [6] "ESZ1.WAP"     "ESZ1.hasGaps" "ESZ1.Count"  
    

    whatToShow must be one of ‘TRADES’, ‘BID’, ‘ASK’, or ‘BID_ASK’. If your request uses whatToShow=’BID’ then you will get the OHLC etc. of the BID prices. “BID_ASK” means that the Ask price will be used for the High and the Bid price will be used for the Low.

    Since you said the vignette was too advanced, it bears repeating that Interactive Brokers limits historical data requests to 6 every 60 seconds. So you should pause for 10 seconds between each request (or for getting lots of data I usually pause for 30 seconds after I make 3 requests so that if I have BID data for something I am also likely have ASK data for it)

    The function getBAT will download the BID, ASK and TRADES data, and merge together only the closing values of those into a single xts object that looks like this:

    > getBAT("ES_Z1")
    Connected with clientId 120.
    waiting for TWS reply on ES ............. done.
    Pausing 10 seconds between requests ...
    waiting for TWS reply on ES .... done.
    Pausing 10 seconds between requests ...
    waiting for TWS reply on ES .... done.
    Pausing 10 seconds between requests ...
    Disconnecting ... 
    [1] "ES_Z1"
    > tail(ES_Z1)
                        ES.Bid.Price ES.Ask.Price ES.Trade.Price ES.Mid.Price
    2011-09-27 15:09:00      1170.25      1170.50        1170.50     1170.375
    2011-09-27 15:10:00      1170.50      1170.75        1170.50     1170.625
    2011-09-27 15:11:00      1171.25      1171.50        1171.25     1171.375
    2011-09-27 15:12:00      1171.50      1171.75        1171.50     1171.625
    2011-09-27 15:13:00      1171.25      1171.50        1171.25     1171.375
    2011-09-27 15:14:00      1169.75      1170.00        1170.00     1169.875
                        ES.Volume
    2011-09-27 15:09:00      6830
    2011-09-27 15:10:00      4509
    2011-09-27 15:11:00      4902
    2011-09-27 15:12:00      6089
    2011-09-27 15:13:00      6075
    2011-09-27 15:14:00     14380
    

    You asked for both LastSize and Volume. The “Volume” that getBAT returns is the total amount traded over the time of the bar. So, with 1 minute bars, it’s the total volume that took place in that 1 minute.

    Here’s an answer that doesn’t use twsInstrument:
    I’m almost certain this will work, but as I said, I don’t have the required market data subscription, so I can’t test.

    reqHistoricalData(tws, twsFuture("YG","NYSELIFFE","201112"))
    

    Using the e-mini S&P again:

    > mydata <- reqHistoricalData(tws, twsFuture("ES","GLOBEX","201112"), barSize='1 min', duration='5 D', useRTH='0', whatToShow='TRADES')
    waiting for TWS reply on ES .... done.
    
    > head(mydata)
                        ESZ1.Open ESZ1.High ESZ1.Low ESZ1.Close ESZ1.Volume ESZ1.WAP ESZ1.hasGaps ESZ1.Count
    2011-09-21 15:30:00   1155.25   1156.25  1155.00    1155.75        3335  1155.50            0        607
    2011-09-21 15:31:00   1155.75   1156.25  1155.50    1155.75         917  1155.95            0        164
    2011-09-21 15:32:00   1155.75   1156.25  1155.50    1156.00         859  1155.90            0        168
    2011-09-21 15:33:00   1156.00   1156.25  1155.50    1155.75         642  1155.83            0        134
    2011-09-21 15:34:00   1155.50   1156.00  1155.25    1155.25        1768  1155.65            0        232
    2011-09-21 15:35:00   1155.25   1155.75  1155.25    1155.25         479  1155.45            0         94
    

    One of the problems with your attempt is that if you’re using a barSize of ‘1 S’, your duration cannot be greater than ’60 S’ See IB Historical Data Limitations

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What should data look like before data encoding in: urllib2.Request(someurl,data) I tried [('name1','value1'),('name2','value2'),...] but
I tried to make http get request with code: String username = test\\v100; String
I tried to use view parameters in conjunction with a request scoped bean. I
I tried to read a file in a view like this: def foo(request): f
I already tried getting the current URL of my UIWebView with: webview.request.URL . Unfortunately
I cannot request url http://www.besondere-raumdüfte.de with urllib2.urlopen(). I tried to encode string using urllib.urlencode
How do you set the content type of an HTTP Request? I've tried this:
tried uncommenting pam_limits.so from the pam.d directory but no luck. Basic PAM seems to
Possible Duplicate: How do I set HTTP_REFERER when testing in Rails? I tried request.env[HTTP_REFERER]
I have this data structure: request ======= building_id lot_code building ======== building_id lot_id lot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.