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

Converting amounts from quote token to base token #157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions data_handler/handlers/order_books/ekubo/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from decimal import Decimal, getcontext
import pandas as pd
from handlers.order_books.abstractions import OrderBookBase
Expand All @@ -19,7 +20,7 @@ def __init__(self, token_a: str, token_b: str) -> None:
super().__init__(token_a, token_b)
self.connector = EkuboAPIConnector()

def set_current_price(self) -> str:
def set_current_price(self) -> None:
"""
Get the current price of the pair.
:return: str - The current price of the pair.
Expand Down Expand Up @@ -137,6 +138,9 @@ def add_bids(self, liquidity_data: list[dict], row: pd.Series) -> None:
:param liquidity_data: liquidity data list of dict with tick and net_liquidity_delta_diff
:param row: pool row data
"""
if not self.current_price:
logging.log(logging.INFO, "Can't convert bids to base token.")
return
bid_ticks = [i for i in liquidity_data if i["tick"] <= row["tick"]][::-1]
if not bid_ticks:
return
Expand All @@ -153,7 +157,7 @@ def add_bids(self, liquidity_data: list[dict], row: pd.Series) -> None:
((glob_liq * prev_sqrt) - (glob_liq * next_sqrt)) / 10**self.token_b_decimal
)
price = self.tick_to_price(prev_tick)
self.bids.append((price, supply))
self.bids.append((price, supply / self.current_price))

for index, tick in enumerate(bid_ticks):
if index == 0:
Expand All @@ -170,7 +174,7 @@ def add_bids(self, liquidity_data: list[dict], row: pd.Series) -> None:
/ 10**self.token_b_decimal
)
price = self.tick_to_price(prev_tick)
self.bids.append((price, supply))
self.bids.append((price, supply / self.current_price))

def _get_pure_sqrt_ratio(self, tick: Decimal) -> Decimal:
"""
Expand Down