Skip to content

Commit

Permalink
corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
jepidoptera committed Oct 8, 2024
1 parent e236e4c commit 5f072c7
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions hydradx/model/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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]}

0 comments on commit 5f072c7

Please sign in to comment.