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 endpoint returns a random stock and random 100 consecutive days of prices.
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.
leaderboard endpoint returns a list of the top 10 players based on portfolio percentage gain.
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:
- Click the green Clone or download button above and click the copy to clipboard button
- From your terminal, run
git clone [paste the link from step 1]
- Then run
cd stock-trading-game-apito navigate to the stock-trading-game-api directory
bundle installto install the necessary gems and dependencies
rails db:migrateto perform the database migrations
rake db:seedto seed a sample of 5 stocks and their historical prices
rails s -p 4000to 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)