Mean encoding in times series
The main rule when doing mean encoding is not using the test data. As long as you don't use the test data, you'll be mostly alright.
That being said, if you encode with all your training data you're probably going to see a drop of performance in the test set, which will not happen if you encode in a cross-validated fashion. So, the second option has some advantages with respect to the first one, but the first one is simpler. Still, I'd go for the second one.
In addition, you can add regularisation to the mean as done in the python package category-encoders, and it will be more robust to overfitting. This package allows for other options like leave one out encoding, that ensures that a sample's target is not used to compute the encoding for that sample.