Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staging #10

Merged
merged 11 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Test

on:
- push
- pull_request

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
poetry run pip install -e .
- name: Run tests
run: poetry run pytest

# TODO: add coverage as well
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

[![PyPi](https://img.shields.io/badge/PyPi-2.3.0-yellow)](https://pypi.org/project/tradingview-screener/)
[![PyPi](https://img.shields.io/badge/PyPi-2.3.1-yellow)](https://pypi.org/project/tradingview-screener/)
[![Downloads](https://static.pepy.tech/badge/tradingview-screener)](https://pepy.tech/project/tradingview-screener)
[![Downloads](https://static.pepy.tech/badge/tradingview-screener/month)](https://pepy.tech/project/tradingview-screener)

Expand Down
436 changes: 208 additions & 228 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[tool.poetry]
name = "tradingview-screener"
version = "2.3.0"
version = "2.3.1"
description = "A package for creating stock screeners with the TradingView API"
authors = ["shner-elmo <770elmo@gmail.com>"]
license = "MIT"
readme = "README.md"
packages = [{include = "tradingview_screener"}]
packages = [{include = "tradingview_screener", from = "src"}]
repository = "https://github.com/shner-elmo/TradingView-Screener"
documentation = "https://github.com/shner-elmo/TradingView-Screener/blob/master/README.md"
classifiers = [
Expand Down
File renamed without changes.
37 changes: 19 additions & 18 deletions tradingview_screener/query.py → src/tradingview_screener/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__all__ = ['Query', 'Column']

import pprint
from typing import TypedDict, Any, Literal, NotRequired
from typing import TypedDict, Any, Literal

import requests
import pandas as pd
Expand Down Expand Up @@ -41,13 +41,13 @@ class QueryDict(TypedDict):
"""

# TODO: test which optional ...
markets: NotRequired[list[str]]
symbols: NotRequired[dict]
options: NotRequired[dict]
columns: NotRequired[list[str]]
filter: NotRequired[list[FilterOperationDict]]
sort: NotRequired[SortByDict]
range: NotRequired[list[int]] # a list with two integers, i.e. `[0, 100]`
markets: list[str]
symbols: dict
options: dict
columns: list[str]
filter: list[FilterOperationDict]
sort: SortByDict
range: list[int] # a with two integers, i.e. `[0, 100]`


class Column:
Expand Down Expand Up @@ -476,19 +476,19 @@ def set_markets(self, *markets: str) -> Query:
:param markets: one or more markets from `tradingview_screener.constants.MARKETS`
:return: Self
"""
match markets:
case [single_market]:
assert single_market in MARKETS
if len(markets) == 1:
market = markets[0]
assert market in MARKETS

self.url = URL.format(market=single_market)
self.query['markets'] = [single_market]
self.url = URL.format(market=market)
self.query['markets'] = [market]

case [*multiple_markets]:
for m in multiple_markets:
assert m in MARKETS
elif len(markets) >= 1:
for m in markets:
assert m in MARKETS

self.url = URL.format(market='global')
self.query['markets'] = multiple_markets
self.url = URL.format(market='global')
self.query['markets'] = list(markets)

return self

Expand Down Expand Up @@ -526,6 +526,7 @@ def set_tickers(self, *tickers: str) -> Query:
:return: Self
"""
# no need to select the market if we specify the symbol we want
# noinspection PyTypedDict
self.query.pop('markets', None)

self.query['symbols'] = {'tickers': list(tickers)}
Expand Down
File renamed without changes.
21 changes: 21 additions & 0 deletions tests/test_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest

from tradingview_screener.query import Query


@pytest.mark.parametrize(
['markets', 'expected_url'],
[
(['crypto'], 'https://scanner.tradingview.com/crypto/scan'),
(['forex'], 'https://scanner.tradingview.com/forex/scan'),
(['america'], 'https://scanner.tradingview.com/america/scan'),
(['israel'], 'https://scanner.tradingview.com/israel/scan'),
(['america', 'israel'], 'https://scanner.tradingview.com/global/scan'),
(['crypto', 'israel'], 'https://scanner.tradingview.com/global/scan'),
],
)
def test_set_markets(markets: list[str], expected_url: str):
q = Query().set_markets(*markets)

assert q.url == expected_url
assert q.query['markets'] == markets
9 changes: 7 additions & 2 deletions tests/test_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import re

import pandas as pd

def main():
with open('../README.md', 'r') as f:

def test_readme_examples():
with open('README.md', 'r', encoding='utf8') as f:
source = f.read()

matches = re.findall(r'(?<=```python)(.*?)(?=```)', source, re.DOTALL)
Expand All @@ -15,7 +17,10 @@ def main():
line = line.strip().lstrip('>>> ')
lines.append(line)

pd.options.display.max_rows = 10 # hard limit, even on small DFs

code = '\n'.join(lines)
print(code)

assert '>>>' not in code, 'cleaning failed'

Expand Down
Loading