def hot_us_stk(abovePrice, belowPrice, locationCode, scanCode): #! [hotusvolume] #Hot US stocks by volume scanSub = ScannerSubscription() scanSub.instrument = "STK" scanSub.locationCode = locationCode #scanSub.locationCode = "STK.NASDAQ" #scanSub.scanCode = "HOT_BY_VOLUME" scanSub.scanCode = scanCode #scanSub.scanCode = "MOST_ACTIVE" scanSub.belowPrice = str(belowPrice) scanSub.abovePrice = str(abovePrice) return scanSub
def HottestPennyStocks(): """ Subscribe to US stocks 1 < price < 10 and vol > 1M. Scan code = TOP_PERC_GAIN """ scanSub = ScannerSubscription() scanSub.instrument = "STK" scanSub.locationCode = "STK.US" scanSub.scanCode = "TOP_PERC_GAIN" scanSub.abovePrice = 2 scanSub.belowPrice = 50 scanSub.aboveVolume = 1000000 return scanSub
def scan(self, req_id: int, exchange_abbrev: str): """Performs a market scan of contracts through the IB API""" # Creates the scanner object to be used in reqScannerSubscription() scanner = ScannerSubscription() scanner.instrument = 'STK' scanner.locationCode = 'STK.' + exchange_abbrev scanner.stockTypeFilter = 'CORP' scanner.scanCode = "MOST_ACTIVE_AVG_USD" scanner.abovePrice = 10.0 scanner.belowPrice = 20.0 # Third argument of reqScannerSubscription() should always be an empty list. It is used internally by IB API. # Fourth argument is an optional list of filters as TagValue objects. self.reqScannerSubscription(req_id, scanner, [], [])
def assemble_stock_list(client, sentiment): ''' Use scanner to obtain stock list ''' # Define scanner subscription ss = ScannerSubscription() ss.instrument = 'STK' ss.locationCode = 'STK.US.MAJOR' ss.abovePrice = 10.0 ss.belowPrice = client.funds / 200.0 ss.aboveVolume = 20000 ss.numberOfRows = 5 # Set scan code according to sentiment if sentiment == Sentiment.BULLISH: ss.scanCode = 'HIGH_VS_13W_HL' else: ss.scanCode = 'LOW_VS_13W_HL' # Request securities client.reqScannerSubscription(4, ss, [], []) time.sleep(3)