-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbasic-example.r
More file actions
29 lines (23 loc) · 896 Bytes
/
basic-example.r
File metadata and controls
29 lines (23 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
library(httr)
library(jsonlite)
# define ticker, for SimFin+ users, this can be multiple tickers separated with a comma
ticker <- "AAPL"
# the API key from SimFin: https://simfin.com/data/api
apiKey <- "YOUR_API_KEY"
# the statement to retrieve, SimFin+ users can also retrieve all statements via statement=all
statement <- "pl"
# the period & financial year to retrieve, SimFin+ users can omit this parameter to retrieve all statements
period <- "q1"
fyear <- 2020
# make url
url <- paste("https://simfin.com/api/v2/companies/statements?api-key=",apiKey,"&ticker=",ticker,"&statement=",statement,"&period=",period,"&fyear=",fyear,sep="")
# make request
get_data <- GET(url)
# convert JSON
data <- fromJSON(content(get_data, "text"),flatten = TRUE)
# print columns
columns <- data[,c("columns")]
print(columns)
# print statement data
statement_data <- data[,c("data")]
print(statement_data)