Spaces:
Running
Running
Update utils/model_inference.py
Browse files- utils/model_inference.py +27 -9
utils/model_inference.py
CHANGED
@@ -2,10 +2,30 @@ import numpy as np
|
|
2 |
import pandas as pd
|
3 |
from datetime import datetime
|
4 |
import pytz
|
|
|
5 |
|
6 |
-
#
|
|
|
7 |
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
# Ensure the user timezone is valid
|
10 |
try:
|
11 |
user_tz = pytz.timezone(user_timezone)
|
@@ -13,7 +33,6 @@ def generate_forex_signals(trading_capital, market_risk, user_timezone):
|
|
13 |
raise ValueError("Invalid timezone entered. Please check the format.")
|
14 |
|
15 |
# Example of how you might process trading capital and risk level:
|
16 |
-
# Assume this logic is based on the user input for market risk
|
17 |
risk_level = {'Low': 0.01, 'Medium': 0.03, 'High': 0.05}
|
18 |
|
19 |
if market_risk not in risk_level:
|
@@ -21,14 +40,13 @@ def generate_forex_signals(trading_capital, market_risk, user_timezone):
|
|
21 |
|
22 |
risk_percentage = risk_level[market_risk]
|
23 |
|
24 |
-
# Perform model inference based on the user's inputs:
|
25 |
-
# For example, load the model and predict
|
26 |
-
# signal = model.predict(features)
|
27 |
-
|
28 |
# Dummy signal generation (Replace with your model inference logic)
|
29 |
currency_pair = "EUR/USD"
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
32 |
roi = np.random.uniform(5, 15) # Random ROI between 5% and 15%
|
33 |
signal_strength = np.random.uniform(0.7, 1.0) # Random strength between 0.7 and 1.0
|
34 |
|
|
|
2 |
import pandas as pd
|
3 |
from datetime import datetime
|
4 |
import pytz
|
5 |
+
import requests
|
6 |
|
7 |
+
# Access token for ipinfo.io
|
8 |
+
ACCESS_TOKEN = '37b621e95809fa'
|
9 |
|
10 |
+
# Function to get user timezone based on their IP address
|
11 |
+
def get_user_timezone():
|
12 |
+
try:
|
13 |
+
# Get the public IP address of the user
|
14 |
+
response = requests.get(f'https://ipinfo.io?token={ACCESS_TOKEN}')
|
15 |
+
data = response.json()
|
16 |
+
|
17 |
+
# Extract the timezone information from the response
|
18 |
+
user_timezone = data['timezone']
|
19 |
+
return user_timezone
|
20 |
+
except Exception as e:
|
21 |
+
print(f"Error fetching timezone: {e}")
|
22 |
+
return 'UTC' # Fallback to UTC if there's an error
|
23 |
+
|
24 |
+
# Function to generate forex signals
|
25 |
+
def generate_forex_signals(trading_capital, market_risk):
|
26 |
+
# Get the user's timezone based on their IP address
|
27 |
+
user_timezone = get_user_timezone()
|
28 |
+
|
29 |
# Ensure the user timezone is valid
|
30 |
try:
|
31 |
user_tz = pytz.timezone(user_timezone)
|
|
|
33 |
raise ValueError("Invalid timezone entered. Please check the format.")
|
34 |
|
35 |
# Example of how you might process trading capital and risk level:
|
|
|
36 |
risk_level = {'Low': 0.01, 'Medium': 0.03, 'High': 0.05}
|
37 |
|
38 |
if market_risk not in risk_level:
|
|
|
40 |
|
41 |
risk_percentage = risk_level[market_risk]
|
42 |
|
|
|
|
|
|
|
|
|
43 |
# Dummy signal generation (Replace with your model inference logic)
|
44 |
currency_pair = "EUR/USD"
|
45 |
+
|
46 |
+
# Get current time in the user's timezone and format it
|
47 |
+
entry_time = datetime.now(user_tz).strftime("%Y-%m-%d %I:%M:%S %p")
|
48 |
+
exit_time = (datetime.now(user_tz) + pd.Timedelta(hours=2)).strftime("%Y-%m-%d %I:%M:%S %p")
|
49 |
+
|
50 |
roi = np.random.uniform(5, 15) # Random ROI between 5% and 15%
|
51 |
signal_strength = np.random.uniform(0.7, 1.0) # Random strength between 0.7 and 1.0
|
52 |
|