-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagiceden_functions.py
37 lines (28 loc) · 1.04 KB
/
magiceden_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import requests
import json
import streamlit as st
def get_popular_collections(time_range="1d", top=10):
if time_range.endswith('d'):
num_days = int(time_range[:-1])
if num_days <= 1:
time_range = "1d"
elif num_days <= 7:
time_range = "7d"
else:
time_range = "30d"
if time_range.endswith('h'):
time_range = "1h"
st.write({"time_range": time_range, "top": top})
url = "https://api-mainnet.magiceden.dev/v2/marketplace/popular_collections"
headers = {"accept": "application/json"}
params = {"timeRange": time_range}
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
data = json.loads(response.text)
for collection in data:
collection.pop('description', None)
collection['floorPrice'] = collection['floorPrice'] / 1_000_000_000
limited_data = data[:top]
return limited_data
else:
response.raise_for_status()