stop
: Stop the running server
rm
: Remove all unused containers
rm-all
: Stop and remove all containers
rmi
: Remove stockstalker images without removing base images. Useful for speeding up build time when switching from one start script to another such as make start
to make test
rmi-all
: Remove all images
purge
: Use with caution Completely purge Docker containers, networks, images, volumes, and cache
lint
: Run prettier and eslint
build
: Build development server without running the server
start
: Start development server at port 8080
reload
: Stop development server and restart the server at port 8080
hard-reload
: Stop container, remove container, rebuild container, and start development server
debug
: Start development server in debug mode
test
: Start test server
test-security
: Test security vulnerabilities (must have snyk installed globally)
test-image-security
: Test security vulnerabilities for base images (must have snyk installed globally)
reload-test
: Reload test server
hard-reload-test
: Stop container, remove container, rebuild container, and start test server
Clone the repo
git clone [email protected]:Stock-Stalker/backend.git
cd into the directory
cd backend
Rename .env.sample
to .env
mv .env.sample .env
Edit the .env
file to contain your environment variables
vim .env
Run the application!
make start
To stop the app press CNTRL + C
. Then run:
make stop
Base URL
https://stockstalker.tk/api
GET https://stockstalker.tk/api/stock
Success status code: 200
This route returns all names and symbols of the NASDAQ and DOW companies currently supported by StockStalker.
Example response:
[
{
"symbol": "AACG",
"companyName": "ATA Creativity Global - American Depositary Shares, each representing two common shares"
},
{
"symbol": "AACQ",
"companyName": "Artius Acquisition Inc. - Class A Common Stock"
},
...
]
Types:
- symbol: String
- companyName: String
Error status code: 500
An unsuccessful request, for any reason (such as the database connection times out, or there's another server-side issue) will result in an error response:
{
"message": "Connection refused."
}
GET https://stockstalker.tk/api/stock/:symbol
Where :symbol refers to the unique ticker symbol for a given stock.
Ex: AAPL for Apple
Can also accept the company name, case insensitive.
Ex: Apple, ApPle, apple, or APPLE
The company name or symbol sent in the query parameters will be validated.
Success status code: 200
Successful responses will return stockData
. An example response:
{
"stockData": {
"symbol": "AAPL",
"companyName":"Apple Inc. - Common Stock",
"historicalData": [{
"datetime": "2021-03-16",
"open":"125.70000",
"high":"127.22000",
"low":"124.71500",
"close":"125.57000",
"volume":"114813750"
},
{
"datetime":"2021-03-15",
"open":"121.41000",
"high":"124.00000",
"low":"120.43000",
"close":"123.99000",
"volume":"92590555"
}
... ]
}
}
}
Types:
- stockData: Object
- symbol: String
- companyName: String
- historicalData: Array(Objects)
- datetime: String
- open: String
- high: String
- low: String
- close: String
- volume: String
Error status code: 404
An unsuccessful validation (for example, inserting a company name that doesn't exist) will return a 404 status code for "resource not found". An example error response:
{
"message": "Cannot Find The Company or Symbol"
}
GET https://stockstalker.tk/api/stock/popular
The route returns the current price of popular stocks: Apple Inc (AAPL), Tesla (TSLA), Netflix (NFLX), Amazon (AMZN), Facebook (FB).
Success status code: 200
An example response:
{
"AAPL": {
"price": "123.71500"
},
...
}
Types:
- Array
- Symbol: Object
- price: Number
- Symbol: Object
Error status code: 500
In the event that there is another error due to a failure on the server side, a status code of 500 will be returned, along with a message stating the error.
GET https://stockstalker.tk/api/stock/prediction/:symbol
Where :symbol refers to the unique ticker symbol for a given stock.
Ex: AAPL for Apple
Can also accept the company name, case insensitive.
Ex: Apple, ApPle, apple, or APPLE
The company name or symbol sent in the query parameters will be validated.
Success status code: 200
An example response:
{
"prediction": 0
}
Types:
- prediction: Integer
Error status code: 500
In the event that there is another error due to a failure on the server side, a status code of 500 will be returned, along with a message stating the error.
Users are able to make accounts with StockStalker to track their own watchlist. This enables users to quickly access the stocks that matter to them.
POST https://stockstalker.tk/api/user/signup
The request expects in the body a username and password.
Username must be between 4 and 25 characters long.
Password must be between 8 and 25 characters long.
Example request body:
{
"username": "newuser",
"password": "password"
}
Types:
- username: String
- password: String
Success status code: 200
A successful response will send a Bearer token to be set in the Authorization header. This header will be evaluated for all restricted routes.
Example Authorization header for your reference:
headers: {
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IkZBS0VVU0VSIiwidXNlcklkIjoiNjA1M2JlZTg5YzU3MTcwMTQyMDExYzM2IiwiaWF0IjoxNjE2MTAxMTIzLCJleHAiOjE2MTYxMDQ3MjN9.IzWXlrFS7mQqR652keVEHnR4ayspk5yyyMjRpYTY7gw'
}
The response will send a success message and your new user's username.
Example response:
{
"message": "Sign up successful!",
"user": {
"username": "newuser"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IkZBS0VVU0VSIiwidXNlcklkIjoiNjA1M2JlZTg5YzU3MTcwMTQyMDExYzM2IiwiaWF0IjoxNjE2MTAxMTIzLCJleHAiOjE2MTYxMDQ3MjN9.IzWXlrFS7mQqR652keVEHnR4ayspk5yyyMjRpYTY7gw"
}
Types:
-
message: String
-
user: Object
- username: String
-
token: String
Validation error status code: 422
In the event that the request body cannot be validated, a status code of 422 will be returned, along with an error message containing something similar to (for example):
"ValidationError": "Username must be more than 4 characters"
Error status code: 409
In the event that the username you are attempting to sign up with already exists, a status code of 409 will be returned, along with a message stating that the user already exists.
Example 409 error message:
{
"message": "User already exists!"
}
Error status code: 500
In the event that there is another error due to a failure on the server side, a status code of 500 will be returned, along with a message stating the error.
Example 500 error message:
{
"err": "[error] 29#29: *17 upstream timed out (110: Operation timed out) while reading response header from upstream, client: 172.18.0.1, server: stockstalker.tk"
}
POST https://stockstalker.tk/api/user/signin
The request expects in the body a username and password.
Username must be between 4 and 25 characters long.
Password must be between 8 and 25 characters long.
Example request body:
{
"username": "newuser",
"password": "password"
}
Types:
- username: String
- password: String
Success status code: 200
A successful response will send a Bearer token to be set in the Authorization header. This header will be evaluated for all restricted routes.
Example Authorization header for your reference:
headers: {
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IkZBS0VVU0VSIiwidXNlcklkIjoiNjA1M2JlZTg5YzU3MTcwMTQyMDExYzM2IiwiaWF0IjoxNjE2MTAxMTIzLCJleHAiOjE2MTYxMDQ3MjN9.IzWXlrFS7mQqR652keVEHnR4ayspk5yyyMjRpYTY7gw'
}
Additionally, the response will send a success message to verify your user is now signed in.
Example response:
{
"message": "Sign in successful!",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IkZBS0VVU0VSIiwidXNlcklkIjoiNjA1M2JlZTg5YzU3MTcwMTQyMDExYzM2IiwiaWF0IjoxNjE2MTAxMTIzLCJleHAiOjE2MTYxMDQ3MjN9.IzWXlrFS7mQqR652keVEHnR4ayspk5yyyMjRpYTY7gw"
}
Types:
- message: String
- token: String
Validation error status code: 422
In the event that the request body cannot be validated, a status code of 422 will be returned, along with an error message containing something similar to (for example):
"ValidationError": "Username must be more than 4 characters"
Cannot find user error status code: 401
In the event that the username entered does not correspond to an existing user, a status code of 401 will be returned, along with an error message like the following:
{
"message": "User does not exist!"
}
Error status code: 500
In the event that there is another error due to a failure on the server side, a status code of 500 will be returned, along with a message stating the error.
Example 500 error message:
{
"err": "[error] 29#29: *17 upstream timed out (110: Operation timed out) while reading response header from upstream, client: 172.18.0.1, server: stockstalker.tk"
}
Each user is able to track a watchlist - a list of stocks they're interested in tracking the performance of.
PATCH https://stockstalker.tk/api/user/watchlist
To add or remove a stock from a user's watchlist, send the symbol
in the request body. StockStalker will then check for the presence of this stock in the watchlist. If the stock is already present, it will interpret the request as a "remove" request. If the stock is not present, it will be interpreted as an "add" request.
Example request body:
{
"symbol": "AAPL"
}
Types:
- symbol: String
Success status code: 200
A successful response will return the user's watchlist. An example response is as follows:
{
"watchlist": [
{
"_id": "6052a534e808fd0e72580cf2",
"symbol": "AAPL",
"companyName": "Apple, Inc. - Common Stock"
},
{
"_id": "6052a534e808fd0e72580cf2",
"symbol": "TSLA",
"companyName": "Tesla - Common Stock"
}
]
}
Types:
- watchlist: List containing objects
- _id: String (representing objectId)
- symbol: String
- companyName: String
Error status code: 403
An erroneous response will resolve with a status code of 403, and send the error message.
{
"message": "error message"
}
To get the logged in user's watchlist, you will make the following request.
GET https://stockstalker.tk/api/user/watchlist
Success status code: 200
A successful response will return the user's watchlist. An example response is as follows:
{
"watchlist": [
{
"_id": "6052a534e808fd0e72580cf2",
"symbol": "AAPL",
"companyName": "Apple, Inc. - Common Stock"
},
{
"_id": "6052a534e808fd0e72580cf2",
"symbol": "TSLA",
"companyName": "Tesla - Common Stock"
}
]
}
Types:
- watchlist: List containing objects
- _id: String (representing objectId)
- symbol: String
- companyName: String
Error status code: 403
An erroneous response will resolve with a status code of 403, and send the error message.
{
"message": "error message"
}
`
Let's face it - the most interesting thing about StockStalker is the ability to receive predictions about the potential performance of a stock.
GET https://stockstalker.tk/api/stock/prediction/:symbol
Example request url:
GET http://stockstalker.tk/api/stock/prediction/aapl
GET http://stockstalker.tk/api/stock/prediction/AAPL
Success status code: 200
A successful response will return a status code of 200, and the prediction or list of predictions for the given stock.
The current version of StockStalker does not return predictions if there is no news that day for the given stock. If there are no headlines matching your desired company's stock keywords, our prediction model will return a neutral prediction.
Example neutral response:
{
"prediction": 2
}
Types:
- prediction:Integer
When there are headlines about a given company, StockStalker will return to you a list of predictions. The most common prediction is the most likely for the day. Each headline generates a prediction.
Example response when headlines are present for the day:
{
"prediction": [0, 1, 1, 1, 1]
}
Types:
- prediction: List of integers
Error status code: 500
When there is an error, a status code of 500 will be returned, along with the error message.
Example error response:
{
"message": "This is an error message"
}
To run tests simple run:
make test
If any of the tests fail or if the tests do not have at least 90% coverage the command will exit with a status code of 1
.