Skip to content

Commit

Permalink
Add new R-Function
Browse files Browse the repository at this point in the history
  • Loading branch information
Conor Flynn committed Jan 15, 2023
1 parent 268939e commit eb72bc8
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
File renamed without changes.
85 changes: 85 additions & 0 deletions R-Code-Samples/aave-protocol-dated-func-v2.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
title: "DFDE-Method"
author: "Conor Flynn"
date: "2022-12-15"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
library("httr")
library("jsonlite")
library("lubridate")
library(stringr)
library(tidyverse)
getJson <- function(startdate, enddate) {
httr::GET(url = "http://defi-de.idea.rpi.edu:8080/defi/v1/rest/initialize?source=amber_data&auth_data=key,UAK7ed69235426c360be22bfc2bde1809b6")
engine_key <- "b6c810a7f35f4fa0d28258278325b4b5ab82ba79868ab33d01d5c878e13872ec129a91a3fbf702e59c2404f0fb4a53420a3ffb50130c35b4d06b32d81e56c1f4"
socket <- socketConnection("defi-de.idea.rpi.edu", 61200, blocking=TRUE)
ss <- readLines(socket, 1)
ss
reqString <- paste(
"SRC&&&RQST&&&destination&&&", ss,
"&&&key&&&", engine_key, "&&&",
"start_date&&&", startdate, "&&&",
"end_date&&&", enddate, "&&&",
"query&&&aave-protocol-dated&&&",
"request&&&aave-protocol-dated\n", sep="")
writeLines(reqString, socket)
data <- readLines(socket, 1)
while (TRUE) {
temp <- readLines(socket, 1)
data <- paste(data, temp, "")
if (grepl("<<<end>>>", temp, fixed=TRUE)) {break}
}
data
data <- str_replace(data, " <<<end>>> ", "")
data <- str_replace_all(data, " ", "")
data <- str_replace_all(data, "\\}\\{", "\\},\\{")
data <- paste("[", data, "]", sep="")
output <- fromJSON(data)
output <- output[,-(colnames(output) == "_id")]
colnames(output)[colnames(output) == "action"] = "type"
output$type <- as.factor(output$type)
output <- output %>% mutate(datetime = as_datetime(as.numeric(substr(timestamp, 1, nchar(timestamp)-3))))
colnames(output)[colnames(output) == "assetId"] = "reserveId"
colnames(output)[colnames(output) == "assetSymbol"] = "reserve"
output$amount <- as.double(output$amount)
output$borrowRate <- as.double(output$borrowRate)
colnames(output)[colnames(output) == "user"] = "userId"
output <- output %>% unite(col = "onBehalfOfId", onBehalfOf,repayer,initiator, na.rm = TRUE, sep = "")
colnames(output)[colnames(output) == "collateralAssetId"] = "collateralReserveId"
colnames(output)[colnames(output) == "collateralAssetSymbol"] = "collateralReserve"
colnames(output)[colnames(output) == "principalAssetId"] = "principalReserveId"
colnames(output)[colnames(output) == "principalAssetSymbol"] = "principalReserve"
output$principalAmount <- as.double(output$principalAmount)
output <- output[,-15]
output
return(output)
}
temp <- getJson("2022-08-01", "2022-08-02")
temp
```

0 comments on commit eb72bc8

Please sign in to comment.