I have a couple of questions. Any reference or code example (any language) would be very helpful. 1. Is there a property that tell us if a security is currently shortable (marked red in the tws "shortable" column) 2. Is there a way to detect programmatically if we are connected to a demo or paper trading tws or to a real trading tws port (independently of the user id) ? Thanks a lot in advance, T.
There is a ticktype that will show whether a stock is shortable, but it is not entirely reliable. See the Release Notes for more information. The only way I know of to distinguish a demo account is via the user id.
reqMktDataEx() Call this method to request market data. The market data will be returned by the tickPrice(), tickSize(), tickOptionComputation(), tickGeneric(), tickString() and tickEFP() events in dispinterface_DTwsEvents. Sub reqMktDataEx(ByVal tickerId As Integer, ByVal contract As TWSLib.IContract, ByVal genericTicks As String, ByVal snapshot As Integer) Parameter Description tickerId The ticker id. Must be a unique value. When the market data returns, it will be identified by this tag. This is also used when canceling the market data. contract This object contains a description of the contract for which market data is being requested. genericTicks A comma delimited list of generic tick types. For more information about tick types, seeâGeneric Tick Typesâ on page -30. snapshot Check to return a single snapshot of market data and have the market data subscription cancel. Do not enter any genericTicklist values if you use snapshot. Tick Values The Resulting Tick Values are: Tick Values Description 15 LOW_13_WEEK 16 HIGH_13_WEEK 17 LOW_26_WEEK 18 HIGH_26_WEEK 19 LOW_52_WEEK 20 HIGH_52_WEEK 21 AVG_VOLUME 23 OPTION_HISTORICAL_VOL 24 OPTION_IMPLIED_VOL 27 OPTION_CALL_OPEN_INTEREST 28 OPTION_PUT_OPEN_INTEREST 29 OPTION_CALL_VOLUME 30 OPTION_PUT_VOLUME 31 INDEX_FUTURE_PREMIUM 34 AUCTION_VOLUME 35 AUCTION_PRICE 36 AUCTION_IMBALANCE 37 MARK_PRICE 46 SHORTABLE 47 FUNDAMENTAL_RATIOS The Shortable tick tells whether SHORT SELL orders for a contract will be accepted. The value returned from the tickGeneric(int tickerId, int tickType, double value) method can be analyzed as follows: if (value > 2.5) { // 3.0 // There are at least 1000 shares available for a short sale } else if (value > 1.5) { // 2.0 // This contract will be available for short sale if shares can be located } else if (value > 0.5) { // 1.0 // Not available for short sale } else { // unknown value } Note: This feature is supported as of server version 33 (872 release of TWS).