datas.append(x.toDict()) pMsg['datas'] = datas pMsg['result'] = True strJson = myData_Json.Trans_ToJson_str(pMsg) path = self.Dir_Swaps + "/Quote_" + myData_Trans.Tran_ToDatetime_str( None, "%Y-%m-%d-%H-%M-%S") + ".json" myIO.Save_File(path, strJson, isUtf=True, isNoBoom=True) return True return False #缓存全局对象 from myGlobal import gol gol._Init() #先必须在主模块初始化(只在Main模块需要一次即可) gol._Set_Value('quoteSource', Source_Control()) #实例 行情对象 quoteSource = gol._Get_Value('quoteSource') #线程执行-行情监测 def quoteStart(): global quoteSource if (quoteSource == None): quoteSource = initSource() thrdQuote = gol._Get_Value('quoteSourceThread', None) if (quoteSource != None and (thrdQuote == None or thrdQuote.threadRunning == False)): thrdQuote = Quote_Thread(quoteSource) thrdQuote.setDaemon(True) thrdQuote.start()
pTrade = myObj_Trade() return pTrade.OnCreat_TradeInfo() #当前数据进行保存 def Save_DB(self): #组装行数据 self.dtDB.dataMat = [] for x in self.indLst: trade = self._Find(x) self.dtDB.dataMat.append(trade.ToList()) #保存 self.dtDB.Save_csv(self.dir, self.usrID, True, 0, 0) #初始全局交易管理器 gol._Init() #先必须在主模块初始化(只在Main模块需要一次即可) gol._Set_Value('tradeAppetit', myObj_Trades()) #主启动程序 if __name__ == "__main__": #测试交易记录 zxcTrades = gol._Get_Value('tradeAppetit') # 添加 print(zxcTrades.Add_ForSimply("成功", "看涨 600060 目标价格 10.99元")) print(zxcTrades.Add("成功", "sh.600060", 6.6, 0, "看跌")) print(zxcTrades.Add("成功", "sh.600060", 6.6, 0, "看平")) print()
#发送消息 if(strR != ""): msg = self.msgManger.OnCreatMsg() msg["usrName"] = "@*股票风控监测群" msg["msgType"] = "TEXT" msg["usrPlat"] = "wx" msg["msg"] = strR self.msgManger.OnHandleMsg(msg, '', True) #必须check #初始全局消息管理器 from myGlobal import gol gol._Init() #先必须在主模块初始化(只在Main模块需要一次即可) gol._Set_Value('zxcDB_StockTradeRisk', myDataDB_StockTradeRisk()) #实例 股票收益库对象 gol._Get_Value('zxcDB_StockTradeRisk').Add_Fields(['用户名', '标的编号', '标的名称', '标的均价', '标的数量', "标的仓位", "手续费率", '止盈线', '动态止盈', '止盈回撤', '止盈比例', '止损线', '动态止损', '止损回撤', '止盈比例', '最高价格', '成本价格', '当前价格', '卖出均价','阶段浮盈','当前浮盈','止盈状态', '日期', '备注', '操作日志'], ['string','string','string','float','int','float','float','float','bool','float','float','float','bool','float','float','float','float','float','float','float','float','bool','datetime','string','list'], []) gol._Set_Value('zxcRisk_Control', myRisk_Control()) #实例 风险控制操作类 """ 交易策略: 1.前20/10/5日高点取最高,日内高点,回撤起始1%建议平仓 20%,回撤2%建议平仓 20%,回撤3%建议平仓 20%,回撤4%建议平仓 20%,回撤5%建议平仓 20% 2.建议需要记录,便于分阶段处理。 3.止盈规则: 达到指定涨幅时(默认6%),触发交易止盈/动态止盈。 动态止盈: 按回撤比例分阶段分步卖出,从当前最高点回撤1%时第一次触发,之后每回撤1%触发一次,连续回撤5%时全部卖出。 当涨幅回升,突破新高时,初始回撤触发状态,即从高点再次回撤1%时触发,直到卖出完毕。 突破新高规则:涨幅突破前一阶段止盈点,涨幅突破止盈涨幅线,涨幅突破10/5日高点。突破后实时比对更新新高。
return None #设置数据 qd.value = qd.lastPrice qd.quotePlat = 'JQDataAPI' qd.quoteTimeType = dataInfo['dataFrequency'] return qd return None #生成数据集对象--未完成 def newDatas(self, data, interval): return myData_Stock.Datas_Stock(data, interval) #缓存全局对象 gol._Set_Value('quoteSource_JqData', Source_JQData_Stock()) #实例 行情对象 #主启动程序 if __name__ == "__main__": # 提取标的信息 pSource = gol._Get_Value('quoteSource_JqData', None) import myListener_Printer, time pSource.addListener(myListener_Printer.Quote_Listener_Printer()) # 单独查询,不纪录 pParams = { 'dataFrequency': "1d", 'stockBars': 1, 'stockTag': "10003418.XSHG" }
if (bResult): self._Save() return bResult # 设置更新--移除多余 def _Refresh(self, pSet, usrID): #for x in pSet.settings.keys(): # if(len(pSet.settings[x].msgUsers) == 0): # pSet.settings.pop(x) #报错 pUser = self.setUsers.get(usrID, {}) #初始全局消息管理器 from myGlobal import gol gol._Init() #先必须在主模块初始化(只在Main模块需要一次即可) gol._Set_Value('setsQuote', myQuote_Sets()) #查找 def _Find(setName, setTag='', bCreatAuto=False): pSets = gol._Get_Value('setsQuote') if (pSets != None): pSet = pSets._Find(setName, setTag) if (pSet == None and bCreatAuto): pSet = myQuote_Setting(setTag, setName) return pSet return None #主启动程序 if __name__ == "__main__":
if (length_nameEN > 0): if (x.code_name_En[0:length_nameEN] == code_nameEN): #等长匹配 if (len(lstR) < nReturn): lstR.append(x) continue return lstR #设置索引 def _Index(self, pStock): self.lstStock.append(pStock) #初始全局消息管理器 from myGlobal import gol gol._Init() #先必须在主模块初始化(只在Main模块需要一次即可) gol._Set_Value('setsStock', myStocks()) #主启动程序 if __name__ == "__main__": #示例股票查询 pStocks = myStocks() print("代码查询:") for x in pStocks._Find("00002"): print(x.getIndustries()) print("名称查询:") for x in pStocks._Find("", "银行"): print(x.toJsonstr()) print("名称查询_EN:") for x in pStocks._Find("", "JS"):
# 按消息类型记录 self.funChanges[type] = fn return fn return _fun_register # 回调装饰函数,封装触发消息,并回调 def change_reply(self, type, name): # 提取消息类型对应的装饰函数 funChange = self.funChanges.get(type, None) if(funChange != None): r = funChange(name) #初始全局消息管理器 from myGlobal import gol gol._Init() #先必须在主模块初始化(只在Main模块需要一次即可) gol._Set_Value('setsSpider', mySpider_Settings()) #查找 def _Find(setName, bCreatAuto = False): pSets = gol._Get_Value('setsSpider') if(pSets != None): pSet = pSets._Find(setName) if(pSet == None and bCreatAuto): pSet = mySpider_Setting(setName, "", "", "") return pSet return None #主启动程序 if __name__ == "__main__":
#-*- coding: utf-8 -*- """ Created on 张斌 2021-01-24 12:16:00 @author: zhang bin @email: [email protected] Python的数据交换接口实现 """ import sys, os, ast, re, mySystem #引用根目录类文件夹--必须,否则非本地目录起动时无法找到自定义类 mySystem.Append_Us("", False) import myWeb, myIO from myGlobal import gol gol._Init() #先必须在主模块初始化(只在Main模块需要一次即可) gol._Set_Value("msgSet_usrMQ", False) strDir, strName = myIO.getPath_ByFile(__file__) dirBase = os.path.abspath(os.path.join(strDir, "..")) gol._Set_Setting('dirMsgsSwaps', dirBase + "/Data/Swaps") #实例 消息缓存 #初始数据教会对象 import myData_Swap pDataSwap_In = myData_Swap.myData_Swap_FileIO("msgWx", dirBase + "/Data/Swaps/SwapMsg", isSender=True, stepSwaps=1, delayedTime=0, useAck=True, nameSwap="zxcSwap_wx") pDataSwap_Out = myData_Swap.myData_Swap_FileIO(
import myWeb, myDebug, myMMap, myMQ_Rabbit, myWeixin_Cmd from myGlobal import gol #主程序启动 if __name__ == '__main__': gol._Init() #先必须在主模块初始化(只在Main模块需要一次即可) useCmdMMap = False errStr = "" try: # 创建内存映射(写) if(useCmdMMap): pMMap_Manager = myMMap.myMMap_Manager("Data/zxcMMap.dat") gol._Set_Value('manageMMap', pMMap_Manager, True) errStr = "创建内存映射失败." else: # 创建消息队列 nameMQ = 'zxcMQ_wx' pMQ_Sender = myMQ_Rabbit.myMQ_Rabbit(True) pMQ_Sender.Init_Queue(nameMQ, True) gol._Set_Value('zxcMQ_Wx_Sender', pMQ_Sender, True) errStr = "创建消息队列失败." #测试 #users = ['茶叶一主号', '老婆'] #pAPI = myWeixin_Cmd.myAPI_Weixin_Cmd() #for i in range(0, 15): # for x in users: # strMsg = "Hello " + x
'money': 0, 'avg': 0 } for x in range(0, num): if (dictValue['high'] < values['high'][x]): dictValue['high'] = values['high'][x] if (dictValue['low'] > values['low'][x]): dictValue['low'] = values['low'][x] dictValue['volume'] += values['volume'][x] dictValue['money'] += values['money'][x] dictValue['avg'] = dictValue['money'] / dictValue['volume'] return dictValue #缓存全局对象 gol._Set_Value('quoteSource_API', Source_JQData_API()) #实例 行情对象 myDebug.Debug(jqdatasdk.get_query_count()) #打印当日可请求条数 #主启动程序 if __name__ == "__main__": # 提取标的信息 pSource = gol._Get_Value('quoteSource_API', None) print(pSource.getSecurities()) print(pSource.getSecurities('index')) values = pSource.getPrice(security="600332.XSHG", frequency='1m', start_date='2020-02-05 09:00:00', end_date='2020-02-05 15:00:00') lstPrices = [] strList = ""
pMQ_Sender.Send_Msg(pMQ_Sender.nameQueue, str(msg)) myDebug.Debug(pMQ_Sender.nameQueue, msg) try: return True except: return False #主程序启动 if __name__ == '__main__': # 创建消息队列 gol._Init() #先必须在主模块初始化(只在Main模块需要一次即可) nameMQ = 'zxcMQ_wx' pMQ_Sender = myMQ_Rabbit.myMQ_Rabbit(True) pMQ_Sender.Init_Queue(nameMQ, True) gol._Set_Value('zxcMQ_Wx_Sender', pMQ_Sender, True) errStr = "创建消息队列失败." pMQ = myAPI_Weixin_Cmd_ByMQ() pMQ.get('茶叶一主号', 'text--登陆') # 创建内存映射 try: pMMap_Manager = myMMap.myMMap_Manager( "D:\myGit\zxcProj\src\Zxc.Python\zxcPy.Weixin\Data/zxcMMap.dat") ind = 0 while (True): dict0 = {'usrName': '茶叶一主号', 'msg': 'text--登陆', 'msgType': 'Text'} pMMdata = myMMap.myMMap_Data(dict0, 0) #ind = pMMap_Manager.Write(pMMdata)