Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- api_keys.json +4 -0
- app.py +507 -0
- requirements (1).txt +10 -0
- users.json +3 -0
api_keys.json
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"coinmarketcap_key": "bb9edc9f-53fe-4709-85d7-c51ade37920e",
|
| 3 |
+
"newsapi_key": "b19b9e2abfa34a158d6391d6c622d9b4"
|
| 4 |
+
}
|
app.py
ADDED
|
@@ -0,0 +1,507 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import numpy as np
|
| 6 |
+
import yfinance as yf
|
| 7 |
+
import datetime as dt
|
| 8 |
+
import pandas as pd
|
| 9 |
+
import pandas_ta as ta
|
| 10 |
+
from pytz import timezone
|
| 11 |
+
import plotly.graph_objects as go
|
| 12 |
+
from sklearn.linear_model import LinearRegression
|
| 13 |
+
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
| 14 |
+
from sklearn.model_selection import train_test_split
|
| 15 |
+
from sklearn.ensemble import RandomForestClassifier
|
| 16 |
+
from sklearn.metrics import accuracy_score
|
| 17 |
+
|
| 18 |
+
USERS_FILE = 'users.json'
|
| 19 |
+
API_KEYS_FILE = 'api_keys.json'
|
| 20 |
+
|
| 21 |
+
def load_users():
|
| 22 |
+
if not os.path.exists(USERS_FILE):
|
| 23 |
+
with open(USERS_FILE, 'w') as file:
|
| 24 |
+
json.dump({"users": []}, file)
|
| 25 |
+
with open(USERS_FILE, 'r') as file:
|
| 26 |
+
return json.load(file)
|
| 27 |
+
|
| 28 |
+
def save_users(users):
|
| 29 |
+
with open(USERS_FILE, 'w') as file:
|
| 30 |
+
json.dump(users, file)
|
| 31 |
+
|
| 32 |
+
def login(username, password):
|
| 33 |
+
users = load_users()
|
| 34 |
+
for user in users['users']:
|
| 35 |
+
if user['username'] == username and user['password'] == password:
|
| 36 |
+
return True
|
| 37 |
+
return False
|
| 38 |
+
|
| 39 |
+
def signup(username, password):
|
| 40 |
+
users = load_users()
|
| 41 |
+
for user in users['users']:
|
| 42 |
+
if user['username'] == username:
|
| 43 |
+
return False
|
| 44 |
+
users['users'].append({"username": username, "password": password})
|
| 45 |
+
save_users(users)
|
| 46 |
+
return True
|
| 47 |
+
|
| 48 |
+
def admin_login(username, password):
|
| 49 |
+
if username == "admin" and password == "admin":
|
| 50 |
+
return True
|
| 51 |
+
return False
|
| 52 |
+
|
| 53 |
+
def load_api_keys():
|
| 54 |
+
if not os.path.exists(API_KEYS_FILE):
|
| 55 |
+
with open(API_KEYS_FILE, 'w') as file:
|
| 56 |
+
json.dump({"newsapi_key": "", "coinmarketcap_key": ""}, file)
|
| 57 |
+
with open(API_KEYS_FILE, 'r') as file:
|
| 58 |
+
return json.load(file)
|
| 59 |
+
|
| 60 |
+
def save_api_keys(newsapi_key, coinmarketcap_key):
|
| 61 |
+
api_keys = load_api_keys()
|
| 62 |
+
api_keys['newsapi_key'] = newsapi_key
|
| 63 |
+
api_keys['coinmarketcap_key'] = coinmarketcap_key
|
| 64 |
+
with open(API_KEYS_FILE, 'w') as file:
|
| 65 |
+
json.dump(api_keys, file)
|
| 66 |
+
|
| 67 |
+
def get_crypto_news(api_key, crypto_symbol, sort_by='publishedAt'):
|
| 68 |
+
url = f"https://newsapi.org/v2/everything?q={crypto_symbol}&apiKey={api_key}&language=en&sortBy={sort_by}"
|
| 69 |
+
response = requests.get(url)
|
| 70 |
+
if response.status_code == 200:
|
| 71 |
+
news_data = response.json()
|
| 72 |
+
articles = news_data.get('articles', [])
|
| 73 |
+
crypto_news = []
|
| 74 |
+
for article in articles:
|
| 75 |
+
title = article.get('title', 'No Title')
|
| 76 |
+
description = article.get('description', 'No Description')
|
| 77 |
+
url = article.get('url', '#')
|
| 78 |
+
published_at = article.get('publishedAt', 'No Date')
|
| 79 |
+
relevancy = article.get('relevancy', 'unknown') # Ensure 'relevancy' is present
|
| 80 |
+
popularity = article.get('popularity', 'unknown') # Ensure 'popularity' is present
|
| 81 |
+
crypto_news.append({
|
| 82 |
+
"title": title,
|
| 83 |
+
"description": description,
|
| 84 |
+
"url": url,
|
| 85 |
+
"publishedAt": published_at,
|
| 86 |
+
"relevancy": relevancy,
|
| 87 |
+
"popularity": popularity
|
| 88 |
+
})
|
| 89 |
+
return crypto_news
|
| 90 |
+
else:
|
| 91 |
+
return []
|
| 92 |
+
|
| 93 |
+
def analyze_news_sentiment(news):
|
| 94 |
+
analyzer = SentimentIntensityAnalyzer()
|
| 95 |
+
for article in news:
|
| 96 |
+
title = article['title']
|
| 97 |
+
description = article['description']
|
| 98 |
+
sentiment_score = analyzer.polarity_scores(title + " " + description)
|
| 99 |
+
article['sentiment'] = sentiment_score
|
| 100 |
+
return news
|
| 101 |
+
|
| 102 |
+
def train_price_prediction_model(data):
|
| 103 |
+
X = data[['Open', 'High', 'Low', 'Volume']]
|
| 104 |
+
y = data['Close']
|
| 105 |
+
model = LinearRegression()
|
| 106 |
+
model.fit(X, y)
|
| 107 |
+
return model
|
| 108 |
+
|
| 109 |
+
def predict_crypto_price(data, model):
|
| 110 |
+
latest_data = data.iloc[-1]
|
| 111 |
+
latest_features = latest_data[['Open', 'High', 'Low', 'Volume']].values.reshape(1, -1)
|
| 112 |
+
predicted_price = model.predict(latest_features)[0]
|
| 113 |
+
return predicted_price
|
| 114 |
+
|
| 115 |
+
def analyze_indicators(data):
|
| 116 |
+
if 'Close' in data:
|
| 117 |
+
data['RSI'] = ta.rsi(data['Close'], length=14)
|
| 118 |
+
data['Stochastic'] = ta.stoch(data['High'], data['Low'], data['Close'], k=14, d=3)['STOCHk_14_3_3']
|
| 119 |
+
macd = ta.macd(data['Close'], fast=12, slow=26, signal=9)
|
| 120 |
+
data['MACD'] = macd['MACD_12_26_9']
|
| 121 |
+
data['SMA'] = ta.sma(data['Close'], length=50)
|
| 122 |
+
data['EMA'] = ta.ema(data['Close'], length=50)
|
| 123 |
+
else:
|
| 124 |
+
data['RSI'] = pd.Series([None]*len(data))
|
| 125 |
+
data['Stochastic'] = pd.Series([None]*len(data))
|
| 126 |
+
data['MACD'] = pd.Series([None]*len(data))
|
| 127 |
+
data['SMA'] = pd.Series([None]*len(data))
|
| 128 |
+
data['EMA'] = pd.Series([None]*len(data))
|
| 129 |
+
return data
|
| 130 |
+
|
| 131 |
+
def calculate_indicators(data):
|
| 132 |
+
data['MA'] = data['Close'].rolling(window=10).mean()
|
| 133 |
+
data['CCI'] = (data['Close'] - data['Close'].rolling(window=20).mean()) / (0.015 * data['Close'].rolling(window=20).std())
|
| 134 |
+
data['MACD'] = data['Close'].ewm(span=12, adjust=False).mean() - data['Close'].ewm(span=26, adjust=False).mean()
|
| 135 |
+
return data
|
| 136 |
+
|
| 137 |
+
def generate_signals(data):
|
| 138 |
+
buy_signal = None
|
| 139 |
+
sell_signal = None
|
| 140 |
+
|
| 141 |
+
# محاسبه اندیکاتورها
|
| 142 |
+
data = calculate_indicators(data)
|
| 143 |
+
data.dropna(inplace=True)
|
| 144 |
+
|
| 145 |
+
# آمادهسازی ویژگیها و برچسبها
|
| 146 |
+
features = data[['RSI', 'Stochastic', 'MA', 'CCI', 'MACD']]
|
| 147 |
+
labels = ((data['RSI'] < 30) & (data['Stochastic'] < 20)).astype(int) - ((data['RSI'] > 70) & (data['Stochastic'] > 80)).astype(int)
|
| 148 |
+
|
| 149 |
+
# تقسیم دادههای آموزش و تست
|
| 150 |
+
X_train, X_test, y_train, y_test = train_test_split(features, labels, test_size=0.2, random_state=42)
|
| 151 |
+
|
| 152 |
+
# آموزش مدل RandomForest
|
| 153 |
+
model = RandomForestClassifier(n_estimators=100, random_state=42)
|
| 154 |
+
model.fit(X_train, y_train)
|
| 155 |
+
|
| 156 |
+
# پیشبینی و ارزیابی مدل
|
| 157 |
+
y_pred = model.predict(X_test)
|
| 158 |
+
accuracy = accuracy_score(y_test, y_pred)
|
| 159 |
+
|
| 160 |
+
if 0.8 <= accuracy <= 1.0:
|
| 161 |
+
latest_data = data.iloc[-1]
|
| 162 |
+
prediction = model.predict([latest_data[['RSI', 'Stochastic', 'MA', 'CCI', 'MACD']].values])
|
| 163 |
+
|
| 164 |
+
if prediction == 1:
|
| 165 |
+
buy_signal = (latest_data.name, latest_data['Close'], latest_data['Close'] * 0.95, "High Risk", 3)
|
| 166 |
+
elif prediction == -1:
|
| 167 |
+
sell_signal = (latest_data.name, latest_data['Close'], latest_data['Close'] * 1.05, "High Risk", 3)
|
| 168 |
+
|
| 169 |
+
return buy_signal, sell_signal
|
| 170 |
+
|
| 171 |
+
def get_fear_and_greed_index():
|
| 172 |
+
response = requests.get("https://api.alternative.me/fng/?limit=1")
|
| 173 |
+
if response.status_code == 200:
|
| 174 |
+
return response.json()["data"][0]["value"]
|
| 175 |
+
else:
|
| 176 |
+
return None
|
| 177 |
+
|
| 178 |
+
def get_crypto_data_from_coinmarketcap(api_key, crypto_symbol):
|
| 179 |
+
url = "https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest"
|
| 180 |
+
parameters = {'symbol': crypto_symbol, 'convert': 'USD'}
|
| 181 |
+
headers = {'Accepts': 'application/json', 'X-CMC_PRO_API_KEY': api_key}
|
| 182 |
+
response = requests.get(url, headers=headers, params=parameters)
|
| 183 |
+
data = response.json()
|
| 184 |
+
return data['data'][crypto_symbol]['quote']['USD']
|
| 185 |
+
|
| 186 |
+
def display_time_information(language):
|
| 187 |
+
if language == "English":
|
| 188 |
+
st.subheader("Time Information")
|
| 189 |
+
st.write("Below are the current times for different global markets and the best trading time in Iran.")
|
| 190 |
+
else:
|
| 191 |
+
st.subheader("اطلاعات زمان")
|
| 192 |
+
st.write("در زیر زمانهای فعلی برای بازارهای جهانی و بهترین زمان معامله در ایران آورده شده است.")
|
| 193 |
+
|
| 194 |
+
iran_tz = timezone('Asia/Tehran')
|
| 195 |
+
utc_tz = timezone('UTC')
|
| 196 |
+
japan_tz = timezone('Asia/Tokyo')
|
| 197 |
+
europe_tz = timezone('Europe/Berlin')
|
| 198 |
+
us_tz = timezone('America/New_York')
|
| 199 |
+
|
| 200 |
+
iran_time = dt.datetime.now(iran_tz).strftime('%H:%M:%S')
|
| 201 |
+
utc_time = dt.datetime.now(utc_tz).strftime('%H:%M:%S')
|
| 202 |
+
japan_open = dt.datetime.now(japan_tz).replace(hour=9, minute=0, second=0, microsecond=0).strftime('%H:%M:%S')
|
| 203 |
+
europe_open = dt.datetime.now(europe_tz).replace(hour=8, minute=0, second=0, microsecond=0).strftime('%H:%M:%S')
|
| 204 |
+
us_open = dt.datetime.now(us_tz).replace(hour=9, minute=30, second=0, microsecond=0).strftime('%H:%M:%S')
|
| 205 |
+
|
| 206 |
+
if language == "English":
|
| 207 |
+
st.write(f"Iran Time: {iran_time}")
|
| 208 |
+
st.write(f"UTC Time: {utc_time}")
|
| 209 |
+
|
| 210 |
+
st.subheader("Global Crypto Markets Open Times")
|
| 211 |
+
data = {
|
| 212 |
+
"Country": ["Japan", "Europe", "USA"],
|
| 213 |
+
"Open Time": [japan_open, europe_open, us_open]
|
| 214 |
+
}
|
| 215 |
+
df = pd.DataFrame(data)
|
| 216 |
+
st.table(df)
|
| 217 |
+
|
| 218 |
+
st.subheader("Best Trading Time in Iran")
|
| 219 |
+
st.write("The best time for trading in Iran is when the global crypto markets are active, especially during the overlapping hours of the European and American markets.")
|
| 220 |
+
else:
|
| 221 |
+
st.write(f"زمان ایران: {iran_time}")
|
| 222 |
+
st.write(f"زمان هماهنگ جهانی: {utc_time}")
|
| 223 |
+
|
| 224 |
+
st.subheader("زمان باز شدن بازارهای جهانی ارز دیجیتال")
|
| 225 |
+
data = {
|
| 226 |
+
"کشور": ["ژاپن", "اروپا", "آمریکا"],
|
| 227 |
+
"زمان باز شدن": [japan_open, europe_open, us_open]
|
| 228 |
+
}
|
| 229 |
+
df = pd.DataFrame(data)
|
| 230 |
+
st.table(df)
|
| 231 |
+
|
| 232 |
+
st.subheader("بهترین زمان معامله در ایران")
|
| 233 |
+
st.write("بهترین زمان برای معامله در ایران زمانی است که بازارهای جهانی ارز دیجیتال فعال هستند، به ویژه در ساعت های همپوشانی بازارهای اروپا و آمریکا.")
|
| 234 |
+
|
| 235 |
+
def generate_learning_tips(language):
|
| 236 |
+
tips = [
|
| 237 |
+
{"en": "Diversify your portfolio to manage risk effectively.", "fa": "سبد سرمایهگذاری خود را متنوع کنید تا ریسک را به طور مؤثری مدیریت کنید."},
|
| 238 |
+
{"en": "Use technical analysis to identify market trends.", "fa": "از تحلیل تکنیکال برای شناسایی روندهای بازار استفاده کنید."},
|
| 239 |
+
{"en": "Stay updated with the latest news in the crypto world.", "fa": "با آخرین اخبار دنیای ارز دیجیتال بهروز باشید."},
|
| 240 |
+
{"en": "Understand the fundamentals of the cryptocurrencies you invest in.", "fa": "اصول اولیه ارزهای دیجیتالی که در آنها سرمایهگذاری میکنید را درک کنید."},
|
| 241 |
+
{"en": "Use stop-loss orders to protect your investments.", "fa": "از دستورات توقف ضرر برای محافظت از سرمایهگذاریهای خود استفاده کنید."},
|
| 242 |
+
{"en": "Regularly review your investment strategy and adjust as needed.", "fa": "استراتژی سرمایهگذاری خود را به طور منظم بازبینی کنید و در صورت نیاز آن را تنظیم کنید."},
|
| 243 |
+
{"en": "Don't invest more than you can afford to lose.", "fa": "بیش از آنچه که میتوانید از دست بدهید سرمایهگذاری نکنید."}
|
| 244 |
+
]
|
| 245 |
+
|
| 246 |
+
if language == "English":
|
| 247 |
+
st.subheader("Learning Tips")
|
| 248 |
+
for tip in tips:
|
| 249 |
+
st.write(f"- {tip['en']}")
|
| 250 |
+
else:
|
| 251 |
+
st.subheader("نکات آموزشی")
|
| 252 |
+
for tip in tips:
|
| 253 |
+
st.write(f"- {tip['fa']}")
|
| 254 |
+
|
| 255 |
+
def main():
|
| 256 |
+
st.title("Crypto Trading Dashboard")
|
| 257 |
+
#زبان ها
|
| 258 |
+
language = st.sidebar.selectbox("Select Language / زبان را انتخاب کنید", ("English", "فارسی"))
|
| 259 |
+
#منو کار
|
| 260 |
+
menu = ["Home", "Login", "SignUp", "Admin", "Time", "Charts", "Market Data", "News"]
|
| 261 |
+
choice = st.sidebar.selectbox("Menu", menu)
|
| 262 |
+
|
| 263 |
+
if choice == "Home":
|
| 264 |
+
if language == "English":
|
| 265 |
+
st.subheader("Welcome to the Crypto Trading Dashboard")
|
| 266 |
+
st.write("""
|
| 267 |
+
This dashboard provides you with tools and insights to trade cryptocurrencies effectively.
|
| 268 |
+
You can track prices, perform technical analysis, get buy/sell signals, predict prices, and stay updated with the latest news.
|
| 269 |
+
Use the sidebar to navigate through different sections.
|
| 270 |
+
""")
|
| 271 |
+
st.write("Website: [Taha Tehrani Nasab](https://ththt.ir)")
|
| 272 |
+
st.write("© 2024 FTN. All rights reserved.")
|
| 273 |
+
else:
|
| 274 |
+
st.subheader("به داشبورد معاملات ارز دیجیتال خوش آمدید")
|
| 275 |
+
st.write("""
|
| 276 |
+
این داشبورد ابزارها و بینشهایی را برای تجارت ارزهای دیجیتال به شما ارائه میدهد.
|
| 277 |
+
میتوانید قیمتها را پیگیری کنید، تحلیل تکنیکال انجام دهید، سیگنالهای خرید/فروش دریافت کنید، قیمتها را پیشبینی کنید و با آخرین اخبار بهروز باشید.
|
| 278 |
+
از نوار کناری برای پیمایش در بخشهای مختلف استفاده کنید.
|
| 279 |
+
""")
|
| 280 |
+
st.write("وبسایت: [Taha Tehrani nasab](https://ththt.ir)")
|
| 281 |
+
st.write("© 2024 Taha Tehrani Nasab. تمامی حقوق محفوظ است.")
|
| 282 |
+
|
| 283 |
+
elif choice == "Login":
|
| 284 |
+
if language == "English":
|
| 285 |
+
st.subheader("Login Section")
|
| 286 |
+
else:
|
| 287 |
+
st.subheader("بخش ورود")
|
| 288 |
+
|
| 289 |
+
username = st.sidebar.text_input("Username / نام کاربری")
|
| 290 |
+
password = st.sidebar.text_input("Password / رمز عبور", type='password')
|
| 291 |
+
|
| 292 |
+
if st.sidebar.checkbox("Login"):
|
| 293 |
+
if login(username, password):
|
| 294 |
+
st.success("Logged in as {}".format(username))
|
| 295 |
+
|
| 296 |
+
if language == "English":
|
| 297 |
+
st.subheader("Select Cryptocurrency")
|
| 298 |
+
else:
|
| 299 |
+
st.subheader("انتخاب ارز دیجیتال")
|
| 300 |
+
|
| 301 |
+
crypto_symbol = st.selectbox("Cryptocurrency Symbol", ["BTC", "ETH", "LTC", "BCH"])
|
| 302 |
+
|
| 303 |
+
end_date = dt.datetime.now()
|
| 304 |
+
start_date = end_date - dt.timedelta(days=365)
|
| 305 |
+
|
| 306 |
+
data = yf.download(crypto_symbol + "-USD", start=start_date, end=end_date)
|
| 307 |
+
|
| 308 |
+
if language == "English":
|
| 309 |
+
st.subheader(f"Price Data for {crypto_symbol}")
|
| 310 |
+
else:
|
| 311 |
+
st.subheader(f"دادههای قیمت برای {crypto_symbol}")
|
| 312 |
+
|
| 313 |
+
st.write(data.tail())
|
| 314 |
+
|
| 315 |
+
if language == "English":
|
| 316 |
+
st.subheader(f"Technical Analysis for {crypto_symbol}")
|
| 317 |
+
else:
|
| 318 |
+
st.subheader(f"تحلیل تکنیکال برای {crypto_symbol}")
|
| 319 |
+
|
| 320 |
+
data = analyze_indicators(data)
|
| 321 |
+
st.write(data[['RSI', 'Stochastic', 'MACD', 'SMA', 'EMA']].tail())
|
| 322 |
+
|
| 323 |
+
if language == "English":
|
| 324 |
+
st.subheader("Buy/Sell Signals")
|
| 325 |
+
else:
|
| 326 |
+
st.subheader("سیگنالهای خرید/فروش")
|
| 327 |
+
|
| 328 |
+
buy_signal, sell_signal = generate_signals(data)
|
| 329 |
+
if buy_signal:
|
| 330 |
+
st.success(f"Buy Signal: {buy_signal}")
|
| 331 |
+
if sell_signal:
|
| 332 |
+
st.error(f"Sell Signal: {sell_signal}")
|
| 333 |
+
|
| 334 |
+
if language == "English":
|
| 335 |
+
st.subheader("Price Prediction")
|
| 336 |
+
else:
|
| 337 |
+
st.subheader("پیشبینی قیمت")
|
| 338 |
+
|
| 339 |
+
model = train_price_prediction_model(data)
|
| 340 |
+
predicted_price = predict_crypto_price(data, model)
|
| 341 |
+
|
| 342 |
+
if language == "English":
|
| 343 |
+
st.write(f"The predicted price for the next trading day is: ${predicted_price:.2f}")
|
| 344 |
+
else:
|
| 345 |
+
st.write(f"قیمت پیشبینی شده برای روز معاملاتی بعدی: ${predicted_price:.2f}")
|
| 346 |
+
|
| 347 |
+
if language == "English":
|
| 348 |
+
st.subheader("Fear and Greed Index")
|
| 349 |
+
else:
|
| 350 |
+
st.subheader("شاخص ترس و طمع")
|
| 351 |
+
|
| 352 |
+
fear_and_greed_index = get_fear_and_greed_index()
|
| 353 |
+
if fear_and_greed_index:
|
| 354 |
+
st.write(f"The current Fear and Greed Index is: {fear_and_greed_index}")
|
| 355 |
+
else:
|
| 356 |
+
if language == "English":
|
| 357 |
+
st.write("Could not retrieve the Fear and Greed Index.")
|
| 358 |
+
else:
|
| 359 |
+
st.write("امکان دریافت شاخص ترس و طمع وجود ندارد.")
|
| 360 |
+
else:
|
| 361 |
+
if language == "English":
|
| 362 |
+
st.warning("Incorrect Username/Password")
|
| 363 |
+
else:
|
| 364 |
+
st.warning("نام کاربری/رمز عبور اشتباه است")
|
| 365 |
+
|
| 366 |
+
elif choice == "SignUp":
|
| 367 |
+
if language == "English":
|
| 368 |
+
st.subheader("Create a New Account")
|
| 369 |
+
else:
|
| 370 |
+
st.subheader("ایجاد حساب جدید")
|
| 371 |
+
|
| 372 |
+
new_user = st.text_input("Username / نام کاربری")
|
| 373 |
+
new_password = st.text_input("Password / رمز عبور", type='password')
|
| 374 |
+
if st.button("Sign Up"):
|
| 375 |
+
if signup(new_user, new_password):
|
| 376 |
+
if language == "English":
|
| 377 |
+
st.success("Account created successfully. You can now log in.")
|
| 378 |
+
else:
|
| 379 |
+
st.success("حساب با موفقیت ایجاد شد. اکنون میتوانید وارد شوید.")
|
| 380 |
+
else:
|
| 381 |
+
if language == "English":
|
| 382 |
+
st.warning("Username already exists. Please choose another.")
|
| 383 |
+
else:
|
| 384 |
+
st.warning("نام کاربری از قبل وجود دارد. لطفاً نام دیگری انتخاب کنید.")
|
| 385 |
+
|
| 386 |
+
elif choice == "Admin":
|
| 387 |
+
if language == "English":
|
| 388 |
+
st.subheader("Admin Section")
|
| 389 |
+
else:
|
| 390 |
+
st.subheader("بخش مدیریت")
|
| 391 |
+
|
| 392 |
+
username = st.sidebar.text_input("Admin Username / نام کاربری مدیر")
|
| 393 |
+
password = st.sidebar.text_input("Admin Password / رمز عبور مدیر", type='password')
|
| 394 |
+
if st.sidebar.checkbox("Login"):
|
| 395 |
+
if admin_login(username, password):
|
| 396 |
+
if language == "English":
|
| 397 |
+
st.success("Admin login successful")
|
| 398 |
+
st.subheader("Set API Keys")
|
| 399 |
+
else:
|
| 400 |
+
st.success("ورود مدیر موفقیتآمیز بود")
|
| 401 |
+
st.subheader("تنظیم کلیدهای API")
|
| 402 |
+
|
| 403 |
+
newsapi_key = st.text_input("NewsAPI Key")
|
| 404 |
+
coinmarketcap_key = st.text_input("CoinMarketCap Key")
|
| 405 |
+
if st.button("Save API Keys"):
|
| 406 |
+
save_api_keys(newsapi_key, coinmarketcap_key)
|
| 407 |
+
if language == "English":
|
| 408 |
+
st.success("API keys saved successfully")
|
| 409 |
+
else:
|
| 410 |
+
st.success("کلیدهای API با موفقیت ذخیره شد")
|
| 411 |
+
else:
|
| 412 |
+
if language == "English":
|
| 413 |
+
st.warning("Incorrect Admin Username/Password")
|
| 414 |
+
else:
|
| 415 |
+
st.warning("نام کاربری/رمز عبور مدیر اشتباه است")
|
| 416 |
+
|
| 417 |
+
elif choice == "Time":
|
| 418 |
+
display_time_information(language)
|
| 419 |
+
generate_learning_tips(language)
|
| 420 |
+
|
| 421 |
+
elif choice == "Charts":
|
| 422 |
+
if language == "English":
|
| 423 |
+
st.subheader("Cryptocurrency Charts")
|
| 424 |
+
else:
|
| 425 |
+
st.subheader("نمودارهای ارز دیجیتال")
|
| 426 |
+
|
| 427 |
+
crypto_symbol = st.selectbox("Cryptocurrency Symbol", ["BTC", "ETH", "LTC", "BCH", "TON","NOT"])
|
| 428 |
+
end_date = dt.datetime.now()
|
| 429 |
+
start_date = end_date - dt.timedelta(days=365)
|
| 430 |
+
data = yf.download(crypto_symbol + "-USD", start=start_date, end=end_date)
|
| 431 |
+
|
| 432 |
+
if language == "English":
|
| 433 |
+
st.subheader(f"{crypto_symbol} TradingView-like Chart")
|
| 434 |
+
else:
|
| 435 |
+
st.subheader(f"نمودار شبیه TradingView برای {crypto_symbol}")
|
| 436 |
+
|
| 437 |
+
fig1 = go.Figure(data=[go.Candlestick(x=data.index,
|
| 438 |
+
open=data['Open'],
|
| 439 |
+
high=data['High'],
|
| 440 |
+
low=data['Low'],
|
| 441 |
+
close=data['Close'])])
|
| 442 |
+
st.plotly_chart(fig1)
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
elif choice == "Market Data":
|
| 446 |
+
if language == "English":
|
| 447 |
+
st.subheader("Cryptocurrency Market Data")
|
| 448 |
+
else:
|
| 449 |
+
st.subheader("دادههای بازار ارز دیجیتال")
|
| 450 |
+
|
| 451 |
+
crypto_symbol = st.selectbox("Cryptocurrency Symbol", ["BTC", "ETH", "LTC", "BCH","TON","NOT"])
|
| 452 |
+
api_keys = load_api_keys()
|
| 453 |
+
if 'coinmarketcap_key' in api_keys and api_keys['coinmarketcap_key']:
|
| 454 |
+
market_data = get_crypto_data_from_coinmarketcap(api_keys['coinmarketcap_key'], crypto_symbol)
|
| 455 |
+
if language == "English":
|
| 456 |
+
st.write(f"Price: ${market_data['price']:.2f}")
|
| 457 |
+
st.write(f"Market Cap: ${market_data['market_cap']:.2f}")
|
| 458 |
+
st.write(f"24h Volume: ${market_data['volume_24h']:.2f}")
|
| 459 |
+
st.write(f"Change (24h): {market_data['percent_change_24h']:.2f}%")
|
| 460 |
+
else:
|
| 461 |
+
st.write(f"قیمت: ${market_data['price']:.2f}")
|
| 462 |
+
st.write(f"ارزش بازار: ${market_data['market_cap']:.2f}")
|
| 463 |
+
st.write(f"حجم معاملات 24 ساعته: ${market_data['volume_24h']:.2f}")
|
| 464 |
+
st.write(f"تغییرات (24 ساعت): {market_data['percent_change_24h']:.2f}%")
|
| 465 |
+
else:
|
| 466 |
+
if language == "English":
|
| 467 |
+
st.warning("API key for CoinMarketCap is not set. Please contact the admin.")
|
| 468 |
+
else:
|
| 469 |
+
st.warning("کلید API برای CoinMarketCap تنظیم نشده است. لطفاً با مدیر تماس بگیرید.")
|
| 470 |
+
|
| 471 |
+
elif choice == "News":
|
| 472 |
+
if language == "English":
|
| 473 |
+
st.subheader("Cryptocurrency News")
|
| 474 |
+
else:
|
| 475 |
+
st.subheader("اخبار ارز دیجیتال")
|
| 476 |
+
|
| 477 |
+
crypto_symbol = st.selectbox("Cryptocurrency Symbol", ["BTC", "ETH", "LTC", "BCH"])
|
| 478 |
+
api_keys = load_api_keys()
|
| 479 |
+
if 'newsapi_key' in api_keys and api_keys['newsapi_key']:
|
| 480 |
+
news = get_crypto_news(api_keys['newsapi_key'], crypto_symbol)
|
| 481 |
+
news = analyze_news_sentiment(news)
|
| 482 |
+
|
| 483 |
+
# Sorting and categorizing news
|
| 484 |
+
sort_by = st.radio("Sort News By", ("publishedAt", "relevancy", "popularity"), index=0)
|
| 485 |
+
news = sorted(news, key=lambda x: x[sort_by])
|
| 486 |
+
|
| 487 |
+
if language == "English":
|
| 488 |
+
st.subheader(f"News for {crypto_symbol}")
|
| 489 |
+
else:
|
| 490 |
+
st.subheader(f"اخبار برای {crypto_symbol}")
|
| 491 |
+
# Paginate news
|
| 492 |
+
page = st.slider("Select page", min_value=1, max_value=(len(news) // 5) + 1)
|
| 493 |
+
news_to_display = news[(page - 1) * 5: page * 5]
|
| 494 |
+
|
| 495 |
+
for article in news_to_display:
|
| 496 |
+
st.write(f"Title: {article['title']}")
|
| 497 |
+
st.write(f"Description: {article['description']}")
|
| 498 |
+
st.write(f"Sentiment: {article['sentiment']}")
|
| 499 |
+
st.write(f"Published At: {article['publishedAt']}")
|
| 500 |
+
st.write(f"Read more: [Link]({article['url']})")
|
| 501 |
+
else:
|
| 502 |
+
if language == "English":
|
| 503 |
+
st.warning("API key for NewsAPI is not set. Please contact the admin.")
|
| 504 |
+
else:
|
| 505 |
+
st.warning("کلید API برای NewsAPI تنظیم نشده است. لطفاً با مدیر تماس بگیرید.")
|
| 506 |
+
if __name__ == '__main__':
|
| 507 |
+
main()
|
requirements (1).txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
yfinance
|
| 3 |
+
plotly
|
| 4 |
+
pandas
|
| 5 |
+
pandas_ta
|
| 6 |
+
pytz
|
| 7 |
+
numpy
|
| 8 |
+
requests
|
| 9 |
+
scikit-learn
|
| 10 |
+
vaderSentiment
|
users.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"users": []
|
| 3 |
+
}
|