From 2f195e7f14e57e07ec291e8bfeee6da54ef35575 Mon Sep 17 00:00:00 2001 From: loit Date: Thu, 31 Jul 2025 13:20:08 -0400 Subject: attemp using the alpaca api for history data --- app.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'app.py') diff --git a/app.py b/app.py index 952edf5..fc8276b 100644 --- a/app.py +++ b/app.py @@ -1,8 +1,10 @@ from dash import Dash, dcc, html, Input, Output import plotly.graph_objects as go import json -from datetime import datetime +from datetime import datetime, timedelta from ema_algo import Ema_Algo +from api import fetch_chart_data_yahoo +import pytz app = Dash(__name__) @@ -79,7 +81,7 @@ def display_color(ticker, period, interval): # Code to execute no matter what (optional) raw_timestamps = chart_data['timestamps'] - timestamps = [datetime.fromtimestamp(t) for t in raw_timestamps] + timestamps = [datetime.fromtimestamp(t).astimezone(pytz.timezone('US/Eastern')) for t in raw_timestamps] prices = chart_data['prices'] # test to see if graphc works, TODO make it abstracted @@ -102,10 +104,16 @@ def display_color(ticker, period, interval): go.Scatter(name='Buys', x=buy_times, y=buy_prices, line=dict(color='rgb(0, 0, 255)'), mode='markers', marker_size=10), go.Scatter(name='Sells', x=sell_times, y=sell_prices, line=dict(color='rgb(255, 255, 0)'), mode='markers', marker_size=10) ] + data = fetch_chart_data_yahoo('XRP-USD', '1m') + times = [datetime.fromtimestamp(t).astimezone(pytz.timezone('US/Eastern')) for t in data['timestamps']] + comp_scatter = go.Scatter(name='Price (yahoo)', x=times, y=data['prices'], line=dict(color='rgb(255, 0, 0)'), mode='lines') fig = go.Figure( data = [ go.Scatter(name='Price', x=timestamps, y=prices, line=dict(color='rgb(0, 0, 0)'), mode='lines'), - ] + algo_graphs + buy_sell_scatters, + comp_scatter + ] + # + algo_graphs + buy_sell_scatters + , layout = go.Layout( title=go.layout.Title(text='Chart for ' + chart_data['name']), xaxis=go.layout.XAxis(title='Date (dt=' + url_params['interval'] + ', range=' + url_params['period'] + ')'), -- cgit v1.2.3-70-g09d2