From b5a56848250a28033c3325dc491e547d58814c4e Mon Sep 17 00:00:00 2001 From: CoCoNuTeK Date: Tue, 8 Apr 2025 16:09:29 +0200 Subject: [PATCH] feat: implement Unisat API for BTC NFTs; fetch NFTs, collections, offers, listings --- .../v2/api/data/unisat/collection_stats.json | 40 ++++++++++--------- blockapi/test/v2/api/nft/test_unisat.py | 10 ++--- blockapi/v2/api/nft/unisat.py | 2 +- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/blockapi/test/v2/api/data/unisat/collection_stats.json b/blockapi/test/v2/api/data/unisat/collection_stats.json index 12eaf324..9d8ab159 100644 --- a/blockapi/test/v2/api/data/unisat/collection_stats.json +++ b/blockapi/test/v2/api/data/unisat/collection_stats.json @@ -1,21 +1,23 @@ { - "code": 0, - "msg": "OK", - "data": { - "collectionId": "6fb976ab49dcec017f1e2015b625126c5c4d6b71174f5bc5af4f39b274a4b6b5i0", - "name": "Ordinal Punks", - "desc": "The first 10,000 Punks inscribed on Bitcoin", - "icon": "https://ordinals.com/content/6fb976ab49dcec017f1e2015b625126c5c4d6b71174f5bc5af4f39b274a4b6b5i0", - "iconContentType": "image/png", - "btcValue": 1.5, - "floorPrice": 0.1, - "pricePercent": 10.5, - "listed": 50, - "total": 1000, - "supply": 10000, - "twitter": "https://twitter.com/ordinalpunks", - "discord": "https://discord.gg/ordinalpunks", - "website": "https://ordinalpunks.com", - "verification": true - } + "code": 0, + "msg": "ok", + "data": { + "collectionId": "pixel-pepes", + "name": "Pixel Pepes", + "desc": "The first ever airdrop on the Bitcoin network. 1563 rare Pixel Pepes airdropped to users who had made a transaction on ordinalswallet.com before block 777888.", + "icon": "47c1d21c508f6d49dfde64d958f14acd041244e1bb616f9b78114b8d9dc7b945i0", + "iconContentType": "image/png", + "btcValue": 39900000, + "btcValuePercent": 1, + "floorPrice": 990000, + "listed": 20, + "total": 1563, + "supply": null, + "attrs": [], + "twitter": "https://twitter.com/PepesPixel", + "discord": "https://discord.gg/ordinalswallet", + "website": "", + "pricePercent": 1, + "verification": false + } } \ No newline at end of file diff --git a/blockapi/test/v2/api/nft/test_unisat.py b/blockapi/test/v2/api/nft/test_unisat.py index c555be21..f46e2d09 100644 --- a/blockapi/test/v2/api/nft/test_unisat.py +++ b/blockapi/test/v2/api/nft/test_unisat.py @@ -113,10 +113,10 @@ def test_parse_nfts_edge_cases( assert nft.asset_type == AssetType.AVAILABLE -def test_fetch_collection(requests_mock, unisat_client, collection_stats_v4): +def test_fetch_collection(requests_mock, unisat_client, collection_stats): requests_mock.post( - f"{unisat_client.api_options.base_url}market-v4/collection/auction/collection_statistic", - text=collection_stats_v4, + f"{unisat_client.api_options.base_url}v3/market/collection/auction/collection_statistic", + text=collection_stats, ) test_collection = "pixel-pepes" @@ -268,5 +268,5 @@ def offers_data(): @pytest.fixture -def collection_stats_v4(): - return read_file('data/unisat/collection_stats_v4.json') +def collection_stats(): + return read_file('data/unisat/collection_stats.json') diff --git a/blockapi/v2/api/nft/unisat.py b/blockapi/v2/api/nft/unisat.py index ceaed11f..0f97737b 100644 --- a/blockapi/v2/api/nft/unisat.py +++ b/blockapi/v2/api/nft/unisat.py @@ -51,7 +51,7 @@ class UnisatApi(BlockchainApi, INftParser, INftProvider): 'get_nfts': 'v1/indexer/address/{address}/inscription-data', 'get_listings': 'v3/market/collection/auction/list', 'get_offers': 'v3/market/collection/auction/actions', - 'get_collection_stats': 'market-v4/collection/auction/collection_statistic', + 'get_collection_stats': 'v3/market/collection/auction/collection_statistic', } def __init__(self, api_key: str, sleep_provider: Optional[ISleepProvider] = None):