diff --git a/hydradx/model/processing.py b/hydradx/model/processing.py index ded49f0d..fee1c420 100644 --- a/hydradx/model/processing.py +++ b/hydradx/model/processing.py @@ -836,7 +836,7 @@ def download_history_files(): os.rmdir(source_folder) -def get_historical_omnipool_balance(tkn, date=None, block=None, end_date=None) -> float or dict[str: float]: +def get_historical_omnipool_balance(tkn, date=None, end_date=None) -> float or dict[str: float]: """ get the balance of a particular token on a particular date or range of dates (hopefully) without having to load the entire history or download anything @@ -870,7 +870,7 @@ def find_data_files(): last_line = f.readlines()[-1][:-1] last_date = dateutil.parser.parse(json.loads(last_line)[1]) last_block = json.loads(last_line)[0] - if date is not None and last_date < date or block is not None and last_block < block: + if date is not None and last_date < date or end_date is not None and last_date < end_date: get_omnipool_balance_history() file_data = json.load(open(find_data_files()[-1])) else: @@ -880,7 +880,7 @@ def find_data_files(): first_line = f.readline()[1:] start_date = dateutil.parser.parse(json.loads(first_line.strip()[:-1])[1]) start_block= json.loads(first_line.strip()[:-1])[0] - if date is not None and start_date < date or block is not None and start_block < block: + if date is not None and start_date < date: print(f'loading {file_name}') with open(f'./{file_name}', 'r') as file: file_data = json.load(file) @@ -894,12 +894,10 @@ def find_data_files(): mid = (left + right) // 2 if date and dateutil.parser.parse(tkn_data[mid][1]) < date : left = mid + 1 - elif block and tkn_data[mid][0] < block: - left = mid + 1 else: right = mid if not end_date: - print(f"Retrieved balance of {tkn} on {start_date.strftime('%Y-%m-%d')}: {tkn_data[left][3]}") + print(f"Retrieved balance of {tkn} on {date.strftime('%Y-%m-%d')}: {tkn_data[left][3]}") return tkn_data[left][3] else: # find the end block @@ -911,5 +909,5 @@ def find_data_files(): file_name = file_ls[file_ls.index(file_name) + 1] with open(file_name) as f: tkn_data += [line for line in json.load(f) if line[2] == tkn] - print(f"Retrieved balance of {tkn} from {start_date.strftime('%Y-%m-%d')} - {end_date.strftime('%Y-%m-%d')}.") + print(f"Retrieved balance of {tkn} from {date.strftime('%Y-%m-%d')} - {end_date.strftime('%Y-%m-%d')}.") return {data[1]: data[3] for data in tkn_data[left:end]}