¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io
Date

Re: reqHistoricalTIcks - request more than 1000 ticks at some point in time

 

Good point I will run some tests on spy in March. Thanks.


El mar., 2 jun. 2020 3:21 a. m., Tinglu Xu <tianjinxtl@...> escribi¨®:
Yes document said that would return more than 1000 ticks to finish full second.? I haven¡¯t verify this but I think in lat March SPY could be more than 1000 ticks per seconds.


Re: Data delay!

 

Latest timestamp I have right now is:?1591105787000
So, 4 hours.
It doesn't seem to catch up, only falls more and more behind.


Re: Looking for TWS/Gateway versions v965-970

 

On Tue, Jun 2, 2020 at 09:24 AM, Ryan Ballentine wrote:
Gateway v972 still works.?Thus I must conclude that all Gateway and TWS versions <v972 cannot be used anymore. Please let me know if you are still able to login using any versions <v972, or if you know a way around the "this version is no longer supported" error, etc.
I tried logging in with 967.1f and 968.2e, and both attempts failed with the error you mentioned.? It looks like there was a recent forced upgrade with the TWS.
[rwk]


Re: Data delay!

 

¿ªÔÆÌåÓý

How many hours exactly?


On Jun 2, 2020, at 9:44 AM, stepan.samarin@... wrote:

This is latest output from tickString method for micro futures ES. It's off by 6 points and several hours, according to timestamp (which I receive from IB).?

18:42:11.670 tickString: 3055.75;4;1591105536638;291578;3053.71797941;true
18:42:13.345 tickString: 3056.00;8;1591105536838;291586;3053.71804202;true
18:42:22.928 tickString: 3055.75;15;1591105537742;291601;3053.71814654;false
18:42:23.155 tickString: 1591105538
18:42:29.986 tickString: 3055.75;8;1591105538043;291609;3053.71820228;true
18:42:33.243 tickString: 3055.75;12;1591105538144;291621;3053.71828589;false
18:42:52.652 tickString: 3055.75;3;1591105538947;291624;3053.71830679;true
18:42:59.940 tickString: 3055.75;8;1591105539049;291632;3053.71836253;false
18:43:01.303 tickString: 1591105539
18:43:07.161 tickString: 3055.75;26;1591105540151;291658;3053.71854364;true
18:43:07.397 tickString: 3056.00;5;1591105540252;291663;3053.71858189;false
18:43:07.663 tickString: 1591105541
18:43:12.150 tickString: 3056.00;18;1591105540553;291681;3053.71872268;false
?


Re: Data delay!

 

This is latest output from tickString method for micro futures ES. It's off by 6 points and several hours, according to timestamp (which I receive from IB).?

18:42:11.670 tickString: 3055.75;4;1591105536638;291578;3053.71797941;true
18:42:13.345 tickString: 3056.00;8;1591105536838;291586;3053.71804202;true
18:42:22.928 tickString: 3055.75;15;1591105537742;291601;3053.71814654;false
18:42:23.155 tickString: 1591105538
18:42:29.986 tickString: 3055.75;8;1591105538043;291609;3053.71820228;true
18:42:33.243 tickString: 3055.75;12;1591105538144;291621;3053.71828589;false
18:42:52.652 tickString: 3055.75;3;1591105538947;291624;3053.71830679;true
18:42:59.940 tickString: 3055.75;8;1591105539049;291632;3053.71836253;false
18:43:01.303 tickString: 1591105539
18:43:07.161 tickString: 3055.75;26;1591105540151;291658;3053.71854364;true
18:43:07.397 tickString: 3056.00;5;1591105540252;291663;3053.71858189;false
18:43:07.663 tickString: 1591105541
18:43:12.150 tickString: 3056.00;18;1591105540553;291681;3053.71872268;false
?


Re: reqHistoricalTIcks - request more than 1000 ticks at some point in time

Dean Williams
 

As previously mentioned, it is to complete the last second in the request.

It may be easier to see by looking at a contract with less volume and setting the?numberOfTicks?to a small quantity.


Re: Looking for TWS/Gateway versions v965-970

Ryan Ballentine
 

I tried TWS v968.2e from Richard and unfortunately I am getting the "this version is no longer supported" error on that as well.?

I realized I should test my install of Gateway v971... anddd that is no longer supported either.

Gateway v972 still works.?Thus I must conclude that all Gateway and TWS versions <v972 cannot be used anymore. Please let me know if you are still able to login using any versions <v972, or if you know a way around the "this version is no longer supported" error, etc.

Thanks again for all the help.

Best,
- Ryan


Re: Data delay!

 

Hello,

Assuming this is a data feed that you should be receiving in realtime, are you sure you are getting delayed data rather than data with a different timestamp to that in your local timezone?

Best wishes,

M


On Tue, 2 Jun 2020 at 15:47, <stepan.samarin@...> wrote:
Hello,

I was surprised, to say the least, to discover that I'm getting delayed data in API (1 hour to be exact). I'm doing the following:?

? ? private static Contract getMicroESFuturesContract() {
? ? ? ? Contract contract = new Contract();
? ? ? ? contract.localSymbol("MESM0");
? ? ? ? contract.secType("FUT");
? ? ? ? contract.currency("USD");
? ? ? ? contract.exchange("GLOBEX");
? ? ? ? return contract;
? ? }

? ? public void subscribe(int tickerId, Contract contract, String period,
? ? ? ? ? ? ? ? ? ? ? ? ? boolean reqRealTimeBars, boolean reqTickByTickData, boolean reqMarketDepth, boolean reqHistoricalData) {
? ? ? ? if (reqRealTimeBars) socket.reqRealTimeBars(tickerId, contract, 5, "MIDPOINT", false, null);
? ? ? ? if (reqTickByTickData) {
? ? ? ? ? ? socket.reqTickByTickData(tickerId, contract, "AllLast", 0, false);
? ? ? ? ? ? socket.reqTickByTickData(tickerId + 1, contract, "BidAsk", 0, false);
? ? ? ? }
? ? ? ? if (reqMarketDepth) {
? ? ? ? ? ? socket.reqMktDepth(tickerId, contract, 8, true, null);
? ? ? ? }
? ? ? ? if (reqHistoricalData) {
? ? ? ? ? ? //socket.reqHistoricalData(tickerId, contract, "", period, "1 day", "TRADES", 0, 1, false, null);
? ? ? ? ? ? //int tickerId, Contract contract, String endDateTime, String durationStr, String barSizeSetting, String whatToShow, int useRTH, int formatDate, boolean keepUpToDate, List<TagValue> chartOptions
? ? ? ? ? ? socket.reqHistoricalData(tickerId, contract, "", period, "5 secs", "BID_ASK", 0, 1, false, null);
? ? ? ? }
? ? ? ? socket.reqMktData(tickerId, contract, "233", false, false, null); //RTVolume
? ? ? ? socket.reqPositions();
? ? ? ? socket.reqIds(-1);
? ? }

And then call:?
?
subscribe(Configuration.MES_CONTRACT_ID, getMicroESFuturesContract(), LOOKBACK_UNITS_PERIOD + " S",
? ? ? ? ? ? ? ? true, true, true, true);

Any ideas why I'm getting delayed data?



--
+44 (0) 7528 551604?
Gulfstream Software - Winner Risk Management Awards 2010
This message is subject to :


Re: Is it highly recommended to include "watchdog" function in every program?

 

Hi Nick,

Thanks so much for your reply. Can you please advise me on any place I can learn what the watchdog function can do for it?

For example, as you mentioned if the program suddenly stops working, what will the watchdog do? Will it prevent that or it will fix the program automatically?

I tried to find resources on how the watchdog works but I can't find any specifically for ib api. Can you please help to suggest some? Thanks so much for your kind help.

Thanks,
Susan


On Wed, 3 Jun. 2020, 00:35 Nick, <news1000@...> wrote:

You can't assume that everything will work all the time. What happens if you have an open position but your program stops working?

You need to defend against outages. The extent you go to will depend on your circumstances and needs.

If you only use bracket orders then it's just lost opportunity cost. If you manage open positions then it could get costly to not be able to send an exit order.


On 6/2/2020 6:08 AM, Susan Smith wrote:
Hi all, can anyone please kindly advise is that highly recommended to include "watchdog" function in every program?
I need some advice on whether I should include watchdog in my program.

I recently wrote a program to automatically buy and sell a certain securities based on their price (i.e. buy when price > y and sell when price < z)
The program run around the clock.

I'm new to Python and as I browse through topic history in this group I saw that many people talking about using "watchdog".
I tried to do some research on it but so far I only know it can print some alerts if there is any connection issue (I'm sure it's much more than that).

When I was trading manually with TWS, the connectivity issue that I realized are:
1) daily mandatory restart of TWS (I have set a specific time for this and I make sure I'm in front of the computer on that time to relogin so it's ok with it)
2) internet connectivity issue (sometimes it will pop up a window saying "attempting to reconnect" probably due to internet issue, usually after a few minutes the tws will be running again, as I observed the api is still connected with tws even it has connectivity issue in between, so it seems should be no issue for my program to keep running in this case?)

My program is not aimed for downloading historical data, just for sending orders if certain price criteria is met.

In my case, is the watchdog function necessary for me?
Usually what is the reason for people using watchdog in ib api?

Thanks so much for your advice in advance!



Data delay!

 

Hello,

I was surprised, to say the least, to discover that I'm getting delayed data in API (1 hour to be exact). I'm doing the following:?

? ? private static Contract getMicroESFuturesContract() {
? ? ? ? Contract contract = new Contract();
? ? ? ? contract.localSymbol("MESM0");
? ? ? ? contract.secType("FUT");
? ? ? ? contract.currency("USD");
? ? ? ? contract.exchange("GLOBEX");
? ? ? ? return contract;
? ? }

? ? public void subscribe(int tickerId, Contract contract, String period,
? ? ? ? ? ? ? ? ? ? ? ? ? boolean reqRealTimeBars, boolean reqTickByTickData, boolean reqMarketDepth, boolean reqHistoricalData) {
? ? ? ? if (reqRealTimeBars) socket.reqRealTimeBars(tickerId, contract, 5, "MIDPOINT", false, null);
? ? ? ? if (reqTickByTickData) {
? ? ? ? ? ? socket.reqTickByTickData(tickerId, contract, "AllLast", 0, false);
? ? ? ? ? ? socket.reqTickByTickData(tickerId + 1, contract, "BidAsk", 0, false);
? ? ? ? }
? ? ? ? if (reqMarketDepth) {
? ? ? ? ? ? socket.reqMktDepth(tickerId, contract, 8, true, null);
? ? ? ? }
? ? ? ? if (reqHistoricalData) {
? ? ? ? ? ? //socket.reqHistoricalData(tickerId, contract, "", period, "1 day", "TRADES", 0, 1, false, null);
? ? ? ? ? ? //int tickerId, Contract contract, String endDateTime, String durationStr, String barSizeSetting, String whatToShow, int useRTH, int formatDate, boolean keepUpToDate, List<TagValue> chartOptions
? ? ? ? ? ? socket.reqHistoricalData(tickerId, contract, "", period, "5 secs", "BID_ASK", 0, 1, false, null);
? ? ? ? }
? ? ? ? socket.reqMktData(tickerId, contract, "233", false, false, null); //RTVolume
? ? ? ? socket.reqPositions();
? ? ? ? socket.reqIds(-1);
? ? }

And then call:?
?
subscribe(Configuration.MES_CONTRACT_ID, getMicroESFuturesContract(), LOOKBACK_UNITS_PERIOD + " S",
? ? ? ? ? ? ? ? true, true, true, true);

Any ideas why I'm getting delayed data?


Re: Is it highly recommended to include "watchdog" function in every program?

Nick
 

¿ªÔÆÌåÓý

You can't assume that everything will work all the time. What happens if you have an open position but your program stops working?

You need to defend against outages. The extent you go to will depend on your circumstances and needs.

If you only use bracket orders then it's just lost opportunity cost. If you manage open positions then it could get costly to not be able to send an exit order.


On 6/2/2020 6:08 AM, Susan Smith wrote:

Hi all, can anyone please kindly advise is that highly recommended to include "watchdog" function in every program?
I need some advice on whether I should include watchdog in my program.

I recently wrote a program to automatically buy and sell a certain securities based on their price (i.e. buy when price > y and sell when price < z)
The program run around the clock.

I'm new to Python and as I browse through topic history in this group I saw that many people talking about using "watchdog".
I tried to do some research on it but so far I only know it can print some alerts if there is any connection issue (I'm sure it's much more than that).

When I was trading manually with TWS, the connectivity issue that I realized are:
1) daily mandatory restart of TWS (I have set a specific time for this and I make sure I'm in front of the computer on that time to relogin so it's ok with it)
2) internet connectivity issue (sometimes it will pop up a window saying "attempting to reconnect" probably due to internet issue, usually after a few minutes the tws will be running again, as I observed the api is still connected with tws even it has connectivity issue in between, so it seems should be no issue for my program to keep running in this case?)

My program is not aimed for downloading historical data, just for sending orders if certain price criteria is met.

In my case, is the watchdog function necessary for me?
Usually what is the reason for people using watchdog in ib api?

Thanks so much for your advice in advance!



Re: reqRealTimeBars returns data only for one stock but error for other stocks

 

Finally I got it working but I am not sure if this is correct way.

If I added 'TATASTEEL' stock in TWS watchlist and view its charts etc and then run the same script again. its works.

May be bug in TWS


Re: Calendar events

 

Ah great - thanks a lot!


Re: reqHistoricalTIcks - request more than 1000 ticks at some point in time

 

Yes document said that would return more than 1000 ticks to finish full second.? I haven¡¯t verify this but I think in lat March SPY could be more than 1000 ticks per seconds.


Is it highly recommended to include "watchdog" function in every program?

 

Hi all, can anyone please kindly advise is that highly recommended to include "watchdog" function in every program?
I need some advice on whether I should include watchdog in my program.

I recently wrote a program to automatically buy and sell a certain securities based on their price (i.e. buy when price > y and sell when price < z)
The program run around the clock.

I'm new to Python and as I browse through topic history in this group I saw that many people talking about using "watchdog".
I tried to do some research on it but so far I only know it can print some alerts if there is any connection issue (I'm sure it's much more than that).

When I was trading manually with TWS, the connectivity issue that I realized are:
1) daily mandatory restart of TWS (I have set a specific time for this and I make sure I'm in front of the computer on that time to relogin so it's ok with it)
2) internet connectivity issue (sometimes it will pop up a window saying "attempting to reconnect" probably due to internet issue, usually after a few minutes the tws will be running again, as I observed the api is still connected with tws even it has connectivity issue in between, so it seems should be no issue for my program to keep running in this case?)

My program is not aimed for downloading historical data, just for sending orders if certain price criteria is met.

In my case, is the watchdog function necessary for me?
Usually what is the reason for people using watchdog in ib api?

Thanks so much for your advice in advance!


reqHistoricalTIcks - request more than 1000 ticks at some point in time

 

Hi all,

I download historical ticks for back testing. So far, the ticks data i got back from the API max out at less than 700 at any particular second. However, what happens if, let's say at market open, 9:30:00, there are more than 2500 ticks at that second. Is it possible to get all 2500 ticks back from the API??

The API allows max 1000 ticks per request and also IB's tick data timestamp resolution is to the second, not the milliseond. I could get 1000 ticks back with one API call, but how can i retrieve all 2500 ticks for that second??I can't change the start time or the end time here as it is at the same second.

If it helps, I always set the request size to 1000. I send requests recursively by updating the start time with the latest from the ticks of the response. i did notice that sometimes the API returns more than 1000 ticks back, like 1017, 1004, etc. But no more than 1030 I'd say.

Any help/pointers is greatly appreciated.

Thanks
LC


Match tickerId (or reqId) to contract after a bust event

 

In my application 5 second real time bars are requested by

?

Application.controller().reqRealTimeBars(contract, WhatToShow.TRADES, rthOnly, handler);

?

where the ¡°handler¡± class implements IRealTimeBarHandler. I have about 10 data subscriptions running at the same time. After a bust event TWS sends an error message like:?

?

10001234 10225 Bust event occurred, current subscription is deactivated¡­

?

The second number is the error code and the first number is the tickerId (or reqId?). However, I do not know which contract (i.e., which symbol) this tickerId refers to and which data subscription I actually need to restart. The id number is assigned in the background somehow. Is there a way to match a tickerId to the associated contract? (code is in Java, API version 9.72.18) Thanks.

?


Re: Calendar events

alpha
 

Yes, you can get this data with a Wall Street Horizon subscript (available under User Settings > Research Subscriptions). I am a non-professional and I have a subscription ($5/mo).

If you're using the Python (IB-insync) API, the code to get this data looks as follows:

ib.reqFundamentalData(contract, 'CalendarReport')

This will return XML data which is pretty straightforward to parse.


Re: retrieve out of regular hours historical data for NYSE tickers

alpha
 

Thanks! I didn't know this option was there :)


reqRealTimeBars returns data only for one stock but error for other stocks

 

Hello,

I am just getting started with IB Python API. I am just playing around to understand how each function works. I have got following function working properly.
reqContractDetails? reqMktData? reqMktDepth? reqHistoricalData?

However I have run into a strange issue while working with reqRealTimeBars.

reqRealTimeBars returns 5 sec OHLC data for one stock ( RELIANCE for NSE) however It does not return any data for any other stocks such as "TATASTEEL".
Note: reqHistoricalData and other functions returns data for both stocks issue is only which reqRealTimeBars

Code


from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract

import threading
import time
import datetime

class IBapi(EWrapper, EClient):
??? def __init__(self):
??????? EClient.__init__(self, self)
??? def historicalData(self, reqId, bar):
??????? print(f'Time: {bar}')
??????? # print(f'Time: {bar.date} Close: {bar.close}')
??????? app.data.append([bar.date, bar.open, bar.high, bar.low, bar.close, bar.volume,bar.average, bar.barCount])

???
??? def realtimeBar(self, reqId, time:int, open_: float, high: float, low: float, close: float,volume: int, wap: float, count: int):
??????? print("Output realtimeBar-->",contract.symbol, reqId,datetime.datetime.fromtimestamp(time).strftime('%c'),open_,high,low,close,volume,wap,count)
???????
def run_loop():
??? app.run()

app = IBapi()
app.connect('127.0.0.1', 7496, 4)

#Start the socket in a thread
api_thread = threading.Thread(target=run_loop, daemon=True)
api_thread.start()

time.sleep(1) #Sleep interval to allow time for connection to server

contract = Contract()
# contract.symbol = "RELIANCE"
contract.symbol = "TATASTEEL"
contract.secType = "STK"
contract.currency = "INR"
contract.exchange = "SMART"
contract.primaryExchange = "NSE"

# app.data = [] #Initialize variable to store candle


print("*** called before ***")

app.reqRealTimeBars(111,contract, 5, "TRADES", True, [])

Output for RELIANCE

ERROR -1 2104 Market data farm connection is OK:hfarm
ERROR -1 2104 Market data farm connection is OK:cashfarm
ERROR -1 2104 Market data farm connection is OK:usfarm
ERROR -1 2106 HMDS data farm connection is OK:hkhmds
ERROR -1 2106 HMDS data farm connection is OK:ushmds
ERROR -1 2158 Sec-def data farm connection is OK:secdefhk
*** called before ***
Output realtimeBar--> RELIANCE 111 Mon Jun? 1 15:17:30 2020 1519.85 1519.9 1519.35 1519.65 78 1519.6 5
Output realtimeBar--> RELIANCE 111 Mon Jun? 1 15:17:35 2020 1519.7 1519.9 1519.65 1519.9 358 1519.8 5
Output realtimeBar--> RELIANCE 111 Mon Jun? 1 15:17:40 2020 1519.55 1520.5 1519.55 1519.8 154 1520.15 5

Output for any other stock


ERROR -1 2104 Market data farm connection is OK:hfarm
ERROR -1 2104 Market data farm connection is OK:cashfarm
ERROR -1 2104 Market data farm connection is OK:usfarm
ERROR -1 2106 HMDS data farm connection is OK:hkhmds
ERROR -1 2106 HMDS data farm connection is OK:ushmds
ERROR -1 2158 Sec-def data farm connection is OK:secdefhk
*** called before ***
ERROR 111 420 Invalid Real-time Query:No data of type DayChart is available for the exchange 'SMART' and the security type 'Stock'' and '5 secs'

Anyone faced issue like this strange behavior ? OR may be I am missing some minute detail here ?