HiÐΞWeb3

ICP NFTフロア価格(その日の最低取引価格とする)のデータを引っ張りたいとき

SHOGAKU
1年前
ICP NFTフロア価格(その日の最低取引価格とする)のデータを引っ張りたいときNFTトランザクションデータを収集するスクリプト取得したデータ確認グラフ化日時を修正、レジェンド追加フロア価格csvファイルに保存するGoogle Driveに保存する

Google Colaboratory で実施した例です

Google Colaboratory → https://colab.research.google.com/?hl=ja#


ICP NFTフロア価格(その日の最低取引価格とする)のデータを引っ張りたいとき

以下に流れを記載


NFTトランザクションデータを収集するスクリプト

!rm -r nfts_data は、繰り返し使ったときにエラー出た対処の名残りで残しています

!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': 'Motoko',
        'id': 'oeee4-qaaaa-aaaak-qaaeq-cai'
    },
    {
        'name': 'BTC Flowers',
        'id': 'pk6rk-6aaaa-aaaae-qaazq-cai'
    },
    {
        'name': 'Poked bots',
        'id': 'bzsui-sqaaa-aaaah-qce2a-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()

以下のような部分はお好みのNFTに置き換えください
nameは適当で良いはず


name: 'Motoko'
id: 'oeee4-qaaaa-aaaak-qaaeq-cai'


取得したデータ確認

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.read_csv("result.txt", header=0)

print(df)


グラフ化

sns.scatterplot(x='timestamp', y='icp', data=df)
plt.show()


日時を修正、レジェンド追加

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.show()


フロア価格

その日の最低取引価格、ない場合は前日を引き継ぐ

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()

# プロットする
ax = sns.scatterplot(x=df_min.index.get_level_values(0), y=df_min, hue=df_min.index.get_level_values(1))
ax.legend(loc='center right', bbox_to_anchor=(1.35, 0.9))
plt.show()


csvファイルに保存する

import pandas as pd

#DataFrameを作成
df_temp = pd.DataFrame({
'date': df_min.index.get_level_values(0),
'ICP': df_min,
'collection': df_min.index.get_level_values(1)
})

#CSV形式で保存する
df_temp.to_csv("min_icp.csv", index=False)

Google Driveに保存する

from google.colab import drive
drive.mount('/content/gdrive')

df_temp.to_csv('/content/gdrive/My Drive/min_icp.csv', index=False)


というような感じとりあえずデータを出せた。


コメント
いいね
投げ銭
最新順
人気順
SHOGAKU
1年前
コメント
いいね
投げ銭
最新順
人気順
トピック
アプリ

Astar Network

DFINITY / ICP

NFT

DAO

DeFi

L2

メタバース

BCG

仮想通貨 / クリプト

ブロックチェーン別

プロジェクト

目次
Tweet
ログイン