示例#1
0
def loadQuoteBars(quote_file, code='', ktype='5m'):
    """
    加哉行情数据
    :param quote_file:
    :param ktype:
    :return:
    """
    bars = []
    lines = open(quote_file).readlines()
    lines = map(str.strip, lines)
    if not code:
        code = lines[0].split(' ')[0]
    lines = lines[2:-1]
    for line in lines:
        fs = line.split(',')
        ymd, hm, open_, high, low, close, vol, amount = fs[:8]
        dt = ymd + ' ' + hm[:2] + ':' + hm[2:] + ':00'
        bar = stbase.BarData()
        bar.code = code
        bar.cycle = ktype
        bar.open = float(open_)
        bar.high = float(high)
        bar.low = float(low)
        bar.close = float(low)
        bar.vol = float(vol)
        bar.amount = float(amount)
        bar.time = parse(dt)
        bars.append(bar)
    return bars
示例#2
0
def loadQuoteBars(quote_file, code, ktype='d'):
    bars = []
    lines = open(quote_file).readlines()
    lines = map(str.strip, lines)
    # if not code:
    #     code = lines[0].split(' ')[0]
    lines = lines[2:-1]
    for line in lines:
        fs = line.split()
        # ymd, hm, open_, high, low, close, vol, amount = fs[:8]
        # dt = ymd + ' ' + hm[:2] + ':' + hm[2:] + ':00'

        ymd, open_, high, low, close, vol = fs[:6]
        dt = parse(ymd)

        bar = stbase.BarData()
        bar.code = code
        bar.cycle = ktype
        bar.open = float(open_)
        bar.high = float(high)
        bar.low = float(low)
        bar.close = float(close)
        bar.vol = float(vol)
        bar.amount = float(0)
        bar.time = dt
        bar.datetime = bar.time
        bars.append(bar)
    return bars
示例#3
0
    def barWrapped(self, code, cycle, kdata):
        name = '{}-{}'.format(code, cycle)
        last = self.bar_last_data[name].get('last')
        current = ','.join(kdata)
        if last == current:
            return
        self.bar_last_data[name]['last'] = current

        dt = kdata[0]
        dt = parse(dt)

        nums = kdata[1:]

        nums = map(float, nums)

        data = stbase.BarData()
        data.amount = nums[5]
        data.open = nums[0]
        data.high = nums[2]
        data.low = nums[3]
        data.close = nums[1]
        data.vol = nums[4]

        data.time = dt
        data.sys_time = datetime.datetime.now()
        data.code = code
        data.trade_object = stbase.stocks.getTradeObject(code)

        data.cycle = cycle
        return data
def get_daily_data():
    """进行爬取上一个交易日的行情日线"""
    for symbol,tag in config.CRAWL_DAILY_SYMBOLS.items():
        last = None
        for i in range(5):
            try:
                last = crawl_it_sina(tag)
                break
            except:
                traceback.print_exc()
                print 'Wait a while ..'
                time.sleep(5)
        if not last:
            print 'Crawl Quotes Error , Broken Out.'
            return

        coll = conn['Ctp_Bar_d'][symbol]
        date = datetime.datetime.now()
        date = date.replace(hour=0,minute=0,second=0,microsecond=0)
        r = coll.find_one({'datetime':date})
        if r:
            coll.delete_one({'_id':r['_id']})
        r = None
        if not r:

            bar = stbase.BarData()
            bar.code = symbol
            bar.cycle = 'd'
            bar.open = float(last[0])
            bar.high = float(last[1])
            bar.low = float(last[2])
            bar.close = float(last[3])
            bar.vol = float(last[4])
            bar.amount = float(0)
            bar.time = date
            bar.datetime = bar.time

            print bar.dict()
            coll.insert(bar.dict())