-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtradingview.py
More file actions
63 lines (52 loc) · 1.96 KB
/
Copy pathtradingview.py
File metadata and controls
63 lines (52 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from tradingview_ta import Interval, TA_Handler
# Mapping of interval strings to TradingView TA intervals
interval_map = {
"1": Interval.INTERVAL_1_MINUTE,
"5": Interval.INTERVAL_5_MINUTES,
"15": Interval.INTERVAL_15_MINUTES,
"30": Interval.INTERVAL_30_MINUTES,
"60": Interval.INTERVAL_1_HOUR,
"120": Interval.INTERVAL_2_HOURS,
"240": Interval.INTERVAL_4_HOURS,
"D": Interval.INTERVAL_1_DAY,
"W": Interval.INTERVAL_1_WEEK,
"M": Interval.INTERVAL_1_MONTH,
}
def get_technical_analysis(symbol="BTCUSDT", interval="D", screener="crypto", exchange="Bybit"):
"""
Retrieve technical analysis for a given symbol, interval, screener, and exchange.
Args:
symbol (str): The trading pair symbol (default is "BTCUSDT").
interval (str): The time interval for the analysis (default is "D").
screener (str): The screener type (default is "crypto").
exchange (str): The exchange name (default is "Bybit").
Returns:
Analysis: An analysis object containing the technical analysis data.
Raises:
ValueError: If the provided interval is not valid.
"""
# Validate the interval
if interval not in interval_map:
raise ValueError(
"Invalid interval. Allowed values: 1, 5, 15, 30, 60, 120, 240, D, W, M."
)
# Create a TA_Handler instance with the provided parameters
handler = TA_Handler(
symbol=symbol,
screener=screener,
exchange=exchange,
interval=interval_map[interval],
)
# Get and return the analysis
try:
analysis = handler.get_analysis()
return analysis
except Exception as e:
raise RuntimeError(f"Error retrieving technical analysis: {e}")
# Example usage
if __name__ == "__main__":
try:
analysis = get_technical_analysis(symbol="BTCUSDT", interval="D")
print(analysis.summary)
except Exception as e:
print(f"Failed to get technical analysis: {e}")