1- IBClient <- R6 :: R6Class(" IBClient" ,
1+ IBClient <- R6Class(" IBClient" ,
22
33 class = FALSE ,
44 cloneable = FALSE ,
@@ -13,8 +13,6 @@ IBClient <- R6::R6Class("IBClient",
1313
1414 Id = NULL , # Client ID
1515
16- wrap = NULL , # Callbacks wrapper
17-
1816 decoder = NULL , # Decoder
1917
2018 #
@@ -121,11 +119,6 @@ IBClient <- R6::R6Class("IBClient",
121119
122120 public = list (
123121
124- initialize = function (wrap ) {
125-
126- self $ replaceWrap(wrap )
127- },
128-
129122 connect = function (host = " localhost" , port = 4002L , clientId = 1L , connectOptions = " " , optionalCapabilities = " " ) {
130123
131124 stopifnot(is.null(private $ socket ))
@@ -183,25 +176,14 @@ IBClient <- R6::R6Class("IBClient",
183176 }
184177 },
185178
186- #
187- # Replace wrapper
188- #
189- replaceWrap = function (wrap ) {
190-
191- # Check if "wrap" is an IBWrap class
192- # TODO Improve this
193- stopifnot(exists(" verifyAndAuthCompleted" , wrap , mode = " function" , inherits = FALSE ))
194-
195- private $ wrap <- wrap
196- },
197-
198179 #
199180 # Process server responses
200181 #
201182 # Block up to timeout
202- # Discard messages if flush=TRUE
183+ # If wrap is missing, messages are discarded
184+ # otherwise callbacks are dispatched
203185 #
204- checkMsg = function (timeout = 0.2 , flush = FALSE ) {
186+ checkMsg = function (wrap , timeout = 0.2 ) {
205187
206188 stopifnot(self $ isOpen )
207189
@@ -213,14 +195,14 @@ IBClient <- R6::R6Class("IBClient",
213195
214196 msg <- private $ readOneMsg()
215197
216- if (! flush ) {
198+ if (! missing( wrap ) ) {
217199
218200 # Decode message
219201 res <- private $ decoder $ decode(msg )
220202
221- # Dispatch
203+ # Dispatch callback
222204 if (! is.null(res ))
223- do.call(private $ wrap [[res $ fname ]], res $ fargs )
205+ do.call(wrap [[res $ fname ]], res $ fargs )
224206 }
225207 }
226208
@@ -602,16 +584,6 @@ IBClient <- R6::R6Class("IBClient",
602584 pack_tagvalue(scannerSubscriptionFilterOptions , mode = " string" ),
603585 pack_tagvalue(scannerSubscriptionOptions , mode = " string" ))
604586
605- # TODO: remove this?
606- # Check that NA's are only in allowed fields
607- idx <- which(is.na(payload ))
608- stopifnot(names(payload )[idx ] %in% c(" numberOfRows" , " abovePrice" , " belowPrice" ,
609- " aboveVolume" , " marketCapAbove" , " marketCapBelow" ,
610- " couponRateAbove" , " couponRateBelow" ,
611- " excludeConvertible" , " averageOptionVolumeAbove" ))
612- # Convert NA -> ""
613- payload [idx ] <- " "
614-
615587 msg <- c(msg , tickerId , private $ sanitize(payload ))
616588
617589 private $ encodeMsg(msg )
0 commit comments