New to the Defi space and I may be overcomplicating this...
I'm trying to find a programmatic way to calculate the total p&l for ERC20 tokens I've staked. I understand that in general to get the current value of my assets staked in a token the calculation would be: [token_current_price
* num_of_tokens
]. (And then for net profit in ETH, go through my previous transactions and keep subtracting (cost_of_eth_at_transaction_time
* num_tokens_staked
)).
What is confusing to me though, is that the value of ETH itself fluctuates, which makes it nearly impossible to calculate my real return in USD (unless I'm misunderstanding)? What if the ETH used to buy the tokens was valued lowered when initially traded (USD -> ETH). Wouldn't this mean that instead of using cost_of_eth_at_transaction_time
, I would have to use cost_of_eth_at_time_eth_was_traded_for_usd
?
Is there an API that abstracts this information, where I can provide my address and see how much I've earned or lost in ETH or USD?