Stock Price Checker Project with testable user stories - Guinea Pigs needed šŸ¹

This project will be part of our new Quality Assurance and Information Security section. It was designed by @JosephLivengood.

The goal is for campers to be able to build these projects step by step following user stories. This will make the projects less intimidating and more fun. Oh, and donā€™t worry - weā€™ll still have plenty of optional projects where we donā€™t provide you with any tests. And if youā€™ve previously built these projects, you donā€™t need to build them again.

If youā€™re interested in attempting this, please reply to the thread and let us know youā€™ve started it. The more people who want to build this, the better, as we can start gathering feedback.

Thanks, and happy coding!

User Stories:

  • Set the content security policies to only allow loading of scripts and css from your server.
  • I can GET /api/stock-prices with form data containing a Nasdaq stock ticker and recieve back an object stockData.
  • In stockData, I can see the stock(string, the ticker), price(decimal in string format), and likes(int).
  • I can also pass along field like as true(boolean) to have my like added to the stock(s). Only 1 like per ip should be accepted.
  • If I pass along 2 stocks, the return object will be an array with both stockā€™s info. Instead of likes, it will display rel_likes(the difference between the likes on both stocks) on both.
  • A good way to receive current price is the following external API(replacing ā€˜GOOGā€™ with your stock): https://finance.google.com/finance/info?q=NASDAQ%3AGOOG
  • All 5 functional tests are complete and passing.

Example usage:

/api/stock-prices?stock=goog
/api/stock-prices?stock=goog&like=true
/api/stock-prices?stock=goog&stock=msft
/api/stock-prices?stock=goog&stock=msft&like=true

Example return:

{"stockData":{"stock":"GOOG","price":"786.90","likes":1}}
{"stockData":[{"stock":"MSFT","price":"62.30","rel_likes":-1},{"stock":"GOOG","price":"786.90","rel_likes":1}]}

Completed passing project: https://gomix.com/#!/project/giant-chronometer
Boilerplate: https://gomix.com/#!/project/fcc-stock
Tester(ISQA_5-Nasdaq Stock Prices): https://pricey-hugger.gomix.me/

This is a smaller project but is very good experience as it involves 2-4 async processes per call making the camper use promises/callbacks before responding!

2 Likes

i am not getting the json response to display anything on the interface. Is this a bug?

Demo ==> https://brusbilis.com/freecodecamp/6-backEnd/stock/stock.html

Code ==> https://github.com/brusbilis/freeCodeCamp/tree/master/6-backEnd/stock

Backend is made with Golang instead of node

Security requirements are implemented in nginx adding to nginx conf

add_header Content-Security-Policy ā€œdefault-src ā€˜selfā€™ā€;

Sorry, but looks like Google dismissed the service and now that links give an error message. What service/api should we use to get the data?

3 Likes

I am working on that project too, I found this article who talks about alternatives, not sure yet if the tests will play nice with it:

I searched around a bit and I suggest this free API which has a plethora of information:

This is the direct link to the documentation about the most useful data for the project:

An example:
https://api.iextrading.com/1.0/stock/aapl/quote

2 Likes

I used Alphavantage.co, but itā€™s limited to 5 calls per minute.

I also tried using a node package - google-finance-data - which works, but is painfully slow.

Hereā€™s my working version - https://moor-skink.glitch.me - but this project does currently have several issues in its instructions and suggestions. The example doesnā€™t work at all.

I can also confirm that the glitch example is not working. I guess I will try and use the resources others have posted

2 Likes

Sending back the like in a GET is a bad practice. GET should be idempotent. It would probably be a better idea to do it in a PATCH.

Also if you actually restrict your content security policies to only allow the loading of scripts and css from your server, then jQuery wonā€™t work because the script comes from the domain jquery.com.

edit: Will probably create a Github issue for this.

can someone explain the purpose behind ā€œrel-likesā€?
I donā€™t understand the point of showing the difference of like between the two stocks; it is not explained well.
Is it just a matter of subtracting the smaller likes from the bigger likes and showing that on both stocks?

Its purpose is to show the difference between the two stocks. It makes more sense when you think of bigger numbers, for example 36587 likes and 36731 likes. It quickly shows the difference between the two. Or an even worse example: 1111111111111 likes and 11111111111111. Which one is bigger? And by how much? :smiley:

But its not just bigger minus smaller, its meant to be shown from the perspective of each stock. For the first stock you do ā€œlikes of first stockā€ minus ā€œlikes of second stockā€. And for the second stock it flips around: ā€œlikes of second stockā€ minus ā€œlikes of first stockā€.

An example:

likes of first stock: 5; relative likes: 5 - 3 = 2
likes of second stock: 3; relative likes: 3 - 5 = -2

Now you can immidiately see how much each stock is bigger or smaller then the other one.

1 Like

I see, thanks for the reply. So I guess if they have equal likes then it will display 0 for the ā€œrel_likesā€ of both stocksā€¦