Function Resource

Function Repository Resource:

CryptocurrencyData

Source Notebook

Cryptocurrency data retrieval

Contributed by: Anton Antonov

CryptocurencyData[name]

gives daily closing price data for the cryptocurrency name.

CryptocurencyData[name,start]

gives daily closing price data for the cryptocurrency name from start to current date.

CryptocurencyData[name,{start,end}]

gives daily closing price data for the cryptocurrency name from start to end.

CryptocurencyData[name,prop,{start,end}]

gives value of the specified property for the cryptocurrency name from start to end.

Details and Options

Generally speaking, CryptcurrencyData adheres to the signatures design of FinancialData, but there are a number of differences.
ResourceFunction["CryptocurrencyData"] utilizes two data sources: Yahoo Finance and data.bitcoinity.org.
ResourceFunction["CryptocurrencyData"] caches the source-retrived-and-processed data in order to provide results faster.
Here are the options taken:
CurrencyUSDcurrency
LedgerStart{2009, 1, 3}ledger start date
QuantitiesFalsewether quantity units to be used or not
ResultTypeTimeSeriestype of the result
SourceYahooFinancesource for cryptocurrency data

Examples

Basic Examples (3) 

Here is time series for Bitcoin (BTC):

In[1]:=
ResourceFunction[
CloudObject[
  "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]]["BTC"]
Out[1]=
In[2]:=
DateListPlot[%, PlotRange -> All]
Out[2]=

Here is trading volume time series for BTC since 2018:

In[3]:=
DateListPlot[ResourceFunction[
CloudObject[
   "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]]["BTC", "Volume", "Jan 1 2018"], PlotRange -> All]
Out[3]=

Get trading volume data for Bitcoin (BTC) and Ether (ETH) since January 1st 2021:

In[4]:=
ResourceFunction[
CloudObject[
  "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]][{"BTC", "ETH"}, "Volume", "Jan 2021"]
Out[4]=

Here is the corresponding plot:

In[5]:=
DateListPlot[%]
Out[5]=

Scope (8) 

Here are time series of different properties for Bitcoin (BTC) and Ether (ETH):

In[6]:=
ResourceFunction[
CloudObject[
  "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]][{"BTC", "ETH"}, {"Open", "Volume"}]
Out[6]=

Instead of time series we can get Dataset objects instead:

In[7]:=
ResourceFunction[
CloudObject[
  "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]][{"BTC", "ETH"}, {"Open", "Volume"}, "Jan 2021", "ResultType" -> Dataset]
Out[7]=

Get the cryptocurrency summary data from Yahoo Finance:

In[8]:=
ResourceFunction[
CloudObject[
  "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]][All, "Summary"]
Out[8]=

Get all classes of metadata and show the corresponding metadata values:

In[9]:=
ResourceFunction["GridTableForm"][{#, ResourceFunction[
CloudObject[
      "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]][#]} & /@ ResourceFunction[
CloudObject[
    "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]]["Classes"], TableHeadings -> {"Class", "Values"}]
Out[9]=

Get Bitcoin (BTC) data from the exchange "coinbase":

In[10]:=
ResourceFunction[
CloudObject[
  "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]][{"coinbase", "BTC"}, "Source" -> "DataBitcoinityOrg"]
Out[10]=

Cryptocurrencies symbols and names:

In[11]:=
ResourceFunction[
CloudObject[
  "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]]["CryptocurrencyNames"]
Out[11]=

Currencies that can be used CryptocurrencyData:

In[12]:=
ResourceFunction[
CloudObject[
  "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]]["Currencies"]
Out[12]=

Exchanges that can be used in CryptocurrencyData with the option "Source" set to "DataBitcoinityOrg":

In[13]:=
ResourceFunction[
CloudObject[
  "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]]["Exchanges"]
Out[13]=

Options (8) 

Currency (2) 

The option "Currency" specifies the currency of the results. It is expected to be one of:

In[14]:=
ResourceFunction[
CloudObject[
  "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]]["Currencies"]
Out[14]=

Here are examples of opening prices of Ether (ETH) with different currencies:

In[15]:=
Table[DateListPlot[ResourceFunction[
CloudObject[
    "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]]["ETH", "Open", "Jan 1 2021", "Currency" -> c], PlotLabel -> c], {c, {"USD", "EUR", "RUB"}}]
Out[15]=

LedgerStart

The option "LedgerStart" specifies the start date of the cryptocurrency ledger. That start date is used when retrieval of all values is specified.

Quantities (4) 

If the option "ResultType" is set to TimeSeries, then the option "Quantities" specifies weather the result time series should be with numeric values with quantity values.

Here we obtain Ether opening price time series:

In[16]:=
aRes = Association[# -> ResourceFunction[
CloudObject[
       "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]]["ETH", "Open", {"Jan 1, 2021", "Jan, 7, 2021"}, "ResultType" -> TimeSeries, "Quantities" -> #] & /@ {True, False}]
Out[16]=

Here from each time series the values are extracted:

In[17]:=
aRes2 = Map[#["Values"] &, aRes]
Out[17]=

QuantityArray is used in order to have faster data retrieval. After normalizing the results we see the actual quantities and values:

In[18]:=
Map[Normal, aRes2]
Out[18]=

Note that for trading volume the unit "Items" is used, since there is not unit "Coins":

In[19]:=
Normal@ResourceFunction[
CloudObject[
   "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]]["ETH", "Volume", {"Jan 1, 2021", "Jan, 3, 2021"}, "ResultType" -> TimeSeries, "Quantities" -> True]
Out[19]=

ResultType (1) 

The option "ResultType" specifies the type of the results. It is expected to be Automatic, Dataset, or TimeSeries. Automatic is the same as TimeSeries. Here is are examples:

In[20]:=
# -> ResourceFunction[
CloudObject[
     "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]]["ETH", "Close", {"Jan 1, 2021", "Jan, 7, 2021"}, "ResultType" -> #] & /@ {Automatic, Dataset, TimeSeries}
Out[20]=

Source (1) 

The option "Source" specifies the data source. It is expected to be Automatic, "YahooFinance", "YF", "DataBitcoinityOrg", or "DBO". The abbreviations "YF" and "DBO" correspond to the "YahooFinance" and "DataBitcoinityOrg" respectively. With "YahooFinance" data from the page https://finance.yahoo.com/cryptocurrencies is used. With "DataBitcoinityOrg" data from https://data.bitcoinity.org is used. Here are examples:

In[21]:=
# -> ResourceFunction[
CloudObject[
     "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]]["BTC", "Close", {"Jan 1, 2021", "Jan, 7, 2021"}, "Source" -> #] & /@ {Automatic, "YahooFinance", "DataBitcoinityOrg"}
Out[21]=

Applications (4) 

Find 100-day moving averages of a opening price of BTC:

In[22]:=
DateListPlot[MovingAverage[ResourceFunction[
CloudObject[
    "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]]["BTC", "Open", "Jan. 1, 2016"], 30], PlotRange -> All, PlotTheme -> "Detailed"]
Out[22]=

Find the summary of the opening price daily differences for BTC for the passed two years:

In[23]:=
lsRes = ResourceFunction[
CloudObject[
     "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]]["BTC", "Open", DatePlus[Now, -Quantity[2, "Years"]]]["Values"];
Row[{ResourceFunction["RecordsSummary"][Differences[lsRes], "Differences"], Spacer[5], ResourceFunction["RecordsSummary"][Log10 /@ Abs[Differences[lsRes]],
    "lg|differences|"]}]
Out[17]=

Plot a histogram of the corresponding to log 10 of the absolute values:

In[24]:=
Histogram[Log10 /@ Abs[Differences[lsRes]], 20, "Probability", PlotRange -> All, PlotTheme -> "Detailed", FrameLabel -> {"Log10 |USD|", "Probability"}]
Out[24]=

Note the summary and plot above demonstrate the volatility of BTC.


Show the top eight "priciest" cryptocurrencies using data from the last two weeks:

In[25]:=
aMeans = Association[# -> Mean[ResourceFunction[
CloudObject[
          "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]][#, "Open", DatePlus[Now, -Quantity[2, "Weeks"]]]["Values"]] & /@ ResourceFunction[
CloudObject[
      "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]]["Cryptocurrencies"]];
aTopMeans = Take[ReverseSort[aMeans], 8]
Out[17]=

Plot the opening prices of top cryptocurrencies since 2018:

In[26]:=
lsCCTop = Keys@aTopMeans;
DateListPlot[Log10 /@ Association[# -> ResourceFunction[
CloudObject[
        "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]][#, "Open", "Jan 1, 2018"] & /@ lsCCTop], Joined -> True, Filling -> Bottom, PlotRange -> All]
Out[17]=

Properties and Relations (2) 

FinancialData has ten of the cryptocurrencies for which CryptocurrencyData can provide data for (through Yahoo Finance.) Here are the cryptocurrencies FinancialData knows the prices of:

In[27]:=
Keys@Select[
  Association[# -> FinancialData[#, "Jan. 1, 2021", "Value"] & /@ ResourceFunction[
CloudObject[
      "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]]["Cryptocurrencies"]], Head[#] =!= Missing &]
Out[27]=

Here is a time series for ETH:

In[28]:=
FinancialData["ETH", "Jan 1 2021"]
Out[28]=

FinancialData does not provide cryptocurrency data other than price (e.g. trading volume, etc.) or data from different exchanges. Here are examples of a failed retrieval:

In[29]:=
FinancialData["BTC", "Volume", "Jan 1 2021"]
Out[29]=

Also, FinancialData returns cryptocurrency results without units. See comparison with stocks:

In[30]:=
Table[a -> ResourceFunction["RecordsSummary"][
   FinancialData[a, "Jan 1 2021"]["Values"]], {a, {"BTC", "GE", "APPL"}}]
Out[30]=

Here is a 30 day moving average of the price of BTC with using FinancialData:

In[31]:=
DateListPlot[
 MovingAverage[FinancialData["BTC", "Jan. 1, 2018", "Value"], 30], {"Jan. 1, 2016", Automatic, "Day"}, PlotRange -> All, Joined -> True]
Out[31]=

Here is a 30 day moving average of the price of BTC with using CryptocurrencyData:

In[32]:=
DateListPlot[MovingAverage[ResourceFunction[
CloudObject[
    "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]]["BTC", "Open", "Jan. 1, 2018"], 30], {"Jan. 1, 2016", Automatic, "Day"}, PlotRange -> All, Joined -> True]
Out[32]=

Possible Issues (3) 

The cryptocurrency data is retrieved from source sites using certain ad-hoc derived assumptions of how the data is organized. Hence if the data organization changes the code of CryptocurrencyData has to be updated.


The data sources used (Yahoo Finance and data.bitcoinity.org) provide different properties, with different time granularities. Hence, switching sources (with option "Source") might produce differently structured (or empty) results.


For optimization purposes data retrieved from the sources is stored in a dedicated data structure. If the computational session is "too long" that stored data might not be recent enough. In those situations the argument "ClearCachedData" can be used.

Neat Examples (2) 

Plot passed year opening prices and trading volumes of the top cryptocurrencies:

In[33]:=
startDate = DatePlus[Now, -Quantity[1, "Years"]];
lsCCFocus = {"BTC", "ETH", "BCH", "BNB", "XMR", "LTC", "FIL"};
lsPropFocus = {"Open", "Volume"};
Map[Function[{prop}, DateListPlot[Log10 /@ Association[# -> ResourceFunction[
CloudObject[
          "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]][#, prop, startDate, "Currency" -> "USD"] & /@ lsCCFocus], PlotLabel -> prop, ImageSize -> Medium, PlotTheme -> "Detailed"]], lsPropFocus]
Out[30]=

Compute correlations between the passed year time series of the top cryptocurrencies:

In[34]:=
startDate = DatePlus[Date[], -Quantity[1, "Years"]];
aRes = ResourceFunction[
CloudObject[
    "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/CryptocurrencyData"]][lsCCFocus, "Open", startDate, "ResultType" -> TimeSeries];
aRes = Quiet[
   TimeSeriesResample[#, {startDate, Date[], Quantity[1, "Days"]}] & /@
     aRes];
matCor = Outer[{#1, #2, Correlation[aRes[#1]["Values"], aRes[#2]["Values"]]} &, Keys[aRes], Keys[aRes]];
dsCor = ResourceFunction["CrossTabulate"][Flatten[matCor, 1]]
Out[35]=

Source Metadata