Devendra21 commited on
Commit
a2a7548
·
verified ·
1 Parent(s): 9f2fedd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -53
app.py CHANGED
@@ -1,17 +1,11 @@
1
  import streamlit as st
2
  import os
3
  import sys
4
- import requests
5
 
6
  # Add the 'utils' directory to sys.path so Python can find modules within it
7
  sys.path.append(os.path.join(os.path.dirname(__file__), "utils"))
8
 
9
- # Importing the necessary function
10
  from utils.forex_signals import generate_forex_signals
11
- from config import RISK_LEVELS # Assuming config.py defines risk levels if needed
12
-
13
- # List of allowed usernames
14
- ALLOWED_USERNAMES = ["ddilloud", "ved", "aditya", "karlmax", "bento"]
15
 
16
  # Streamlit page configuration
17
  st.set_page_config(page_title="AI Forex Bot", page_icon=":guardsman:", layout="wide")
@@ -24,6 +18,8 @@ if not st.session_state.authenticated:
24
  st.title("Authentication Required")
25
  username = st.text_input("Enter your username", "")
26
  if st.button("Login"):
 
 
27
  if username in ALLOWED_USERNAMES:
28
  st.session_state.authenticated = True
29
  st.success("Login successful! Welcome!")
@@ -33,60 +29,42 @@ else:
33
  # Title of the application
34
  st.title("AI Forex Trading Bot")
35
 
36
- # Description
37
  st.markdown("""
38
- This tool is for informational purposes only and does not provide financial advice. Forex trading involves significant risk, including potential loss of capital.
39
- Users should exercise caution, conduct their own research, and consult a licensed financial advisor. Use at your own risk.
40
  """)
41
 
42
- # Automatically fetch the user's timezone using IPInfo API
43
- access_token = "37b621e95809fa" # Replace with your actual IPInfo API token
44
- try:
45
- response = requests.get(f"https://ipinfo.io/json?token={access_token}")
46
- response.raise_for_status()
47
- user_timezone = response.json().get("timezone", "UTC")
48
- except requests.exceptions.RequestException:
49
- user_timezone = "UTC" # Default to UTC if the API call fails
50
-
51
  # Sidebar for user inputs
52
  st.sidebar.header("User Input")
53
-
54
- # Get user trading capital
55
  trading_capital = st.sidebar.number_input("Enter Trading Capital (USD)", min_value=1, max_value=10000, value=1000)
 
 
 
 
 
56
 
57
- # Get user market risk level
58
- market_risk = st.sidebar.selectbox("Select Market Risk Level", options=["Low", "Medium", "High"])
59
-
60
- # Display the detected timezone
61
- st.sidebar.write(f"**Detected Timezone**: {user_timezone}")
62
-
63
- # When the user presses the button, generate trading signals
64
  if st.sidebar.button("Get Trading Signals"):
65
  try:
66
- # List of currency pairs to generate signals for
67
- additional_pairs = ['EUR/USD', 'GBP/USD', 'USD/JPY', 'AUD/USD', 'CAD/JPY', 'NZD/USD', 'CHF/JPY', 'AUD/JPY', 'GBP/CHF', 'EUR/GBP']
68
-
69
- # Generate signals
70
- signals = generate_forex_signals(trading_capital, market_risk, user_timezone, additional_pairs=additional_pairs)
71
-
72
- # Display the best signal
73
- best_signal = signals["best_signal"]
74
- st.subheader("Best Recommended Forex Trade")
75
- st.write(f"**Currency Pair**: {best_signal['currency_pair']}")
76
- st.write(f"**Entry Time**: {best_signal['entry_time']}")
77
- st.write(f"**Exit Time**: {best_signal['exit_time']}")
78
- st.write(f"**ROI**: {best_signal['roi']}%")
79
- st.write(f"**Signal Strength**: {best_signal['signal_strength']}")
80
-
81
- # Display all signals
82
- st.subheader("All Generated Signals")
83
- for signal in signals["all_signals"]:
84
- st.write(f"**Currency Pair**: {signal['currency_pair']}")
85
- st.write(f"**Entry Time**: {signal['entry_time']}")
86
- st.write(f"**Exit Time**: {signal['exit_time']}")
87
- st.write(f"**ROI**: {signal['roi']}%")
88
- st.write(f"**Signal Strength**: {signal['signal_strength']}")
89
- st.markdown("---")
90
  except Exception as e:
91
- st.error(f"Error: {str(e)}")
92
-
 
1
  import streamlit as st
2
  import os
3
  import sys
 
4
 
5
  # Add the 'utils' directory to sys.path so Python can find modules within it
6
  sys.path.append(os.path.join(os.path.dirname(__file__), "utils"))
7
 
 
8
  from utils.forex_signals import generate_forex_signals
 
 
 
 
9
 
10
  # Streamlit page configuration
11
  st.set_page_config(page_title="AI Forex Bot", page_icon=":guardsman:", layout="wide")
 
18
  st.title("Authentication Required")
19
  username = st.text_input("Enter your username", "")
20
  if st.button("Login"):
21
+ # Simple authentication
22
+ ALLOWED_USERNAMES = ["ddilloud", "ved", "aditya", "karlmax", "bento"]
23
  if username in ALLOWED_USERNAMES:
24
  st.session_state.authenticated = True
25
  st.success("Login successful! Welcome!")
 
29
  # Title of the application
30
  st.title("AI Forex Trading Bot")
31
 
 
32
  st.markdown("""
33
+ This tool provides forex trading signals based on AI analysis and is for informational purposes only.
34
+ Use at your own risk as forex trading involves substantial risk of loss.
35
  """)
36
 
 
 
 
 
 
 
 
 
 
37
  # Sidebar for user inputs
38
  st.sidebar.header("User Input")
 
 
39
  trading_capital = st.sidebar.number_input("Enter Trading Capital (USD)", min_value=1, max_value=10000, value=1000)
40
+ market_risk = st.sidebar.selectbox("Select Market Risk Level", ["Low", "Medium", "High"])
41
+ additional_pairs = [
42
+ "EUR/USD", "GBP/USD", "USD/JPY", "AUD/USD", "CAD/JPY",
43
+ "NZD/USD", "CHF/JPY", "AUD/JPY", "GBP/CHF", "EUR/GBP"
44
+ ]
45
 
 
 
 
 
 
 
 
46
  if st.sidebar.button("Get Trading Signals"):
47
  try:
48
+ signals = generate_forex_signals(trading_capital, market_risk, "UTC", additional_pairs)
49
+
50
+ if signals["best_signal"]:
51
+ best_signal = signals["best_signal"]
52
+ st.subheader("Best Recommended Forex Trade")
53
+ st.write(f"**Currency Pair**: {best_signal['currency_pair']}")
54
+ st.write(f"**Entry Time**: {best_signal['entry_time']}")
55
+ st.write(f"**Exit Time**: {best_signal['exit_time']}")
56
+ st.write(f"**ROI**: {best_signal['roi']}%")
57
+ st.write(f"**Signal Strength**: {best_signal['signal_strength']}")
58
+
59
+ st.subheader("All Generated Signals")
60
+ for signal in signals["all_signals"]:
61
+ st.write(f"**Currency Pair**: {signal['currency_pair']}")
62
+ st.write(f"**Entry Time**: {signal['entry_time']}")
63
+ st.write(f"**Exit Time**: {signal['exit_time']}")
64
+ st.write(f"**ROI**: {signal['roi']}%")
65
+ st.write(f"**Signal Strength**: {signal['signal_strength']}")
66
+ st.markdown("---")
67
+ else:
68
+ st.warning("No signals were generated. Please try again later.")
 
 
 
69
  except Exception as e:
70
+ st.error(f"An error occurred: {str(e)}")