Market Scanner Subscription
Introduction
Some scans in the TWS Advanced Market Scanner can be accessed via the TWS API through EClient.reqScannerSubscription. Results are delivered via EWrapper.scannerData and the EWrapper.scannerDataEnd marker will indicate when all results have been delivered. The returned results to scannerData simply consist of a list of contracts. There are no market data fields (bid, ask, last, volume, …) returned from the scanner, and so if these are desired they have to be requested separately with the reqMktData function. Since the scanner results do not include any market data fields, it is not necessary to have market data subscriptions to use the API scanner. However to use filters, market data subscriptions are generally required.
Since the EClient.reqScannerSubscription request keeps a subscription open you will keep receiving periodic updates until the request is cancelled via EClient.cancelScannerSubscription.
Scans are limited to a maximum result of 50 results per scan code, and only 10 API scans can be active at a time.
scannerSubscriptionFilterOptions has been added to the API to allow for generic filters. This field is entered as a list of TagValues which have a tag followed by its value, e.g. TagValue(“usdMarketCapAbove”, “10000”) indicates a market cap above 10000 USD. Available filters can be found using the EClient.reqScannerParameters function.
Important: remember the TWS API is just an interface to the TWS. If you are having problems defining a scanner, always make sure you can create a similar scanner using the TWS’ Advanced Market Scanner.
The XML tree returned by reqScannerParameters will relay a tree containing a corresponding code to each ScannerSubscription field:
instrument: <ScanParameterResponse> <InstrumentList> <Instrument> <type>
Location Code: <ScanParameterResponse> <LocationTree> <Location> <LocationTree> <Location> <locationCode>
Scan Code: <ScanParameterResponse> <ScanTypeList> <ScanType> <scanCode>
Subscription Options should be an empty array of TagValues.
Filter Options: <ScanParameterResponse> <FilterList> <RangeFilter> <AbstractField> <code>
Request Market Scanner Subscription
EClient.reqScannerSubscription(reqId, subscription, scannerSubscriptionOptions, scannerSubscriptionFilterOptions)
Starts a subscription to market scan results based on the provided parameters.
Request identifier used for tracking data.
Object containing details on what values should be used to construct and sort the list.
Internal use only.
List of values used to filter the results of the scanner subscription. May result in an empty scanner response from over-filtering.
Python
Java
C++
C#
VB.NET
Receive Market Scanner Subscription
EWrapper.scannerData(reqid, rank, contractDetails, distance, benchmark, projection, legStr)
Provides the data resulting from the market scanner request.
Request identifier used to track data.
The ranking position of the contract in the scanner sort.
Contract object of the resulting object.
Internal use only.
Internal use only.
Internal use only.
Describes the combo legs when the scanner is returning EFP.
Python
Java
C++
C#
VB.NET
Cancel Market Scanner Subscription
EClient.cancelScannerSubscription(tickerId)
Cancels the specified scanner subscription using the tickerId.
Request identifier used to track data.

