Beispiel #1
0
def callback():
    (conn_opt, engine_opt) = genDbConn(localDBInfo, db_name)
    df = pd.read_sql(con=conn_opt, sql='select * from now')

    # 获取权值
    weight_dict = getWeight()

    if not df.empty:
        for idx in df.index:
            stk_code = df.loc[idx, 'stk_code']
            price_last = df.loc[idx, 'price']
            amount_last = df.loc[idx, 'amount']

            try:
                if not pd.isnull(weight_dict[stk_code]):
                    earn_threshold = np.max([
                        weight_dict[stk_code] / basic_ratio, 1
                    ]) * basic_earn_threshold
                else:
                    print(stk_code + ':权值为空!使用基础权值!')
                    earn_threshold = basic_earn_threshold
            except:
                print(stk_code + ':权值获取失败!使用基础权值!')
                earn_threshold = basic_earn_threshold

            JudgeSingleStk(stk_code=stk_code,
                           stk_price_last=price_last,
                           stk_amount_last=amount_last,
                           earn_threshold=int(earn_threshold))

    # print(str(pd.read_sql(con=conn_opt, sql='select * from now')))
    conn_opt.close()
Beispiel #2
0
def updateRSVRecord():
    try:
        (conn_opt, engine_opt) = genDbConn(localDBInfo,  'stk_opt_info')
        df = pd.read_sql(con=conn_opt, sql='select * from now')

        # global  RSV_Record
        if not df.empty:
            for idx in df.index:
                RSV_Record[stk_code] = calRSVRank(df.loc[idx, 'stk_code'], 5)
    except:
        send_qq('影子2', 'RSV数据更新失败!')
Beispiel #3
0
def callback():
    (conn_opt, engine_opt) = genDbConn(localDBInfo, db_name)
    df = pd.read_sql(con=conn_opt, sql='select * from now')

    if not df.empty:
        for idx in df.index:
            stk_code = df.loc[idx, 'stk_code']
            price_last = df.loc[idx, 'price']
            amount_last = df.loc[idx, 'amount']

            JudgeSingleStk(stk_code=stk_code,
                           stk_price_last=price_last,
                           stk_amount_last=amount_last,
                           earn_threshold=int(basic_earn_threshold))

    conn_opt.close()
Beispiel #4
0
def saveWeightFile():
    """
    将持仓stk的权值存为文件
    :param dir:
    :return:
    """

    # 新方式:lacalDBInfo包括除了“数据库名”之外的其他参数
    localDBInfo = {
        'host': 'localhost',
        'port': 3306,
        'user': '******',
        'password': '******',
        'charset': 'utf8'
    }

    db_name = 'stk_opt_info'

    table_history = 'history'
    table_now = 'now'

    (conn_opt, engine_opt) = genDbConn(localDBInfo, db_name)
    df = pd.read_sql(con=conn_opt, sql='select * from now')

    if not df.empty:
        df['weight'] = df.apply(lambda x: calWeight(x['stk_code']), axis=1)

        dumpPickle(data=df, saveLocation='./Weight/', fileName='weight')
        send_qq(
            '影子',
            '更新stk的权值成功!\n' + str(df.loc[:, ['stk_name', 'weight']].values))

    else:
        dumpPickle(data=pd.DataFrame(),
                   saveLocation='./Weight/',
                   fileName='weight')
        send_qq('影子', '更新stk权值时发现 now 表为空!')

    conn_opt.close()
Beispiel #5
0
""" =========================== 链接数据库 ============================ """
# 新方式:lacalDBInfo包括除了“数据库名”之外的其他参数
localDBInfo = {
    'host': 'localhost',
    'port': 3306,
    'user': '******',
    'password': '******',
    'charset': 'utf8'
}

db_name = 'stk_opt_info'

table_history = 'history'
table_now = 'now'

(conn_opt, engine_opt) = genDbConn(localDBInfo, db_name)
cur = conn_opt.cursor()
""" ============================ 命令行输入逻辑 =================================== """
while True:
    input_str = input('输入你的命令:')

    # 按空格解析命令
    input_split = input_str.split(' ')

    if len(input_split) == 4:  # 插入命令

        sql_str_no_reap = 'insert into ' +\
            table_history + ' (stk_code, stk_name, amount, price, opt, input_time, reap_flag) values(' + \
            "'" + input_split[0] + "'" + ',' + \
            "'" + getNameByStkCode(g_total_stk_info_mysql, input_split[0]) + "'" + ',' + \
            str(input_split[2]) + ',' + \
Beispiel #6
0
# encoding=utf-8
"""
数据库名字:stk_JQ_money_flow
mysql 链接句柄 db_JQ_money_flow
"""
from Config.GlobalSetting import localDBInfo
from SDK.DBOpt import genDbConn, is_table_exist
import pandas as pd
from SDK.MyTimeOPT import minus_date_str, get_current_date_str, add_date_str
""" -------------------------- 定义全局参数 -------------------------------- """
start_date = '2009-01-01'
end_date = get_current_date_str()
(conn_JQ_MF, engine_JQ_MF) = genDbConn(localDBInfo, 'stk_JQ_money_flow')
""" -------------------------- 获取 all stks -------------------------------- """
all_stk_list = get_all_securities(types=['stock'], date=None)
for stk in all_stk_list.index:
    table_name = 's' + stk.split('.')[0]
    if is_table_exist(conn=conn_JQ_MF,
                      database_name='stk_JQ_money_flow',
                      table_name=table_name):
        # 读取原表,并获取最后的日期
        df = pd.read_sql('select * from ' + table_name, con=conn_JQ_MF)
        date_last = str(
            df.sort_values(by='date',
                           ascending=True).tail(1)['date'].values[0])[:10]
        # 判断是否是最新日期
        if minus_date_str(date_last, get_current_date_str()) >= 0:
            print(stk + ' 表中的日期已经是最新的了!不需要更新!')
            continue
        df = get_money_flow(stk,