best way to prepare data for real-time auto-trading under IB?

Discussion in 'Automated Trading' started by emk662, Jan 6, 2016.

  1. emk662

    emk662

    What is the best way to prepare bar data for real-time auto-trading under IB API? I need to trigger the code to do calculation and send order at specific time every day, say every 15 minutes, like 9:45 AM. I am thinking to (1) use reqHistoricalData() method to retrieve data immediately after 9:45 AM; or (2)use reqMketData() to continously get the price then store in a SQL Server and right after 9:45 do a SQL query to get the bar data.

    The advantage of (1) is the bar data is neat and I do not need to process, but I need to convert the price data to the bar data under (2). However, under (1), the immediate availability of historical data is under question and any delay in return historial data will mess up the whole trading. But under (2), at least I can control most of the data, but the SQL thing may take some time to process and since I collected data myself, the data quality may not be as neat as that returned from (1).

    Also, what is the best way to implement a trigger action that can fire off at the specific time? I think about timer, but is there a better way? I am using C#.

    Thanks for your time and input.
     
  2. 2rosy

    2rosy

    neither approach. I would use reqMktData() and build bars in the program. You could use this bluemountaincapital.github.io/Deedle/index.html and keep appending to a dataframe drop older stuff. It lets you do stats easily.
     
  3. Bob111

    Bob111

    trading signal based on one 15 min bar? you can use both and run cross reference for sake of security\accuracy. reqhistdata should be pretty quick for one record.not sure why you are concerned about sql request time,if you are in such long time frame and requesting only one record.. you can skip the sql select and insert statement and simply keep the data in the memory, in array or something
     
  4. Bowgett

    Bowgett

    You can also use reqRealTimeBars which will send you real time bars every 5 seconds.
     
  5. I am doing the same approach as what you proposed. As I need two years historical, cannot do this with market data alone, so I use historical data and stitch that with market data for most recent data.

    I am going to verify the different between bar that I created from market data and bar that I get from historical data now.

     
  6. emk662

    emk662

    I would be use 30 10-minute bars to calculate indicator, so the data retrieved would not be heavy. Have you experienced frequent data issues from IB servers, like freezing or bad tick? And how to implement the timer thing? I hate to use timer due to past VB experience since it was not accurate and slow down the system. But I do not how any better ideas to trigger the method at better time. Thanks.
     
  7. Bob111

    Bob111

    ------I hate to use timer due to past VB experience since it was not accurate and slow down the system.--------
    what do you mean by that? how VB timer(or any timer) can slow down the system? maybe it's a poor programming slowing it down? regarding freezes,bad ticks etc-there is TWSAPI group on yahoo. you can try to count ticks for example, to see,if data is still streaming into your application
    i've seen a lot of variations with IB's data in the past.that would include certain fields not updating not via API,not in TWS. example-bid -ask prices are updating-last price and size is not. bid-ask are updating,sizes and high-low-not. and so on. but i believe i'm an exception and those things are rare. at least-no one else was having them at that time.
     
  8. vicirek

    vicirek

    .net has few different types of timers. The one that is the least accurate is running on UI thread and its accuracy is affected by anything compute intensive running on that thread. better choice is to use system timers that are more accurate and less dependent on other computations. the lesson is to know what to use and how it really works.

    As to the original problem how to trigger; trigger can be your own system time, server time or time stamp associated with incoming data. In case of IB the last option is out for real time data requests.

    Best option to use bars is to create and store in your own program during live session and dump copy to disk from time to time.
     
  9. Bob111

    Bob111

    ----
    Best option to use bars is to create and store in your own program during live session and dump copy to disk from time to time.---yep. that was my initial suggestion.
    dunno about .net vb, but when i need accuracy in my good old VB6 apps- i rely on system clock and good old windows .dll
     
  10. emk662

    emk662

    bob111, have u compared the bars you created vs the historical bars from IB API function? How is the difference? I assume their bars are more accurate, so I am reluctant to grab tick prices to create my own. And if you collect prices during live session, when power outrage or network breakdown happens, then what to do? Thanks.
     
    #10     Jan 8, 2016