Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import os | |
| import sys | |
| import requests | |
| # Add the 'utils' directory to sys.path so Python can find modules within it | |
| sys.path.append(os.path.join(os.path.dirname(__file__), "utils")) | |
| # Importing the necessary function | |
| from model_inference import generate_forex_signals | |
| from config import RISK_LEVELS # Assuming config.py defines risk levels if needed | |
| # List of allowed usernames | |
| ALLOWED_USERNAMES = ["ddilloud", "ved", "aditya", "karlmax", "bento"] | |
| # Streamlit page configuration | |
| st.set_page_config(page_title="AI Forex Bot", page_icon=":guardsman:", layout="wide") | |
| # Authentication logic | |
| if "authenticated" not in st.session_state: | |
| st.session_state.authenticated = False | |
| if not st.session_state.authenticated: | |
| st.title("Authentication Required") | |
| username = st.text_input("Enter your username", "") | |
| if st.button("Login"): | |
| if username in ALLOWED_USERNAMES: | |
| st.session_state.authenticated = True | |
| st.success("Login successful! Welcome!") | |
| else: | |
| st.error("Invalid username. Access denied.") | |
| else: | |
| # Title of the application | |
| st.title("AI Forex Trading Bot") | |
| # Description | |
| st.markdown(""" | |
| This tool is for informational purposes only and does not provide financial advice. Forex trading involves significant risk, including potential loss of capital. | |
| Users should exercise caution, conduct their own research, and consult a licensed financial advisor. Use at your own risk. | |
| """) | |
| # Automatically fetch the user's timezone using IPInfo API | |
| access_token = "37b621e95809fa" # Replace with your actual IPInfo API token | |
| try: | |
| response = requests.get(f"https://ipinfo.io/json?token={access_token}") | |
| response.raise_for_status() | |
| user_timezone = response.json().get("timezone", "UTC") | |
| except requests.exceptions.RequestException: | |
| user_timezone = "UTC" # Default to UTC if the API call fails | |
| # Sidebar for user inputs | |
| st.sidebar.header("User Input") | |
| # Get user trading capital | |
| trading_capital = st.sidebar.number_input("Enter Trading Capital (USD)", min_value=1, max_value=10000, value=1000) | |
| # Get user market risk level | |
| market_risk = st.sidebar.selectbox("Select Market Risk Level", options=["Low", "Medium", "High"]) | |
| # Display the detected timezone | |
| st.sidebar.write(f"**Detected Timezone**: {user_timezone}") | |
| # When the user presses the button, generate trading signals | |
| if st.sidebar.button("Get Trading Signals"): | |
| try: | |
| # Generate signals | |
| signals = generate_forex_signals(trading_capital, market_risk, user_timezone) | |
| # Display the best signal | |
| best_signal = signals["best_signal"] | |
| st.subheader("Best Recommended Forex Trade") | |
| st.write(f"**Currency Pair**: {best_signal['currency_pair']}") | |
| st.write(f"**Entry Time**: {best_signal['entry_time']}") | |
| st.write(f"**Exit Time**: {best_signal['exit_time']}") | |
| st.write(f"**ROI**: {best_signal['roi']}%") | |
| st.write(f"**Signal Strength**: {best_signal['signal_strength']}") | |
| # Display all signals | |
| st.subheader("All Generated Signals") | |
| for signal in signals["all_signals"]: | |
| st.write(f"**Currency Pair**: {signal['currency_pair']}") | |
| st.write(f"**Entry Time**: {signal['entry_time']}") | |
| st.write(f"**Exit Time**: {signal['exit_time']}") | |
| st.write(f"**ROI**: {signal['roi']}%") | |
| st.write(f"**Signal Strength**: {signal['signal_strength']}") | |
| st.markdown("---") | |
| except Exception as e: | |
| st.error(f"Error: {str(e)}") | |