-
-
Save daroczig/e5d3ee3664549932bb7f23ce8e93e472 to your computer and use it in GitHub Desktop.
CE DE3 example script for plotting recent BTC prices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## or from the local cache (updated every minute from Jenkins as per above) | |
library(rredis) | |
redisConnect() | |
btc <- redisGet('username:price:BTC') | |
## log whatever was retreived | |
library(logger) | |
log_info('The current price of a Bitcoin is ${btc}') | |
## send alert | |
if (btc < 20000 | btc > 22000) { | |
library(botor) | |
botor(region = 'eu-west-1') | |
token <- ssm_get_parameter('slack') | |
library(slackr) | |
slackr_setup(username = 'jenkins', token = token, icon_emoji = ':jenkins-rage:') | |
slackr_msg( | |
text = paste('uh ... oh... BTC price:', btc), | |
channel = '#ba-de3-2022-bots') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(binancer) | |
library(ggplot2) | |
library(scales) | |
klines <- binance_klines('BTCUSDT', interval = '1m', limit = 60) | |
g <- ggplot(klines, aes(open_time)) + | |
geom_linerange(aes(ymin = open, ymax = close, color = close < open), size = 2) + | |
geom_errorbar(aes(ymin = low, ymax = high), size = 0.25) + | |
theme_bw() + theme('legend.position' = 'none') + xlab('') + | |
ggtitle(paste('Last Updated:', Sys.time())) + | |
scale_y_continuous(labels = dollar) + | |
scale_color_manual(values = c('#1a9850', '#d73027')) | |
ggsave('btc.png', plot = g) | |
print("hello") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(binancer) | |
library(logger) | |
library(rredis) | |
library(data.table) | |
redisConnect() | |
store <- function(s) { | |
## TODO use the checkmate pkg to assert the type of symbol | |
log_info('Looking up and storing {s}') | |
value <- binance_coins_prices()[symbol == s, usd] | |
key <- paste('username', 'price', s, sep = ':') | |
redisSet(key, value) | |
log_info('The price of {s} is {value}') | |
} | |
store('BTC') | |
store('ETH') | |
## list all keys with the "price" prefix and lookup the actual values | |
redisMGet(redisKeys('username:price:*')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment