Skip to content

Commit

Permalink
feat(deribit_fetcher): Functions order
Browse files Browse the repository at this point in the history
  • Loading branch information
akhercha committed Jul 19, 2024
1 parent 151c8e5 commit 5652e96
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions pragma-sdk/pragma_sdk/common/fetchers/generic_fetchers/deribit.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ def __hash__(self) -> int:
(
self.instrument_name,
self.base_currency,
self.creation_timestamp,
self.current_timestamp,
self.mark_price,
)
Expand Down Expand Up @@ -163,7 +162,7 @@ async def fetch(
For every unique base assets in the provided pairs list, fetch all the
available instruments and their option data.
They'll be merged in a merkle tree, and we only return the merkle root
using the GenericEntry type.
using the GenericEntry type (so we only return one Entry in the final list).
"""
currencies_options: Dict[str, List[OptionData]] = {}

Expand All @@ -182,25 +181,6 @@ async def fetch(
)
return [entry]

def _build_merkle_tree(
self,
options: Dict[str, List[OptionData]],
hash_method: HashMethod = HashMethod.PEDERSEN,
) -> MerkleTree:
"""
Builds and return a MerkleTree from all the available fetched options.
"""
leaves = []
for currency, option_data_list in options.items():
for option_data in option_data_list:
leaf = abs(hash(option_data)) % (
2**251 - 1 # Use a prime number close to 2^251
)
leaves.append(leaf)
# Sort the leaves to ensure consistent tree construction
leaves.sort()
return MerkleTree(leaves, hash_method)

async def _fetch_options(
self,
currency: Currency,
Expand Down Expand Up @@ -247,6 +227,25 @@ def _assert_request_succeeded(self, response: Dict[str, Any]) -> None:
else:
raise PublisherFetchError("Unexpected API response format")

def _build_merkle_tree(
self,
options: Dict[str, List[OptionData]],
hash_method: HashMethod = HashMethod.PEDERSEN,
) -> MerkleTree:
"""
Builds and return a MerkleTree from all the available fetched options.
"""
leaves = []
for currency, option_data_list in options.items():
for option_data in option_data_list:
leaf = abs(hash(option_data)) % (
2**251 - 1 # Use a prime number close to 2^251
)
leaves.append(leaf)
# Sort the leaves to ensure consistent tree construction
leaves.sort()
return MerkleTree(leaves, hash_method)

async def fetch_pair( # type: ignore[override]
self, pair: Pair, session: ClientSession
) -> List[Entry] | PublisherFetchError:
Expand Down

0 comments on commit 5652e96

Please sign in to comment.