Skip to content

Instantly share code, notes, and snippets.

@lockefox
Last active July 1, 2016 19:13
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lockefox/9b65be95ec05e8fae266 to your computer and use it in GitHub Desktop.
Save lockefox/9b65be95ec05e8fae266 to your computer and use it in GitHub Desktop.
Single Item CREST market history extraction - Like @EVEprosper
packages.list <- c("data.table",
"quantmod",
"jsonlite")
packages.new <- packages.list[!(packages.list %in% installed.packages()[,"Package"])]
if(length(packages.new)){
install.packages(packages.new)
}
library(data.table)
library(quantmod)
library(jsonlite)
CREST_BASE = "https://crest-tq.eveonline.com/"
## GET TYPEID/REGION ID FROM http://eve-marketdata.com/developers/index.php ##
typeID = "29668"
#typeID = "37455"
regionID = "10000002"
chart_path = paste0(getwd(),"/Plots/")
dir.create(chart_path, showWarnings=FALSE)
plot.width = 1600
plot.height = 900
## SEE quantmod.com for TA ARGS ##
TA_args = "addBBands(15,2);addVo();addMACD(5,15,5);addRSI();addLines(h=30, on=4);addLines(h=70, on=4)"
graph_subset = "last 365 days"
#graph_subset = "last 1 years"
## FETCH ID/NAME CONVERSIONS FROM CREST ##
typeID_addr <- paste0(CREST_BASE, "inventory/types/", typeID, "/")
typeID.json <- fromJSON(readLines(typeID_addr))
typeName <- typeID.json$name
regionID_addr <- paste0(CREST_BASE, "regions/", regionID, "/")
regionID.json <- fromJSON(readLines(regionID_addr))
regionName <- regionID.json$name
## FETCH PRICE HISTORY FROM CREST AND INSERT INTO QUANTMOD ##
priceHistory_addr = paste0(CREST_BASE, "market/", regionID, "/history/?type=", CREST_BASE, "inventory/types/", typeID, "/")
market.json <- fromJSON(readLines(priceHistory_addr))
market.data.json <- data.table(market.json$items)
market.data <- market.data.json[,list(Date = as.Date(date)[-1],
Volume= volume[-1],
High = highPrice[-1],
Low = lowPrice[-1],
Close =avgPrice[-1],
Open = avgPrice)]
n <- nrow(market.data)
market.data <- market.data[1:n-1,]
## FILTER OUT HIGH/LOW FLIERS ##
low_flag = quantile(market.data$Low,.25)/5
high_flag = quantile(market.data$High,.75)*5
market.data$Low[market.data$Low<=low_flag] <-min(market.data$Open,market.data$Close)
market.data$High[market.data$High>=high_flag] <-max(market.data$Open,market.data$Close)
## BUILD GRAPH AND PRINT PNG ##
graph_title <- paste(typeName,Sys.Date(),regionName, sep=" - ")
image_title <- paste(typeName,Sys.Date(),regionID, sep="_")
market.data.ts <- xts(market.data[,-1,with=F], order.by=market.data[,Date], period=7)
png(paste0(chart_path,image_title,".png"), width=plot.width, height=plot.height)
chartSeries(market.data.ts,
name = graph_title,
TA = TA_args,
subset = graph_subset)
dev.off()
## SAVE DATA TO CSV FOR OTHER PLATFORMS ##
write.csv(market.json, paste0(chart_path,image_title,".csv"), row.names=FALSE)
write.csv(market.data, paste0(chart_path,image_title,"_OHLC.csv"), row.names=FALSE)
@lockefox
Copy link
Author

lockefox commented Apr 8, 2016

30 day pilot s license extension plex _2016-04-08_10000002
Makes candlesticks that look like this. Find typeID lookup at eve-marketdata.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment