Dooratre commited on
Commit
573350a
·
verified ·
1 Parent(s): 0833d4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -14
app.py CHANGED
@@ -3,7 +3,7 @@ import requests
3
  import json
4
  import time
5
  import xml.etree.ElementTree as ET
6
- from datetime import datetime
7
  import pytz
8
  import logging
9
  import re
@@ -107,6 +107,15 @@ def get_time_zones():
107
 
108
  return times
109
 
 
 
 
 
 
 
 
 
 
110
  def capture_charts():
111
  """التقاط صور المؤشرات"""
112
  urls = [
@@ -167,12 +176,14 @@ def build_chat_history(alert_message=None):
167
 
168
 
169
  بداية مهمتك هي اما انشاء صفقة او انتظار
170
- في حالة المستخدم حاليا في صفقة يرجى متابعتها وذكر نقاط سواء ربح خسارة او اغلاقها الخ...
171
 
172
  ممنوع منعا باتا ان تنشئ صفقة أخرى مدام المستخدم في صفقة حاليا
173
 
174
  ردك سيكون عبارة عن XML لا غير وهي المفاتيح الأساسية لتحريك النظام هنا شرحها
175
 
 
 
176
  اولا الانتظار :
177
 
178
  <wait>تستخدم هذه في حالة ان المستخدم ينتظر منك انشاء صفقة ولاكن تحليلك يقول ان ليس الوقت المناسب ضع هنا سبب عدم وجود صفقة
@@ -226,17 +237,17 @@ if the user in trade now you need to use the alert as your weapon to know what h
226
  message from developer :
227
 
228
 
229
- we need to focus the price now where will go the price for (NOW) don't give strategy for another price up or down no no that is bad strategy and we will not get our goal
230
 
231
- so what we need is analysis and predction where the price gonna go with some IFs
232
 
233
- most you strategy make our another model can generate PRO trade by your strategy and queck
234
 
235
  the something worest now we get is for example price now 3335
236
 
237
- your analysis say you need to buy if the price 3348
238
 
239
- i don't want this shit i want you to predcion if gonna go up to take the pips from 35 to 48 i want it
240
 
241
  do you understand ??
242
 
@@ -318,7 +329,18 @@ do you understand ??
318
  message_content += f"الدخول: {current_signal.get('entry', 'N/A')}\n"
319
  message_content += f"وقف الخسارة: {current_signal.get('stop_loss', 'N/A')}\n"
320
  message_content += f"الهدف: {current_signal.get('take_profit', 'N/A')}\n"
321
- message_content += f"\n( يرجى التركيز على هذه الصفقة ومراجعتها او اغلاقها، وممنوع انشاء صفقة اخرى الا اذا تعتقد سيحصل عكس التوقغات هنا يجب عليك اغلاق و انشاءاخرى)\n\nTIME NOW : {time_info}\nif the user in trade now you need to use the alert as your weapon to know what happen to the trade by use it for 10 30 50 pip like you want but so close to see what happen to the trade"
 
 
 
 
 
 
 
 
 
 
 
322
  else:
323
  message_content += f" you need to make the signal about SL about 10 mean 1$ okay the pips in gold 100 pip mean 10$ you need to create signals with stop lose max 5 $ and TP to the 100pip mean 10$ 20 30 and TP from 70 80 100 ...المستخدم ليس في اي صفقة حاليا\n\nTIME NOW : {time_info}"
324
 
@@ -391,9 +413,11 @@ def parse_ai_response(ai_response):
391
  signal_data = {
392
  "pair": pair_match.group(1).strip(),
393
  "type": type_match.group(1).strip(),
394
- "entry": entry_match.group(1).strip(),
395
- "stop_loss": sl_match.group(1).strip(),
396
- "take_profit": tp_match.group(1).strip()
 
 
397
  }
398
 
399
  # حفظ الإشارة
@@ -403,12 +427,20 @@ def parse_ai_response(ai_response):
403
  result = db_signals.update_user_json_file(auth_token, commit_oid, new_signal)
404
 
405
  if result["success"]:
406
- # إرسال رسالة للمستخدمين
 
 
 
 
 
 
407
  signal_message = f"🚨 إشارة جديدة XAUUSD\n\n"
408
  signal_message += f"📊 النوع: {signal_data['type']}\n"
409
  signal_message += f"🎯 الدخول: {signal_data['entry']}\n"
410
  signal_message += f"🛑 وقف الخسارة: {signal_data['stop_loss']}\n"
411
- signal_message += f"💰 الهدف: {signal_data['take_profit']}"
 
 
412
 
413
  send_result = send_message_to_api(signal_message)
414
  if send_result["success"]:
@@ -503,6 +535,20 @@ def parse_ai_response(ai_response):
503
 
504
  return actions_performed
505
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
506
  def count_xml_tags(ai_response):
507
  """عد عدد كل XML tag في الرد لأغراض التسجيل"""
508
  counts = {
@@ -673,7 +719,7 @@ def index():
673
  "/test_actions": "اختبار معالجة XML tags (POST)",
674
  "/health": "فحص حالة النظام (GET)"
675
  },
676
- "version": "2.0.0",
677
  "execution_priority": "close_trade → signal → send_user → alert"
678
  })
679
 
 
3
  import json
4
  import time
5
  import xml.etree.ElementTree as ET
6
+ from datetime import datetime, timezone
7
  import pytz
8
  import logging
9
  import re
 
107
 
108
  return times
109
 
110
+ def build_signal_timestamps():
111
+ """يبني طوابع وقت الإشارة في جميع المناطق الزمنية + ISO UTC للآلة"""
112
+ tz_times = get_time_zones()
113
+ iso_utc = datetime.now(timezone.utc).isoformat()
114
+ return {
115
+ "zones": tz_times, # human-friendly labels per city
116
+ "iso_utc": iso_utc # machine-friendly
117
+ }
118
+
119
  def capture_charts():
120
  """التقاط صور المؤشرات"""
121
  urls = [
 
176
 
177
 
178
  بداية مهمتك هي اما انشاء صفقة او انتظار
179
+ في حالة المستخدم حاليا في صفقة يرجى متابعتها وذكر نقاط سواء ربح خسارة او اغلاقها الخ...
180
 
181
  ممنوع منعا باتا ان تنشئ صفقة أخرى مدام المستخدم في صفقة حاليا
182
 
183
  ردك سيكون عبارة عن XML لا غير وهي المفاتيح الأساسية لتحريك النظام هنا شرحها
184
 
185
+ before everything you have <analysis>here take your time to analysis the images for XAUUSD 15min and 1H also the DXY be so pro person and use the SCHOOLS for trading to analysis</analysis>
186
+
187
  اولا الانتظار :
188
 
189
  <wait>تستخدم هذه في حالة ان المستخدم ينتظر منك انشاء صفقة ولاكن تحليلك يقول ان ليس الوقت المناسب ضع هنا سبب عدم وجود صفقة
 
237
  message from developer :
238
 
239
 
240
+ we need to focus the price now where will go the price for (NOW) don't give strategy for another price up or down no no that is bad strategy and we will not get our goal
241
 
242
+ so what we need is analysis and predction where the price gonna go with some IFs
243
 
244
+ most you strategy make our another model can generate PRO trade by your strategy and queck
245
 
246
  the something worest now we get is for example price now 3335
247
 
248
+ your analysis say you need to buy if the price 3348
249
 
250
+ i don't want this shit i want you to predcion if gonna go up to take the pips from 35 to 48 i want it
251
 
252
  do you understand ??
253
 
 
329
  message_content += f"الدخول: {current_signal.get('entry', 'N/A')}\n"
330
  message_content += f"وقف الخسارة: {current_signal.get('stop_loss', 'N/A')}\n"
331
  message_content += f"الهدف: {current_signal.get('take_profit', 'N/A')}\n"
332
+
333
+ # إظهار توقيت إنشاء الصفقة للذكاء الاصطناعي
334
+ ts = current_signal.get("timestamps", {})
335
+ if ts:
336
+ zones = ts.get("zones", {})
337
+ iso_utc = ts.get("iso_utc", "N/A")
338
+ message_content += "أوقات إنشاء الصفقة:\n"
339
+ for city, t in zones.items():
340
+ message_content += f"- {city}: {t}\n"
341
+ message_content += f"- ISO_UTC: {iso_utc}\n"
342
+
343
+ message_content += f"\n(يرجى التركيز على هذه الصفقة ومراجعتها أو إغلاقها، وممنوع إنشاء صفقة أخرى ما دام هناك صفقة مفتوحة. إذا اعتقدت أن الاتجاه سيعكس التوقعات فعليك أولاً إغلاق الصفقة الحالية ثم إنشاء صفقة جديدة. إذا لاحظت أن الصفقة أخذت وقتاً طويلاً دون تحقق الهدف، فتذكّر أن السعر قد يتحرك عكس المطلوب؛ لذلك ليس ضرورياً الإغلاق عند الهدف دائماً، ويمكنك إغلاق ا��صفقة إذا طال زمنها وكان هناك دلائل على الانعكاس، أو الانتظار لفرصة أفضل للدخول مجدداً بسعر مناسب. استعمل المنبّه كأداتك الأساسية لمتابعة الصفقة عبر تحديد مستويات قريبة جداً (10، 30، 50 نقطة) لمعرفة ما يحدث للصفقة.)\n\nالوقت الآن:\n{time_info}"
344
  else:
345
  message_content += f" you need to make the signal about SL about 10 mean 1$ okay the pips in gold 100 pip mean 10$ you need to create signals with stop lose max 5 $ and TP to the 100pip mean 10$ 20 30 and TP from 70 80 100 ...المستخدم ليس في اي صفقة حاليا\n\nTIME NOW : {time_info}"
346
 
 
413
  signal_data = {
414
  "pair": pair_match.group(1).strip(),
415
  "type": type_match.group(1).strip(),
416
+ "entry": pair_number(entry_match.group(1).strip()),
417
+ "stop_loss": pair_number(sl_match.group(1).strip()),
418
+ "take_profit": pair_number(tp_match.group(1).strip()),
419
+ # NEW: add timestamps at creation time
420
+ "timestamps": build_signal_timestamps()
421
  }
422
 
423
  # حفظ الإشارة
 
427
  result = db_signals.update_user_json_file(auth_token, commit_oid, new_signal)
428
 
429
  if result["success"]:
430
+ # إرسال رسالة للمستخدمين (مع الوقت)
431
+ ts = signal_data["timestamps"]
432
+ zones = ts.get("zones", {})
433
+ iso_utc = ts.get("iso_utc", "")
434
+ # compact one-line times to avoid long messages
435
+ times_line = " | ".join([f"{c}: {t}" for c, t in zones.items()])
436
+
437
  signal_message = f"🚨 إشارة جديدة XAUUSD\n\n"
438
  signal_message += f"📊 النوع: {signal_data['type']}\n"
439
  signal_message += f"🎯 الدخول: {signal_data['entry']}\n"
440
  signal_message += f"🛑 وقف الخسارة: {signal_data['stop_loss']}\n"
441
+ signal_message += f"💰 الهدف: {signal_data['take_profit']}\n"
442
+ signal_message += f"🕒 الوقت: {times_line}\n"
443
+
444
 
445
  send_result = send_message_to_api(signal_message)
446
  if send_result["success"]:
 
535
 
536
  return actions_performed
537
 
538
+ def pair_number(val):
539
+ """Normalize numeric strings to plain numbers, keep as string but ensure clean format."""
540
+ # Remove any non-numeric (except dot and minus)
541
+ cleaned = re.sub(r'[^0-9\.\-]', '', val)
542
+ # Avoid empty
543
+ if cleaned == '' or cleaned == '-' or cleaned == '.':
544
+ return val.strip()
545
+ # Normalize to up to 3 decimals as typical for XAUUSD quotes (broker dependent)
546
+ try:
547
+ num = float(cleaned)
548
+ return f"{num:.2f}".rstrip('0').rstrip('.') if '.' in f"{num:.2f}" else f"{num:.2f}"
549
+ except:
550
+ return val.strip()
551
+
552
  def count_xml_tags(ai_response):
553
  """عد عدد كل XML tag في الرد لأغراض التسجيل"""
554
  counts = {
 
719
  "/test_actions": "اختبار معالجة XML tags (POST)",
720
  "/health": "فحص حالة النظام (GET)"
721
  },
722
+ "version": "2.1.0",
723
  "execution_priority": "close_trade → signal → send_user → alert"
724
  })
725