I need to learn to be able to get OHLC data in seconds from an API and A web-socket. Than I need to learn how a line of data coverts to a time frame calculation like lets say I want a 30 min 21 day moving average and a 60 min 21 moving average. I know how to do this individually but not from data in seconds and have them in the same data frame so I can look at a 30 and 60 in the same data frame on the same line. Then I want to learn how to run a simple machine learning method like linear regression and have a predict fucntion relative to the moving average or any calculation in a dynamic environment as it updates in real time. I need to understand how this all breaks down in a step by step and becomes usable in real time. Can you show me this in R ?