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
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])
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 })
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)
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)
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)
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)
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()
def TestMultiStock(): runConfig = { # 系统指标名字 # "Name":"MA", # 执行的脚本 "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 } ], "Args": [{ "Name": "M1", "Value": 15 }, { "Name": "M2", "Value": 20 }, { "Name": "M3", "Value": 30 }], # 周期 复权 "Period": 0, "Right": 0, # 股票池 "Symbol": ["600000.sh", "600007.sh", "000001.sz", "600039.sh"], # 输出数据个数 如果只需要最后几个数据可以填几个的个数, 数据从最后开始返回的, 如1=返回最后1个数据 2=返回最后2个数组, -1=返回所有的数据 "OutCount": 1, } # 批量执行的股票 #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.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)