diff options
author | loit <michael.foiani@gmail.com> | 2025-07-29 00:21:17 -0400 |
---|---|---|
committer | loit <michael.foiani@gmail.com> | 2025-07-29 00:21:17 -0400 |
commit | 00d89073d7802983b11f9e5931f932444806defd (patch) | |
tree | 3f4e2c91552aa537204ff636971b254d6e2c38c0 /app.py | |
parent | 2411108fe1783d5f03edaa57dad16804b2ce0445 (diff) |
worked on updating html elements and fixing some bugs with switching charts
Diffstat (limited to 'app.py')
-rw-r--r-- | app.py | 33 |
1 files changed, 20 insertions, 13 deletions
@@ -5,6 +5,7 @@ from ema import calc_emas, calculate_profit import plotly.graph_objects as go import json import datetime +import pandas as pd app = Dash(__name__) @@ -24,8 +25,6 @@ app = Dash(__name__) # for x,y in interpolated_intersections: # intersected_x.append(x) # intersected_y.append(y) -percent_gain = 0 -memo_fig = None app.layout = html.Div([ html.H4('Interactive color selection with simple Dash example'), @@ -47,21 +46,24 @@ app.layout = html.Div([ ), html.Hr(), dcc.Graph(id="graph"), - html.P("If bought and sold on these signals, the percent gain/loss would be: " + str(percent_gain)) + html.P("If bought and sold on these signals, the percent gain/loss would be: TODO"), + html.P(id="percent_gain") + ]) @app.callback( Output("graph", "figure"), + Output("percent_gain", "children"), Input("ticker", "value"), Input("period_dropdown", "value"), Input("interval_dropdown", "value") ) def display_color(ticker, period, interval): - try: chart_data = fetch_chart_data(ticker, period, interval) - except: - return memo_fig - else: + if chart_data['error'] == True: + # implement a feeback mechanism for ERROR codes + print("TODO: FIX THIS") + timestamps_raw = chart_data['timestamps'] timestamps = [datetime.datetime.fromtimestamp(t) for t in timestamps_raw] prices = chart_data['prices'] @@ -70,6 +72,7 @@ def display_color(ticker, period, interval): ema_13 = calc_emas(13, prices) profit = calculate_profit(ema_5, ema_13, prices, timestamps, 13) buy_info = profit[-2] + print(buy_info) buy_x = [] buy_y = [] for x,y,_ in buy_info: @@ -85,21 +88,25 @@ def display_color(ticker, period, interval): print("Result Analysis:\n", "Percent gain/loss:\t", profit[0], profit[1], profit[2]) percent_gain = profit[0] * 100 - finally: + # Code to execute no matter what (optional) fig = go.Figure( - [ + data = [ go.Scatter(name='Price', x=timestamps, y=prices, line=dict(color='rgb(0, 0, 0)'), mode='lines'), # go.Scatter(name='5 day EMA', x=timestamps, y=ema_5, line=dict(color='rgb(0, 255, 0)'), mode='lines'), # go.Scatter(name='13 day EMA', x=timestamps, y=ema_13, line=dict(color='rgb(0, 0, 255)'), mode='lines'), # go.Scatter(name='EMA Intersections', x=intersected_x, y=intersected_y, line=dict(color='rgb(255, 0, 0)'), mode='markers'), go.Scatter(name='Buys', x=buy_x, y=buy_y, line=dict(color='rgb(0, 0, 255)'), mode='markers', marker_size=10), go.Scatter(name='Sells', x=sell_x, y=sell_y, line=dict(color='rgb(255, 255, 0)'), mode='markers', marker_size=10), - ] + ], + layout = go.Layout( + title=go.layout.Title(text='Chart for ' + chart_data['name']), + xaxis=go.layout.XAxis(title='Date (dt=' + interval + ', range=' + period + ')'), + yaxis=go.layout.YAxis(title='Price ($)') + ) ) - print(ticker, period, interval) - memo_fig = fig - return fig + return (fig, percent_gain) + app.run(debug=True)
\ No newline at end of file |