Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7a2579e
fix(unisat): cursor fix
SimSef May 22, 2025
e0a9b52
fix(unisat): cursor fix
SimSef May 22, 2025
35d7744
fix(unisat): cursor fix
SimSef May 22, 2025
ae3c783
fix(unisat): cursor fix
SimSef May 22, 2025
9cca195
fix(unisat): cursor fix
SimSef May 22, 2025
6fa64d1
fix(unisat): cursor fix
SimSef May 22, 2025
c2e11d4
fix(unisat): get_collection_summary + fetch_collection internal serve…
SimSef May 27, 2025
58a7aaf
Merge branch 'master' into 2149-blockapi-btc-nft-api-replacement-afte…
SimSef May 27, 2025
1391c09
fix(unisat): get_collection_summary + fetch_collection internal serve…
SimSef May 27, 2025
ecb9286
Revert "fix(unisat): get_collection_summary + fetch_collection intern…
SimSef May 27, 2025
40825c1
fix(unisat): fetch collection adjustment
SimSef May 27, 2025
82303ff
fix: unisat fetch collection adjustment
SimSef May 27, 2025
20d823d
fix: unisat collection fetch adjustment
SimSef May 27, 2025
61e5fc1
fix: unisat collection fetch adjustment
SimSef May 27, 2025
c98570a
fix: unisat fetch collection adjustment
SimSef May 27, 2025
61404b3
fix: unisat collection fetch adjustment
SimSef May 29, 2025
90bef73
Merge branch 'master' into 2149-blockapi-btc-nft-api-replacement-afte…
SimSef May 29, 2025
0b2c5d4
fix: unisat collection fetch adjustment
SimSef May 29, 2025
69d2e8c
Merge branch '2149-blockapi-btc-nft-api-replacement-after-simplehash-…
SimSef May 29, 2025
9c784af
fix: pricing + images naive fetch
SimSef May 29, 2025
a98cc23
fix: pricing + images naive fetch
SimSef May 29, 2025
0b9b6f9
fix: pricing + images naive fetch
SimSef May 29, 2025
e549b66
fix: pricing + images naive fetch
SimSef May 29, 2025
9c93dfd
fix: pricing + images naive fetch
SimSef May 29, 2025
9351e03
fix: pricing + images naive fetch
SimSef May 29, 2025
f8595a7
fix: pricing + images naive fetch
SimSef May 29, 2025
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
6 changes: 3 additions & 3 deletions blockapi/test/v2/api/nft/test_unisat.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ def test_fetch_collection(requests_mock, unisat_client, collection_stats):
assert not collection.is_disabled
assert not collection.is_nsfw
assert collection.blockchain == Blockchain.BITCOIN
assert str(collection.total_stats.floor_price) == "990000"
assert str(collection.total_stats.floor_price) == "0.0099"
assert str(collection.total_stats.owners_count) == "1563"
assert str(collection.total_stats.sales_count) == "20"
assert str(collection.total_stats.volume) == "39900000"
assert str(collection.total_stats.market_cap) == str(990000 * 1563)
assert str(collection.total_stats.volume) == "0.399"
assert str(collection.total_stats.market_cap) == "15.4737"


def test_fetch_listings(requests_mock, unisat_client, listings_data):
Expand Down
30 changes: 14 additions & 16 deletions blockapi/v2/api/nft/unisat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
NftOfferDirection,
BtcNftType,
)
from blockapi.utils.num import raw_to_decimals
from requests import HTTPError
import requests

Expand Down Expand Up @@ -81,7 +82,7 @@ def __init__(
}
self.limit = limit

self._collection_map: Dict[str, Tuple[str, str]] | None = None
self._collection_map = None

def fetch_nfts(self, address: str) -> FetchResult:
"""
Expand Down Expand Up @@ -187,12 +188,12 @@ def _yield_parsed_nfts(self, data: Dict) -> Generator[NftToken, None, None]:
ident=iid,
collection=cid,
collection_name=cname,
contract=utxo["txid"],
contract=cid,
standard="ordinals",
name=f"Ordinal #{item['inscriptionNumber']}",
description="",
amount=1,
image_url="",
image_url=f"https://open-api.unisat.io/v1/indexer/inscription/content/{iid}",
metadata_url=None,
updated_time=str(item["timestamp"]),
is_disabled=False,
Expand Down Expand Up @@ -295,14 +296,15 @@ def parse_collection(self, fetch_result: FetchResult) -> ParseResult:
if icon:
icon_url = f"https://static.unisat.io/content/{icon}"

# Create NftCollectionTotalStats
floor_price = stats.get("floorPrice", 0)
floor_price = raw_to_decimals(stats.get("floorPrice", 0), self.coin.decimals)

volume = raw_to_decimals(stats.get("btcValue", 0), self.coin.decimals)

total_nfts = stats.get("total", 0)
# Calculate market cap as floor price × total supply
market_cap = floor_price * total_nfts if floor_price and total_nfts else 0
market_cap = floor_price * total_nfts if total_nfts else 0

total_stats = NftCollectionTotalStats.from_api(
volume=str(stats.get("btcValue", 0)),
volume=str(volume),
sales_count=str(stats.get("listed", 0)),
owners_count=str(total_nfts),
market_cap=str(market_cap),
Expand Down Expand Up @@ -515,9 +517,7 @@ def _yield_parsed_listings(
if amount is None:
amount = 1

price = item.get('price')
if price is None:
price = 0
price_sat = item.get('price') or 0

yield NftOffer.from_api(
offer_key=item["auctionId"],
Expand All @@ -534,7 +534,7 @@ def _yield_parsed_listings(
offer_ident=item["inscriptionId"],
pay_contract=None,
pay_ident=None,
pay_amount=price,
pay_amount=price_sat,
pay_coin=self.coin,
)

Expand Down Expand Up @@ -674,9 +674,7 @@ def _yield_parsed_offers(
f"Could not parse timestamp {timestamp} for item {item.get('auctionId')}"
)

price = item.get('price')
if price is None:
price = 0
price_sat = item.get('price') or 0

yield NftOffer.from_api(
offer_key=item["auctionId"],
Expand All @@ -693,6 +691,6 @@ def _yield_parsed_offers(
offer_ident=item["inscriptionId"],
pay_contract=None,
pay_ident=None,
pay_amount=price,
pay_amount=price_sat,
pay_coin=self.coin,
)