Hi,
I'm new to algotrading and quantconnect. To familiarize myself with the framework I wanted to try to implement a simple strategy I read about:
- buy SPY on the close of the last trading day of the month

- sell SPY on close on the first trading day of the month

I tried to implement it using the Algorithm Framework from the docs, but I am having some trouble.
(I am aware that this would be fairly simple to implement without the algorithm framework, by just setting 2 market orders using scheduling rules, but I would like to know how this could be implemented using the framework)
I attached my code, but I still have a lot of things that are not working:

- Currently the algorithm buys/sells at open (because I'm using Resolution.Daily I presume), how could I switch it to buying/selling on close?

- I am using `list(algorithm.DateRules.MonthEnd(symbol, 0).GetDates(algorithm.Time, algorithm.Time)):` to check if today is the last trading day, but it seems clumsy (and i'm not sure it would work in liveTrading). Is there a better way?

- Sometimes, buys or sells are spread across the opening of 2 days. Is it because market order on open have a different behaviour than during the day? How can I tell the algorithm to keep trying to buy in real time until everything is bought, instead of trying at the next day's open? (so instead of buying 387 shares on day 1 open, and 1 share on day 2 open, it buys 387 shares on day 1 open, and 1 share on day 1 open + 1 minute)

- for some reason an insight is not emitted on Aug 31 2020, which should be the last tradable day of the month (and the date doesn't seem to even be taken into account

Any other feedback on how I could improve the code would be really appreciated!