New R Package: cryptotrackr

[This article was first published on R in Trevor French on Medium, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

cryptotrackr allows you to connect to data sources across the crypto ecosystem. This data can enable a range of activity such as portfolio tracking, programmatic trading, or industry analysis.

cryptotrackr hex logo

The package currently connects to 20 of the top data sources in the crypto world and has over 100 functions to help you quickly pull data from exchanges, blockchains, and data aggregators.

Links

Supported Data Sources

Installation

The package must currently be installed through GitHub as it is not yet available through CRAN.

install.packages("remotes")
remotes::install_github("TrevorFrench/cryptotrackr")

Dependencies

cryptotrackr is dependent on the following packages: httr, jsonlite, stringi, openssl, utils, digest

Examples

Below are a few examples demonstrating how one might leverage the cryptotrackr package to retrieve data from various data sources.

Amberdata

api_key <- "..."
metrics <- amberdata_market_metrics(api_key, "btc")
metrics

# $nvt
# $nvt$signal
# [1] 11.91642
# 
# $sharpe
# $sharpe$historicalVolatility
# [1] 1.785101
# 
# $sharpe$ratio
# [1] 0.06860491
# 
# $stockToFlow
# $stockToFlow$blockNumber
# [1] 769324
# 
# $stockToFlow$circulation
# [1] 19245781
# 
# $stockToFlow$lastYearCirculation
# [1] 18913625
# 
# $stockToFlow$ratio
# [1] 57.94195
# 
# $stockToFlow$price
# [1] 111869.7

Binance.US

symbol <- 'LTCBTC'
limit <- '1000'
recent_trades <- binance_us_recent_trades(symbol, limit)
head(recent_trades)

# id      price        qty   quoteQty         time isBuyerMaker isBestMatch
# 1 1284646 0.00394600 0.06000000 0.00023676 1.671991e+12         TRUE        TRUE
# 2 1284647 0.00393900 0.03000000 0.00011817 1.671993e+12         TRUE        TRUE
# 3 1284648 0.00394000 0.38000000 0.00149720 1.671993e+12         TRUE        TRUE
# 4 1284649 0.00394500 0.12000000 0.00047340 1.671994e+12         TRUE        TRUE
# 5 1284650 0.00395200 0.10000000 0.00039520 1.671996e+12        FALSE        TRUE
# 6 1284651 0.00395700 0.53000000 0.00209721 1.671996e+12        FALSE        TRUE

Blockchain.com

symbol <- 'BTC-USD'
l2_order_book <- blockchain_dot_com_l2_order_book(symbol)
bids <- l2_order_book$bids
asks <- l2_order_book$asks

head(bids)
#         px        qty num
# 1 16528.94 0.06110495   1
# 2 16528.32 0.54996515   1
# 3 16527.49 0.91665462   1
# 4 16526.67 1.52783350   1
# 5 16525.84 3.05582046   1
# 6 16200.50 0.20000000   1

head(asks)
#         px        qty num
# 1 16530.92 0.06109763   1
# 2 16531.54 0.54985803   1
# 3 16532.36 0.91638459   1
# 4 16533.19 1.52723098   1
# 5 16534.02 3.05430863   1
# 6 16620.90 1.73778630   1

CEX.IO

symbol_1 <- 'btc'
symbol_2 <- 'usd'
ticker_info <- cex_io_ticker(symbol_1, symbol_2)
ticker_info

# $timestamp
# [1] "1672267856"
# 
# $low
# [1] "16500.1"
# 
# $high
# [1] "16798.2"
# 
# $last
# [1] "16559.5"
# 
# $volume
# [1] "17.01190547"
# 
# $volume30d
# [1] "498.21497337"
# 
# $bid
# [1] 16559.5
# 
# $ask
# [1] 16562.9
# 
# $priceChange
# [1] "-160.9"
# 
# $priceChangePercentage
# [1] "-0.96"
# 
# $pair
# [1] "BTC:USD"

Coinbase

currencies <- coinbase_all_currencies()
head(currencies[,1:6])

# id                  name min_size   status message max_precision
# 1   ANKR                  Ankr       10   online            0.00000001
# 2   ATOM                Cosmos        1   online              0.000001
# 3   CTSI               Cartesi        1   online                   0.1
# 4    ZRX                    0x  0.00001   online            0.00000001
# 5 BADGER            Badger DAO     0.01   online                 0.001
# 6    RGT Rari Governance Token     0.01 delisted                 0.001

CoinGecko

categories <- coingecko_categories()
head(categories)

#               category_id                    name
# 1             aave-tokens             Aave Tokens
# 2      algorand-ecosystem      Algorand Ecosystem
# 3               analytics               Analytics
# 4      arbitrum-ecosystem      Arbitrum Ecosystem
# 5 arbitrum-nova-ecosystem Arbitrum Nova Ecosystem
# 6 artificial-intelligence Artificial Intelligence

Coinlist

symbols <- coinlist_symbols()
head(symbols)

#     symbol base_currency is_trader_geofenced                list_time type
# 1   ETH-BTC           ETH               FALSE 2020-07-08T00:00:00.000Z spot
# 2 COMP-USDT          COMP               FALSE 2022-02-16T00:00:00.000Z spot
# 3   ETH-USD           ETH               FALSE 2020-06-22T00:00:00.000Z spot
# 4  MKR-USDT           MKR               FALSE 2021-09-16T00:00:00.000Z spot
# 5  BLD-USDT           BLD               FALSE 2022-10-18T00:00:00.000Z spot
# 6   BLD-USD           BLD               FALSE 2022-10-18T00:00:00.000Z spot
#      series_code long_name asset_class minimum_price_increment minimum_size_increment
# 1   ETH-BTC-SPOT     Ether      CRYPTO                 0.00001                 0.0001
# 2 COMP-USDT-SPOT  Compound      CRYPTO                  0.0001                 0.0001
# 3   ETH-USD-SPOT     Ether      CRYPTO                    0.01                 0.0001
# 4  MKR-USDT-SPOT     Maker      CRYPTO                  0.0001                 0.0001
# 5  BLD-USDT-SPOT    Agoric      CRYPTO                  0.0001                 0.0001
# 6   BLD-USD-SPOT    Agoric      CRYPTO                  0.0001                 0.0001
#   quote_currency index_code price_band_threshold_market price_band_threshold_limit
# 1            BTC         NA                        0.05                       0.25
# 2           USDT         NA                        0.05                       0.25
# 3            USD         NA                        0.05                       0.25
# 4           USDT         NA                        0.05                       0.25
# 5           USDT         NA                        0.05                       0.25
# 6            USD         NA                        0.05                       0.25
#      last_price    fair_price index_price
# 1    0.07155000    0.07181000          NA
# 2   33.43600000   31.81450000          NA
# 3 1205.31000000 1185.25000000          NA
# 4  526.65820000  513.81010000          NA
# 5    0.50020000    0.49400000          NA
# 6    0.49430000    0.49370000          NA

CoinMarketCap

api_key <- "..."
id_map <- coinmarketcap_id_map(api_key)
head(id_map)

#   id      name symbol      slug rank displayTV manualSetTV tvCoinSymbol is_active    first_historical_data
# 1  1   Bitcoin    BTC   bitcoin    1         1           0                      1 2013-04-28T18:47:21.000Z
# 2  2  Litecoin    LTC  litecoin   14         1           0                      1 2013-04-28T18:47:22.000Z
# 3  3  Namecoin    NMC  namecoin  607         1           0                      1 2013-04-28T18:47:22.000Z
# 4  4 Terracoin    TRC terracoin 1686         1           0                      1 2013-04-28T18:47:22.000Z
# 5  5  Peercoin    PPC  peercoin  675         1           0                      1 2013-04-28T18:47:23.000Z
# 6  6  Novacoin    NVC  novacoin 2140         1           0                      1 2013-04-28T18:47:23.000Z
#       last_historical_data platform.id platform.name platform.symbol platform.slug platform.token_address status
# 1 2022-12-28T22:49:00.000Z          NA          <NA>            <NA>          <NA>                   <NA> active
# 2 2022-12-28T22:49:00.000Z          NA          <NA>            <NA>          <NA>                   <NA> active
# 3 2022-12-28T22:49:00.000Z          NA          <NA>            <NA>          <NA>                   <NA> active
# 4 2022-12-28T22:49:00.000Z          NA          <NA>            <NA>          <NA>                   <NA> active
# 5 2022-12-28T22:49:00.000Z          NA          <NA>            <NA>          <NA>                   <NA> active
# 6 2022-12-28T22:49:00.000Z          NA          <NA>            <NA>          <NA>                   <NA> active

Covalent

api_key <- "..."
balances <- covalent_balances(api_key, "1", "trevorfrench.eth", csv = FALSE)
balances$data$items[,c(2,10)]

#           contract_name               balance
# 1         Developer DAO 817210000000000000000
# 2              USD Coin              50000000
# 3           Matic Token  45000000000000000000
# 4                 Ether     27185952941495928
# 5                  SAND   6360502580000000000
# 6 Ethereum Name Service     23119820924391424
# 7                   AMY                 61616

Crypto.com

instruments <- crypto_dot_com_instruments()
head(instruments[1:4])

#   instrument_name quote_currency base_currency price_decimals
# 1        RSR_USDT           USDT           RSR              7
# 2       PERP_USDT           USDT          PERP              5
# 3       MATIC_BTC            BTC         MATIC              9
# 4       MATIC_USD            USD         MATIC              5
# 5       SHIB_USDT           USDT          SHIB              9
# 6         GRT_BTC            BTC           GRT             10

Etherscan

address <- "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae"
api_key <- "..."
account_balance <- etherscan_account_balance(address, api_key)

# [1] "337271480606123395679776"

Gemini

prices <- gemini_price_feed()
head(prices)

#      pair  price percentChange24h
# 1  MIMUSD      1           0.0029
# 2  CVCUSD 0.0749          -0.0660
# 3  NMRUSD  12.98          -0.0387
# 4 GUSDGBP  0.829          -0.0024
# 5  XTZUSD 0.7364          -0.0443
# 6  SBRUSD  0.001          -0.0244

Helium

block_stats <- helium_block_stats()
block_stats

# $last_week
# $last_week$stddev
# [1] 2.831961
# 
# $last_week$avg
# [1] 61.25213
# 
# 
# $last_month
# $last_month$stddev
# [1] 6.065927
# 
# $last_month$avg
# [1] 58.50106
# 
# 
# $last_hour
# $last_hour$stddev
# [1] 11.32656
# 
# $last_hour$avg
# [1] 62.52727
# 
# 
# $last_day
# $last_day$stddev
# [1] 3.560346
# 
# $last_day$avg
# [1] 61.28551

Huobi

period <- '1day'
size <- '200'
symbol <- 'btcusdt'
candles <- huobi_candles(period, size, symbol)
head(candles)

#           id     open    close      low     high    amount      vol count
# 1 1672243200 16576.54 16536.72 16460.00 16664.10  906.5396 15013196 12964
# 2 1672156800 16797.69 16577.37 16569.87 16800.86 2500.7686 41690406 48376
# 3 1672070400 16806.50 16809.16 16735.00 16963.78 2732.5807 46028473 49839
# 4 1671984000 16793.01 16806.53 16735.00 16911.00 1840.5360 30985514 40178
# 5 1671897600 16832.69 16793.33 16730.00 16856.98 1306.6446 21979506 25427
# 6 1671811200 16832.36 16832.70 16770.25 16853.00 1453.2314 24449308 31415

Kraken

ticker_info <- kraken_ticker_info("ETHUSD")
ticker_info

# $XETHZUSD
# $XETHZUSD$a
# [1] "1186.84000" "4"          "4.000"     
# 
# $XETHZUSD$b
# [1] "1186.83000" "32"         "32.000"    
# 
# $XETHZUSD$c
# [1] "1186.54000" "0.01624995"
# 
# $XETHZUSD$v
# [1] "22961.13930147" "22999.13515131"
# 
# $XETHZUSD$p
# [1] "1195.32538" "1195.35277"
# 
# $XETHZUSD$t
# [1] 13927 14041
# 
# $XETHZUSD$l
# [1] "1180.50000" "1180.50000"
# 
# $XETHZUSD$h
# [1] "1214.38000" "1214.38000"
# 
# $XETHZUSD$o
# [1] "1211.14000"

Kucoin

symbols <- kucoin_symbols_list('btc')
head(symbols)

#     symbol     name baseCurrency quoteCurrency feeCurrency market
# 1 LOKI-BTC OXEN-BTC         LOKI           BTC         BTC    BTC
# 2  NRG-BTC  NRG-BTC          NRG           BTC         BTC    BTC
# 3  FET-BTC  FET-BTC          FET           BTC         BTC    BTC
# 4 ANKR-BTC ANKR-BTC         ANKR           BTC         BTC    BTC
# 5  XMR-BTC  XMR-BTC          XMR           BTC         BTC    BTC
# 6  MTV-BTC  MTV-BTC          MTV           BTC         BTC    BTC
#   baseMinSize quoteMinSize baseMaxSize quoteMaxSize baseIncrement
# 1         0.1      0.00001 10000000000     99999999        0.0001
# 2        0.01      0.00001 10000000000     99999999        0.0001
# 3         0.1      0.00001 10000000000     99999999        0.0001
# 4          10      0.00001 10000000000     99999999        0.0001
# 5       0.001      0.00001 10000000000     99999999        0.0001
# 6           1      0.00001 10000000000     99999999        0.0001
#   quoteIncrement priceIncrement priceLimitRate minFunds isMarginEnabled
# 1     0.00000001     0.00000001            0.1 0.000001           FALSE
# 2     0.00000001     0.00000001            0.1 0.000001           FALSE
# 3    0.000000001    0.000000001            0.1 0.000001           FALSE
# 4     0.00000001   0.0000000001            0.1 0.000001           FALSE
# 5       0.000001       0.000001            0.1 0.000001            TRUE
# 6   0.0000000001   0.0000000001            0.1 0.000001           FALSE
#   enableTrading
# 1          TRUE
# 2          TRUE
# 3          TRUE
# 4          TRUE
# 5          TRUE
# 6          TRUE

Magic Eden

symbol <- "gothic_degens"
stats <- magic_eden_collection_stats(symbol)
stats

# $symbol
# [1] "gothic_degens"
# 
# $floorPrice
# [1] 5.88e+09
# 
# $listedCount
# [1] 273
# 
# $avgPrice24hr
# [1] 5955933374
# 
# $volumeAll
# [1] 9.72372e+13

Nifty Gateway

creators <- nifty_gateway_creators('beeple')
head(creators[1:2])

#                              contractAddress   tokenId
# 1 0x12f28e2106ce8fd8464885b80ea865e98b465149 100010001
# 2 0x12f28e2106ce8fd8464885b80ea865e98b465149 100020001
# 3 0x12f28e2106ce8fd8464885b80ea865e98b465149 100030025
# 4 0x12f28e2106ce8fd8464885b80ea865e98b465149 100030080
# 5 0x12f28e2106ce8fd8464885b80ea865e98b465149 100030066
# 6 0x12f28e2106ce8fd8464885b80ea865e98b465149 100030013

OkCoin

trading_pairs <- okcoin_trading_pairs()
head(trading_pairs)

# base_currency category instrument_id min_size quote_currency size_increment tick_size
# 1           BTC        1       BTC-USD   0.0001            USD         0.0001      0.01
# 2           ETH        1       ETH-USD    0.001            USD         0.0001      0.01
# 3           MIA        1       MIA-USD       10            USD       0.000001  0.000001
# 4           HKC        1       HKC-USD        1            USD         0.0001    0.0001
# 5           NYC        1       NYC-USD       10            USD       0.000001  0.000001
# 6          USDC        1     USDC-USDT        1           USDT       0.000001    0.0001

Paxos (itBit)

client_id <- "..."
client_secret <- "..."
profiles <- paxos_list_profiles(client_id, client_secret)

New R Package: cryptotrackr was originally published in Trevor French on Medium, where people are continuing the conversation by highlighting and responding to this story.

To leave a comment for the author, please follow the link and comment on their blog: R in Trevor French on Medium.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)