Skip to content

anthonygharvey/stock-trading-game-api

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
app
 
 
bin
 
 
 
 
db
 
 
 
 
log
 
 
 
 
 
 
tmp
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

forthebadge

Description

A Ruby on Rails API to for the Anonymous Stock Game (repo), which is built with React and Redux.

The API saves historical stock prices from the Alpha Vantage API and exposes several endpoints to the React frontend: random_stock, save_game and leaderboard.

The random_stock endpoint returns a random stock and random 100 consecutive days of prices.

The save_game endpoint accepts POST requests from the React frontend to save a player’s game information, including username, portfolio data and data for each trade.

The leaderboard endpoint returns a list of the top 10 players based on portfolio percentage gain.

Local Installation

The API saves historical stock prices in order to avoid unnecessary requests to the Alpha Vantage API.

To install and run the API on your local machine:

  1. Click the green Clone or download button above and click the copy to clipboard button
  2. From your terminal, run git clone [paste the link from step 1]
  3. Then run cd stock-trading-game-api to navigate to the stock-trading-game-api directory
  4. Run bundle install to install the necessary gems and dependencies
  5. Run rails db:migrate to perform the database migrations
  6. Run rake db:seed to seed a sample of 5 stocks and their historical prices
  7. Run rails s -p 4000 to start the local rails server (you can choose any port number; I chose 4000 to avoid a conflict with the default port 3000 for the React frontend)

Rake Tasks

Note: The rake tasks require an Alpha Vantage API key, which can be obtained for free here. Create a .env file at the root level and add:

ALPHA_VANTAGE_API_KEY=<Your API key>

To add historical prices for the Dow Jones stocks using an Alpha Vantage API key, run: bundle exec rake stocks:add_dow_jones_historical_prices

To add historical prices for individual stocks, pass comma-separated ticker symbols to the add_historical_prices_for rake task:

bundle exec rake stocks:add_historical_prices_for[<ticker symbol or symbols>]

Examples: bundle exec rake stocks:add_historical_prices_for[AMZN]

bundle exec rake stocks:add_historical_prices_for[AMZN,TSLA]

Releases

No releases published

Packages

No packages published

Languages