-
Notifications
You must be signed in to change notification settings - Fork 7
/
factory.R
41 lines (30 loc) · 997 Bytes
/
factory.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
#
# Helper functions to generate IB structs
#
setfields <- function(s, ...)
{
args <- list(...)
k <- names(args)
stopifnot(!is.null(k))
idx <- match(k, names(s))
stopifnot(!is.na(idx))
s[idx] <- args
s
}
IBContract <- function(...) setfields(Contract, ...)
IBOrder <- function(...) setfields(Order, ...)
#
# Generate Condition structs
#
fCondition <- function(type)
{
res <- switch(type,
Price= list(is_more= FALSE, value= 0, conId= 0L, exchange= "", triggerMethod= 0L),
Time= list(is_more= FALSE, value= ""),
Margin= list(is_more= FALSE, value= 0L),
Execution= list(secType= "", exchange= "", symbol= ""),
Volume= list(is_more= FALSE, value= 0L, conId= 0L, exchange= ""),
PercentChange= list(is_more= FALSE, value= NA_real_, conId= 0L, exchange= ""),
stop("unknown Condition type"))
c(type=type, conjunction="o", res)
}