-
Notifications
You must be signed in to change notification settings - Fork 0
/
signalsamplemod.py
97 lines (84 loc) · 3.38 KB
/
signalsamplemod.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from tradingview_ta import TA_Handler, Interval, Exchange
# use for environment variables
import os
# use if needed to pass args to external modules
import sys
# used for directory handling
import glob
import time
MY_EXCHANGE = 'BINANCE'
MY_SCREENER = 'CRYPTO'
MY_FIRST_INTERVAL = Interval.INTERVAL_1_MINUTE
MY_SECOND_INTERVAL = Interval.INTERVAL_5_MINUTES
TA_BUY_THRESHOLD = 18 # How many of the 26 indicators to indicate a buy
PAIR_WITH = 'USDT'
TICKERS = 'signalsample.txt'
TIME_TO_WAIT = 4 # Minutes to wait between analysis
FULL_LOG = False # List anylysis result to console
def analyze(pairs):
taMax = 0
taMaxCoin = 'none'
signal_coins = {}
first_analysis = {}
second_analysis = {}
first_handler = {}
second_handler = {}
if os.path.exists('signals/signalsample.exs'):
os.remove('signals/signalsample.exs')
for pair in pairs:
first_handler[pair] = TA_Handler(
symbol=pair,
exchange=MY_EXCHANGE,
screener=MY_SCREENER,
interval=MY_FIRST_INTERVAL,
timeout= 10
)
second_handler[pair] = TA_Handler(
symbol=pair,
exchange=MY_EXCHANGE,
screener=MY_SCREENER,
interval=MY_SECOND_INTERVAL,
timeout= 10
)
for pair in pairs:
try:
first_analysis = first_handler[pair].get_analysis()
second_analysis = second_handler[pair].get_analysis()
except Exception as e:
print("Signalsample:")
print("Exception:")
print(e)
print (f'Coin: {pair}')
print (f'First handler: {first_handler[pair]}')
print (f'Second handler: {second_handler[pair]}')
tacheckS = 0
first_tacheck = first_analysis.summary['BUY']
second_tacheck = second_analysis.summary['BUY']
if FULL_LOG:
print(f'Signalsample:{pair} First {first_tacheck} Second {second_tacheck}')
#else:
#print(".", end = '')
if first_tacheck > taMax:
taMax = first_tacheck
taMaxCoin = pair
if first_tacheck >= TA_BUY_THRESHOLD and second_tacheck >= TA_BUY_THRESHOLD:
signal_coins[pair] = pair
print(f'Signalsample: Signal detected on {pair}')
with open('signals/signalsample.exs','a+') as f:
f.write(pair + '\n')
print(f'Signalsample: Max signal by {taMaxCoin} at {taMax} on shortest timeframe')
return signal_coins
def do_work():
signal_coins = {}
pairs = {}
pairs=[line.strip() for line in open(TICKERS)]
for line in open(TICKERS):
pairs=[line.strip() + PAIR_WITH for line in open(TICKERS)]
while True:
print(f'Signalsample: Analyzing {len(pairs)} coins')
signal_coins = analyze(pairs)
if len(signal_coins) == 0:
print(f'Signalsample: No coins above {TA_BUY_THRESHOLD} threshold on both timeframes. Waiting {TIME_TO_WAIT} minutes for next analysis')
else:
print(f'Signalsample: {len(signal_coins)} coins above {TA_BUY_THRESHOLD} treshold on both timeframes. Waiting {TIME_TO_WAIT} minutes for next analysis')
time.sleep((TIME_TO_WAIT*60))