MATLAB Answers

Program stuck in a while loop

10 views (last 30 days)
Or Shem Tov
Or Shem Tov on 15 May 2020
I am using MATLAB to connect with the MONEY.NET API, they have a function to import financial news, it looks like this:
symbols = ["AAPL" "MSFT" "TSLA"]
N = numel(symbols)
for i = 1:N
connection = moneynet(username,pwd);
news = news(connection,'Number',5,'Symbol',symbol(i));
The thing is... I am actually scanning a lot more than 3 symbols, the list is over 1400 and sometimes one of the symbols gets removed from MONEY.NET or something so the news function gets stuck in a while loop, this just keeps running infinitely:
%Send the request
emptyFlag = true;
while emptyFlag
newsResponse = cell(this.Connection.getNewsResponse());
if strcmp(newsResponse,moneynet.Disconnected)
emptyFlag = numel(newsResponse) == 1 && strcmp(newsResponse{1,1},moneynet.NoResponse);
So I'm having trouble with that because:
1) It's not a function I have written or have control of
2) It runs perfectly except for certain symbols in the loop
3) The loop gets stuck inside the news function if the symbol is not good
So I have to manually go over 1400 symbols and check which one gets the code stuck, I am sure there is a way to either check the symbols or have the program break out whenever it gets stuck (let's say if a loop takes over 5-10 seconds then continue to the next iteration or something)
I will be very thankful for any help here!


Sign in to comment.

Answers (0)