Rで解析:変わり種!暗号資産の情報を取得できます。「crypto2」パッケージ

暗号資産の情報をcoinmarketcapから取得するパッケージの紹介です。APIを利用せずにデータを取得しています。取得コマンドを実行すると次の実行まで1分間の待機時間があることに注意です。実行コマンドではXYM(Symbol)の情報を取得し、USD価格をプロットしました。

興味があれば下記リンクで他のコマンドを確認してください。

crypto2:https://github.com/sstoeckl/crypto2

パッケージのバージョンは1.4.0。実行コマンドはwindows 11のR version 4.1.2で動作を確認しています。

パッケージのインストール

下記コマンドを実行してください。

#パッケージのインストール
install.packages("crypto2")

実行コマンド

詳細はコマンド、パッケージヘルプを確認してください。

#パッケージの読み込み
library("crypto2")

#tidyverseパッケージがなければインストール
if(!require("tidyverse", quietly = TRUE)){
  install.packages("tidyverse");require("tidyverse")
}

#暗号資産のリストを取得:crypto_listコマンド
coins <- crypto_list(only_active = TRUE)

#XYM(Symbol)&#12398;&#24773;&#22577;&#12434;&#25244;&#12365;&#20986;&#12375;
coins %>%
  filter(symbol == "XYM") -> XYMList

#&#30906;&#35469;
XYMList
#A tibble: 1 x 8
id name   symbol     slug  rank is_active first_historical_data last_historical_data
<int> <chr>  <chr>  <chr>  <int>     <int> <date>                <date>              
8677 Symbol XYM    symbol   212         1 2021-03-19            2022-01-11   

#&#26263;&#21495;&#36039;&#29987;&#12398;&#24773;&#22577;&#12434;&#21462;&#24471;:crypto_info&#12467;&#12510;&#12531;&#12489;
#&#21462;&#24471;&#12522;&#12473;&#12488;&#12434;&#22522;&#12395;&#24773;&#22577;&#12434;&#21462;&#24471;&#12375;&#12414;&#12377;
#&#12522;&#12473;&#12488;&#12363;&#12425;&#21462;&#24471;&#12377;&#12427;&#21508;&#26263;&#21495;&#36039;&#29987;&#12398;&#24773;&#22577;:limit&#12458;&#12503;&#12471;&#12519;&#12531;
coin_info <- crypto_info(XYMList, limit = NULL)
#&#30906;&#35469;
coin_info
# A tibble: 1 x 18
#id name   symbol category description slug  logo  subreddit notice date_added
#* <int> <chr>  <chr>  <chr>    <chr>       <chr> <chr> <chr>     <chr>  <chr>     
#  1  8677 Symbol XYM    coin     "## What i~ symb~ http~ ""        ""     2021-03-0~
# ... with 8 more variables: twitter_username <chr>, is_hidden <int>,
#   date_launched <chr>, self_reported_circulating_supply <lgl>, tags <lgl>,
#   self_reported_tags <lgl>, urls <list>, platform <lgl>

#&#26263;&#21495;&#36039;&#29987;&#12398;&#20385;&#26684;&#12434;&#21462;&#24471;:crypto_history&#12467;&#12510;&#12531;&#12489;
coin_hist <- crypto_history(XYMList, limit = 1,
                            start_date = "20211001", end_date = "20220111")
#&#21462;&#24471;&#12375;&#12383;&#20385;&#26684;&#19968;&#35239;&#12363;&#12425;&#31665;&#12402;&#12370;&#22259;&#12434;&#20316;&#12427;
coin_hist %>% select(timestamp, open, high, low, close) %>%
  mutate(timestamp = as.POSIXct(timestamp)) %>%
  gather(key = stock, value = price, open, high, low, close) %>%
  arrange(timestamp) -> PlotData
#&#12503;&#12525;&#12483;&#12488;
ggplot(PlotData, aes(x = timestamp, y = price, group = timestamp)) +
  labs(y = "price USD") +
  geom_boxplot(fill = "#8d33e5")

出力例

2021.10.01から2022.01.11までのXYM(Symbol)のUSD価格の推移です。


少しでも、あなたの解析が楽になりますように!!

Prices and shipping availability may change. Please refer to the product page at time of purchase.
Content displayed on this site is provided by Amazon and may be updated or removed.
Amazon Associate, karada-good earns income through qualifying sales.
タイトルとURLをコピーしました