Programming a Crypto Tracking Bot
programming·@makerhacks·
0.000 HBDProgramming a Crypto Tracking Bot
 [In my earlier post I wrote about my annoying but fun Bitcoin price bot](https://steemit.com/cryptocurrency/@makerhacks/i-made-a-robot-read-out-the-bitcoin-price-and-i-made-a-terrible-mistake). After my video appeared a couple of people have asked me how I did it. First of all, it was a bit of fun - ideally you wouldn't have the price read out constantly because that is a good way to enrage yourself rather than inform yourself :) Second, for this I used EZ-Robots platform, because the eventual plan is to build a full astromech droid. Your computer, Raspberry Pi, or even ESP8266 are entirely sufficient for this purpose. ## Bitcoin API There are many, many APIs out there tracking crypto prices. I wanted the one I used to be ... * Free * Public, not protected * Relatively up to date and accurate * Available * Responsive * Easy Ideally I didn't want to have to install libraries either. Folks think that makes things easier, but for me the easiest thing is to have access to a URL and get JSON back, especially as the EZ-Robot scripting environment was unlikely to be supported. ## Talking to APIs As mentioned above, I like to GET a URL and get JSON back. What does this mean? A GET is very much like clicking a link or entering a web address in your browser. You are asking your machine to go fetch that location and return the text of whatever it finds. The text we get back ends up formatted in a data format so that the information can be easily interpreted. Some use XML, but I prefer JSON. This is what the data from our chosen API, Coindesk, looks like when supplied the information that we want USD data in JSON format.  ## Extracting the Price If you are working in a modern development environment then your tool of choice might well just slurp in JSON and understand what all the delimiters are for. You might alternatively have easy access to libraries that take the heavy lifting for you. With EZ-Robot, it appears in the forums people have successfully processed JSON (the platform is based off the Microsoft .NET framework), but it seemed too much effort to go digging through how to do that when I just wanted the price out of this returned text string. So I did a hacky string manipulation instead. Seeing as the data is always returned in the same format, I look for a certain : character, and then a period. The number before the period is the digits I am looking for. After that, I simply asked my robot to say the number out loud. In the real world use of this you would want to 1. display the number 1. make it only read out loud if the number was significantly different 1. not check and read out every second! ## Next steps The implementation was annoying but the idea of updating myself when the BTC rises or falls was surprisingly useful to me, so I will create a new non-annoying version, with more utility - check back! **What do you think would be useful? Please let me know in the comments**