Spaces:
Runtime error
Runtime error
File size: 6,503 Bytes
22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 c65698a 4a77343 22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 c65698a 4a77343 22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 c65698a 4a77343 22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 c65698a 4a77343 22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 22de2e7 4a77343 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
import logging
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import streamlit as st
# Setting up logging
logging.basicConfig(level=logging.INFO)
# Importing constants
from constants import (
MARKET_DATA_TITLE,
UPPER_BOLLINGER_BAND_DESCRIPTION,
UPPER_BOLLINGER_BAND_USAGE,
LOWER_BOLLINGER_BAND_DESCRIPTION,
LOWER_BOLLINGER_BAND_USAGE,
MA50_DESCRIPTION,
MA50_USAGE,
MA200_DESCRIPTION,
MA200_USAGE,
VOLUME_TRADED_TITLE,
VOLUME_DESCRIPTION,
VOLUME_USAGE,
VWAP_DESCRIPTION,
VWAP_USAGE,
VOLATILITY_TITLE,
VOLATILITY_DESCRIPTION,
VOLATILITY_USAGE,
MACD_ANALYSIS_TITLE,
MACD_LINE_DESCRIPTION,
MACD_LINE_USAGE,
SIGNAL_LINE_DESCRIPTION,
SIGNAL_LINE_USAGE,
)
def display_description_and_usage(description, usage):
"""Displays the description and usage information."""
st.write(f"""
Description: {description}
Usage:
- Buy: {usage['Buy']}
- Sell: {usage['Sell']}
- Risk/Opportunity Detection: {usage['Risk/Opportunity Detection']}
""")
def market_data(df):
"""Visualizes market data using various indicators."""
try:
st.title(MARKET_DATA_TITLE)
market_data_description = st.checkbox("Market Data Help")
if market_data_description:
display_description_and_usage(VWAP_DESCRIPTION, VWAP_USAGE)
display_description_and_usage(UPPER_BOLLINGER_BAND_DESCRIPTION, UPPER_BOLLINGER_BAND_USAGE)
display_description_and_usage(LOWER_BOLLINGER_BAND_DESCRIPTION, LOWER_BOLLINGER_BAND_USAGE)
display_description_and_usage(MA50_DESCRIPTION, MA50_USAGE)
display_description_and_usage(MA200_DESCRIPTION, MA200_USAGE)
fig = make_subplots(rows=1, cols=1, shared_xaxes=True, subplot_titles=("Market Data",))
fig.add_trace(go.Candlestick(
x=df["time_period_start"],
open=df["price_open"],
high=df["price_high"],
low=df["price_low"],
close=df["price_close"],
name="Market data"))
fig.add_trace(go.Scatter(x=df["time_period_start"], y=df["vwap"], mode="lines", name="Volume Weighted Average Price (VWAP)", line=dict(width=2, color="purple")))
fig.add_trace(go.Scatter(x=df["time_period_start"], y=df["bollinger_upper"], marker=dict(color="blue"), line=dict(width=0.5), name="Upper Bollinger Band"))
fig.add_trace(go.Scatter(x=df["time_period_start"], y=df["bollinger_lower"], marker=dict(color="red"), line=dict(width=0.5), name="Lower Bollinger Band"))
fig.add_trace(go.Scatter(x=df["time_period_start"], y=df["ma50"], marker=dict(color="orange"), line=dict(width=0.5), name="50-period Moving Average"))
fig.add_trace(go.Scatter(x=df["time_period_start"], y=df["ma200"], marker=dict(color="green"), line=dict(width=0.5), name="200-period Moving Average"))
fig.update_layout(title="Bitcoin Candlestick Chart with Market Data", yaxis_title="Price (USD)")
st.plotly_chart(fig, use_container_width=True)
except Exception as e:
logging.error(f"An error occurred while visualizing market data: {e}")
st.write("An error occurred while visualizing market data. Please check the logs for more details.")
def volatility(df):
"""Visualizes the volatility of the market data."""
try:
st.title(VOLATILITY_TITLE)
volatility_description = st.checkbox('Volatility Help')
if volatility_description:
display_description_and_usage(VOLATILITY_DESCRIPTION, VOLATILITY_USAGE)
fig = make_subplots(rows=1, cols=1, shared_xaxes=True, subplot_titles=('Volatility Analysis',))
fig.add_trace(go.Scatter(x=df['time_period_start'], y=df['volatility'], mode='lines', name='Volatility', line=dict(width=2, color='red')))
fig.update_layout(title='Bitcoin Price Volatility Analysis', yaxis_title='Volatility (%)')
st.plotly_chart(fig, use_container_width=True)
except Exception as e:
logging.error(f"An error occurred while visualizing volatility data: {e}")
st.write("An error occurred while visualizing volatility data. Please check the logs for more details.")
def trade_velocity(df):
"""Visualizes the trade velocity based on volume traded."""
try:
st.title(VOLUME_TRADED_TITLE)
volume_traded_description = st.checkbox('Volume Traded Help')
if volume_traded_description:
display_description_and_usage(VOLUME_DESCRIPTION, VOLUME_USAGE)
fig = make_subplots(rows=1, cols=1, shared_xaxes=True, subplot_titles=('Volume Traded',))
fig.add_trace(go.Bar(x=df['time_period_start'], y=df['volume_traded'], name='Volume Traded'))
fig.update_layout(title='Bitcoin Volume Traded Analysis', yaxis_title='Volume')
st.plotly_chart(fig, use_container_width=True)
except Exception as e:
logging.error(f"An error occurred while visualizing trade velocity data: {e}")
st.write("An error occurred while visualizing trade velocity data. Please check the logs for more details.")
def rsi_and_macd(df):
"""Visualizes the RSI and MACD indicators."""
try:
st.title(MACD_ANALYSIS_TITLE)
macd_description = st.checkbox('MACD Help')
if macd_description:
display_description_and_usage(MACD_LINE_DESCRIPTION, MACD_LINE_USAGE)
display_description_and_usage(SIGNAL_LINE_DESCRIPTION, SIGNAL_LINE_USAGE)
fig = make_subplots(rows=2, cols=1, shared_xaxes=True, subplot_titles=('MACD Line and Signal Line', 'MACD Histogram'))
fig.add_trace(go.Scatter(x=df['time_period_start'], y=df['macd'], mode='lines', name='MACD Line', line=dict(width=2, color='blue')), row=1, col=1)
fig.add_trace(go.Scatter(x=df['time_period_start'], y=df['macd_signal'], mode='lines', name='Signal Line', line=dict(width=2, color='red')), row=1, col=1)
fig.add_trace(go.Bar(x=df['time_period_start'], y=df['macd'] - df['macd_signal'], name='MACD Histogram'), row=2, col=1)
fig.update_layout(title='Bitcoin Moving Average Convergence Divergence (MACD) Analysis', yaxis_title='MACD Value')
st.plotly_chart(fig, use_container_width=True)
except Exception as e:
logging.error(f"An error occurred while visualizing RSI and MACD data: {e}")
st.write("An error occurred while visualizing RSI and MACD data. Please check the logs for more details.")
|