import requests
import json
from numpy import *
import time
import pandas as pd
import matplotlib.pyplot as plt
response = requests.get("https://api-mainnet.magiceden.dev/v2/collections/theorcs/stats")
data = response.json()
num = data['listedCount']
limit = 20 #max listings taken is 20
data = []
i=0
while(i<num):
response = requests.get("https://api-mainnet.magiceden.dev/v2/collections/theorcs/listings?offset="+str(i)+"&limit=20")
data.extend(response.json())
i = len(data)
#price_array.extend([data[j]['price'] for j in range(len(data))])
#token_array.extend([data[j]['tokenMint'] for j in range(len(data))])
df = pd.DataFrame(data)
df = df.sort_values('price').reset_index(drop=True)
headers = {
"Accept": "application/json;q=0.9,image/avif,image/webp,*/*;q=0.8",
# "Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.5",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "cross-site",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0",
"Alt-Used": "api-mainnet.magiceden.io",
"TE": "trailers",
"Sec-Fetch-User": "?1"
# "Pragma": "no-cache",
# "Cache-Control": "no-cache"
}
df
data_low_price = df[df['price']<2.3]
hist = pd.read_csv('hist.csv').drop_duplicates()
data_low_price.to_csv('hist.csv', index=False)
merged = data_low_price.merge(hist, how='inner', on='tokenMint')
listed_num = len(data_low_price)
stay_num = len(merged)
old_num = len(hist)
in_num = listed_num - stay_num
out_num = old_num - stay_num
change = listed_num - old_num
from datetime import datetime
# datetime object containing current date and time
now = datetime.now()
# dd/mm/YY H:M:S
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
an_array = [dt_string, listed_num, change, in_num, out_num]
f = open("test.txt", "a")
f.write("\n"+str(an_array[0])+","+str(an_array[1])+","+str(an_array[2])+","+str(an_array[3])+","+str(an_array[4]))
f.close()
#plot_data = loadtxt('test.txt', delimiter=',', usecols=(1,2,3,4)).transpose()
#time_data = loadtxt('test.txt', delimiter=',', usecols=0, dtpye=str)
plot_data = pd.read_csv('test.txt', delimiter=',', header=None)
date = array(plot_data[0], dtype=datetime)
plot_data = plot_data.drop(0, 1)
plot_data = array(plot_data, dtype=int).transpose()
length = len(date)
if(length > 15):
date = date[length-15:]
plot_data = plot_data[:, length-15:]
plot_data[0]
fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1, sharex=True,figsize=(5,10))
ax1.plot_date(date,plot_data[0],"b-")
ax1.set_title("Listed number")
ax2.plot_date(date,plot_data[1], "r-")
ax2.set_title("Change")
ax3.plot_date(date,plot_data[2],"g-")
ax3.set_title("Newly listed")
ax4.plot_date(date,plot_data[3], "y-")
ax4.set_title("Sold/Delisted")
fig.autofmt_xdate(rotation=25)
fig.savefig('temp.png', dpi=fig.dpi)