import streamlit as st import requests import pandas as pd from datetime import…
- User
import streamlit as st import requests import pandas as pd from datetime import datetime, timedelta
Function to get current Tehran time from API
def get_tehran_time(): response = requests.get('http://worldtimeapi.org/api/timezone/Asia/Tehran') time_data = response.json() return time_data['datetime']
Function to get current Bitcoin price
@st.cache_data def get_current_price(currency='USD'): url = f'https://api.coindesk.com/v1/bpi/currentprice/{currency}.json' response = requests.get(url) data = response.json() price = data['bpi'][currency]['rate_float'] return price
Function to calculate RSI
def calculate_rsi(prices, period=14): delta = prices.diff() gains = delta.where(delta > 0, 0) losses = -delta.where(delta < 0, 0) average_gain = gains.rolling(window=period).mean() average_loss = losses.rolling(window=period).mean() rs = average_gain / average_loss rsi = 100 - (100 / (1 + rs)) return rsi
Function to calculate MACD
def calculate_macd(prices, short_period=12, long_period=26, signal_period=9): short_ema = prices.ewm(span=short_period, adjust=False).mean() long_ema = prices.ewm(span=long_period, adjust=False).mean() macd = short_ema - long_ema signal = macd.ewm(span=signal_period, adjust=False).mean() histogram = macd - signal return macd, signal, histogram
Function to generate buy/sell signals
def generate_signals(prices, rsi_period=14, macd_short_period=12, macd_long_period=26, macd_signal_period=9): signals = pd.DataFrame(index=prices.index) signals['rsi'] = calculate_rsi(prices, rsi_period) macd, signal, _ = calculate_macd(prices, macd_short_period, macd_long_period, macd_signal_period) signals['macd'] = macd signals['signal'] = signal signals['buy'] = (signals['rsi'] < 30) & (signals['macd'] > signals['signal']) signals['sell'] = (signals['rsi'] > 70) & (signals['macd'] < signals['signal']) return signals
Set page configuration
st.set_page_config(page_title='Bitcoin Price Tracker', page_icon=':moneybag:', layout='wide')
Header
st.header('Bitcoin Price Tracker :chart_with_upwards_trend:')
Tehran time
tehran_time = get_tehran_time() st.sidebar.write('Current time in Tehran:', tehran_time)
Current Bitcoin price
currency = st.sidebar.selectbox('Select Currency', ['USD', 'EUR', 'GBP']) price = get_current_price(currency) st.write(f'Current Bitcoin Price in {currency}: {price}')
Refresh button
if st.button('Refresh'): st.experimental_rerun()
Trading signals subheader
- Assistant
Overall, the Streamlit app is designed to track Bitcoin prices and generate trading signals based on historical price data. The app allows users to monitor the current Bitcoin price in various currencies, such as USD, EUR, and GBP. It provides information on buy and sell signals generated by analyzing RSI (Relative Strength Index) and MACD (Moving Average Convergence Divergence) indicators.
Here is how the app functions:
- Current Bitcoin Price: Displays the current Bitcoin price based on the selected currency.
- Trading Signals: Shows the number of buy and sell signals generated from historical price data.
- Adjustment of Signal Parameters: Allows users to adjust parameters for RSI and MACD indicators to see updated trading signals.
- Historical Prices and Signals: Displays the historical Bitcoin prices and trading signals with buy and sell indicators on a line chart.
- Downloadable CSV for Signals: Users can download the trading signals data in CSV format for further analysis.
- User
کد کامل بده بدون هیچ حرفی
- Assistant
- User
AttributeError: enter ارور برطرف کن و کد نهایی بده بدون هیچ حرفی
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.