Python Script to get Historical H.E prices longer than a year to use for taxes and other data analysis

in #splinerlands11 days ago

Hi everyone I have been reconstructing my taxes for multiple years going back to 2019 and have had a hell of a time figuring out how to get price data and since no one would give me a script I finally figured out one that worked using chat gpt after putting in a few items like the hive engine and hive nodes and apis to extract from as well as having it write the script to overcome the limit on returning data so this script is set to go from 3/20/2020 to 10/15/2025 and pulls the voucher prices from hive engines data as these and other SPL and GLG tokens are a nightmare to get unlike SPS and DEC etc which are traded elsewhere.

I figured I would post my script that worked for me and you can use this to get any Hive Engine traded tokens historical trading prices by day so no one else will need to spend as much time or pay anyone for a script as I feel like it was designed that way in order to make it very hard to extract data for people who have a lot of activity so people can make money off of simple scripts that they already have. See below for the script that you need to get vouchers price history in HIVE which would need to be converted to USD or what ever your currency is but that is easy once you have in excel with a VLOOKUP as you can look up the daily HIVE closing price and multiply it by in this script the vouchers hive price on the dates which will give you the daily voucher price in USD and then you can apply that to your SPL spreadsheets downloaded from the website as well as the GLX spread sheets from the glx reports page where you get a similar spreadsheet to SPL but that one is not shown or obvious so if anyone needs it I have the link just message me and you can click it then type your accounts and it pulls all of your APP activity in GLG or you can ask Aggroed which is where I got it from. If you used many accounts like I did and hive engine you can use the tribal dex tax tool to easily get your yearly data but there are many issues with it like it doesn't track basis from the app to he so if you earned vouchers say at 10 per voucher but transfer them to he at 4 per voucher your missing a deduction of 6 per voucher as the tribal dex tax tool does not account for that difference so make sure you are manually adjusting your basis or you will lose a lot of deduction as most people lost out on value if they bought in 2022 or late 2021 during the peak and held as prices tanked.

Also anyone new to the game and not thinking about taxes make sure you keep track or have a way to get the records as the SPL spread sheets do not provide you with the info needed nor does the HE tax tool without adjustments and you also need your hive main net activity. There are people who will help you do it but it costs a ton of money and there is no incentive to make it easy for people. Once I am done catching up on my taxes I am going to be hopefully developing a tool that will give people full tax reports that account for the short comings of the current confusing and possible errors especially if you do not know accounting or taxes and provide it as a much cheaper subscription model that charges based on activity probably having a low medium and high activity tier monthly pricing or annual pricing which will be very cheap compared to what you just even have to spend on Hive Engine reports that are only 1/5 of the picture and need a lot of adjustments to make them correct especially if you have like 13 accounts or more like many do.

If you paste this in a .txt file then change.txt to.py you can run the program and generate a nice excel sheet that looks like this with any HE token and get the prices in hive daily.

import csv
import time
import requests
from datetime import datetime, timedelta

-----------------------------------

CONFIGURATION

-----------------------------------

SYMBOL = "VOUCHER"
HISTORY_API = "https://history.hive-engine.com" # archival node with full range
OUTFILE = f"voucher_history_hiveonly_2021_2025.csv"

Date range: 2021-10-18 → 2025-10-15

start_date = datetime(2021, 10, 18)
end_date = datetime(2025, 10, 15)
chunk_days = 180 # fetch ~6 months per API call

-----------------------------------

FETCH FUNCTION

-----------------------------------

def get_history_chunk(start: datetime, end: datetime):
"""Fetch one date chunk of Hive Engine market history."""
url = f"{HISTORY_API}/marketHistory"
params = {
"symbol": SYMBOL,
"timestampStart": int(time.mktime(start.timetuple())),
"timestampEnd": int(time.mktime(end.timetuple()))
}
try:
r = requests.get(url, params=params, timeout=120)
r.raise_for_status()
data = r.json()
print(f"✅ {start.date()} → {end.date()} | {len(data)} records")
return data
except Exception as e:
print(f"⚠️ Error on {start.date()} → {end.date()}: {e}")
return []

-----------------------------------

MAIN DOWNLOAD LOOP

-----------------------------------

all_data = []
current = start_date

print(f"Fetching {SYMBOL} market history from {start_date.date()} to {end_date.date()}...")

while current < end_date:
chunk_end = min(current + timedelta(days=chunk_days), end_date)
part = get_history_chunk(current, chunk_end)
all_data.extend(part)
current = chunk_end
time.sleep(2) # polite delay to avoid rate limits

print(f"\nTotal combined records: {len(all_data)}")

-----------------------------------

PROCESS + EXPORT

-----------------------------------

rows = []
for d in all_data:
ts = d.get("timestamp") or d.get("date") or d.get("_id")
if isinstance(ts, (int, float)):
date_utc = time.strftime("%Y-%m-%d", time.gmtime(int(ts)))
elif isinstance(ts, str):
date_utc = ts[:10]
else:
continue

high = float(d.get("highestPrice", 0))
low = float(d.get("lowestPrice", 0))
volume_token = float(d.get("volumeToken", 0))
volume_hive = float(d.get("volumeHive") or d.get("volumeSteem") or 0)
avg_price = (high + low) / 2 if high and low else 0

rows.append({
    "date_utc": date_utc,
    "symbol": SYMBOL,
    "high_hive": high,
    "low_hive": low,
    "avg_hive": avg_price,
    "volume_token": volume_token,
    "volume_hive": volume_hive
})

rows.sort(key=lambda r: r["date_utc"])

with open(OUTFILE, "w", newline="", encoding="utf-8") as f:
writer = csv.DictWriter(
f,
fieldnames=["date_utc", "symbol", "high_hive", "low_hive", "avg_hive", "volume_token", "volume_hive"]
)
writer.writeheader()
writer.writerows(rows)

print(f"\n✅ Wrote {len(rows)} rows to {OUTFILE}")
print(f"📁 Saved file: {OUTFILE}")

image.png