Skip to content

Instantly share code, notes, and snippets.

View Cawinchan's full-sized avatar

Cawin Chan Cawinchan

View GitHub Profile
import sqlite3
from sqlite3 import Error
def add_items_to_database(db_file,stock_name,stock_quantity,stock_bought_price_weighted_avg,stock_fees,stock_currency):
try:
conn = sqlite3.connect(db_file)
print("INSERT INTO stocks (Stock,Bought_Price_Avg,Currency,Fees,Quantity) VALUES ('"+str(stock_name)+"',"+str(stock_bought_price_weighted_avg)+",'"+str(stock_currency)+"',"+str(stock_fees)+","+str(stock_quantity)+")")
conn.execute("INSERT INTO stocks (Stock,Bought_Price_Avg,Currency,Fees,Quantity) VALUES ('"+stock_name+"',"+stock_bought_price_weighted_avg+",'"+stock_currency+"',"+stock_fees+","+stock_quantity+")")
conn.commit()
except Error as e:
# Summary which deals with different markets
st.write('Summary')
summary_df = df.reindex(columns=['Profit/Loss','Profit/Loss (%)','Market Value','Total Spent','Currency']).groupby(['Currency']).agg('sum')
summary_df['Profit/Loss (%)'] = ((summary_df['Market Value'] - summary_df['Total Spent']) / summary_df['Market Value']) *100
st.table(summary_df)
# Final Tally (SGD)
st.write('Final Table (SGD)')
final_df = df.reindex(columns=['Market Value (SGD)','Total Spent (SGD)','Currency']).groupby(['Currency']).agg('sum')
final_df_sgd = final_df.sum()
@echo off
call activate.bat activate money
call streamlit run C:\Users\USER\Documents\Stocktracker\main_stock_app.py
import sqlite3
from sqlite3 import Error
DATABASE_FILE_LOCATION = os.getcwd()+"\pythonsqlite.db" ## in C:\User\User\Desktop
TABLE_DIC = {'stocks':'stocks','crypto':'crypto','stock_trans':'stock_transaction','crypto_trans':'crypto_transaction'} ## Stocks always first, cryto always second
def create_connection(db_file):
""" create a database connection to a SQLite database """
@Cawinchan
Cawinchan / page_helper_function.py
Last active April 13, 2021 21:29
main_stock_app.py
from streamlit.hashing import _CodeHasher
try:
# Before Streamlit 0.65
from streamlit.ReportThread import get_report_ctx
from streamlit.server.Server import Server
except ModuleNotFoundError:
# After Streamlit 0.65
from streamlit.report_thread import get_report_ctx
from streamlit.server.server import Server
@Cawinchan
Cawinchan / page_main.py
Last active April 13, 2021 21:29
main_stock_app.py
import streamlit as st
def main(test):
st.set_page_config(layout="wide")
state = _get_state()
st.sidebar.title(":floppy_disk: Dashboard")
page = st.sidebar.radio("Select your page", tuple(pages.keys()))
#Removing and add pages