Пример #1
0
    def Run(self, config):
        jsConfig = json.dumps(config)  # 运行配置项
        hqData = TushareHQChartData(TUSHARE_AUTHORIZATION_KEY,
                                    startDate=config["StartDate"],
                                    endDate=config["EndDate"])
        result = HQSelectResult()  # 实例计算结果接收类

        start = time.process_time()
        res = FastHQChart.Run(jsConfig,
                              hqData,
                              proSuccess=result.RunSuccess,
                              procFailed=result.RunFailed)

        elapsed = (time.process_time() - start)
        log = '''
---------------------------------------------------------------------------
TushareSelect::Run() 
Success:{4},
ID:{3}
执行时间:{0},
K线返回:{6}-{7},
股票个数:{1}, 
脚本:
{2}
参数:{5}
---------------------------------------------------------------------------
    '''.format(elapsed, len(config['Symbol']), config["Script"],
               config['JobID'], res, config["Args"], config["StartDate"],
               config["EndDate"])
        print(log)

        return result
Пример #2
0
def RunIndexTest(runConfig):
    jsConfig = json.dumps(runConfig)    # 运行配置项
    hqData=TushareKLocalHQChartData(TushareConfig.TUSHARE_AUTHORIZATION_KEY,startDate=20200421, endDate=20201231, cachePath="test_data\\")    # 实例化数据类

    result=HQSelectDataFrameResult()   # 实例计算结果接收类

    start = time.process_time()

    res=FastHQChart.Run(jsConfig,hqData,proSuccess=result.RunSuccess, procFailed=result.RunFailed)

    elapsed = (time.process_time() - start)
    
    log='''RunSingleStockIndex() 
---------------------------------------------------------------
耗时:{0}s, 
股票个数:{1}, 
脚本:
{2}
执行是否成功:{3}
---------------------------------------------------------------'''.format(elapsed,len(runConfig['Symbol']), runConfig["Script"], res)
    print(log)
    if (res==True):
        for item in result.dfResult.items() :
            symbol= item[0]
            print('{0} 数据:'.format(symbol))
            print(item[1])
Пример #3
0
def SelectRun(message):
    runConfig = message['data']
    startDate = 20200421
    endDate = 20201231
    jobID = str(uuid.uuid1())

    if ("StartDate" in runConfig):
        startDate = runConfig["StartDate"]
    if ("EndDate" in runConfig):
        endDate = runConfig["EndDate"]

    if ("JobID" in runConfig):
        jobID = runConfig["JobID"]
    else:
        runConfig["JobID"] = jobID

    if ("OutCount" not in runConfig):
        runConfig["OutCount"] = 1  # 默认输出最后一个数据

    script = runConfig["Script"]

    jsConfig = json.dumps(runConfig)  # 运行配置项
    hqData = TushareHQChartData(TUSHARE_AUTHORIZATION_KEY,
                                startDate=startDate,
                                endDate=endDate)
    result = HQSelectResult()  # 实例计算结果接收类

    start = time.process_time()

    res = FastHQChart.Run(jsConfig,
                          hqData,
                          proSuccess=result.RunSuccess,
                          procFailed=result.RunFailed)

    elapsed = (time.process_time() - start)
    log = '''
---------------------------------------------------------------------------
HQChartPy_Run() 
ID:{3}
执行时间:{0},
股票个数:{1}, 
脚本:
{2}
---------------------------------------------------------------------------
    '''.format(elapsed, len(runConfig['Symbol']), script, jobID)

    print(log)

    emit('HQChartPy_SelectFinish', {
        'Result': res,
        "Tick": elapsed,
        "JobID": jobID
    })
Пример #4
0
def TestSingleStock():
    runConfig = {
        "Script":
        '''
        T2:MA(C,10);
        T3:FINANCE(1);
        T4:DYNAINFO(5);
        T5:INDEXA;
        T6:INDEXC;
        ''',
        # 脚本参数
        "Args": [{
            "Name": 'N1',
            "Value": 5
        }, {
            "Name": 'N2',
            "Value": 10
        }, {
            "Name": 'N3',
            "Value": 15
        }],
        # 周期 复权
        "Period":
        0,
        "Right":
        0,
        "Symbol":
        "600000.sh",

        #jobID (可选)
        "JobID":
        "1234-555-555"
    }

    jsConfig = json.dumps(runConfig)  # 运行配置项
    hqData = HQChartData()  # 实例化数据类
    result = HQResultTest()  # 实例计算结果接收类
    result.IsOutLog = False

    start = time.process_time()

    res = FastHQChart.Run(jsConfig,
                          hqData,
                          proSuccess=result.RunSuccess,
                          procFailed=result.RunFailed)

    elapsed = (time.process_time() - start)
    log = "TestSingleStock() Time used:{0}, 股票{1}".format(
        elapsed, runConfig['Symbol'])
    print(log)
Пример #5
0
def TestSingleStock():
    runConfig = {
        # 系统指标名字
        # "Name":"MA",
        "Script":
        '''
       T2:FINANCE(7); 
       T3:FINONE(1,2,3);
        ''',
        # 脚本参数
        # "Args":[ { "Name": 'N1', "Value": 5 },{ "Name": 'N2', "Value": 10 },{ "Name": 'N3', "Value": 15 } ],
        "Args": [{
            "Name": "M1",
            "Value": 15
        }, {
            "Name": "M2",
            "Value": 20
        }, {
            "Name": "M3",
            "Value": 30
        }],
        # 周期 复权
        "Period":
        1,
        "Right":
        0,
        "Symbol":
        "600000.sh",

        #jobID (可选)
        "JobID":
        "1234-555-555"
    }

    jsConfig = json.dumps(runConfig)  # 运行配置项
    hqData = HQChartData()  # 实例化数据类
    result = HQResultTest()  # 实例计算结果接收类
    result.IsOutLog = True

    start = time.process_time()

    res = FastHQChart.Run(jsConfig,
                          hqData,
                          proSuccess=result.RunSuccess,
                          procFailed=result.RunFailed)

    elapsed = (time.process_time() - start)
    log = "TestSingleStock() Time used:{0}, 股票{1}".format(
        elapsed, runConfig['Symbol'])
    print(log)
Пример #6
0
def HQChartPy_Run():
    symbol = '600000.sh'
    startDate = 20200421
    endDate = 20201231
    period = 0
    right = 0
    jobID = str(uuid.uuid1())

    if (request.method == "POST"):
        # data = request.get_data()
        if (request.mimetype == "application/x-www-form-urlencoded"):
            requestData = request.form
        else:
            requestData = json.loads(request.get_data(as_text=True))

        symbol = requestData['Symbol']
        script = requestData["Script"]
        args = []

        # 可选参数
        if ("Period" in requestData):
            period = requestData["Period"]
        if ("Right" in requestData):
            right = requestData["Right"]
        if ("Args" in requestData):
            args = requestData["Args"]
        if ("StartDate" in requestData):
            startDate = requestData["StartDate"]
        if ("EndDate" in requestData):
            endDate = requestData["EndDate"]

        runConfig = {
            # 系统指标名字
            # "Name":"MA",
            "Script": script,
            # 脚本参数
            "Args": args,
            # 周期 复权
            "Period": period,
            "Right": right,
            "Symbol": symbol,
            # "OutCount":1,

            #jobID (可选)
            "JobID": jobID
        }

    else:
        runConfig = {
            # 系统指标名字
            # "Name":"MA",
            "Script":
            TEST_CODE,
            # 脚本参数
            "Args": [{
                "Name": "M1",
                "Value": 15
            }, {
                "Name": "M2",
                "Value": 20
            }, {
                "Name": "M3",
                "Value": 30
            }],
            # 周期 复权
            "Period":
            period,
            "Right":
            right,
            "Symbol":
            symbol,

            #jobID (可选)
            "JobID":
            jobID
        }

    jsConfig = json.dumps(runConfig)  # 运行配置项
    hqData = TushareHQChartData(TUSHARE_AUTHORIZATION_KEY,
                                startDate=startDate,
                                endDate=endDate)  # 实例化数据类
    result = HQResultTest()  # 实例计算结果接收类

    start = time.process_time()

    res = FastHQChart.Run(jsConfig,
                          hqData,
                          proSuccess=result.RunSuccess,
                          procFailed=result.RunFailed)

    elapsed = (time.process_time() - start)
    log = '''
---------------------------------------------------------------------------
HQChartPy_Run() 
ID:{3}
执行时间:{0},
股票{1}, 
脚本:
{2}
---------------------------------------------------------------------------
    '''.format(elapsed, runConfig['Symbol'], script, jobID)

    print(log)

    if (res):
        jsonData = result.Result[0]["Data"]
        df = HQChartPy2Helper.JsonDataToPandas(jsonData)  # 指标数据转pandas
        print(df)
        responseData = json.loads(jsonData)
        responseData["Code"] = 0  # 成功
        responseData['Tick'] = elapsed  # 耗时
        responseData['StartDate'] = startDate
        responseData["EndDate"] = endDate
        responseData["JobID"] = jobID
        return jsonify(responseData)
    else:
        responseData = {
            'Code': 1,
            "Tick": elapsed,
            "Error": result.Error,
            "JobID": jobID
        }
        return jsonify(responseData)
Пример #7
0
def home():
    version = FastHQChart.GetVersion()
    return '''<h1>HQChartPy2</h1>
<p>版本号:{0}</p>
<p>授权信息:{1}</p>'''.format(version, FastHQChart.Authorize)
Пример #8
0
def SelectOnConnect():
    version = FastHQChart.GetVersion()
    emit('HQChartPy_Ready', {
        'Version': version,
        "Authorize": FastHQChart.Authorize
    })
Пример #9
0
---------------------------------------------------------------------------
    '''.format(elapsed, len(runConfig['Symbol']), script, jobID)

    print(log)

    emit('HQChartPy_SelectFinish', {
        'Result': res,
        "Tick": elapsed,
        "JobID": jobID
    })


@socketio.on('connect', namespace='/select')
def SelectOnConnect():
    version = FastHQChart.GetVersion()
    emit('HQChartPy_Ready', {
        'Version': version,
        "Authorize": FastHQChart.Authorize
    })


@socketio.on('disconnect', namespace='/select')
def SelectOnDisconnect():
    print('Client disconnected')


if __name__ == '__main__':
    FastHQChart.Initialization(HQCHART_AUTHORIZATION_KEY)
    # app.run(host='127.0.0.1', port=8712, debug=True)
    socketio.run(app, debug=True, host="127.0.0.1", port=8712)
Пример #10
0
def TestMultiStock():
    runConfig = {
        # 执行的脚本
        "Script":
        '''
        JJ:=(HIGH+LOW+CLOSE)/3;
        QJ0:=VOL/IF(HIGH=LOW,4,HIGH-LOW);
        QJ1:=QJ0*(MIN(OPEN,CLOSE)-LOW);
        QJ2:=QJ0*(JJ-MIN(CLOSE,OPEN));
        QJ3:=QJ0*(HIGH-MAX(OPEN,CLOSE));
        QJ4:=QJ0*(MAX(CLOSE,OPEN)-JJ);
        DDX:=IF(HIGH=LOW,4*QJ0,((QJ1+QJ2)-(QJ3+QJ4)))/SUM(VOL,10)*100;
        DDY:=((QJ2+QJ4)-(QJ1+QJ3))/SUM(VOL,10)*100;
        DDZ:=((QJ1+QJ2)-(QJ3+QJ4))/((QJ1+QJ2)+(QJ3+QJ4))*100*17;
        AA:((DDX+DDY+DDZ)/3);
        ''',
        # 脚本参数
        "Args": [{
            "Name": 'N1',
            "Value": 5
        }, {
            "Name": 'N2',
            "Value": 10
        }, {
            "Name": 'N3',
            "Value": 15
        }],
        # 周期 复权
        "Period":
        0,
        "Right":
        0,
        # 股票池
        "Symbol": ["600000.sh", "600007.sh", "000001.sz", "600039.sh"],
        # 并行计算加速模式
        "Mode": {
            "Thread": False,
            "MinRunCount": 1000,
            "Count": 5
        },
        # 输出数据个数 如果只需要最后几个数据可以填几个的个数, 数据从最后开始返回的, 如1=返回最后1个数据 2=返回最后2个数组,  -1=返回所有的数据
        "OutCount":
        1,
        # 单个股票执行完是否立即清空缓存, 更具K线个数配置, 不清空缓存到占用很多内存
        "ClearCache":
        True
    }

    # 批量执行的股票
    for i in range(3700):
        # runConfig["Symbol"].append("600000.sh")
        runConfig["Symbol"].append("000421.sz")

    jsConfig = json.dumps(runConfig)  # 运行配置项
    hqData = HQChartData()  # 实例化数据类
    result = HQResultTest()  # 实例计算结果接收类
    result.IsOutLog = False

    # 预加载K线数据
    # start = time.process_time()
    # loadCount=0
    # loadCount=HQChart.PreLoadKData(runConfig,data,guid=strGuid)
    # elapsed = (time.process_time() - start)
    # log="加载数据 Time used:{0}, 股票个数:{1}".format(elapsed, loadCount)
    # print(log)

    start = time.process_time()
    res = FastHQChart.Run2(jsConfig,
                           hqData,
                           proSuccess=result.RunSuccess,
                           procFailed=result.RunFailed)
    elapsed = (time.process_time() - start)
    log = "执行指标 Time used:{0}, 股票个数:{1}".format(elapsed,
                                                len(runConfig['Symbol']))
    print(log)
Пример #11
0
    result.IsOutLog = False

    # 预加载K线数据
    # start = time.process_time()
    # loadCount=0
    # loadCount=HQChart.PreLoadKData(runConfig,data,guid=strGuid)
    # elapsed = (time.process_time() - start)
    # log="加载数据 Time used:{0}, 股票个数:{1}".format(elapsed, loadCount)
    # print(log)

    start = time.process_time()
    res = FastHQChart.Run2(jsConfig,
                           hqData,
                           proSuccess=result.RunSuccess,
                           procFailed=result.RunFailed)
    elapsed = (time.process_time() - start)
    log = "执行指标 Time used:{0}, 股票个数:{1}".format(elapsed,
                                                len(runConfig['Symbol']))
    print(log)


if __name__ == "__main__":

    key = "FeArQfG7PG1WjRuzKH/JPlJCpF9zTKVg8gl1AqSoaIfMbmVGmc8BFRZGKFK2Foca2Icu1Q/uSsi+38T51oEHMmSRCfX3zkEZsicW6jLcXUnOXhvzE/E9mq8P0D25zO9Zti1Qxlo7cgMLZOCnpUDYOa9+w3+ecy3voiCV57c+V6o="
    FastHQChart.Initialization(key)

    TestSingleStock()

    TestMultiStock()

    TestMultiStock()
Пример #12
0
def TestSingleStock():
    # 授权码
    HQCHARTPY2_KEY = "oTjOc1CNCuxtcAqs6+/FHeKmYcPpFv+M9y7seNd6eBTE9tq1El9mGLi7bj6gtMf3RpWtGJ0K7Tu2wbEBUjunGb5mgGskWii4vlUK+5XFr7fI/nDysxdWOebKqJ+RLif0MptDIGdQP8nbyw1osZdXJuWpb4RYYNrzeXtbQVDI2UNnuJUm8DpGs/SgKrw9l+Q2QT/hMnJ6/MMsjMpsgHmV5iHWQTzzAU2QXnX5rtMuAISFKcLlbPzKF809lexHbtqXqoPxQfJkqh0YzTyJOZLhkvZ+Sm5vIu4EhJjIQBTLrX229t8rIvwKwLZ/UEuewSQFgq2QkpBQMPlBU/HVy5h7WQ=="
    TUSHARE_TOKEN = "836dcc340f026bd41b378d702d5e11950df18c1750b18ec18dc4ea09"

    FastHQChart.Initialization(HQCHARTPY2_KEY)

    runConfig = {
        # 系统指标名字
        # "Name":"MA",
        "Script":
        '''
        //CALCSTOCKINDEX('SH600036', 'KDJ', 3);
        //STKINDI('sz300059','KDJ.T1#WEEK',9,4,4);
        MA(C,M1);
        GPJYVALUE(1,1,0);
        //T2:C#WEEK;
        //T2:MA(C,M2);
        //T3:MA(C,M3);
        //T4:COST(10);
        //T5:TOTALCAPITAL;
        //T6:CAPITAL;
        //T9:DYNAINFO(8);
        T7:FINANCE(18);
        //T8:FINANCE(40);
        ''',
        # 脚本参数
        "Args": [{
            "Name": "M1",
            "Value": 15
        }, {
            "Name": "M2",
            "Value": 20
        }, {
            "Name": "M3",
            "Value": 30
        }],
        # 周期 复权
        "Period":
        0,
        "Right":
        0,
        "Symbol":
        "600000.sh",

        #jobID (可选)
        "JobID":
        "1234-555-555"
    }

    jsConfig = json.dumps(runConfig)  # 运行配置项
    hqData = TushareHQChartData(TUSHARE_TOKEN,
                                startDate=20200421,
                                endDate=20201231)  # 实例化数据类
    result = HQResultTest()  # 实例计算结果接收类

    start = time.process_time()

    res = FastHQChart.Run(jsConfig,
                          hqData,
                          proSuccess=result.RunSuccess,
                          procFailed=result.RunFailed)

    elapsed = (time.process_time() - start)
    log = "TestSingleStock() Time used:{0}, 股票{1}".format(
        elapsed, runConfig['Symbol'])
    print(log)
Пример #13
0
    emit('HQChartPy_SelectFinish', {
        'Result': res,
        "Tick": elapsed,
        "JobID": jobID
    })


@socketio.on('connect', namespace='/select')
def SelectOnConnect():
    version = FastHQChart.GetVersion()
    emit('HQChartPy_Ready', {
        'Version': version,
        "Authorize": FastHQChart.Authorize
    })


@socketio.on('disconnect', namespace='/select')
def SelectOnDisconnect():
    print('Client disconnected')


if __name__ == '__main__':
    if (TushareConfig.HQCHART_AUTHORIZATION_KEY == None):
        # 请求试用账户, 把mac地址改成你本机的mac地址
        TushareConfig.HQCHART_AUTHORIZATION_KEY = FastHQChart.GetTrialAuthorize(
            mac="A4-B1-C1-4B-4D-7B")
    FastHQChart.Initialization(TushareConfig.HQCHART_AUTHORIZATION_KEY)
    # app.run(host='127.0.0.1', port=8712, debug=True)
    socketio.run(app, debug=True, host="127.0.0.1", port=8712)
Пример #14
0
def TestSingleStock():
    TUSHARE_TOKEN = TushareConfig.TUSHARE_AUTHORIZATION_KEY
    if (TushareConfig.HQCHART_AUTHORIZATION_KEY == None):
        TushareConfig.HQCHART_AUTHORIZATION_KEY = FastHQChart.GetTrialAuthorize(
            mac="A4-B1-C1-4B-4D-7B")  # 请求试用账户, 把mac地址改成你本机的mac地址

    FastHQChart.Initialization(TushareConfig.HQCHART_AUTHORIZATION_KEY)

    runConfig = {
        # 系统指标名字
        # "Name":"MA",
        "Script":
        '''
        //CALCSTOCKINDEX('SH600036', 'KDJ', 3);
        //STKINDI('sz300059','KDJ.T1#WEEK',9,4,4);
        //MA(C,M1);
        K:KDJ.K;
        D:KDJ.D;
        J:KDJ.J;

        K:KDJ.K#WEEK;
        D:KDJ.D#WEEK;
        J:KDJ.J#WEEK;
        //GPJYVALUE(1,1,0);
        //T2:C#WEEK;
        //T2:MA(C,M2);
        //T3:MA(C,M3);
        //T4:COST(10);
        //T5:TOTALCAPITAL;
        //T6:CAPITAL;
        //T9:DYNAINFO(8);
        //T7:FINANCE(18);
        //T8:FINANCE(40);
        ''',
        # 脚本参数
        "Args": [{
            "Name": "M1",
            "Value": 15
        }, {
            "Name": "M2",
            "Value": 20
        }, {
            "Name": "M3",
            "Value": 30
        }],
        # 周期 复权
        "Period":
        0,
        "Right":
        0,
        "Symbol":
        "600000.sh",

        #jobID (可选)
        "JobID":
        "1234-555-555"
    }

    jsConfig = json.dumps(runConfig)  # 运行配置项
    hqData = TushareHQChartData(TUSHARE_TOKEN,
                                startDate=20200421,
                                endDate=20201231)  # 实例化数据类
    result = HQResultTest()  # 实例计算结果接收类

    start = time.process_time()

    res = FastHQChart.Run(jsConfig,
                          hqData,
                          proSuccess=result.RunSuccess,
                          procFailed=result.RunFailed)

    elapsed = (time.process_time() - start)
    log = "TestSingleStock() Time used:{0}, 股票{1}".format(
        elapsed, runConfig['Symbol'])
    print(log)


# TestSingleStock()
Пример #15
0
    # 预加载K线数据
    # start = time.process_time()
    # loadCount=0
    # loadCount=HQChart.PreLoadKData(runConfig,data,guid=strGuid)
    # elapsed = (time.process_time() - start)
    # log="加载数据 Time used:{0}, 股票个数:{1}".format(elapsed, loadCount)
    # print(log)

    start = time.process_time()
    res = FastHQChart.Run(jsConfig,
                          hqData,
                          proSuccess=result.RunSuccess,
                          procFailed=result.RunFailed)
    elapsed = (time.process_time() - start)
    log = "执行指标 Time used:{0}, 股票个数:{1}".format(elapsed,
                                                len(runConfig['Symbol']))
    print(log)


if __name__ == "__main__":

    key = "oTjOc1CNCuxtcAqs6+/FHeKmYcPpFv+M9y7seNd6eBTE9tq1El9mGLi7bj6gtMf3RpWtGJ0K7Tu2wbEBUjunGb5mgGskWii4vlUK+5XFr7fI/nDysxdWOebKqJ+RLif0MptDIGdQP8nbyw1osZdXJuWpb4RYYNrzeXtbQVDI2UNnuJUm8DpGs/SgKrw9l+Q2QT/hMnJ6/MMsjMpsgHmV5iHWQTzzAU2QXnX5rtMuAISFKcLlbPzKF809lexHbtqXqoPxQfJkqh0YzTyJOZLhkvZ+Sm5vIu4EhJjIQBTLrX229t8rIvwKwLZ/UEuewSQFgq2QkpBQMPlBU/HVy5h7WQ=="
    FastHQChart.Initialization(key)

    jsSystemIndex = json.dumps(FastHQChart.HQCHART_SYSTEM_INDEX)
    FastHQChart.AddSystemIndex(jsSystemIndex)

    TestSingleStock()

    TestMultiStock()