HiÐΞClassic

Entrepot NFT Floor Price (ICP) / Bar Chart Race (修正前)

SHOGAKU
a year ago
Entrepot NFT Floor Price (ICP)データ取得データ確認日ごとの最低価格でplotSaveBar Chart Race

Google Colaboratory で python勉強

Entrepot NFT Floor Price (ICP)


データ取得

!rm -r nfts_data
!git clone https://github.com/lukasvozda/nfts_data.git
!pip install -r nfts_data/requirements.txt

from ic.agent import *
from ic.identity import *
from ic.client import *
from ic.candid import Types, encode, decode

# Inicialisation
client = Client(url = "https://ic0.app")
iden = Identity()
agent= Agent(iden, client)

# Endpoint that we want to pull data from
function_to_call = 'transactions'

# List of NFTs canisters we want to pull data from
# You can find it on Entrepot clicking on NFTs 
canisters = [
    {
        'name': 'Poked bots',
        'id': 'bzsui-sqaaa-aaaah-qce2a-cai'
    },
    {
        'name': 'OG MEDALS',
        'id': 'rw623-hyaaa-aaaah-qctcq-cai'
    },
    {
        'name': 'ICPuppies',
        'id': '5movr-diaaa-aaaak-aaftq-cai'
    },
    {
        'name': 'Dfinity Space Apes',
        'id': '3mttv-dqaaa-aaaah-qcn6q-cai'
    },
    {
        'name': 'IC Dinos',
        'id': 'yrdz3-2yaaa-aaaah-qcvpa-cai'
    },
    {
        'name': 'ICPCS',
        'id': 'j3dqa-byaaa-aaaah-qcwfa-cai'
    },
    {
        'name': 'D-City',
        'id': 'gtb2b-tiaaa-aaaah-qcxca-cai'
    },
    {
        'name': 'Meme Cake',
        'id': 'txr2a-fqaaa-aaaah-qcmkq-cai'
    },
    {
        'name': 'Pineapple Punks',
        'id': 'skjpp-haaaa-aaaae-qac7q-cai'
    },
    {
        'name': 'BTC Flower',
        'id': 'pk6rk-6aaaa-aaaae-qaazq-cai'
    },
    {
        'name': 'ETH Flower',
        'id': 'dhiaa-ryaaa-aaaae-qabva-cai'
    },
    {
        'name': 'ICP Flower',
        'id': '4ggk4-mqaaa-aaaae-qad6q-cai'
    },
    {
        'name': 'Motoko',
        'id': 'oeee4-qaaaa-aaaak-qaaeq-cai'
    },
    {
        'name': 'Motoko Mechs',
        'id': 'ugdkf-taaaa-aaaak-acoia-cai'
    },
    {
        'name': 'Cubetopia Islands',
        'id': '3vdxu-laaaa-aaaah-abqxa-cai'
    },

    {
        'name': 'ICKitties',
        'id': 'rw7qm-eiaaa-aaaak-aaiqq-cai'
    },
    {
        'name': 'Cubetopia Islands',
        'id': '3vdxu-laaaa-aaaah-abqxa-cai'
    },
    {
        'name': 'Poked Bots Mutant Army',
        'id': 'jv55j-riaaa-aaaal-abvnq-cai'
    },
    {
        'name': 'ICPunks',
        'id': 'bxdf4-baaaa-aaaah-qaruq-cai'
    },
    
    {
        'name': 'Pet bots',
        'id': 't2mog-myaaa-aaaal-aas7q-cai'
    },
    {
        'name': 'IC BUCKS',
        'id': '6wih6-siaaa-aaaah-qczva-cai'
    },
    {
        'name': 'MoonWalkers',
        'id': 'er7d4-6iaaa-aaaaj-qac2q-cai'
    },
    {
        'name': 'Finterest EA Card',
        'id': '4fcza-biaaa-aaaah-abi4q-cai'
    }, 
    {
        'name': 'ICmojis',
        'id': 'gevsk-tqaaa-aaaah-qaoca-cai'
    },  

    {
        'name': 'ICTuTs',
        'id': 'ahl3d-xqaaa-aaaaj-qacca-cai'
    },
    {
        'name': 'Starverse',
        'id': 'nbg4r-saaaa-aaaah-qap7a-cai'
    },
]

# File to write results to
f  = open('result.txt','w')
# Header row
f.write(f"collection,index,token,icp,time_updated,timestamp,seller,buyer")

for c in canisters:
    params = []

    params = encode(params)

    response = agent.query_raw(c["id"], function_to_call, params)

    print("Getting collection:", c["name"])

    trans = response[0]["value"]
    for i,t in enumerate(trans):
        price = str(t['_3364572809']/100000000)
        timestamp = t['_1291635725']
        token = t['_338395897']
        seller = t['_1782082687']
        buyer = t['_3136747827']
        f.write(f"\n{c['name']},{i},{token},{price},,{timestamp},{seller},{buyer}")

f.close()

Cronic was excluded because the date data was strange.
ICPbunny was excluded because of an error
Various others are also excluded.


データ確認

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns


df = pd.read_csv("result.txt", header=0)
df['timestamp'] = pd.to_datetime(df['timestamp'])

sns.scatterplot(x='timestamp', y='icp', hue='collection', legend=True, data=df)
plt.grid(linestyle='dotted')

#レジェンド
#plt.legend(loc='upper left')

#X軸のラベルを変更
import matplotlib.dates as mdates

plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%y/%m'))
plt.gca().xaxis.set_major_locator(mdates.MonthLocator())
plt.gca().xaxis.set_major_locator(mdates.MonthLocator(interval=3))
plt.gcf().autofmt_xdate()

#Y軸 Max1000
import matplotlib.pyplot as plt

# Place legend outside of the plot
plt.legend(loc='center left', bbox_to_anchor=(1.0, 0.5))

#plt.ylim(0, 1000)

plt.show()
df = df.sort_values(by='timestamp')


日ごとの最低価格でplot

それをフロア価格とする

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

df['day'] = df['timestamp'].dt.date
df_min = df.groupby(['day', 'collection'])['icp'].min()

# ffillメソッドを使用して、前日のデータで空欄を埋める
df_min = df_min.ffill()

# プロットする
sns.scatterplot(x=df_min.index.get_level_values(0), y=df_min, hue=df_min.index.get_level_values(1), legend=True)

plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%y/%m'))
plt.gca().xaxis.set_major_locator(mdates.MonthLocator())
plt.gca().xaxis.set_major_locator(mdates.MonthLocator(interval=3))
plt.gcf().autofmt_xdate()

# Place legend outside of the plot
plt.legend(loc='center left', bbox_to_anchor=(1.0, 0.5))

plt.grid(linestyle='dotted')

plt.show()


Save

# CSV形式で保存する
df_min.to_csv("min_icp.csv")

Bar Chart Race

!pip install bar_chart_race

import pandas as pd
import bar_chart_race as bcr

# CSVファイルを読み込む
df = pd.read_csv('min_icp.csv')

# ピボットテーブルを作成する
df = df.pivot_table(index='day', 
    columns='collection',
    values='icp')

# バーグラフを作成する
bcr.bar_chart_race(df=df, n_bars=10)

コメント
いいね
投げ銭
最新順
人気順
SHOGAKU
a year ago
コメント
いいね
投げ銭
最新順
人気順
トピック
アプリ

Astar Network

DFINITY / ICP

NFT

DAO

DeFi

L2

メタバース

BCG

仮想通貨 / クリプト

ブロックチェーン別

プロジェクト

目次
Tweet
ログイン