Update: There’s a really cool app called blockfolio that tracks all your profits and losses. It’s really useful and does everything I was trying to do with this project. However, this project could be handy later on since the Bittrex data will available to me programatically to make automated trade decisions if I should choose to. This was a fun project but really not suited for PHP when there are already tons of libraries for Node.js. Apparently there is a blockfolio API but I haven’t tried it. Anyways, I hope you enjoy the article anyways, maybe it will give you inspiration for a project! 🙂
Part of the problem with trading cryptocurrency is that it’s so volatile. I had trouble figuring out if I was making any money or not. Let me illustrate the problem.
On Bittrex there are 2 major exchanges, BTC and ETH. Some tokens are only available if you buy with BTC, or ETH.
Let’s say you bought 240 FUN tokens at 0.00004912 ETH per unit, for a cost of 0.01287766 ETH. What is the cost in USD? It’s easy to lookup, right? Ok, but what about in 2 months when you want to sell your FUN tokens? Will you remember what the ETH / USD exchange rate was that day? You could do it all manually, old school style. In fact, you should do it manually if you want accuracy because prices fluctuate so much hourly.
In Bittrex your total estimated balance is shown at the top of the wallets page in BTC and USD. The problem occurs when the price of Ether or Bitcoin fluctuates. If you do your profit takeaway calculations using ETH or BTC as the base, it’s hard to know right away which of your holdings has increased in value.
I wanted a program to calculate the trade commissions and let me know when a token was ready to sell (more than 0 profit after commissions). At first, I would see the total USD value of my account go up, but individual value of tokens would be down. (Because ETH was going up). I found this to be really inconvenient when trying to make trade decisions. I needed everything in USD, all the time. I want to know how much I paid for a token in USD, and how much I can sell it for after commissions.
Example from my program:
Bought ETH-FUN 241.69791948 @ 0.00005327
Cost: 0.01287766 ETH ($3.822 USD)
Sell @0.00004912 for profit: $-0.34 USD
Here’s an overview of the program and how it works:
1) Retrieve Bittrex balances
2) For each balance, go through the order history and get the dates of purchase
3) Get ETH or BTC value in USD from day of purchase using historical data from api.cryptocompare.com
4) Get current ETH or BTC value in USD from api.coinmarketcap.com
5) Get last price for token from Bittrex API
6) Calculate trade commissions and profit by substracting purchase and commissions from sale price.
7) Display potential profitable trades in green, others in red
Bought ETH-ZEC 0.0694223 @ 0.8029997500
Cost: 0.05574609 ETH ()($16.3531155015 USD)
Sell @0.9100000000 for profit: $2.42 USD