Skip to content

Commit

Permalink
raw file fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mahs4d committed Dec 18, 2020
1 parent 27b260b commit b5f7693
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/tsetmc_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from .watch import Watch, Filter, AtiFilter, SahamFilter, WatchTick, SandoghFilter, KalaForoushFilter, \
EkhtiarForoushFilter, HaghTaghaddomFilter, OraghMosharekatFilter, PayeFarabourseFilter

__version__ = '4.2.0'
__version__ = '4.2.1'
2 changes: 1 addition & 1 deletion lib/tsetmc_api/bin/tsetmc_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def generate(symbol_id: SymbolId, start_time: jdatetime, end_time: jdatetime):
end_time=end_time,
file_location=file_name)


generate('35425587644337450', jdatetime(1399, 9,3), jdatetime(1399, 9, 7))
def install(file_location: str):
SymbolDataFile.install_data_file(file_location)

Expand Down
4 changes: 2 additions & 2 deletions lib/tsetmc_api/day_details/day_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ def _save_to_cache(self, is_raw: bool = False, raw_data: Optional[Dict] = None):

def _get_cache_minor(self, is_raw: bool = False):
if is_raw:
return f'{self.symbol.id}-{self.date.year}-{self.date.month}-{self.date.day}'
return f'{self.symbol.id}-{self.date.year}-{self.date.month}-{self.date.day}.raw'
else:
return f'{self.symbol.id}-{self.date.year}-{self.date.month}-{self.date.day}-raw'
return f'{self.symbol.id}-{self.date.year}-{self.date.month}-{self.date.day}'

def get_final_major_shareholders(self) -> List[SymbolMajorShareholder]:
"""
Expand Down
11 changes: 6 additions & 5 deletions lib/tsetmc_api/day_details/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from dataclasses import dataclass
from datetime import date
from typing import List, Dict, Iterator
from typing import List, Dict, Iterator, Optional

from tsetmc_api.types import Price
from tsetmc_api.utils import get_timestamp
Expand Down Expand Up @@ -56,7 +56,7 @@ def copy(self):
)

@staticmethod
def from_raw_day_details(date: date, price_data: Dict, orders_data: List[Dict]) -> Snapshot:
def from_raw_day_details(date: date, price_data: Dict, orders_data: List[Optional[Dict]]) -> Snapshot:
max_t = price_data['t']
snapshot = Snapshot(
time=get_timestamp(date, max_t),
Expand Down Expand Up @@ -97,12 +97,13 @@ def from_raw_day_details(date: date, price_data: Dict, orders_data: List[Dict])
@staticmethod
def generate_snapshots_from_raw_day_detail_data(date: date, price_data: List[Dict], orders_data: List[Dict]) -> \
Iterator[Snapshot]:
MAX_ORDERS_COUNT = 5
max_pdi = len(price_data)
max_odi = len(orders_data)
pdi = 0
odi = -1
last_price_data = price_data[pdi]
last_orders_data = [None, None, None]
last_orders_data = [None] * MAX_ORDERS_COUNT

while True:
phase = -1
Expand All @@ -129,13 +130,13 @@ def generate_snapshots_from_raw_day_detail_data(date: date, price_data: List[Dic
# step orders
if phase == 2 or phase == 3:
t = orders_data[odi + 1]['t']
orders_found = [None, None, None]
orders_found = [None] * MAX_ORDERS_COUNT
while True:
if odi + 1 >= max_odi:
break

order = orders_data[odi + 1]
rank = min(order['rank'] - 1, 2)
rank = min(order['rank'] - 1, MAX_ORDERS_COUNT - 1)
if orders_found[rank] is not None or order['t'] > t:
break

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="tsetmc-api",
version="4.2.0",
version="4.2.1",
python_requires=">=3.7",
install_requires=[
"beautifulsoup4==4.9.3",
Expand Down

0 comments on commit b5f7693

Please sign in to comment.