Thu, 18 Feb 2021

td 0.0.2 on CRAN: Updated and Expanded

The still very recent td package for accessing the twelvedata API for financial data has been updated and is now at version 0.0.2.

The time_series access point is now vectorised: supply a vector of symbols, and you receive list of data.frame (or xts) objects. See this tweet teasing out the earliest support for this new featire, and showing a quick four-securities plot. We also added simpler accessors get_quote() and get_price() rounding out the basic API support.

One first bug report alerting us to the fact that our use of RcppSimdJson requires an additional sanitizing of the temporary filename if used on Windows. We will fix that properly soon in new release 0.1.5 of that package; in the meantime you can get hot-fix binary 0.1.4.1 for Windows via install.packages("RcppSimdJson", repos="https://ghrr.github.io/drat") from the ghrr drat.

The NEWS entry follows.

Changes in version 0.0.2 (2021-02-18)

  • The time_series is now vectorised and can return a list of return objects when given a vector of symbols

  • The use of tools::R_user_dir() is now conditional on having R 4.0.0 or later, older versions can use env.var for api key

  • New helper function store_key to save api key.

  • New simple accessors get_quote and get_price

Courtesy of my CRANberries, there is a comparison to the previous release. For questions or comments use the issue tracker off the GitHub repo.

If you like this or other open-source work I do, you can now sponsor me at GitHub.

This post by Dirk Eddelbuettel originated on his Thinking inside the box blog. Please report excessive re-aggregation in third-party for-profit settings.

/code/td | permanent link

Thu, 11 Feb 2021

td 0.0.1 on CRAN: New Finance Data Package

Thrilled to announce that a new package of mine just made it to CRAN: the td package accesses the twelvedata API for financial data.

Currently only the time_series REST access point is supported, but it is already supported with all meaningful options (we skipped only ‘JSON or CSV’ which makes no sense here) so for example any resolution between 1 minute and 1 month can be requested for any stock, etf or currency symbol for a wide array of exchanges. Historical access is available too via (optional) start and end dates. We return either raw JSON or a data.frame or an xts object making it trivial to call high-end plotting functions on the data–the project and repo pages show several examples.

As just one example, here is GME during the follies. We simply request via

> gme <- time_series("GME", "1min",
+                    start_date="2021-01-25 09:30:00",
+                    end_date="2021-02-04 16:00:00", as="xts")

(where the API key is either in a user-local config file accessed via the new-ish R function tools::R_user_dir("td") pointing at this package’s directory, or via an environment variable; either is accessed at package load or attachment) from which we can then plot via quantmod

> quantmod::chart_Series(gme, name=paste0(attr(gme, "symbol"), "/", attr(gme, "exchange")))

which shows how we also helpfully store metadata returned by twelvedata as extra attributes of the object. The chart is

You will need an API key to have up to 800 daily accesses for free, higher-performance plans (including websocket access) are available for paying customers too. I have only used the free API so far myself.

I plan to add quote and price support this weekend, and generalize the time series access to returning lists of objects as the API does in fact support multi-security access. As always, feedback is welcomed. Please post comments and suggestions at the GitHub repo.

If you like this or other open-source work I do, you can now sponsor me at GitHub.

This post by Dirk Eddelbuettel originated on his Thinking inside the box blog. Please report excessive re-aggregation in third-party for-profit settings.

/code/td | permanent link