JoranSlingerland / StockTracker

Python stock tracker
MIT License
2 stars 1 forks source link
api azure-functions python

StockTracker Project - API

Ruff linting CodeQL Pytest

CodeFactor codecov

Maintained License Issues

The target of this project is to get data about your stock portfolio and make this viewable in a web application.

To see what's being worked on check out the project board.

Related repos

The project consists of three repositories:

Name Notes Language
API This repo which will be used to gather data Python
Frontend Frontend repo which will create the website React
Infrastructure Code to deploy all resources to Azure Bicep

Table of contents

API

This project makes use of the Alpha vantage API and clearbit API.

Setup

prerequisites

Azure environment

For the azure environment you can either use the One time deployment or the Pipeline deployment

One time deployment

Pipeline deployment

Name Value
AZURE_CREDENTIALS I'm not sure anymore but it has something to do with the azure/login@v1 action : )
AZURE_SUBSCRIPTION Your Azure subscription ID
SWA_REPO_TOKEN The PAT token you generated

local development environment

Name Notes Example
COSMOSDB_ENDPOINT < Link to your database> https://localhost:8081
COSMOSDB_KEY < CosmosDB Access key > A1B2C3
COSMOSDB_DATABASE < CosmosDB Database name> stocktracker
COSMOSDB_OFFER_THROUGHPUT < CosmosDB Throughput > 1000

Usage

Azure Functions

All Azure functions available in the api.

Orchestrator

start

Method URL Usage
POST {{base_url}}/orchestrator/start Function will start an orchestrator
Query parameters
Param Allowed values Required
functionName stocktracker_orchestrator true
daysToUpdate all | int true

list

Method URL Usage
GET {{base_url}}/orchestrator/list Function will list orchestrators
Query parameters
Param Allowed values Required
days int true

purge

Method URL Usage
DELETE {{base_url}}/orchestrator/purge Function will purge orchestrator
Query parameters
Param Allowed values Required
instanceId string true

terminate

Method URL Usage
POST {{base_url}}/orchestrator/terminate Function will terminate orchestrator
Query parameters
Param Allowed values Required
instanceId string true

Chart

bar

Method URL Usage
GET {{base_url}}/chart/bar Function will get data for barcharts
Query parameters
Param Allowed values Required
allData boolean false
startDate yyyy-mm-dd false
endDate yyyy-mm-dd false
dataType dividend | transaction_cost true

If allData is true then startDate and endDate can not be set. If allData is false then startDate and endDate must be set.

line

Method URL Usage
GET {{base_url}}/chart/line Function will get data for linecharts
Query parameters
Param Allowed values Required
allData boolean false
startDate yyyy-mm-dd false
endDate yyyy-mm-dd false
dataType invested_and_value | total_gains true

If allData is true then startDate and endDate can not be set. If allData is false then startDate and endDate must be set.

pie

Method URL Usage
GET {{base_url}}/chart/pie Function will get data for piecharts
Query parameters
Param Allowed values Required
dataType stocks | currency | country | sector true

input

delete

Method URL Usage
POST {{base_url}}/input/delete Function will delete a list of items in the input containers
Body

Body needs to confirm to the stock_input or transaction_input in the schema file.

add

Method URL content-type Usage
POST {{base_url}}/input/add json Function will add item to input
Body

Body needs to confirm to the stock_input or transaction_input in the schema file.

table

basic

Method URL Usage
GET {{base_url}}/table/basic Function will get data used by tables
Query parameters
Param Allowed values Required
containerName input_invested | input_transactions | stocks_held" true
andOr and | or false
fullyRealized Boolean false
partialRealized Boolean false
symbol string false

performance

Method URL Usage
GET {{base_url}}/table/performance Function will get data used by tables
Query parameters
Param Allowed values Required
allData boolean false
startDate yyyy-mm-dd false
endDate yyyy-mm-dd false
containerName stocks_held | totals true

If allData is true then startDate and endDate can not be set. If allData is false then startDate and endDate must be set.

user

add

Method URL Usage
POST {{base_url}}/user/add Function will update user data
Body

Body needs to confirm to the user_data schema in the schema file.

get

Method URL Usage
GET {{base_url}}/user/get Function will get user data

Main stocktracker function

Function Usage Link and options
stocktracker_orchestrator Function will get all the data from the input tables and use this to create the output data. This will then be outputted to the CosmosDB. /api/orchestrators/stocktracker_orchestrator/{days_to_update}

Function will get all the data from the input tables and use this to create the output data. This will then be outputted to the CosmosDB.

functions diagram

Azure Functions

graph generated by az-func-as-a-graph