07 Mar 2022 | Cryptocurrency-Portfolio-Performance-Tracking
Cryptocurrency is still young. It’s hard to think of it that way when you’ve
been in the ecosystem for many years, but when you start to look at the
capabilities of modern exchanges compared to modern trading platforms like TD
Ameritrade, these differences become obvious.
I was originally tempted to start out with the usual, “this is not investment
advice” spiel, but this actually is investment advice:
If you do not know whether you are making or losing money, there is a problem.
Although relatively sophisticated for its short lifespan, looking at a popular
exchange like Coinbase reveals that you actually have very little useful
information about your assets.
Most importantly, what’s my bottom line?
It’s great that PoopCoin is up 5% today, but if I’m $1,000 in the hole on my
investment, that’s a relevant piece of information to have.
Aside
Your reply to this may be, “Well you shouldn’t be storing your assets on an
exchange,” which is very true. You shouldn’t be. However, two things: a) if you
think that the majority of people aren’t doing this anyway, you are
disillusioned my friend, and b) even if you don’t do that, you still need a way
to get this information as the wallet is not going to tell you either.
TD Ameritrade (not without its own issues, of course) shows a wealth of relevant
information like net portfolio gain - both in percentage and in USD - as well as
daily gain/loss information broken down per asset. This kind of information is
invaluable for making informed decisions. What you choose to actually do with
that information is investment advice, but I’m just advocating for having it
available.
Realizing how vitally important this information is, I threw together a
prototype relatively quickly to calculate this for me in real time. It pains me
to present a shell script (essentially a polished turd) but I had no intention
of sharing this at the time and it was quick and easy for prototyping. If there
was enough demand for such a utility (and there should be) I would consider
rewriting it, but I am also very busy so no promises.
Feature Wish List
Net portfolio gain/loss in USD
Percentage portfolio gain/loss
Net gain/loss in USD per asset
Percentage of gain/loss per asset
Daily net portfolio gain/loss in USD
Daily percentage of portfolio gain/loss
Daily Net gain/loss in USD per asset
Daily Percentage of gain/loss per asset
“Cost per share” (not sure how TD calculates this, really nice though)
Clearly this is not a comprehensive investment tool at this time, but it is a
step in the right direction.
Source
Obviously, these numbers are all doctored and do not represent my actual
portfolio. This is also not an endorsement for any cryptocurrency listed here -
invest at your own risk.
For price data, we need to query a reliable source that has a lot of great data
we can leverage. I chose CoinMarketCap, but unfortunately the API requires an
account and limits you to some X amount of queries per day without a paid
account. Fortunately for me, without spastically checking the market every 10
minutes it’s almost impossible to exceed the allotted 300 requests or whatever.
So you have to plop an API token in there from your CoinMarketCap account.
Can We Do Better?
The main issue with this, of course, is that bash can be jank. It’s not always
jank, but it’s hard to test and can very often end up essentially held together
by duct tape and bailing wire. So while this is great for prototyping and creating
a proof-of-concept, if we are going to create a robust program we should really
consider using a programing language with a solid unit testing framework.
Enter the rust prototype.
So using serde I created some nested structs in the same format as the JSON response I was
getting back from CMC. This actually works really well, and makes me feel a lot better
about what I’m writing.
The Rabbit Hole
After this was working, I went down a rabbit hole I should have gone down a decade ago:
Creating a Terminal UI
This is pretty barebones, but I’d be lying if I said I didn’t have fun making this.
If I decide to continue on this path, the next step here is to create a flow where users
can easily add their assets. Maybe by pressing ‘A’ or something, and having a help menu
on-screen. Then promps will pop up and ask users for the currency ticker symbol, their
current account balance, and most importantly, the cost.
Figuring out the cost might be tricky for some, but typically exchanges store that data
in an exportable format you can parse through. It’s not the funnest activity you could
spend your time doing, but it will give you a clear picture on what your actual gains
and losses are on your cryptocurrency investments.