Skip to content

Commit c74a8cc

Browse files
committed
feat: magic eden: parametrize listing/offers max limits
1 parent 5276853 commit c74a8cc

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

blockapi/v2/api/nft/magic_eden.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ class MagicEdenApi(BlockchainApi, INftProvider, INftParser):
4646

4747
coin_map = NotImplemented
4848

49-
def __init__(self, sleep_provider):
49+
def __init__(self, sleep_provider, max_listings=15000, max_offers=15000):
5050
super().__init__()
51-
5251
self._sleep_provider = sleep_provider
52+
self.max_listings = max_listings
53+
self.max_offers = max_offers
5354

5455
def fetch_nfts(self, address: str) -> FetchResult:
5556
offset = 0
@@ -192,7 +193,12 @@ def fetch_offers(
192193
data_len = len(results)
193194
offset += limit
194195

195-
if data.errors or not data.data or data_len < limit or offset > 15000:
196+
if (
197+
data.errors
198+
or not data.data
199+
or data_len < limit
200+
or offset > self.max_offers
201+
):
196202
return FetchResult(
197203
status_code=data.status_code,
198204
headers=data.headers,
@@ -257,7 +263,11 @@ def _get_offer_price(self, item: dict) -> str:
257263
return str(spot_price * (1 - seller_fee - takers_fee - lp_fee))
258264

259265
def fetch_listings(
260-
self, collection: str, cursor: Optional[str] = None
266+
self,
267+
collection: str,
268+
cursor: Optional[str] = None,
269+
sort="updatedAt",
270+
sort_direction="desc",
261271
) -> FetchResult:
262272
offset = 0
263273
limit = 100
@@ -266,7 +276,7 @@ def fetch_listings(
266276
while True:
267277
self._sleep_provider.sleep(self.base_url, self.api_options.rate_limit)
268278
data = self.get_data(
269-
'get_listings', slug=collection, offset=offset, limit=limit
279+
'get_listings', slug=collection, offset=offset, limit=limit, sort=sort
270280
)
271281

272282
if self._should_retry(data):
@@ -277,7 +287,12 @@ def fetch_listings(
277287
offset += limit
278288

279289
# note: if offset is greater than 15000, causes response "offset should be non-negative integer"
280-
if data.errors or not data.data or len(data.data) < limit or offset > 15000:
290+
if (
291+
data.errors
292+
or not data.data
293+
or len(data.data) < limit
294+
or offset > self.max_listings
295+
):
281296
return FetchResult(
282297
status_code=data.status_code,
283298
headers=data.headers,

0 commit comments

Comments
 (0)