-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.R
129 lines (112 loc) · 4.05 KB
/
global.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#
# IB Trading specific variables
#
platform <- c("IBG", "TWS")[1] # Options: TWS, IBG
acct <- c("Live", "Paper")[1] # Options: Live, Paper
trade_time_limit <- 10
active_trade_ids <- c()
brewed_colors <- rep(RColorBrewer::brewer.pal(n = 9, name = "Set3"), 100)
#
# Common parameters for server and ui
#
button_field_default_width <- "100px"
blotter_field_default_width <- "150px"
blotter_field_default_width_wide <- "250px"
perfor_table_oa_input_width <- "150px"
# equity blotter
eq_max_blotter_size <- 10
eq_max_message_count <- 10
eq_blotter_size_tracker <- 1
eq_message_count_trader <- 1
# option blotter
opt_max_blotter_size <- 10
opt_max_message_count <- 10
opt_blotter_size_tracker <- 1
opt_message_count_trader <- 1
# option blotter
fut_max_blotter_size <- 10
fut_max_message_count <- 10
fut_blotter_size_tracker <- 1
fut_message_count_trader <- 1
# other
econ_indi_panel_default_width <- 12
econ_indi_tab_names <- c("gei_dt", "lei_dt", "coi_dt", "lai_dt")
unit_refresh_time <- 60 * 1000 # 1 minute
refresh_time <- unit_refresh_time
ei_refresh_time <- 24 * 60 * unit_refresh_time # 1 day
perfor_refresh_time <- 30 * unit_refresh_time # 30 minutes
#
# connection for database
#
db_obj <- list(
srv = "10.0.0.200",
prt = 3307,
dbn = "WebappAdmin",
id = "dspeast2",
pwd = "yuheng"
)
#
# load IBKR account code
#
tmp_accts <- ReadDataFromSS(db_obj, "MyBroKe_Accounts") %>%
dplyr::arrange(Sort.Order)
acct_number1 <- tmp_accts[tmp_accts$Account.Number == 'U1989090','Account.Number'][1]
acct_number2 <- tmp_accts[tmp_accts$Account.Number == 'U10048362','Account.Number'][1]
acct_alias1 <- tmp_accts[tmp_accts$Account.Number == 'U1989090','Alias'][1]
acct_alias2 <-tmp_accts[tmp_accts$Account.Number == 'U10048362','Alias'][1]
#
# color scheme
#
user_colors <- c("#FE7171", "#28DF99", "#FFC93C")
names(user_colors) <- c("Negative", "Positive", "Flat")
##
# Obtain tradable currencies from DB
tradable_curr <- unique(ReadDataFromSS(db_obj, "MyBroKe_CashBalanceMap")$Currency)
##
# accounts
other_broker_account_alias <- c('LIRA Ke', 'TFSA Tong','RRSP Tong', 'RESP Family', 'Margin Tong')
other_broker_account_numbers <- tmp_accts[tmp_accts$Alias %in% other_broker_account_alias,'Account.Number']
other_broker_account_headers <- tmp_accts[tmp_accts$Alias %in% other_broker_account_alias,'Alias']
names(other_broker_account_numbers) <- other_broker_account_headers
#
# Load API keys
#
api_tbl <- ReadDataFromSS(db_obj, "MyAPI")
fred_api_key <- api_tbl[api_tbl$APIName == "fred","APIKey"]
quandl_key <- api_tbl[api_tbl$APIName == "quandl","APIKey"]
#
# Load economic indicators from DB
#
watchlist <- ReadDataFromSS(db_obj, "MyBroKe_Watchlist")
colnames(watchlist) <- c("Symbol","Currency","Security Type","Valid","Comments")
watchlist <- watchlist %>%
dplyr::filter(Valid == 1) %>%
dplyr::select(c("Symbol","Currency","Security Type","Comments"))
gei_lookup <- ReadDataFromSS(db_obj, "MyBroKe_GeneralEI")
lei_lookup <- ReadDataFromSS(db_obj, "MyBroKe_LeadingEI")
coi_lookup <- ReadDataFromSS(db_obj, "MyBroKe_CoincidentEI")
lai_lookup <- ReadDataFromSS(db_obj, "MyBroKe_LaggingEI")
##
# Make fredr and quandl dictionaries
master_lookup <- dplyr::bind_rows(list(gei_lookup, lei_lookup, coi_lookup, lai_lookup))
ei_fred <- master_lookup[master_lookup$APISource == "fred","Item"]
names(ei_fred) <- master_lookup[master_lookup$APISource == "fred","Key"]
ei_quandl <- master_lookup[master_lookup$APISource == "quandl","Item"]
names(ei_quandl) <- master_lookup[master_lookup$APISource == "quandl","Key"]
#
# Load portfolio status function
#
if(R.Version()$os == "linux-gnu"){
github_folder <- "/home/kmin/Projects/"
} else {
github_folder <- "c:/Github/"
}
source(paste0(github_folder,"IBTWSTradingSession/IB_TWS_TradingSession.R"))
source(paste0(github_folder,"FinancialSecurityHistoricalData/FinancialSecurityHistoricalData.R"))
source(paste0(github_folder,"EconomicIndicators/EconomicIndicators.R"))
source(paste0(github_folder,"Utils/R/shypka.R"))
source(paste0(github_folder,"Utils/R/ggpthemepka.R"))
#
# Buy/Sell trading session
#
ts_static <- IBTradingSession$new(22, platform, acct)