Skip to content

Commit

Permalink
feat(deribit_fetcher): hash function used
Browse files Browse the repository at this point in the history
  • Loading branch information
akhercha committed Jul 19, 2024
1 parent e87afab commit 378b5e7
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions pragma-sdk/pragma_sdk/common/fetchers/generic_fetchers/deribit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import aiohttp
import time
import hashlib

from typing import Optional, List, Dict, Any, Tuple
from aiohttp import ClientSession
Expand Down Expand Up @@ -126,14 +127,8 @@ def from_deribit_response(cls, response: DeribitOptionResponse) -> "OptionData":
)

def __hash__(self) -> int:
return hash(
(
self.instrument_name,
self.base_currency,
self.current_timestamp,
self.mark_price,
)
)
hash_input = f"{self.instrument_name}{self.base_currency}{self.current_timestamp}{self.mark_price}"
return int(hashlib.sha256(hash_input.encode()).hexdigest(), 16)


class DeribitGenericFetcher(FetcherInterfaceT):
Expand Down Expand Up @@ -241,10 +236,9 @@ def _build_merkle_tree(
leaves = []
for currency, option_data_list in options.items():
for option_data in option_data_list:
leaf = abs(hash(option_data)) % (2**251 - 1)
leaf = hash(option_data)
leaves.append(leaf)
# Sort the leaves to ensure consistent tree construction
leaves.sort()
leaves.sort() # Sort the leaves to ensure consistent tree construction
return MerkleTree(leaves, hash_method)

async def fetch_pair( # type: ignore[override]
Expand Down

0 comments on commit 378b5e7

Please sign in to comment.