Skip to content

Commit

Permalink
Migrated packages:
Browse files Browse the repository at this point in the history
* urllib3 v1.26 -> v2.x
* selenium v3.141 -> v4.x

Signed-off-by: timelyart <[email protected]>
  • Loading branch information
timelyart committed Jan 27, 2023
1 parent 12f78f0 commit f84995e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 53 deletions.
29 changes: 13 additions & 16 deletions Kairos.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
Metadata-Version: 2.1
Name: Kairos
Version: 2.85
Version: 2.89
Summary: Kairos aims to help you save time by automating repetitive tasks on TradingView such as refreshing alerts and creating new ones.
Home-page: https://github.com/timelyart/Kairos
Author: timelyart
Author-email: [email protected]
License: End-User License Agreement: https://www.eulatemplate.com/live.php?token=zduUYsiBp0PFzzX0UANHUodYVMifuNRp
Platform: UNKNOWN
Provides-Extra: platform_system == "Windows"
Provides-Extra: platform_system == "Linux"
Provides-Extra: platform_system == "Darwin"
Expand Down Expand Up @@ -173,15 +172,15 @@ If you find yourself copying and pasting a lot, you might want to consider to pu

The files needed to run **root.yaml** can be found in the folder [yaml](yaml) and I highly encourage to look into them to figure out how they work.

When creating/editing [YAML](https://en.wikipedia.org/wiki/YAML) files you have to be careful with indentation and you might want to use a website like [https://yamlchecker.com](https://yamlchecker.com) to check your YAML before running it with Kairos. Also, note that values are **case sensitive**.
When creating/editing [YAML](https://en.wikipedia.org/wiki/YAML) files you have to be careful with indentation, and you might want to use a website like [https://yamlchecker.com](https://yamlchecker.com) to check your YAML before running it with Kairos. Also, note that values are **case-sensitive**.

#### Troubleshooting YAML
When Kairos runs, it will create a temporary copy of your [YAML](https://en.wikipedia.org/wiki/YAML) file called **my_file.yaml.tmp**. This temporary file includes your [YAML](https://en.wikipedia.org/wiki/YAML) file (obviously) but also any [YAML](https://en.wikipedia.org/wiki/YAML) file that gets referenced from your [YAML](https://en.wikipedia.org/wiki/YAML) files.<br>
In case of an error, a **my_file.yaml.err** will be created. Kairos error messages will reference the line and column number of the **.err** file.

#### Examples
The rest of this chapter will elaborate on setting up various use cases with [YAML](https://en.wikipedia.org/wiki/YAML) files.<br>
Signals are the core of Kairos and strategies are really useful for automatic backtesting. Although Alerts have largely become obsolete with Signals, they are still expanded upon here. They were the core of version 1 after all, and may still be provide to be useful to some.
Signals are the core of Kairos and strategies are really useful for automatic backtesting. Although Alerts have largely become obsolete with Signals, they are still expanded upon here. They were the core of version 1 after all, and may still prove to be useful to some.

### Alerts
Please read [Editing YAML files](https://github.com/timelyart/Kairos#editing-yaml-files) if you haven't done so already.
Expand All @@ -196,7 +195,7 @@ Steps:
alerts:
- name:
conditions: []
options: "Once Per Bar Close"
trigger: "Once Per Bar Close"
expiration: 86400
show_popup: no
sound:
Expand All @@ -213,7 +212,7 @@ Steps:
text:
```
* Fill in the timeframe(s) and watchlist(s) you want to use
* Create a mock up alert and write down the options (case sensitive!) you select in order (going from left to right and from top to bottom)
* Create a mock-up alert and write down the options (case-sensitive!) you select in order (going from left to right and from top to bottom)
* Fill in the rest of the template with your written down values

You can define in one file multiple charts with each chart having multiple alerts, like this:
Expand All @@ -225,7 +224,7 @@ charts:
alerts:
- name:
conditions: []
options: "Once Per Bar Close"
trigger: "Once Per Bar Close"
expiration: 86400
show_popup: no
sound:
Expand All @@ -242,7 +241,7 @@ charts:
text:
- name:
conditions: []
options: "Only Once"
trigger: "Only Once"
expiration: 2
show_popup: no
sound:
Expand All @@ -263,7 +262,7 @@ charts:
alerts:
- name:
conditions: []
options: "Once Per Bar Close"
trigger: "Once Per Bar Close"
expiration: 86400
show_popup: no
sound:
Expand Down Expand Up @@ -324,7 +323,7 @@ Steps:
```
python main.py signal.yaml
```
All the settings within the [YAML](https://en.wikipedia.org/wiki/YAML) file are explained. If you miss an explanation, or if an explanation isn't clear. Please, open an [issue](https://github.com/timelyart/Kairos/issues) so it may get addressed.
All the settings within the [YAML](https://en.wikipedia.org/wiki/YAML) file are explained. If you miss an explanation, or if an explanation isn't clear. Please, open an [issue](https://github.com/timelyart/Kairos/issues), so it may get addressed.

#### Golden Cross Template
Use the [_signal_golden_cross.yaml](yaml/_signal_golden_cross.yaml) as a base for your own [yaml](https://en.wikipedia.org/wiki/YAML) file.
Expand All @@ -337,7 +336,7 @@ Steps:
```
python main.py signal_golden_cross.yaml
```
All the settings within the template files are explained. If you miss an explanation, or if an explanation isn't clear. Please, open an issue so it may get addressed.
All the settings within the template files are explained. If you miss an explanation, or if an explanation isn't clear. Please, open an issue, so it may get addressed.

### Strategies
You can use strategies to backtest TradingView strategies, much in the same way as signals or alerts. Kairos will run your TradingView strategy for each symbol on your watchlist(s) and save the results for you in a [JSON](https://en.wikipedia.org/wiki/JSON) file.
Expand Down Expand Up @@ -368,7 +367,7 @@ Steps:
```
python main.py strategies.yaml
```
All the settings within the [YAML](https://en.wikipedia.org/wiki/YAML) file are explained. If you miss an explanation, or if an explanation isn't clear. Please, open an [issue](https://github.com/timelyart/Kairos/issues) so it may get addressed.
All the settings within the [YAML](https://en.wikipedia.org/wiki/YAML) file are explained. If you miss an explanation, or if an explanation isn't clear. Please, open an [issue](https://github.com/timelyart/Kairos/issues), so it may get addressed.
## Command line examples
* Refresh your existing alerts (depends on the settings in your kairos.cfg so proceed with caution).
```
Expand All @@ -389,7 +388,7 @@ python main.py -s
A lot can go wrong running web automation tools like Kairos. These are the most common ones:
* The web page / server hasn't handled the interaction (a click or some input) yet before the next interaction is tried
* A popup is displayed over the point that Kairos wants to interact with, e.g. a tooltip or TradingView's 'too many devices message'.
* A form (e.g. an alert)was submitted but you don't see results.
* A form (e.g. an alert) was submitted, but you don't see results.
* The markup of the web page has changed thereby breaking the flow of Kairos.

These issues are all related and amount to Kairos unable to either find an element or to interact with an element. You will get errors (see debug.log) like:
Expand Down Expand Up @@ -426,9 +425,7 @@ Feedback is invaluable. Please, take the time to give constructive feedback by o
[timelyart](https://github.com/timelyart)

## Donate
If you find value in this project and you would like to donate, please do so [here](DONATE.md)
If you find value in this project, and you would like to donate, please do so [here](DONATE.md)

## License
This project is licensed under the GNU GPLv3 License - see the [LICENSE.md](LICENSE.md) file for details.


4 changes: 2 additions & 2 deletions Kairos.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pyyaml
beautifulsoup4
urllib3
selenium<4,>=3.141
urllib3<3,>=1.26
selenium
configparser
pip
Pillow
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
setuptools
pyyaml
beautifulsoup4
urllib3
selenium>=3.141.0,<4
urllib3>=1.26,<3
selenium
configparser
pip
Pillow
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
packages=find_packages(),
license='End-User License Agreement: https://www.eulatemplate.com/live.php?token=zduUYsiBp0PFzzX0UANHUodYVMifuNRp',
author='timelyart',
version='2.85',
version='2.89',
author_email='[email protected]',
description='Kairos aims to help you save time by automating repetitive tasks on TradingView such as refreshing '
'alerts and creating new ones.',
long_description=long_description,
install_requires=['pyyaml', 'beautifulsoup4', 'urllib3', 'selenium>=3.141,<4', 'configparser', 'pip', 'Pillow',
install_requires=['pyyaml', 'beautifulsoup4', 'urllib3>=1.26,<3', 'selenium', 'configparser', 'pip', 'Pillow',
'requests', 'gspread', 'google-api-python-client', 'oauth2client', 'pymongo', 'dill', 'numpy',
'fastnumbers', 'psutil', 'Cython', 'tqdm', 'soupsieve', 'coloredlogs'],
extras_require={
Expand Down
48 changes: 17 additions & 31 deletions tv/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2226,7 +2226,7 @@ def take_screenshot(browser, symbol, interval, chart_only=True, tpl_strftime="%Y
finally:
# make sure to close the newly opened tab
browser.close()
browser.switch_to_window(previous_window)
browser.switch_to.window(previous_window)
log.info(screenshot_url)

elif screenshot_dir != '':
Expand Down Expand Up @@ -3233,17 +3233,7 @@ def run(file, export_signals_immediately, multi_threading=False):
for screener_yaml in screeners_yaml:
if (not ('enabled' in screener_yaml)) or screener_yaml['enabled']:
log.info("create/update watchlist '{}' from screener. Please be patient, this may take several minutes ...".format(screener_yaml['name']))
max_runs = 3
counter = 0
markets = []
while counter < max_runs:
try:
counter += 1
markets = get_screener_markets(browser, screener_yaml)
except Exception as e:
if counter == max_runs:
log.exception(e)
pass
markets = get_screener_markets(browser, screener_yaml)
if markets:
if update_watchlist(browser, screener_yaml['name'], markets):
log.info('watchlist {} updated ({} markets)'.format(screener_yaml['name'], str(len(markets))))
Expand Down Expand Up @@ -3333,21 +3323,14 @@ def clean_alerts(browser, selector=css_selectors['item_clear_alerts']):


def get_screener_markets(browser, screener_yaml):
max_tries = 5
markets = []

close_all_popups(browser)
url = unquote(screener_yaml['url'])
browser.get(url)
time.sleep(DELAY_BREAK*2)
loaded = False
max_runs = 100
counter = 0
while not loaded and counter < max_runs:
time.sleep(0.1)
el_select = find_element(browser, css_selectors['select_screener'])
hover(browser, el_select, True)
loaded = element_exists(browser, css_selectors['options_screeners'])
counter += 1
el_select = find_element(browser, css_selectors['select_screener'])
hover(browser, el_select, True)

el_options = find_elements(browser, css_selectors['options_screeners'])
found = False
Expand Down Expand Up @@ -3379,33 +3362,36 @@ def get_screener_markets(browser, screener_yaml):
total_found = int(match.group(1))
except StaleElementReferenceException:
pass
log.debug("found {} markets for screener '{}'".format(total_found, screener_yaml['name']))
log.debug("found {} markets".format(total_found, screener_yaml['name']))

while len(markets) < total_found:
i = 0
while len(markets) < total_found and i < max_tries:
rows = find_elements(browser, class_selectors['rows_screener_result'], By.CLASS_NAME, True, False, 30)
i = 0
while i < len(rows):
j = 0
while j < len(rows):
try:
market = rows[i].get_attribute('data-symbol')
market = rows[j].get_attribute('data-symbol')
action = ActionChains(browser)
action.move_to_element_with_offset(rows[i], 5, 5)
action.move_to_element_with_offset(rows[j], 5, 5)
action.perform()
except StaleElementReferenceException:
WebDriverWait(browser, 5).until(
ec.presence_of_element_located((By.CLASS_NAME, class_selectors['rows_screener_result'])))
# try again
browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
rows = find_elements(browser, class_selectors['rows_screener_result'], By.CLASS_NAME)
market = rows[i].get_attribute('data-symbol')
market = rows[j].get_attribute('data-symbol')
markets.append(market)
i += 1
j += 1
markets = list(sorted(set(markets)))
i += 1

log.debug('extracted {} markets'.format(str(len(markets))))
log.info('extracted {} markets'.format(str(len(markets))))
return markets


def update_watchlist(browser, name, markets):
log.info("creating/updating watchlist ...".format(name))
try:
if not find_element(browser, css_selectors['btn_watchlist_submenu'], except_on_timeout=False):
wait_and_click(browser, css_selectors['btn_watchlist'])
Expand Down

0 comments on commit f84995e

Please sign in to comment.