Exemple #1
0
def history_exists(c):
    return False
    if c.offers_at:
        first_date_before = c.offers_at + timedelta(days=7)
        q = Quote.query_one({
            'exchange': c.exchange,
            'symbol': c.symbol,
            'quote_type': '1d',
            'quote_at': {
                '$lte': first_date_before
            }
        })
        count = Quote.count({
            'exchange': c.exchange,
            'symbol': c.symbol,
            'quote_type': '1d'
        })

        past_days = (datetime.utcnow() - c.offers_at).days
        if past_days <= 2:
            return True

        trades_ratio = 1. * count / past_days

        if q and trades_ratio > 3 / 7.:
            return True
    return False
Exemple #2
0
def realtime(site):
    conf = get_conf(site)
    exchange = conf['abbr']
    url = conf['quote']['realtime']['url']
    type_ = conf['quote']['realtime']['type']
    today = datetime.utcnow().replace(
        minute=0, second=0, microsecond=0) + timedelta(hours=8)

    if not url:
        log.warning('{}尚未配置实时行情url'.format(exchange))
        return
    if today.hour < 9 or today.hour > 22:
        log.warning('不在9点到22点之间, 不做解析')
        return

    today = today.replace(hour=0)
    text = session.get(url, timeout=(3, 7)).text
    quotes = parse_quotes(type_, text)
    saved = 0
    for q in quotes:
        Collection.update_one({'exchange': exchange,
                               'symbol': q['symbol'].strip()},
                              {'$set': {'name': q['name']}},
                              upsert=True)
        q['exchange'] = exchange
        q['quote_type'] = '1d'
        q['quote_at'] = today
        if q['open_'] in ['—', '-', None, '']:
            continue
        else:
            # 找到上一个交易日的数据, 如果和lclose不符则舍弃
            # 需要保证数据每天更新/不足时需要把日线补足才能正常显示
            lq = Quote.query_one({'exchange': exchange,
                                  'symbol': q['symbol'].strip(),
                                  'quote_type': '1d',
                                  'quote_at': {'$lt': today}},
                                 sort=[('quote_at', -1)])
            if not lq or abs(lq.close - q['lclose']) < 0.01:
                Quote(q).upsert()
                saved += 1

    log.info('{} 导入 {}/{} 条实时交易记录'.format(exchange, saved, len(quotes)))
Exemple #3
0
def history_exists(c):
    return False
    if c.offers_at:
        first_date_before = c.offers_at + timedelta(days=7)
        q = Quote.query_one({'exchange': c.exchange,
                             'symbol': c.symbol,
                             'quote_type': '1d',
                             'quote_at': {'$lte':
                                          first_date_before}})
        count = Quote.count({'exchange': c.exchange,
                             'symbol': c.symbol,
                             'quote_type': '1d'})

        past_days = (datetime.utcnow() - c.offers_at).days
        if past_days <= 2:
            return True

        trades_ratio = 1. * count / past_days

        if q and trades_ratio > 3 / 7.:
            return True
    return False
Exemple #4
0
 def open_at(exchange):
     q = Quote.query_one({"exchange": exchange}, sort=[("quote_at", 1)])
     d = q.quote_at if q else None
     return d.strftime("%Y年%m月") if d else "尚未"
Exemple #5
0
 def open_at(exchange):
     q = Quote.query_one({'exchange': exchange}, sort=[('quote_at', 1)])
     d = q.quote_at if q else None
     return d.strftime('%Y年%m月') if d else '尚未'