DEV Community

loading...

Building a stock ticker app

terrythreatt profile image Terry Threatt Updated on ・2 min read

Today, I submitted all the final requirements for my very first project in the Flatiron bootcamp. This project was a culmination of the modules we have learned in Ruby thus far including object orientation and building command-line interfaces. I chose to build a gem that will pull top stock gainers in the stock market real-time and I wanted to document parts of my journey.

Struggles

I sometimes feel that the hardest part of starting something new is just 'starting'. This happened to be the challenge on this project as well. My two biggest challenges came with creating my Ruby gem and pushing my ruby gem to https://rubygems.org/. I initially worked to construct my gem with 'gem build '. This method turned out to be light for my project since I'm a first-timer. I discovered a batteries-included method 'bundle gem ' and this got my project going smoothly.

Successes

I was able to have plenty of success building this gem and it has strengthened my understand of building in Ruby. I was able to pull real-time data from a 3rd party API and construct custom ruby objects that were controlled through my command-line. This helped me get an understanding of control-flow in the gem. I hope to continue learning in this capacity in the bootcamp to become a better programmer.

Tools of the trade

I often liken ruby methods as tools and as a developer, we need tools to accomplish our tasks. Choosing the right tools or methods is key to your success. One of my favorite methods is the '#each' method. It allows us to efficiently iterate through objects and it implicitly returns the original object. In my cli project, I used the '#each' method with a pattern called 'chaining' to use multiple methods. I paired the '#each' method with the '#with_index' method in a technique to dynamically create a list of each stock instance in my object. Specifically, I choose the '#with_index' because it allows for an optional argument to start your index. I chose '1' so my output could reflect (e.g. 1. PTON - Peloton - $26.01 - (-6.970)).

Check out my snippet here:

StocktickerCli::STOCK.all.each.with_index(1) do |s, i|
       puts "#{i}. #{s.ticker} - #{s.companyName} - $#{s.price} - #{s.changesPercentage}" 
       end 
...
end 
Enter fullscreen mode Exit fullscreen mode

Feel free to give it a try

Install gem with this command:

gem install stockticker_cli 
Enter fullscreen mode Exit fullscreen mode

Run gem with this command:

stockticker 
Enter fullscreen mode Exit fullscreen mode

Signup and enter your api key: https://fmpcloud.io/register

Welcome to the stock ticker cli app!

Please sign-up for a free account to use this app here: https://fmpcloud.io/register
Please enter your api key to continue.

<YOURAPIKEY>
Enter fullscreen mode Exit fullscreen mode

Thanks for reading!

Happy Coding

Terry Threatt

Discussion (0)

pic
Editor guide