Skip to content

Commit

Permalink
verify and symbol and group
Browse files Browse the repository at this point in the history
  • Loading branch information
mahs4d committed Nov 20, 2020
1 parent 68edd33 commit f594657
Show file tree
Hide file tree
Showing 19 changed files with 26,435 additions and 240 deletions.
7 changes: 5 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pipenv-setup = "*"
twine = "*"

[packages]
requests = "*"
Expand All @@ -14,9 +16,10 @@ jdatetime = "*"
schedule = "*"

[requires]
python_version = "3.7"
python_version = "3.8"

[scripts]
clean = "rm -r dist build \"./lib/tsetmc_api.egg-info\""
sync = "pipenv-setup sync --dev"
build = "python setup.py sdist bdist_wheel"
publish = "twine upload dist/*"
clean = "rm -r dist build tsetmc_api.egg-info \"./*.egg-info\""
587 changes: 539 additions & 48 deletions Pipfile.lock

Large diffs are not rendered by default.

25,288 changes: 25,288 additions & 0 deletions docs/dideban.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def apply(self, asset_id, watch_tick: WatchTick):
def on_poolehooshmand_tick(tick: WatchTick):
print('-----------------------------------------------------------------')

asset_ids = tick.get_asset_ids()
asset_ids = tick.get_symbol_ids()
for asset_id in asset_ids:
print(tick.get_simple_data(asset_id)['symbol_short_name'])

Expand Down
2 changes: 1 addition & 1 deletion lib/tsetmc_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .asset import Asset
from .symbol import Symbol
from .watch import Watch, Filter
Binary file removed lib/tsetmc_api/__pycache__/asset.cpython-37.pyc
Binary file not shown.
Binary file removed lib/tsetmc_api/core/__pycache__/asset.cpython-37.pyc
Binary file not shown.
6 changes: 5 additions & 1 deletion lib/tsetmc_api/core/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections import defaultdict
from os import path

_cache_dir = os.getenv('TSETMC_CACHE_DIRECTORY', path.expanduser('~/.tsetmc-api/cache'))
_cache_dir = os.getenv('TSETMC_API_CACHE_DIRECTORY', path.expanduser('~/.tsetmc-api/cache'))


class PersistentCache:
Expand Down Expand Up @@ -57,3 +57,7 @@ def exists(major, minor):
def remove(major, minor):
if MemoryCache.exists(major, minor):
del MemoryCache._cache[major][minor]

@staticmethod
def clear(self):
MemoryCache._cache.clear()
32 changes: 16 additions & 16 deletions lib/tsetmc_api/core/day_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
_intraday_pattern = re.compile("var (?P<name>.*)=(?P<content>\[[^;]*\]);")


def _load_script_vars_from_web(asset_id, year, month, day):
def _load_script_vars_from_web(symbol_id, year, month, day):
d = f'{year:04}{month:02}{day:02}'
script_variables = {}

# get data from url
daily_content = requests.get(f'http://cdn.tsetmc.com/Loader.aspx?ParTree=15131P&i={asset_id}&d={d}',
timeout=20).text
daily_content = requests.get(f'http://cdn.tsetmc.com/Loader.aspx?ParTree=15131P&i={symbol_id}&d={d}',
timeout=20, verify=False).text

# find and get script tags
all_scripts = BeautifulSoup(daily_content, 'lxml').find_all('script')
Expand All @@ -40,8 +40,8 @@ def _load_script_vars_from_web(asset_id, year, month, day):
return script_variables


def _extract_asset_details_data(script_vars):
asset_details = {
def _extract_symbol_details_data(script_vars):
symbol_details = {
'full_name': script_vars['InstSimpleData'][0],
'short_name': script_vars['InstSimpleData'][1],
'market_short_name': script_vars['InstSimpleData'][2],
Expand All @@ -51,7 +51,7 @@ def _extract_asset_details_data(script_vars):
'base_volume': script_vars['InstSimpleData'][9],
}

return asset_details
return symbol_details


def _extract_price_data(script_vars):
Expand Down Expand Up @@ -137,35 +137,35 @@ def _extract_share_holders_data(script_vars):
'name': shd[5],
})

yesterday_share_holders = []
previous_share_holders = []
for shd in script_vars['ShareHolderDataYesterday']:
yesterday_share_holders.append({
previous_share_holders.append({
'id': shd[0],
'shares_count': shd[2],
'percentage': shd[3],
'name': shd[5],
})

return yesterday_share_holders, share_holders
return previous_share_holders, share_holders


def load_intraday_data(asset_id, year, month, day):
script_vars = _load_script_vars_from_web(asset_id, year, month, day)
def load_intraday_data(symbol_id, year, month, day):
script_vars = _load_script_vars_from_web(symbol_id, year, month, day)

asset_details = _extract_asset_details_data(script_vars)
symbol_details = _extract_symbol_details_data(script_vars)
price_data = _extract_price_data(script_vars)

if not price_data:
raise ValueError('there is no data for this asset in the specified date')
raise ValueError('there is no data for this symbol in the specified date')

yesterday_shareholders, shareholders = _extract_share_holders_data(script_vars)
previous_shareholders, shareholders = _extract_share_holders_data(script_vars)
trades = _extract_trade_data(script_vars)
orders_data = _extract_orders_data(script_vars)

return {
'asset_details': asset_details,
'symbol_details': symbol_details,
'price_data': price_data,
'yesterday_shareholders': yesterday_shareholders,
'previous_shareholders': previous_shareholders,
'shareholders': shareholders,
'trades': trades,
'orders_data': orders_data,
Expand Down
Loading

0 comments on commit f594657

Please sign in to comment.