-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrsi_scr_demo.py
69 lines (49 loc) · 2.22 KB
/
rsi_scr_demo.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
"""Demonstration of RSI screener.
The author is Zmicier Gotowka
Distributed under Fcore License 1.1 (see license.md)
"""
from screener.rsi_scr import RsiScr
from screener.base import ScrResult
from data.fvalues import Timespans
from data import yf
import sqlite3
db_name = 'file:fcdb?mode=memory&cache=shared'
if __name__ == "__main__":
warning = "WARNING! This screener is just an example and do not treat the obtained signals as an investment advice.\n" +\
"Always keep yfinance up to date ( pip install yfinance --upgrade ) and use quotes obtained from this " +\
"datasource only for demonstation purposes!\n"
print(warning)
# Keep in-memory DB connected while screening
fcdb = sqlite3.connect(db_name)
source_btc = yf.YF()
source_ltc = yf.YF()
source_btc.db_name = db_name
source_ltc.db_name = db_name
btc = {'Title': 'BTC-USD', 'Source': source_btc}
ltc = {'Title': 'LTC-USD', 'Source': source_ltc}
# Minimum period for calculation
period = 14
# Interval to update quotes (in seconds)
interval = 60
support = 30
resistance = 70
scr = RsiScr(symbols=[btc, ltc],
period=period,
interval=interval,
support=support,
resistance=resistance,
timespan=Timespans.Minute)
print("Please note that the data is delayed (especially volume) and exceptions due to network errors may happen.\n")
print(f"Press CTRL+C to cancel screening. The interval is {interval} seconds.")
while True:
scr.do_cycle()
results = scr.get_results()
print("--------------------------------------------------------------")
for i in range(2):
print(f"Symbol: {results[i][ScrResult.Title]}")
print(f"Latest update: {results[i][ScrResult.LastDatetime]}")
print(f"Cached quotes: {results[i][ScrResult.QuotesNum]}")
print(f"Previous RSI val: {results[i][ScrResult.Values][0]}")
print(f"Current RSI val: {results[i][ScrResult.Values][1]}")
print(f"Signal to buy: {results[i][ScrResult.Signals][0]}")
print(f"Signal to sell: {results[i][ScrResult.Signals][1]}\n")