Momentum-Trading-Example icon indicating copy to clipboard operation
Momentum-Trading-Example copied to clipboard

Infinite while loop

Open DanOKeefe opened this issue 5 years ago • 2 comments

If the condition in this while loop ever evaluates to True, it will always be True.

current_dt and market_open never change wthin the while loop, which means that since_market_open will never change within the while loop. This means

since_market_open.seconds // 60 <= 14

will never evaluate to False if it is intially True

https://github.com/alpacahq/Momentum-Trading-Example/blob/be4352838eebdd2d124eedd341e31fbae8774f3d/algo.py#L392-L394

I believe it should be:

while since_market_open.seconds // 60 <= 14:
        time.sleep(1)
        current_dt = datetime.today().astimezone(nyc)
        since_market_open = current_dt - market_open

DanOKeefe avatar Feb 18 '20 01:02 DanOKeefe

Hey Dan,

Found these changes although the code has been updated since.

Were you able to get it working? Mine seems to be just stuck on watching symbols...

nickvertucci avatar Jan 29 '21 15:01 nickvertucci

I think so too @DanOKeefe. I also think it should wait until market opens to check this 15 minutes elapsed logic so that the program does not run before 9am.

solaress1980 avatar Feb 09 '21 10:02 solaress1980