if (FALSE) {
# Authenticate and get historical prices
auth <- ig_auth(
username = "your_username",
password = "your_password",
api_key = "your_api_key",
acc_type = "DEMO",
acc_number = "ABC123"
)
hist <- ig_get_historical(
"CS.D.USDCHF.MINI.IP",
from = "2025-09-01",
to = "2025-09-28",
resolution = "D",
page_size = 20,
auth
)
print(hist)
# Using time
hist <- ig_get_historical(
"CS.D.USDCHF.MINI.IP",
from = "2025-09-01 00:00:00",
to = "2025-09-28 23:59:59",
resolution = "D",
page_size = 20,
auth
)
# Using mock response
mock_response <- list(
prices = data.frame(
snapshotTime = "2025/09/01 00:00:00",
openPrice.bid = 0.970,
openPrice.ask = 0.971,
openPrice.lastTraded = NA,
highPrice.bid = 0.975,
highPrice.ask = 0.976,
highPrice.lastTraded = NA,
lowPrice.bid = 0.965,
lowPrice.ask = 0.966,
lowPrice.lastTraded = NA,
closePrice.bid = 0.971,
closePrice.ask = 0.972,
closePrice.lastTraded = NA,
lastTradedVolume = 50000
),
metadata = list(
allowance = list(remainingAllowance = 10000),
pageData = list(pageNumber = 1, totalPages = 1)
)
)
hist <- ig_get_historical(
"CS.D.USDCHF.MINI.IP",
from = "2025-09-01",
to = "2025-09-28",
resolution = "D",
page_size = 20,
auth,
mock_response = mock_response
)
}
Run the code above in your browser using DataLab