ERROR: Your request failed with error "No Data!"

Arindam G. shared this problem 4 years ago
Solved

Hi,


The error in subject line comes from hist api when no data is available for the symbol requested. Two points on this message.

1. This is a print message from get_n_historic_bars, get_hist_bar_data, get_hist_eod_data, etc functions inside TD.py code of the truedata_ws library. Instead of a print, can this be 'raised' so that client python code can catch it in a try except block? Otherwise this print message comes in the main thread where more emergency print statements may be there.

2. This message comes when there is no data for the symbol. Can it be changed to a warning or info message when symbol is correct but data is absent. And an error message if symbol is incorrect. If symbol is correct, should the api not send back the last ohlc data which will be o=h=l=c as we see in broker charts?


Thanks

Arindam

Replies (3)

photo
1

From the Python Library, this is the return you are getting when you have asked for some symbol (which is correct) for some time period where there is no data for that symbol during the requested time period.


ERROR: Your request failed with error "No Data!" 

Empty DataFrame
Columns: []
Index: []


So here you are being returned an Empty list.


What you can do is check for the length of the return. This will help you process the 'No Data' return efficiently and without breaking any code.

photo
1

I am referring to the below code from the function get_n_historic_bars(self, contract, end_time, no_of_bars, bar_size)

if json_response['success']:

## do useful stuff

else:

print(f'{Style.BRIGHT}{Fore.RED}ERROR: Your request failed with error "{json_response["message"]}"{Style.RESET_ALL}')

return []


While the return [] does the job of not breaking the code, the print message shows up in the main thread of my code. I want to log these messages and not see them in main thread as this is harmless event. I want to catch this message in try/catch block of python and log it if I feel it is necessary.

photo
2

Should we remove this print statement 'Error....' ?

Will that help in any way ?

photo
1

I personally will like the print statement to be removed. As the empty return from the function call is telling me all I need to know.

photo
1

Ok ! That makes sense !

No commitments, but let us see what we can do best.

Will get back to you on this.

Thank you so much for your contribution !

photo
1

Thanks!

photo
photo
1

I do check for the the empty df and that is how my code works without breaking. I am pointing that the td library function also prints the error without raising an error or warning. Which results in messages in my main thread. I would rather have a try catch section to process this in my side than a print statement and empty df. I think that will be best practise coding anyway?

Above is about asthetics and non functional, purely technical.

However a functional question here will be, if the symbol is correct and there is no data, should it not return ohlc as same as last available close in the requested time frame?

photo
1

Functional Reply first:-

If you are asking for say candles from midnight to 6 am, there were no trades, how would the OHLC be formed and what time stamp would it have?

We cant send anything here.

If you want data for a specific time, you should be asking for it or sending a request which covers that time range.

photo
1

This error comes when i request for last 2 candles on 1min tf between 9:45 to 14:45. Mostly for illiquid options.

photo
1

I dont think sending you candles when there has been no trade would be the right thing to do.

No trade would make no candle. We should not be creating candles from nothing.

What do you / others think ?


If you have an idea give me an example of a candle during the above time period when there has been no trade in that option.

photo
1

That is a perfectly logical point of view from your side. I am just asking the question. However the broker platform charts do show dashes when no activity is there with o=h=l=c = ltp (comparing with broker chart as we are talking about ohlc). For reference, check the chart of RELIANCE 20 OCT 29 2200 CE in Fyers web. Highly illiquid as you would expect. From 11:30 onwards, the price shows as 125 with 0 volume as that was the ltp. Similarly check the 13:50 candle of RELIANCE 20 SEP 24 2200 CE. The broker platform can do this as they have all the data from start of day. However since I am fetching the last 2 candles in intraday, I cannot know that the ltp was 125.

Actually this is not a big deal for me. Just wanted to share this observation as it seems to not align with how I am used to see the charts. Even if you do end up sending ltp in the ohlc api for such scenarios, I should probably ignore the candles anyway due to 0 volume.

photo
1

Yes, this is a no issue but I respect your effort to explain it to us.

Personally, if you ask me, any chart which shows you a candle or a dash when there is no trade, then you should not be seeing that chart as it will give you wrong figures and would result in wrong indicators.

Also, O=H=L=C=LTP is absolutely fine and would create a dash, but provided there is an LTP ! Just pulling the LTP from the previous candle is wrong, because it means that you have actually created a trade within this candle, even when there was none.

If we do decide to do that, as listed above, then one could never differentiate between an actual trade which happened during this candle or was it a self generated one, which was pulled from the last trade which happened in a previous candle an hour ago.

photo
1

OK. Makes sense to me. Please do what is sensible to you.

photo
photo
1

... try / except

photo
1

About your try except point, we will explore.

But we do not want to break the code, when there is Nodata. Throwing an exception at you would break the code of the python library and would need to then be handled at the client end, everywhere.

We are trying to reduce the work at your end.

photo
1

OK. Understood. Thanks!

photo
Leave a Comment
 
Attach a file