-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
53 lines (39 loc) · 1.28 KB
/
plot.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import datetime
import matplotlib.pyplot as plt
import numpy as np
import requests
import sys
import urllib.request, json
# OpenSea collection slug
os_slug = sys.argv[1]
# OpenSea api key
headers = {
"Accept": "application/json",
"X-API-KEY": sys.argv[3]
}
# Since timestamp
since = int(datetime.datetime.strptime(sys.argv[2], '%Y-%m-%dT%H:%M:%S').timestamp())
os_page_size = 50
os_max_pages = 10000
sales_count = 0
x = []
y = []
cum_price = 0.0
for i in range(os_max_pages):
# Pagination offset
offset = (i*os_page_size)
# Load collection sales data
url = "https://api.opensea.io/api/v1/events?collection_slug=%s&event_type=successful&only_opensea=false&offset=%s&limit=50&occurred_after=%s" % (os_slug, offset, since)
response = requests.request("GET", url, headers=headers)
data = json.loads(response.text)
if not data['asset_events']:
print("Plotted %s sales from the %s collection" % (sales_count, os_slug))
plt.plot(x,y)
plt.show()
break
# Loop through asset events and assign plot variables
for item in data['asset_events']:
if int(item['total_price']) > 0:
x.append(datetime.datetime.strptime(item['transaction']['timestamp'], '%Y-%m-%dT%H:%M:%S'))
y.append(int(item['total_price']) / (10.0 ** 18.0))
sales_count += 1