Need help to create a good energy cost calculation with dynamic energy prices

Here is a link to an approach I have used to quantify the savings from both my battery and solar, my prices change every 5 minutes so I needed a very dynamic solution.