# ICP NFTフロア価格(その日の最低取引価格とする)のデータを引っ張りたいとき **Published by:** [Shogaku](https://paragraph.com/@shogaku/) **Published on:** 2023-01-30 **URL:** https://paragraph.com/@shogaku/icp-nft ## Content ブログコピー元 ↓ https://hide.ac/articles/ocAMI6eK_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() このコードは、Interledger 関連の技術を使用して、NFTトランザクションデータを収集するスクリプトhttps://github.com/lukasvozda/nfts_data.git を見ながら実施以下のような部分はお好みの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) というような感じとりあえずデータを出せた。 ## Publication Information - [Shogaku](https://paragraph.com/@shogaku/): Publication homepage - [All Posts](https://paragraph.com/@shogaku/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@shogaku): Subscribe to updates - [Twitter](https://twitter.com/ussu_ussu_ussu): Follow on Twitter