Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit eb161ed

Browse files
author
Brian
committed
Add test script
1 parent 4500886 commit eb161ed

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
requests
2+
colorama

test.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
from colorama import Fore, Style
2+
from tradingview_ta import TA_Handler, Interval
3+
import tradingview_ta, requests
4+
5+
print("------------------------------------------------")
6+
print("Testing {}Tradingview-TA{} v{}{}".format(Fore.CYAN, Fore.MAGENTA, tradingview_ta.__version__, Style.RESET_ALL))
7+
print("This test is {}semi-automatic{}. Please compare with tradingview's data manually.".format(Fore.LIGHTRED_EX, Style.RESET_ALL))
8+
print("------------------------------------------------")
9+
10+
COUNT = 5
11+
success = 0
12+
13+
print("{}#0{} {}Testing invalid symbol{}".format(Fore.BLUE, Style.RESET_ALL, Fore.LIGHTBLUE_EX, Style.RESET_ALL))
14+
handler = TA_Handler(
15+
symbol="ThisSymbolIsInvalid",
16+
interval="1m",
17+
screener="america",
18+
exchange="NASDAQ"
19+
)
20+
try:
21+
analysis = handler.get_analysis()
22+
if analysis:
23+
print("{}#0{} Invalid symbol test {}failed{}. No exception occured.".format(Fore.BLUE, Style.RESET_ALL, Fore.RED, Style.RESET_ALL))
24+
except Exception as e:
25+
if str(e) == "Exchange or symbol not found.":
26+
print("{}#0{} Invalid symbol test {}success{}.".format(Fore.BLUE, Style.RESET_ALL, Fore.GREEN, Style.RESET_ALL))
27+
success += 1
28+
else:
29+
print("{}#0{} Invalid symbol test {}failed{}. An exception occured, but the symbol is valid.".format(Fore.BLUE, Style.RESET_ALL, Fore.RED, Style.RESET_ALL))
30+
31+
32+
print("{}#1{} {}Testing invalid exchange{}".format(Fore.BLUE, Style.RESET_ALL, Fore.LIGHTBLUE_EX, Style.RESET_ALL))
33+
handler = TA_Handler(
34+
symbol="TSLA",
35+
interval="1m",
36+
screener="america",
37+
exchange="binance"
38+
)
39+
try:
40+
analysis = handler.get_analysis()
41+
if analysis:
42+
print("{}#1{} Invalid exchange test {}failed{}. No exception occured.".format(Fore.BLUE, Style.RESET_ALL, Fore.RED, Style.RESET_ALL))
43+
except Exception as e:
44+
if str(e) == "Exchange or symbol not found.":
45+
print("{}#1{} Invalid exchange test {}success{}.".format(Fore.BLUE, Style.RESET_ALL, Fore.GREEN, Style.RESET_ALL))
46+
success += 1
47+
else:
48+
print("{}#1{} Invalid exchange test {}failed{}. An exception occured, but symbol is valid.".format(Fore.BLUE, Style.RESET_ALL, Fore.RED, Style.RESET_ALL))
49+
50+
print("{}#2{} {}Testing timeout{}".format(Fore.BLUE, Style.RESET_ALL, Fore.LIGHTBLUE_EX, Style.RESET_ALL))
51+
handler = TA_Handler(
52+
symbol="AAPL",
53+
interval=Interval.INTERVAL_1_DAY,
54+
screener="america",
55+
exchange="NASDAQ",
56+
timeout=0.0001
57+
)
58+
try:
59+
analysis = handler.get_analysis()
60+
if analysis:
61+
print("{}#2{} Timeout test {}failed{}.".format(Fore.BLUE, Style.RESET_ALL, Fore.RED, Style.RESET_ALL))
62+
except Exception as e:
63+
if type(e) == requests.exceptions.ConnectTimeout:
64+
print("{}#2{} Timeout test {}success{}.".format(Fore.BLUE, Style.RESET_ALL, Fore.GREEN, Style.RESET_ALL))
65+
success += 1
66+
67+
68+
print("{}#3{} {}Testing invalid interval{}".format(Fore.BLUE, Style.RESET_ALL, Fore.LIGHTBLUE_EX, Style.RESET_ALL))
69+
handler = TA_Handler(
70+
symbol="TSLA",
71+
interval="1 minute",
72+
screener="america",
73+
exchange="NASDAQ"
74+
)
75+
try:
76+
analysis = handler.get_analysis()
77+
if analysis and input('{}#3{} Did you see a "defaulting to 1 day" {}warning{}? (Y/N) '.format(Fore.BLUE, Style.RESET_ALL, Fore.YELLOW, Style.RESET_ALL)).lower() == "y":
78+
print("{}#3{} Invalid interval test {}success{}.".format(Fore.BLUE, Style.RESET_ALL, Fore.GREEN, Style.RESET_ALL))
79+
success += 1
80+
else:
81+
print("{}#3{} Invalid interval test {}failed{}".format(Fore.BLUE, Style.RESET_ALL, Fore.RED, Style.RESET_ALL))
82+
83+
except Exception as e:
84+
print("{}#3{} Invalid interval test {}failed{}. An exception occured: {}".format(Fore.BLUE, Style.RESET_ALL, Fore.RED, Style.RESET_ALL, e))
85+
86+
print("{}#4{} {}Testing stock (NASDAQ:AAPL){}".format(Fore.BLUE, Style.RESET_ALL, Fore.LIGHTBLUE_EX, Style.RESET_ALL))
87+
handler = TA_Handler(
88+
symbol="AAPL",
89+
interval=Interval.INTERVAL_1_DAY,
90+
screener="america",
91+
exchange="NASDAQ"
92+
)
93+
try:
94+
analysis = handler.get_analysis()
95+
print("{}#4{} Please compare with {}https://www.tradingview.com/symbols/NASDAQ-AAPL/technicals/{}.".format(Fore.BLUE, Style.RESET_ALL, Fore.LIGHTMAGENTA_EX, Style.RESET_ALL))
96+
print("{}#4{} (Summary) Rec: {}, Sell: {}, Neutral: {}, Buy: {}".format(Fore.BLUE, Style.RESET_ALL, analysis.summary["RECOMMENDATION"], analysis.summary["SELL"], analysis.summary["NEUTRAL"], analysis.summary["BUY"]))
97+
if input("{}#4{} Are the results the same? (Y/N) ".format(Fore.BLUE, Style.RESET_ALL)).lower() == "y":
98+
print("{}#4{} Stock test {}success{}.".format(Fore.BLUE, Style.RESET_ALL, Fore.GREEN, Style.RESET_ALL))
99+
success += 1
100+
else:
101+
print("{}#4{} Stock test {}failed{}".format(Fore.BLUE, Style.RESET_ALL, Fore.RED, Style.RESET_ALL))
102+
except Exception as e:
103+
print("{}#4{} Stock test {}failed{}. An exception occured: {}".format(Fore.BLUE, Style.RESET_ALL, Fore.RED, Style.RESET_ALL, e))
104+
105+
106+
print("------------------------------------------------")
107+
print("Test finished. Result: {}{}/{}{}.".format(Fore.LIGHTWHITE_EX ,success, COUNT, Style.RESET_ALL))

0 commit comments

Comments
 (0)