How to set-up Market Scanners
JoeFernando opened this issue · 1 comments
Thank you so much for this library. It has helped me tremendously.
I am a bit stuck on how to set-up market scanners. Could you kindly point me to any resource that will help me.
Thanks in advance.
Kind regards
Joe
Here's an example of a scanner:
library(rib)
ew <- IBWrapSimple$new()
ic <- IBClient$new(ew)
ic$connect(port=4002, clientId=1)
reqId <- 123
ss <- ScannerSubscription
ss$numberOfRows <- 10
ss$instrument <- "STK"
ss$locationCode <- "STK.US.MAJOR"
ss$scanCode <- "MOST_ACTIVE"
filters <- c(avgVolumeAbove="1000000", marketCapAbove1e6="100")
ic$reqScannerSubscription(reqId, ss, character(), filters)
ic$checkMsg()
# Results are received and continuously updated
# Finally to cancel the subscription
ic$cancelScannerSubscription(reqId)
# To request the available scanner parameters
ic$reqScannerParameters()
ic$checkMsg()
# Result is a big XML blob found at ew$context$scannerParameters
Few observations:
-
filters are set in two places: fields of the
ScannerSubscription
structure and tag-value pairs in the last argument ofic$reqScannerSubscription()
-
to find out which codes and filters are available use
reqScannerParameters()
which returns what's available in XML format viascannerParameters()
-
this is a subscription: i.e. results are periodically updated until
cancelScannerSubscription()
is sent -
further details can be found in the official IB documentation