Riy777 commited on
Commit
413ec05
·
1 Parent(s): 00bb5c9

Create helpers.py

Browse files
Files changed (1) hide show
  1. helpers.py +35 -0
helpers.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ from datetime import datetime
3
+
4
+ def safe_float_conversion(value, default=0.0):
5
+ try:
6
+ if value is None:
7
+ return default
8
+ if isinstance(value, (int, float)):
9
+ return float(value)
10
+ if isinstance(value, str):
11
+ cleaned = ''.join(character for character in value if character.isdigit() or character in '.-')
12
+ return float(cleaned) if cleaned else default
13
+ return default
14
+ except (ValueError, TypeError):
15
+ return default
16
+
17
+ def _apply_patience_logic(decision, hold_minutes, trade_data, processed_data):
18
+ action = decision.get('action')
19
+
20
+ if action == "CLOSE_TRADE" and hold_minutes < 20:
21
+ current_price = processed_data.get('current_price', 0)
22
+ entry_price = trade_data.get('entry_price', 0)
23
+
24
+ try:
25
+ profit_loss_percent = ((current_price - entry_price) / entry_price) * 100
26
+ except (TypeError, ZeroDivisionError):
27
+ profit_loss_percent = 0
28
+
29
+ if profit_loss_percent < 2:
30
+ print(f"🛑 Blocked premature selling! Only {hold_minutes:.1f} minutes held, PnL: {profit_loss_percent:.2f}%")
31
+ decision['action'] = "HOLD"
32
+ decision['reasoning'] = f"Patience Filter: Blocked premature sell. Held for {hold_minutes:.1f}m. Giving trade more time."
33
+ return decision
34
+
35
+ return decision