Sample app: Bitcoin Watcher

by Marcelo Sarquis
November 16, 2018

Hi there. On this post, I have created a sample iOS app that will fetch the current exchange rate of Bitcoin/EUR. Here are the detailed task instructions:

Task

Task

Create an iOS app with a companion Watch app that will fetch the current exchange rate of Bitcoin/EUR (suggested resources are provided below, however, you may decide to use any other) and display the data in a simple table view (on each the phone and the watch).

Must have

  • Fetch the historical data for the last 2 weeks up to today (daily data, 1 value per day).
  • Show the data in a simple table view on the phone and on the watch (no need for fancy UI/UX here, just a plain UITableView on iOS, will do).

Nice to have (optional):

  • Continuously update the current price for today.
  • Cache the latest data to be shown upon app start while fetching new values.
  • Ability to select another cryptocurrency.

The extra mile (purely optional):

  • Create a Watch glance showing the most recent Bitcoin value (the today value).

Documentation

Please produce a short(!!!) documentation listing the tools you used and explaining how you approached the task. Please also provide a copy of the complete project.

API

CoinDesk Bitcoin Price Index API

CoinDesk provides a simple API to make its Bitcoin Price Index (BPI) data programmatically available to others. You are free to use this API to include our data in any application or website as you see fit, as long as each page or app that uses it includes the text “Powered by CoinDesk”, linking to our price page. CoinDesk data is made available through a number of HTTP resources, and data is returned in JSON format. Please do not abuse our service.

BPI real-time data

On the CoinDesk website, we publish the BPI in USD, EUR, and GBP, calculated every minute, based on criteria as discussed on the CoinDesk BPI page. This same data can be retrieved using the endpoint:
https://api.coindesk.com/v1/bpi/currentprice.json

{"time":{"updated":"Sep 18, 2013 17:27:00 UTC","updatedISO":"2013-09-18T17:27:00+00:00"},"disclaimer":"This data was produced from the CoinDesk Bitcoin Price Index. Non-USD currency data converted using hourly conversion rate from openexchangerates.org","bpi":{"USD":{"code":"USD","symbol":"$","rate":"126.5235","description":"United States Dollar","rate_float":126.5235},"GBP":{"code":"GBP","symbol":"£","rate":"79.2495","description":"British Pound Sterling","rate_float":79.2495},"EUR":{"code":"EUR","symbol":"€","rate":"94.7398","description":"Euro","rate_float":94.7398}}}

Historical BPI data

We offer historical data from our Bitcoin Price Index through the following endpoint:
https://api.coindesk.com/v1/bpi/historical/close.json

{"bpi":{"2013-09-01":128.2597,"2013-09-02":127.3648,"2013-09-03":127.5915,"2013-09-04":120.5738,"2013-09-05":120.5333},"disclaimer":"This data was produced from the CoinDesk Bitcoin Price Index. BPI value data returned as USD.","time":{"updated":"Sep 6, 2013 00:03:00 UTC","updatedISO":"2013-09-06T00:03:00+00:00"}}

Documentation

The application is developed using MVC (model-view-controller) architecture. The app has basically one main Controller: HomeTableViewController. Both, the app and the watch app fetch the historical data for the last 2 weeks up to today, showing one value per day. In both apps, the data is showed in a simple table view.

Upon opening the apps, phone and watch, continuously update the current price for today. I have used two types of caching data: using NSUserDefaults, saving which currency the user have selected, and CoreData, storing the last displayed value of the current value, meaning that value is displayed the next time the app starts while new data is being processed. There is the ability to select three different currencies.

On the Watch app, I have created a Complication that shows the current exchange rate of Bitcoin/EUR.

I have developed the apps using Storyboard.

Tools in place

  • MVC (Model-View-Controller) architecture
  • Storyboard implementation
  • Delegate (one-to-one relationship)
  • Notifications (one-to-many relationship)
  • HTTPS POST requests to the server
  • API handler
  • Custom classes and objects
  • Layout constraint
  • Gesture recognizer
  • Completion blocks
  • Core Data

Points to pay attention to

  • Increment Bundle Version (Build Phases -> Run script)
  • Localizable string to multiple languages
  • Extension helpers

You can download the source code of that project here: https://github.com/marcelosarquis/ios-bitcoin-watcher

If you would have any idea of an app and don’t know how to start, send us a msg or stop by for a cup of coffee so we can go through the steps of developing your app.

Thank you for the time and see you in the next post!

Cheers!

Recent posts