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
lw <- function(v) { | |
if (sum(v, na.rm = TRUE) == 0) { | |
1 / length(v) | |
} else { | |
v / sum(v, na.rm = TRUE) | |
} | |
} |
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
27 9 * * 1-5 /usr/lib/R/bin/R -f '/home/ubuntu/TraderR/script/trading_robot.R' > '/home/ubuntu/TraderR/script/trading_robot.log' 2>&1 |
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
while(hour(Sys.time()) < 16) { | |
# check email | |
try(get_alert_email(), silent = TRUE) | |
# Place order if needed | |
tws_order() | |
Sys.sleep(5) | |
} |
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
mail_query <- paste0('from:"@xxx.com" ', | |
'{subject:trade subject:sell} ', | |
'after:', Sys.Date()) | |
list <- gmailr::threads( | |
search = mail_query, | |
include_spam_trash = TRUE, num_results = 99999) | |
ids <- sapply(list, function(x) sapply(x$threads, function(y) y$id)) %>% | |
unlist() |
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(IBrokers) | |
tws <- twsConnect(verbose = FALSE) | |
symbol <- 'ABC' | |
quantity <- 100 | |
lmtPrice <- 10 | |
placeOrder(twsconn=tws, | |
Contract=twsSTK(symbol), | |
Order=twsOrder(reqIds(tws), | |
"BUY", | |
quantity, |
NewerOlder