forked from dataprofessor/dashboard-v2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Cuttlas90/ta
Ta
- Loading branch information
Showing
8 changed files
with
445 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import streamlit as st | ||
import pandas as pd | ||
import altair as alt | ||
from login import check_local_token | ||
import numpy as np | ||
|
||
from pages.helper.query import Queries | ||
from request import get_stock_monthly | ||
# from slider import create_range_slider | ||
from menu import add_menu | ||
from finta import TA | ||
from request import vasahm_query | ||
import plotly.graph_objs as go | ||
import streamlit.components.v1 as components | ||
|
||
|
||
|
||
def plot_gauge(current_value, min_value, max_value, chart_title, place): | ||
plot_bgcolor = "#def" | ||
quadrant_colors = [plot_bgcolor, "#2bad4e", "#85e043", "#eff229", "#f2a529", "#f25829"] | ||
quadrant_text = ["", "<b>Strong Buy</b>", "<b>Buy</b>", "<b>Neutral</b>", "<b>Sell</b>", "<b>Strong Sell</b>"] | ||
n_quadrants = len(quadrant_colors) - 1 | ||
|
||
hand_length = np.sqrt(2) / 4 | ||
hand_angle = np.pi * (1 - (max(min_value, min(max_value, current_value)) - min_value) / (max_value - min_value)) | ||
|
||
fig = go.Figure( | ||
data=[ | ||
go.Pie( | ||
values=[0.5] + (np.ones(n_quadrants) / 2 / n_quadrants).tolist(), | ||
rotation=90, | ||
hole=0.5, | ||
marker_colors=quadrant_colors, | ||
text=quadrant_text, | ||
textinfo="text", | ||
hoverinfo="skip", | ||
), | ||
], | ||
layout=go.Layout( | ||
showlegend=False, | ||
margin=dict(b=0,t=10,l=10,r=10), | ||
width=450, | ||
height=450, | ||
paper_bgcolor=plot_bgcolor, | ||
annotations=[ | ||
go.layout.Annotation( | ||
text=f"<b>{chart_title}</b>", | ||
x=0.5, xanchor="center", xref="paper", | ||
y=0.25, yanchor="bottom", yref="paper", | ||
showarrow=False, | ||
) | ||
], | ||
shapes=[ | ||
go.layout.Shape( | ||
type="circle", | ||
x0=0.48, x1=0.52, | ||
y0=0.48, y1=0.52, | ||
fillcolor="#333", | ||
line_color="#333", | ||
), | ||
go.layout.Shape( | ||
type="line", | ||
x0=0.5, x1=0.5 + hand_length * np.cos(hand_angle), | ||
y0=0.5, y1=0.5 + hand_length * np.sin(hand_angle), | ||
line=dict(color="#333", width=4) | ||
) | ||
] | ||
) | ||
) | ||
place.plotly_chart(fig) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
|
||
import streamlit as st | ||
import pandas as pd | ||
import altair as alt | ||
from login import check_local_token | ||
import numpy as np | ||
|
||
from pages.helper.gauge_chart import plot_gauge | ||
from pages.helper.query import Queries | ||
from request import get_stock_monthly | ||
# from slider import create_range_slider | ||
from menu import add_menu | ||
from finta import TA | ||
from request import vasahm_query | ||
import plotly.graph_objs as go | ||
import streamlit.components.v1 as components | ||
|
||
|
||
def _update_guage(a, b, c, condition): | ||
if condition in ["EMA","SMA","VAMA", "HMA"]: | ||
if b >= c: | ||
a = a +1 | ||
else: | ||
a=a-1 | ||
return a | ||
elif condition in ["RSI","STOCH"]: | ||
if b >= 70.0: | ||
a = a +1 | ||
elif b <= 30.0: | ||
a=a-1 | ||
return a | ||
elif condition in ["ADX"]: | ||
if b >= 50.0: | ||
a = a +1 | ||
elif b <= 50.0: | ||
a=a-1 | ||
return a | ||
elif condition == "CCI": | ||
if b >= 100.0: | ||
a = a -1 | ||
elif b <= -100.0: | ||
a=a+1 | ||
return a | ||
elif condition in ["AO","MOM", "MACD"]: | ||
|
||
if b >= 0.0: | ||
a = a +1 | ||
elif b <= 0.0: | ||
a=a-1 | ||
return a | ||
elif condition in ["STOCHRSI"]: | ||
if b >= 0.5: | ||
a = a +1 | ||
elif b <= 0.5: | ||
a=a-1 | ||
return a | ||
elif condition in ["WILLIAMS"]: | ||
if b >= -20.0: | ||
a = a +1 | ||
elif b <= -80.0: | ||
a=a-1 | ||
return a | ||
|
||
def add_ta_metrics(stock_data_history, data,metric_label, col, place, num, ind): | ||
if ind == "EMA": | ||
smas = TA.EMA(stock_data_history, data[0]) | ||
sma_df = pd.DataFrame(smas) | ||
place.metric(label=metric_label, value = int(sma_df.iloc[-1][col]), delta = int(sma_df.iloc[-1][col]-sma_df.iloc[-2][col])) | ||
num=_update_guage(num, sma_df.iloc[-1][col], stock_data_history.iloc[-1]['close'],ind) | ||
return num | ||
elif ind == "SMA": | ||
smas = TA.SMA(stock_data_history, data[0]) | ||
sma_df = pd.DataFrame(smas) | ||
place.metric(label=metric_label, value = int(sma_df.iloc[-1][col]), delta = int(sma_df.iloc[-1][col]-sma_df.iloc[-2][col])) | ||
num=_update_guage(num, sma_df.iloc[-1][col], stock_data_history.iloc[-1]['close'], ind) | ||
return num | ||
elif ind == "VAMA": | ||
smas = TA.VAMA(stock_data_history, data[0]) | ||
sma_df = pd.DataFrame(smas) | ||
place.metric(label=metric_label, value = int(sma_df.iloc[-1][col]), delta = int(sma_df.iloc[-1][col]-sma_df.iloc[-2][col])) | ||
num=_update_guage(num, sma_df.iloc[-1][col], stock_data_history.iloc[-1]['close'], ind) | ||
return num | ||
elif ind == "HMA": | ||
smas = TA.HMA(stock_data_history, data[0]) | ||
sma_df = pd.DataFrame(smas) | ||
place.metric(label=metric_label, value = int(sma_df.iloc[-1][col]), delta = int(sma_df.iloc[-1][col]-sma_df.iloc[-2][col])) | ||
num=_update_guage(num, sma_df.iloc[-1][col], stock_data_history.iloc[-1]['close'], ind) | ||
return num | ||
elif ind == "RSI": | ||
smas = TA.RSI(stock_data_history, data[0]) | ||
sma_df = pd.DataFrame(smas) | ||
place.metric(label=metric_label, value = int(sma_df.iloc[-1][col]), delta = int(sma_df.iloc[-1][col]-sma_df.iloc[-2][col])) | ||
num=_update_guage(num, sma_df.iloc[-1][col], stock_data_history.iloc[-1]['close'], ind) | ||
return num | ||
elif ind == "STOCH": | ||
smas = TA.STOCH(stock_data_history, data[0]) | ||
sma_df = pd.DataFrame(smas) | ||
place.metric(label=metric_label, value = int(sma_df.iloc[-1][col]), delta = int(sma_df.iloc[-1][col]-sma_df.iloc[-2][col])) | ||
num=_update_guage(num, sma_df.iloc[-1][col], stock_data_history.iloc[-1]['close'], ind) | ||
return num | ||
elif ind == "CCI": | ||
smas = TA.CCI(stock_data_history, data[0]) | ||
sma_df = pd.DataFrame(smas) | ||
place.metric(label=metric_label, value = int(sma_df.iloc[-1][col]), delta = int(sma_df.iloc[-1][col]-sma_df.iloc[-2][col])) | ||
num=_update_guage(num, sma_df.iloc[-1][col], stock_data_history.iloc[-1]['close'], ind) | ||
return num | ||
elif ind == "ADX": | ||
smas = TA.ADX(stock_data_history, data[0]) | ||
sma_df = pd.DataFrame(smas) | ||
place.metric(label=metric_label, value = int(sma_df.iloc[-1][col]), delta = int(sma_df.iloc[-1][col]-sma_df.iloc[-2][col])) | ||
num=_update_guage(num, sma_df.iloc[-1][col], stock_data_history.iloc[-1]['close'], ind) | ||
return num | ||
elif ind == "AO": | ||
smas = TA.AO(stock_data_history, data[0]) | ||
sma_df = pd.DataFrame(smas) | ||
place.metric(label=metric_label, value = int(sma_df.iloc[-1][col]), delta = int(sma_df.iloc[-1][col]-sma_df.iloc[-2][col])) | ||
num=_update_guage(num, sma_df.iloc[-1][col], stock_data_history.iloc[-1]['close'], ind) | ||
return num | ||
elif ind == "MOM": | ||
smas = TA.MOM(stock_data_history, data[0]) | ||
sma_df = pd.DataFrame(smas) | ||
place.metric(label=metric_label, value = int(sma_df.iloc[-1][col]), delta = int(sma_df.iloc[-1][col]-sma_df.iloc[-2][col])) | ||
num=_update_guage(num, sma_df.iloc[-1][col], stock_data_history.iloc[-1]['close'], ind) | ||
return num | ||
elif ind == "MACD": | ||
smas = TA.MACD(stock_data_history, data[0], data[1]) | ||
sma_df = pd.DataFrame(smas) | ||
place.metric(label=metric_label, value = int(sma_df.iloc[-1][col]), delta = int(sma_df.iloc[-1][col]-sma_df.iloc[-2][col])) | ||
num=_update_guage(num, sma_df.iloc[-1][col], stock_data_history.iloc[-1]['close'], ind) | ||
return num | ||
elif ind == "STOCHRSI": | ||
smas = TA.STOCHRSI(stock_data_history, data[0], data[1]) | ||
sma_df = pd.DataFrame(smas) | ||
place.metric(label=metric_label, value = int(sma_df.iloc[-1][col]), delta = int(sma_df.iloc[-1][col]-sma_df.iloc[-2][col])) | ||
num=_update_guage(num, sma_df.iloc[-1][col], stock_data_history.iloc[-1]['close'], ind) | ||
return num | ||
elif ind == "WILLIAMS": | ||
smas = TA.WILLIAMS(stock_data_history, data[0]) | ||
sma_df = pd.DataFrame(smas) | ||
place.metric(label=metric_label, value = int(sma_df.iloc[-1][col]), delta = int(sma_df.iloc[-1][col]-sma_df.iloc[-2][col])) | ||
num=_update_guage(num, sma_df.iloc[-1][col], stock_data_history.iloc[-1]['close'], ind) | ||
return num | ||
elif ind == "UO": | ||
smas = TA.UO(stock_data_history) | ||
sma_df = pd.DataFrame(smas) | ||
st.write(sma_df.iloc[-1][col]) | ||
place.metric(label=metric_label, value = int(sma_df.iloc[-1][col]), delta = int(sma_df.iloc[-1][col]-sma_df.iloc[-2][col])) | ||
_update_guage(num, sma_df.iloc[-1][col], stock_data_history.iloc[-1]['close'], ind) | ||
return num | ||
elif ind == "EBBP": | ||
smas = TA.EBBP(stock_data_history) | ||
sma_df = pd.DataFrame(smas) | ||
place.metric(label=metric_label, value = int(sma_df.iloc[-1][col]), delta = int(sma_df.iloc[-1][col]-sma_df.iloc[-2][col])) | ||
_update_guage(num, sma_df.iloc[-1][col], stock_data_history.iloc[-1]['close'], ind) | ||
return num | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"""Query Workbench.""" | ||
|
||
import streamlit as st | ||
import pandas as pd | ||
import altair as alt | ||
|
||
from login import check_local_token | ||
from pages.helper.query import Queries | ||
from request import vasahm_query | ||
from menu import add_menu | ||
|
||
|
||
|
||
st.set_page_config(layout='wide', | ||
page_title="وسهم - میزکار، دسترسی آزاد اطلاعات", | ||
page_icon="./assets/favicon.ico", | ||
initial_sidebar_state='expanded') | ||
|
||
with open( "style.css", encoding="UTF-8") as css: | ||
st.markdown( f'<style>{css.read()}</style>' , unsafe_allow_html= True) | ||
|
||
|
||
add_menu() | ||
|
||
df = pd.read_csv("data.csv").dropna() | ||
list_of_name = df['name'].to_list() | ||
if "stock" in st.query_params: | ||
STOCK_INDEX = list_of_name.index(st.query_params.stock) | ||
else: | ||
STOCK_INDEX = 0 | ||
name = st.sidebar.selectbox("لیست سهام", options = list_of_name, index=STOCK_INDEX) | ||
selected_stock = df.iloc[df.loc[df['name'] == name].index[0]] | ||
|
||
if "ver" in st.session_state: | ||
st.sidebar.header(f'Vasahm DashBoard `{st.session_state.ver}`') | ||
|
||
check_local_token() | ||
if "token" in st.session_state: | ||
|
||
queries = Queries(name) | ||
|
||
error, stock_data = vasahm_query(queries.get_daily_social()) | ||
if error: | ||
st.error(stock_data, icon="🚨") | ||
else: | ||
if len(stock_data) > 0: | ||
st.header("اقبال به سهم", divider='rainbow') | ||
stock_data_history = pd.DataFrame(stock_data, columns=[ | ||
"number", | ||
"date"]) | ||
# stock_data_history["date"] = stock_data_history[ | ||
# "date"].astype(str) | ||
|
||
chart = alt.Chart(stock_data_history).mark_bar().encode( | ||
# alt.Color('row_title:N', title="سرفصلها"), | ||
alt.Y('number:Q', title="تعداد کامنت"), | ||
alt.X('date:N',title="تاریخ") | ||
) | ||
st.altair_chart(chart, use_container_width=True) |
Oops, something went wrong.