コード例 #1
0
ファイル: stockta.py プロジェクト: hsun/python-collection
class StockTa(object):

    HOST = "www.stockta.com"
    PORT = 80
    ANALYSIS_PATH = "/cgi-bin/analysis.pl?symb=%s"
    THRESHOLD = 5

    def __init__(self):
        self.site = Site(self.HOST, self.PORT)
        self.cache = {}

    def get_price_levels(self, symbol):

        prices = self.cache.get(symbol)
        if prices:
          return prices
        path = self.ANALYSIS_PATH % (symbol)
        raw = self.site.fetch(path)
        soup = BeautifulSoup(raw)
        try:
            summary = soup.body.find("td", text="Last Trade").parent.parent.parent.findAll("tr")[1].findAll("td")
            prices = {}
            prices['open'] = float(summary[4].string)
            prices['close'] = float(summary[1].font.string)
            prices['low'] = float(summary[6].string)
            prices['high'] = float(summary[5].string)

            prices['resist'] = self.find_resist(soup)
            prices['support'] = self.find_support(soup)
            self.cache[symbol] = prices
            return prices
        except Exception, e:
            print "Failed to get price levels for %s: %s" % (symbol, e)
            return {}
コード例 #2
0
ファイル: sc.py プロジェクト: hsun/python-collection
class StockChartSignals(object):

    HOST = "stockcharts.com"
    PORT = 80
    MIN_PRICE = 10.0
    MIN_VOLUME = 1000000.0
 
    # summary of the signals
    SIGNAL_SUMMARY_PAGE = "/def/servlet/SC.scan?s=runreport,predefall"

    # interested exchanges
    EXCHANGES = ["NASD", "NYSE", "AMEX"]

    # each identifies the description of a specific signal
    BULL_CANDLES = [
        "  Bullish Engulfing",
        "  Piercing Line",
        "  Morning Star",
        "  Rising Three Methods",
        "  Dragonfly Doji",
        "  Hammer",
        "Breakaway Gap Ups",
        "Runaway Gap Ups",
    ]
    BEAR_CANDLES = [
        "  Bearish Engulfing",
        "  Evening Star",
        "  Falling Three Methods",
        "  Gravestone Doji",
        "  Shooting Star",
        "Breakaway Gap Downs",
        "Runaway Gap Downs",
    ]

    # below are some other signals available from the site
    BULL_SIGNALS = [
        "New 52-week Highs",
        "Strong Volume Gainers",
        "Bullish 50/200-day MA Crossovers",
        "Bullish MACD Crossovers",
        "Improving Chaikin Money Flow",
        "New CCI Buy Signals",
        "Parabolic SAR Buy Signals",
        "Stocks in a New Uptrend (Aroon)",
        "Stocks in a New Uptrend (ADX)",
        "Gap Ups",
        "Runaway Gap Ups",
        "  Piercing Line",
        "  Bullish Harami",
        "  Dragonfly Doji",
        "  Hammer",
        "P&F Bullish Signal Reversal Alerts",
        "P&F Bullish Catapult Alerts",
        "P&F Bullish Triangle Alerts",
        "Oversold with an Improving RSI",
        "Moved Below Lower Bollinger Band",
        "Breakaway Gap Ups",
        "Island Bottoms",
        "  Bullish Engulfing",
        "  Morning Star",
        "  Three White Soldiers",
    ]

    BEAR_SIGNALS = [
        "Overbought with a Declining RSI",
        "Moved Above Upper Bollinger Band",
        "Runaway Gap Downs",
        "  Dark Cloud Cover",
        "  Bearish Harami",
        "  Filled Black Candles",
        "New 52-week Lows",
        "Strong Volume Decliners",
        "Bearish 50/200-day MA Crossovers",
        "Bearish MACD Crossovers",
        "Declining Chaikin Money Flow",
        "New CCI Sell Signals",
        "Parabolic SAR Sell Signals",
        "Stocks in a New Downtrend (Aroon)",
        "Stocks in a New Downtrend (ADX)",
        "Island Tops",
        "Breakaway Gap Downs",
        "  Bearish Engulfing",
        "  Evening Star",
        "  Three Black Crows",
        "  Gravestone Doji",
        "  Shooting Star",
        "P&F Bearish Signal Reversal Alerts",
        "P&F Bearish Catapult Alerts",
        "P&F Bearish Triangle Alerts",
    ]


    def __init__(self):

        self.site = Site(self.HOST, self.PORT)
        self.signal_paths = {}
        self.bulls = {}
        self.bears = {}
        
    def scan(self):
        self.load_signal_paths()
        self.load_signals(self.BULL_SIGNALS, self.bulls)
        self.load_signals(self.BEAR_SIGNALS, self.bears)

    def load_signal_paths(self):
        print "Start to load signal paths..."
        raw = self.site.fetch(self.SIGNAL_SUMMARY_PAGE)
        soup = BeautifulSoup(raw)
        signal = "N/A"
        try:
            rows = soup.findAll("tr", {"class":"odd"}) + soup.findAll("tr", {"class":"even"})
            for row in rows:
                fields = row.findAll("td")
                signal = fields[0].string
                if signal is not None:
                    signal_path = fields[6].a['href']
                    symbol_count = int(fields[6].a.string)
                    if symbol_count > 0:
                        self.signal_paths[signal] = signal_path
                    else:
                        print "Skip signal %s as its count is ZERO" % (signal)
        except Exception, e:
            print "Failed processing signal paths %s: %s" % (signal, e)
        print "Loaded signal paths"