-
Notifications
You must be signed in to change notification settings - Fork 31
/
os_pausebot_MA.py
77 lines (61 loc) · 2.88 KB
/
os_pausebot_MA.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
from tradingview_ta import TA_Handler, Interval, Exchange
import os
import time
import threading
INTERVAL = Interval.INTERVAL_1_MINUTE #Timeframe for analysis
EXCHANGE = 'BINANCE'
SCREENER = 'CRYPTO'
SYMBOL = 'BTCUSDT'
TIME_TO_WAIT = 1
SIGNAL_NAME = 'os_pausebot_MA'
SIGNAL_FILE = 'signals/pausebot.pause'
def analyze():
analysis = {}
handler = {}
handler = TA_Handler(
symbol=SYMBOL,
exchange=EXCHANGE,
screener=SCREENER,
interval=INTERVAL,
timeout= 10)
try:
analysis = handler.get_analysis()
except Exception as e:
print("{SIGNAL_NAME}:")
print("Exception:")
print(e)
return
ma_analysis_sell = analysis.moving_averages['SELL']
ma_analysis_buy = analysis.moving_averages['BUY']
ma_analysis_neutral = analysis.moving_averages['NEUTRAL']
# if ma_analysis_sell >= (ma_analysis_buy + ma_analysis_neutral) or price_downward_trend():
if ma_analysis_sell >= (ma_analysis_buy + ma_analysis_neutral):
paused = True
# print(f'pausebotmod: {SYMBOL} Market not looking too good, bot paused from buying. SELL indicators: {ma_analysis_sell}. BUY/NEUTRAL indicators: {ma_analysis_buy + ma_analysis_neutral}. P: {price} | LP: {lastprice} | Waiting {TIME_TO_WAIT} minutes for next market checkup')
print(f'{SIGNAL_NAME}: {SYMBOL} Market not looking too good, bot paused from buying. SELL indicators: {ma_analysis_sell}. BUY/NEUTRAL indicators: {ma_analysis_buy + ma_analysis_neutral}. Waiting {TIME_TO_WAIT} minutes for next market checkup')
else:
#print(f'pausebotmod: {SYMBOL} Market looks ok, bot is running. SELL indicators: {ma_analysis_sell}. BUY/NEUTRAL indicators: {ma_analysis_buy + ma_analysis_neutral}. P: {price} | LP: {lastprice} | Waiting {TIME_TO_WAIT} minutes for next market checkup')
print(f'{SIGNAL_NAME}: {SYMBOL} Market looks ok, bot is running. SELL indicators: {ma_analysis_sell}. BUY/NEUTRAL indicators: {ma_analysis_buy + ma_analysis_neutral}. Waiting {TIME_TO_WAIT} minutes for next market checkup')
paused = False
#lastprice = price
return paused
#if __name__ == '__main__':
def do_work():
while True:
try:
if not threading.main_thread().is_alive(): exit()
# print(f'pausebotmod: Fetching market state')
paused = analyze()
if paused:
with open(SIGNAL_FILE,'a+') as f:
f.write('yes')
else:
if os.path.isfile(SIGNAL_FILE):
os.remove(SIGNAL_FILE)
# print(f'pausebotmod: Waiting {TIME_TO_WAIT} minutes for next market checkup')
time.sleep((TIME_TO_WAIT*60))
except Exception as e:
print(f'{SIGNAL_NAME}: Exception do_work() 1: {e}')
continue
except KeyboardInterrupt as ki:
continue