Esempio n. 1
0
def get_one(index=0):
    mongo_client = pymongo.MongoClient(settings['MONGO_SERVER'],
                                       settings['MONGO_PORT'])
    db = mongo_client[settings['MONGO_DB']]
    db.authenticate(settings['MONGO_DB_USER'], settings['MONGO_DB_PSW'])
    table = db[settings['MONGO_TABLE_STOCK_BASIC']]
    table = quantbase.get_mongo_table_instance(settings['MONGO_TABLE_HISTORY'])
    row = table.find().limit(1).skip(index)[0]
    return row.get("code"), row.get("timeToMarket")
Esempio n. 2
0
def get_today_all_sina():
    """
    当前全市场实时数据,每五分钟取一次
    """
    table = quantbase.get_mongo_table_instance(
        settings['MONGO_TABLE_STOCK_CODE'])
    code_list = table.find({"ipodate": {"$ne": "-"}}, {"scode": -1})
    sina = Sina()

    stock_codes = [code.get("scode") for code in code_list]
    stock_codes = sina.gen_stock_list(stock_codes)

    table = quantbase.get_mongo_table_instance(
        settings['MONGO_TABLE_STOCK_TODAY_ALL'])
    stock_day_data = sina.get_stock_data(stock_codes)
    for item in stock_day_data:
        table.update({"code": item.get("code")}, item, True)

    print datetime.datetime.now().ctime(), "当天实时数据存入数据库"
Esempio n. 3
0
def get_day_all():
    """
    当前全市场实时数据,每五分钟取一次
    """
    df = ts.get_day_all()
    data = json.loads(df.to_json(orient='records'))

    table = quantbase.get_mongo_table_instance("stock_day_all")
    for item in data:
        print item.get("code"), ".. save"
        table.update({"code": item.get("code")}, item, True)
    print datetime.datetime.now().ctime(), "当天实时数据存入数据库"
Esempio n. 4
0
def get_today_all():
    """
    当前全市场实时数据,每五分钟取一次
    """
    df = ts.get_today_all()
    data = json.loads(df.to_json(orient='records'))

    table = quantbase.get_mongo_table_instance(
        settings['MONGO_TABLE_STOCK_TODAY_ALL'])
    for item in data:
        print item.get("code"), ".. save"
        table.update({"code": item.get("code")}, item, True)
    print datetime.datetime.now().ctime(), "当天实时数据存入数据库"
Esempio n. 5
0
def init_stock_code():
    """
    基本面数据
    :return:
    """
    df = ts.get_stock_basics()
    # 重设索引
    data = json.loads(df.reset_index().to_json(orient='records'))
    # f = file('log3.txt', "wb")
    # f.write(json.dumps(data))
    # f.close()

    # print data
    # df.to_csv(path_or_buf='d/log.txt')

    table = quantbase.get_mongo_table_instance(
        settings['MONGO_TABLE_STOCK_BASIC'])
    for stock in data:
        table.update({"code": stock.get("code")}, stock, True)

    print "股票代码存入数据库"
Esempio n. 6
0
def init_history(code=None, start=None, end=None):
    """
    初始化数据,直接存入
    :param code: 股票代码
    :param start:开始时间,单位日
    :param end:结束时间,单位日
    :return:
    """
    df = ts.get_k_data(code=code,
                       start=start,
                       end=end,
                       ktype="D",
                       autype="hfq",
                       index=False,
                       retry_count=3,
                       pause=0.001)
    data = json.loads(df.to_json(orient='records'))
    if len(data) == 0:
        print code, "from", start, "to", end, "没有数据"
        return

    table = quantbase.get_mongo_table_instance(settings['MONGO_TABLE_HISTORY'])
    table.insert(data)
    print code, "from", start, "to", end, "存入数据库"