Skip to content

Commit efc2920

Browse files
authored
fix: pricing + images naive fetch (#235)
* fix(unisat): cursor fix * fix(unisat): cursor fix * fix(unisat): cursor fix * fix(unisat): cursor fix * fix(unisat): cursor fix * fix(unisat): cursor fix * fix(unisat): get_collection_summary + fetch_collection internal server error on unisat side * fix(unisat): get_collection_summary + fetch_collection internal server error on unisat side * Revert "fix(unisat): get_collection_summary + fetch_collection internal server error on unisat side" This reverts commit 1391c09. * fix(unisat): fetch collection adjustment * fix: unisat fetch collection adjustment * fix: unisat collection fetch adjustment * fix: unisat collection fetch adjustment * fix: unisat fetch collection adjustment * fix: unisat collection fetch adjustment * fix: unisat collection fetch adjustment * fix: pricing + images naive fetch * fix: pricing + images naive fetch * fix: pricing + images naive fetch * fix: pricing + images naive fetch * fix: pricing + images naive fetch * fix: pricing + images naive fetch * fix: pricing + images naive fetch
1 parent abe7f40 commit efc2920

2 files changed

Lines changed: 16 additions & 18 deletions

File tree

blockapi/test/v2/api/nft/test_unisat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ def test_fetch_collection(requests_mock, unisat_client, collection_stats):
4949
assert not collection.is_disabled
5050
assert not collection.is_nsfw
5151
assert collection.blockchain == Blockchain.BITCOIN
52-
assert str(collection.total_stats.floor_price) == "990000"
52+
assert str(collection.total_stats.floor_price) == "0.0099"
5353
assert str(collection.total_stats.owners_count) == "1563"
5454
assert str(collection.total_stats.sales_count) == "20"
55-
assert str(collection.total_stats.volume) == "39900000"
56-
assert str(collection.total_stats.market_cap) == str(990000 * 1563)
55+
assert str(collection.total_stats.volume) == "0.399"
56+
assert str(collection.total_stats.market_cap) == "15.4737"
5757

5858

5959
def test_fetch_listings(requests_mock, unisat_client, listings_data):

blockapi/v2/api/nft/unisat.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
NftOfferDirection,
2222
BtcNftType,
2323
)
24+
from blockapi.utils.num import raw_to_decimals
2425
from requests import HTTPError
2526
import requests
2627

@@ -81,7 +82,7 @@ def __init__(
8182
}
8283
self.limit = limit
8384

84-
self._collection_map: Dict[str, Tuple[str, str]] | None = None
85+
self._collection_map = None
8586

8687
def fetch_nfts(self, address: str) -> FetchResult:
8788
"""
@@ -192,7 +193,7 @@ def _yield_parsed_nfts(self, data: Dict) -> Generator[NftToken, None, None]:
192193
name=f"Ordinal #{item['inscriptionNumber']}",
193194
description="",
194195
amount=1,
195-
image_url="",
196+
image_url=f"https://open-api.unisat.io/v1/indexer/inscription/content/{iid}",
196197
metadata_url=None,
197198
updated_time=str(item["timestamp"]),
198199
is_disabled=False,
@@ -295,14 +296,15 @@ def parse_collection(self, fetch_result: FetchResult) -> ParseResult:
295296
if icon:
296297
icon_url = f"https://static.unisat.io/content/{icon}"
297298

298-
# Create NftCollectionTotalStats
299-
floor_price = stats.get("floorPrice", 0)
299+
floor_price = raw_to_decimals(stats.get("floorPrice", 0), self.coin.decimals)
300+
301+
volume = raw_to_decimals(stats.get("btcValue", 0), self.coin.decimals)
302+
300303
total_nfts = stats.get("total", 0)
301-
# Calculate market cap as floor price × total supply
302-
market_cap = floor_price * total_nfts if floor_price and total_nfts else 0
304+
market_cap = floor_price * total_nfts if total_nfts else 0
303305

304306
total_stats = NftCollectionTotalStats.from_api(
305-
volume=str(stats.get("btcValue", 0)),
307+
volume=str(volume),
306308
sales_count=str(stats.get("listed", 0)),
307309
owners_count=str(total_nfts),
308310
market_cap=str(market_cap),
@@ -515,9 +517,7 @@ def _yield_parsed_listings(
515517
if amount is None:
516518
amount = 1
517519

518-
price = item.get('price')
519-
if price is None:
520-
price = 0
520+
price_sat = item.get('price') or 0
521521

522522
yield NftOffer.from_api(
523523
offer_key=item["auctionId"],
@@ -534,7 +534,7 @@ def _yield_parsed_listings(
534534
offer_ident=item["inscriptionId"],
535535
pay_contract=None,
536536
pay_ident=None,
537-
pay_amount=price,
537+
pay_amount=price_sat,
538538
pay_coin=self.coin,
539539
)
540540

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

677-
price = item.get('price')
678-
if price is None:
679-
price = 0
677+
price_sat = item.get('price') or 0
680678

681679
yield NftOffer.from_api(
682680
offer_key=item["auctionId"],
@@ -693,6 +691,6 @@ def _yield_parsed_offers(
693691
offer_ident=item["inscriptionId"],
694692
pay_contract=None,
695693
pay_ident=None,
696-
pay_amount=price,
694+
pay_amount=price_sat,
697695
pay_coin=self.coin,
698696
)

0 commit comments

Comments
 (0)