knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The goal of lemonmarkets is to provide an R interface to the lemon.markets trading API. The API docs are available at docs.lemon.markets.
You can install the development version of lemonmarkets like so:
remotes::install_github("quantargo/lemonmarkets")
Before you can get started with the lemonmarkets API you need to get an API key from the web page . Currently there is still a waitlist since the service is not publicly available yet.
After you acquired the API keys we recommend to create a new file .Renviron
within your R project directory and enter the keys there:
```{bash, eval=FALSE}
LEMON_MARKETS_CLIENT_ID=
The `LEMON_MARKETS_CLIENT_ID` and `LEMON_MARKETS_CLIENT_SECRET` are then available as environment variables within your R session. Alternatively, you can also set the environment variables directly within the R session as ```r Sys.setenv(LEMON_MARKETS_CLIENT_ID="<your-client-id>", LEMON_MARKETS_CLIENT_SECRET="<your-client-secret>")
Once you have set the environment variables you can load the lemonmarkets package and get your access token through the auth()
function:
library(lemonmarkets) auth()
All subsequent calls will use the resulting access token which is stored in options("LEMON_MARKETS_TOKEN")
.
Currenly, all trading operations are done through pre-defined sub-accounts (spaces). These spaces need to be created via the web fronted to retrieve its ID.
You can search for an instrument, like Daimler stock, through instrument_search()
:
instruments_search(list(search = "daimler", type = "stock"))
To retrieve historical Open-High-Low-Close (OHCL) data for the German Daimler listing you can use the ohcl()
function:
ohcl("DE0007100000", from = Sys.Date() - 7, freq = "daily")
The example above retrieves daily data for the last week. Also other frequencies
like like hourly
and min
(minute) are available.
Alternatively, you can also use quotes()
to only retrieve the last market quote
for an instrument:
quotes("DE0007100000")
The current cash balance of a specified space can be retrieved as
space_id <- "e44907b7-d131-4ec9-9647-a2649480003d" bal <- balance(space_id)
You can place an order with the create_order()
function. To place a market order of 5 shares for Daimler stock we can use
create_order(space_id, "DE0007100000", 5)
Note, that orders are immediatly activated per default. You can disable this
features through the parameter activate=FALSE
.
To get a list of the current portfolio we can use
portfolio(space_id)
The link below contains a fully-functioning Quantargo workspace which uses the package to daily re-balance a mean-reversion portfolio strategy:
https://www.quantargo.com/qbits/qbit-example-lemonmarkets-reversion-dax40?panel=viewer
Please raise an issue through Github.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.