Skip to content
Merged
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
59 changes: 51 additions & 8 deletions blockapi/v2/api/nft/simple_hash.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from enum import Enum
from functools import cached_property
from typing import Iterable, Optional

Expand Down Expand Up @@ -29,6 +30,20 @@
}


class BidOrderBy(str, Enum):
BID_TIMESTAMP_ASC = 'bid_timestamp__asc'
BID_TIMESTAMP_DESC = 'bid_timestamp__desc'
BID_PRICE_ASC = 'bid_price__asc'
BID_PRICE_DESC = 'bid_price__desc'


class ListingOrderBy(str, Enum):
LISTING_TIMESTAMP_ASC = 'listing_timestamp_asc'
LISTING_TIMESTAMP_DESC = 'listing_timestamp_desc'
PRICE_ASC = 'price_asc'
PRICE_DESC = 'price_desc'


class SimpleHashApi(BlockchainApi, INftProvider, INftParser):
"""
API docs: https://docs.simplehash.com/reference/overview
Expand Down Expand Up @@ -358,22 +373,36 @@ def _get_coin(token: Optional[dict], chain) -> Optional[Coin]:
)

def fetch_offers(
self, collection: str, cursor: Optional[str] = None
self,
collection: str,
cursor: Optional[str] = None,
order_by: BidOrderBy = BidOrderBy.BID_PRICE_DESC,
) -> FetchResult:
params = {'order_by': order_by}
if cursor:
params['cursor'] = cursor

return self.get_data(
'get_bids',
headers=self.headers,
params=dict(cursor=cursor) if cursor else None,
params=params,
slug=collection,
)

def fetch_wallet_offers(
self, address: str, cursor: Optional[str] = None
self,
address: str,
cursor: Optional[str] = None,
order_by: BidOrderBy = BidOrderBy.BID_PRICE_DESC,
) -> FetchResult:
params = {'order_by': order_by}
if cursor:
params['cursor'] = cursor

return self.get_data(
'get_wallet_bids',
headers=self.headers,
params=dict(cursor=cursor) if cursor else None,
params=params,
chain=self.simplehash_blockchains,
address=address,
)
Expand Down Expand Up @@ -421,22 +450,36 @@ def _yield_parsed_offers(self, items: list[dict]) -> Iterable[NftOffer]:
)

def fetch_listings(
self, collection: str, cursor: Optional[str] = None
self,
collection: str,
cursor: Optional[str] = None,
order_by: ListingOrderBy = ListingOrderBy.PRICE_DESC,
) -> FetchResult:
params = {'order_by': order_by}
if cursor:
params['cursor'] = cursor

return self.get_data(
'get_listings',
headers=self.headers,
params=dict(cursor=cursor) if cursor else None,
params=params,
slug=collection,
)

def fetch_wallet_listings(
self, address: str, cursor: Optional[str] = None
self,
address: str,
cursor: Optional[str] = None,
order_by: ListingOrderBy = ListingOrderBy.PRICE_DESC,
) -> FetchResult:
params = {'order_by': order_by}
if cursor:
params['cursor'] = cursor

return self.get_data(
'get_wallet_listings',
headers=self.headers,
params=dict(cursor=cursor) if cursor else None,
params=params,
chain=self.simplehash_blockchains,
include_nft_details=0,
address=address,
Expand Down