Update ai.py
Browse files
ai.py
CHANGED
@@ -72,7 +72,7 @@ def fetch_pair_data(pair):
|
|
72 |
"""
|
73 |
Fetch data for a pair in multiple timeframes with appropriate time ranges:
|
74 |
- 15m: 3 days of data
|
75 |
-
-
|
76 |
|
77 |
Returns data for both timeframes or only what's available
|
78 |
"""
|
@@ -117,14 +117,14 @@ def fetch_pair_data(pair):
|
|
117 |
symbol=symbol,
|
118 |
start_date=five_min_start,
|
119 |
end_date=now,
|
120 |
-
interval="
|
121 |
)
|
122 |
|
123 |
if five_min_data['success']:
|
124 |
-
timeframes["
|
125 |
else:
|
126 |
-
print(f"⚠️ Failed to fetch
|
127 |
-
# Try 1-hour data as fallback if
|
128 |
try:
|
129 |
hour_start = now - timedelta(days=7) # Get a week of hourly data
|
130 |
hour_data = fetch_financial_data(
|
@@ -140,7 +140,7 @@ def fetch_pair_data(pair):
|
|
140 |
except Exception as e:
|
141 |
print(f"⚠️ Error fetching fallback 1h data for {pair}: {str(e)}")
|
142 |
except Exception as e:
|
143 |
-
print(f"⚠️ Error fetching
|
144 |
# Try 1-hour data as fallback
|
145 |
try:
|
146 |
hour_start = now - timedelta(days=7) # Get a week of hourly data
|
@@ -341,7 +341,7 @@ Also include if the current time is outside the required session overlap.
|
|
341 |
pair_data_added = False
|
342 |
|
343 |
# Add data for each available timeframe
|
344 |
-
for timeframe in ["15m", "
|
345 |
if timeframe in timeframes_data and timeframes_data[timeframe]['success']:
|
346 |
chat_history.append({
|
347 |
"role": "user",
|
|
|
72 |
"""
|
73 |
Fetch data for a pair in multiple timeframes with appropriate time ranges:
|
74 |
- 15m: 3 days of data
|
75 |
+
- 5min: 1 day of data
|
76 |
|
77 |
Returns data for both timeframes or only what's available
|
78 |
"""
|
|
|
117 |
symbol=symbol,
|
118 |
start_date=five_min_start,
|
119 |
end_date=now,
|
120 |
+
interval="5min"
|
121 |
)
|
122 |
|
123 |
if five_min_data['success']:
|
124 |
+
timeframes["5min"] = five_min_data
|
125 |
else:
|
126 |
+
print(f"⚠️ Failed to fetch 5min data for {pair}: {five_min_data['message']}")
|
127 |
+
# Try 1-hour data as fallback if 5min fails
|
128 |
try:
|
129 |
hour_start = now - timedelta(days=7) # Get a week of hourly data
|
130 |
hour_data = fetch_financial_data(
|
|
|
140 |
except Exception as e:
|
141 |
print(f"⚠️ Error fetching fallback 1h data for {pair}: {str(e)}")
|
142 |
except Exception as e:
|
143 |
+
print(f"⚠️ Error fetching 5min data for {pair}: {str(e)}")
|
144 |
# Try 1-hour data as fallback
|
145 |
try:
|
146 |
hour_start = now - timedelta(days=7) # Get a week of hourly data
|
|
|
341 |
pair_data_added = False
|
342 |
|
343 |
# Add data for each available timeframe
|
344 |
+
for timeframe in ["15m", "5min", "1h"]:
|
345 |
if timeframe in timeframes_data and timeframes_data[timeframe]['success']:
|
346 |
chat_history.append({
|
347 |
"role": "user",
|