S Lazy-H
  • Home
  • About
  • Posts
  • Contact
  • Slide Rules
  • A Biker’s Tale

Cryptocurrency Part 2

R Programming
Stocks
cryptocurrency
Author

Sam Hutchins

Published

June 24, 2024

As mentioned in Cryptocurrency, I wanted to add a small post detailing the basics of acquiring cryptocurrency market data. This will be a short post, and will show code found on the Internet using R (R Core Team 2024) with the cryptoQuotes library and is modified from this data.

As in the first post, we are using NANO as the example, and the program is currently designed to acquire only data using kraken as the source.

However, it can easily be modified to access other exchanges and other coins. Some research is necessary to determine which ticker is used for which exchange. The coins usually are paired with some fiat currency and listed in that fashion on a particular exchange. Using NANO with the ticker of XNO, selected exchanges list it as so.

- binance: XNOUSDT
- kucoin: XNO-USDT
- kraken: NANOUSD

So, without further ado, here is the modified program.

#library(cryptoQuotes)
system("clear")
currentDate <- Sys.Date()
writeLines("\n-- Using Kraken to check NANO/XNO\n")
Source <- 'kraken'
show(cryptoQuotes::available_intervals(source=Source))
interVal <- readline(prompt="Interval (default 1d): ")
if (str_length(interVal) == 0) { interVal <- '1d' } # default 1d
From <- readline(prompt="Start date (default 2024-1-1): ")
if (str_length(From) == 0) { # limit range if no date entered
    From <- '2024-01-01'
    interVal <- '1d'
}
xno <- cryptoQuotes::get_quote(
  ticker   = 'NANOUSD',
  interval = interVal,
  source   = Source,
  futures  = FALSE,
  from     = From,
  to       = currentDate
)
# Candlestick chart
xno_chart <- cryptoQuotes::chart(
  ticker     = xno,
  main       = cryptoQuotes::kline(),
  sub  = list(
    cryptoQuotes::volume()
  ),
  options = list(
    dark = FALSE
  )
)
show(xno_chart)

Note the first line is commented out as I have used only particular functions instead of loading the entire library. This uses the format cryptoQuotes::chart for example. If the library were loaded, the cryptoQuotes:: would not be necessary.

Notice there are some lines setting default selections when a prompt is bypassed. This prevents errors as some combinations will not work with fantastical data. For example, it would not be useful to attempt to collect 1 minute data for several years time span.

Lastly, the data is depicted in a candlestick chart for inspection. There is not enough room available in this post to attempt to explain the various evaluation tools used for market evaluation and analysis. However, Pring (2002) is a good reference to analyze investment trends and turning points. It follows that the cryptocurrency market does not necessarily behave as the stock market.

Have a great day, and God Bless!

References

Pring, Martin J. 2002. Technical Analysis Explained, Fourth Edition. McGraw-Hill.
R Core Team. 2024. R: A Language and Environment for Statistical Computing. Vienna, Austria: R Foundation for Statistical Computing. https://www.R-project.org/.
© S Lazy-H 2019 - 2025