There are 2 options for using API from Cassandra.
NOTE : API requires Basic Auth in both options.
To use it with postman -> Select type as 'Basic Auth' from Authorization Menu.
Username: demo
Password: demo_password123
-
The public API is managed by YTD team. 'BASE URL': https://cassandra-api.herokuapp.com
-
It can be used locally too (We support Linux/MacOS/Docker):
Preconditions:
- Python3
- Pip3
Firstly, create an Python environment and activate it. Then install project dependencies.
python3 -m venv env
source env/bin/activate
pip3 install -r requirements.txt
Then go inside /api folder. And run tests by
pytest test_api.py
In order to run API in local env:
uvicorn app:app --reload
The API will be available at http://127.0.0.1:8000
GET: /stockprice
Body:
{
"stock": "META",
"start_date": "2022-10-26",
"end_date": "2022-10-27",
"interval": "1h"
}
For interval, the following values can be used:
- minute = '1m'
- half_hour = '30m'
- hour = '1h'
- day = '1d'
- week = '1wk'
- month = '1mo'
POST: /forecast
Body:
{
"stock": "META",
"start_date": "2022-10-01",
"end_date": "2022-10-27",
"interval": "1h",
"n_forecast": 12,
"strategy": "naive_forecast"
}
For strategy, the following values can be used:
- random_walk
- gaussian
- naive_forecast
- multivariate_diff
import requests
forecast_endpoint = 'https://cassandra-api.herokuapp.com/forecast' # If you want to use local endpoint: 'https://localhost:8000/forecast'
payload = {
"stock": "META",
"start_date": "2022-11-02",
"end_date": "2022-11-09",
"interval": "1h",
"n_forecast": 12,
"strategy": "naive_forecast"
}
auth = requests.auth.HTTPBasicAuth("demo", "demo_password123")
res = requests.post(forecast_endpoint, json=payload, auth=auth)
print(res.status_code)
print(res.json())