-
Notifications
You must be signed in to change notification settings - Fork 2
/
ergodex.R
89 lines (72 loc) · 2.06 KB
/
ergodex.R
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
##########################################
################# ErgoDEX ################
##########################################
#####
##### PLATFORM STATISTICS
##### https://api.ergodex.io/v1/docs/#operation/Platform%20stats
#####
#' Platform Statistics
#'
#' Get statistics on whole AMM.
#'
#' @return A tibble with platform statistics for volume and TVL.
#' @import dplyr
#' @import httr
#' @import jsonlite
#' @import purrr
#' @import tidyr
#' @export
#'
#' @examples
#' ed_platformStats()
ed_platformStats <- function(){
url_request <- paste0("https://api.ergodex.io/v1/amm/platform/stats")
df <- GET(url_request) %>%
content(as = "text", encoding = "UTF-8") %>%
jsonlite::fromJSON(flatten = TRUE) %>%
purrr::map(unlist) %>%
as_tibble() %>%
tidyr::pivot_longer(1:2) %>%
group_by(name) %>%
mutate(category = row_number()) %>%
ungroup() %>%
mutate(category = case_when(category == 1 ~ "value",
category == 2 ~ "currency",
category == 3 ~ "decimals")) %>%
arrange(name) %>%
tidyr::pivot_wider(names_from = category, values_from = value)
return(df)
}
#####
##### ALL POOL STATS
##### https://api.ergodex.io/v1/docs/#operation/All%20pools%20stats
#####
#' All Pool Stats
#'
#' Get statistics on all liquidity pools.
#'
#' @param from Window lower bound (UNIX timestamp millis).
#' @param to Window upper bound (UNIX timestamp millis).
#'
#' @return A tibble with all liquidity pool statistics.
#' @import dplyr
#' @import httr
#' @import jsonlite
#' @export
#'
#' @examples
#' ed_allPoolStats()
#'
#' start <- 1648796400000
#' end <- 1648926788038
#' ed_allPoolStats(from = start, to = end)
ed_allPoolStats <- function(from = NULL, to = NULL){
url_request <- paste0("https://api.ergodex.io/v1/amm/markets",
ifelse(!is.null(from),
paste0("?from=", from, "&to=", to), ""))
df <- GET(url_request) %>%
content(as = "text", encoding = "UTF-8") %>%
jsonlite::fromJSON(flatten = TRUE) %>%
as_tibble()
return(df)
}