the esi market history path allows you to get the historical prices of an item, for a region, for a year.
this is the result of calling it for tritanium(id=34) in TheForge(id=10000002)
this is one of the last entry :
3466 new orders were added on the 2020-04-12, 7108686963 unit were sold, at an average price of 9.44, a max price of 9.61, and a low price of 8.99.
That means on this day, 7108686963×9.44 was spent for tritanium : that the value of the tritanium paid
We are the 2020-04-14 but the day is not done, so you want all the orders from 2020-04-13 and back to 2020-03-14 in order to get the orders.
Then you need to sum up the quantities and the total isk spent for each of those days ; you divide the later by the former, and it gives you the average price of tritanium for the last 30 days before current one.
If you are willing to evaluate the SELL value or BUY value, you need to estimate it using the min and max value. eg if for a day, the average is 9, min is 5, and max is 10, it means we can estimate that (9-5) out of (10-5) of the orders were to sell order. This is not exact, actually it can be kind of very far and can be manipulated, just the same as average value can.
If you want to remove errors and manipulation, I suggest you to remove a few percentile of the highest/lowest day values before making the average. eg you can remove the 5 days out of 30 that have the highest average, and the 5 out of 30 that have the lowest average, THEN use the method I described before on the remaining 20 orders.