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
def sync_collections(): from ybk.config import setup_config from ybk.models import Collection as C1 from ybk.models import Quote as Q1 setup_config() for c in C1.query(): print(c.exchange, c.symbol) td = Q1.count({'exchange': c.exchange, 'symbol': c.symbol, 'type_': '1d'}) + 1 if td == 1: if not c.offers_at: # 没录入过, 基本上会挂 continue # 如果K线不存在, 可能是交易行情无法获取, 直接用估算数字 td = (datetime.utcnow() - c.offers_at).days - 1 c2 = Collection({ 'exchange': c.exchange, 'symbol': c.symbol, 'name': c.name, 'trade_day': td, }) c2.upsert()
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