| | |
| | | |
| | | # 委托列表 |
| | | class DelegateRecordManager: |
| | | mysqldb = mysql_data.Mysqldb() |
| | | |
| | | @classmethod |
| | | def add(cls, datas): |
| | | mysqldb = mysql_data.Mysqldb() |
| | | try: |
| | | if datas: |
| | | for d in datas: |
| | | # 查询是否有数据 |
| | | _id = f"{d['insertDate']}-{d['orderLocalID']}" |
| | | result = mysqldb.select_one( |
| | | f"select * from hx_trade_delegate_record where id='{_id}'") |
| | | if not result: |
| | | # 新增数据 |
| | | nameDict = HistoryKDatasUtils.get_gp_codes_names([d['securityID']]) |
| | | name = nameDict.get(d['securityID']) |
| | | mysqldb.execute( |
| | | "insert into hx_trade_delegate_record values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')" % ( |
| | | _id, d["orderLocalID"], d["securityID"], name, d["direction"], |
| | | d["orderSysID"], d["insertTime"], d["insertDate"], d["acceptTime"], d["cancelTime"], |
| | | d["limitPrice"], d["turnover"], d["volume"], d["volumeTraded"], d["orderStatus"], |
| | | d["orderSubmitStatus"], d["statusMsg"], tool.get_now_datetime_str(), |
| | | tool.get_now_datetime_str(), d["accountID"])) |
| | | else: |
| | | # 修改数据 |
| | | updateDict = {} |
| | | if result[5] != d['orderSysID']: |
| | | updateDict['orderSysID'] = d['orderSysID'] |
| | | if result[8] != d['acceptTime']: |
| | | updateDict['acceptTime'] = d['acceptTime'] |
| | | if result[9] != d['cancelTime']: |
| | | updateDict['cancelTime'] = d['cancelTime'] |
| | | if result[11] != str(d['turnover']): |
| | | updateDict['turnover'] = d['turnover'] |
| | | if result[13] != d['volumeTraded']: |
| | | updateDict['volumeTraded'] = d['volumeTraded'] |
| | | if result[14] != int(d['orderStatus']): |
| | | updateDict['orderStatus'] = d['orderStatus'] |
| | | if result[15] != int(d['orderSubmitStatus']): |
| | | updateDict['orderSubmitStatus'] = d['orderSubmitStatus'] |
| | | if result[16] != d['statusMsg']: |
| | | updateDict['statusMsg'] = d['statusMsg'] |
| | | if updateDict: |
| | | # 有更新数据 |
| | | updateDict['updateTime'] = tool.get_now_datetime_str() |
| | | where_list = [] |
| | | for k in updateDict: |
| | | if type(updateDict[k]) == str: |
| | | where_list.append(f"{k}='{updateDict[k]}'") |
| | | else: |
| | | where_list.append(f"{k}={updateDict[k]}") |
| | | mysqldb.execute( |
| | | f"update hx_trade_delegate_record set {','.join(where_list)} where id='{result[0]}'") |
| | | cls.add_one(d) |
| | | finally: |
| | | pass |
| | | |
| | | @classmethod |
| | | def add_one(cls, d): |
| | | # 查询是否有数据 |
| | | _id = f"{d['insertDate']}-{d['orderLocalID']}" |
| | | result = cls.mysqldb.select_one( |
| | | f"select * from hx_trade_delegate_record where id='{_id}'") |
| | | if not result: |
| | | # 新增数据 |
| | | nameDict = HistoryKDatasUtils.get_gp_codes_names([d['securityID']]) |
| | | name = nameDict.get(d['securityID']) |
| | | cls.mysqldb.execute( |
| | | "insert into hx_trade_delegate_record values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')" % ( |
| | | _id, d["orderLocalID"], d["securityID"], name, d["direction"], |
| | | d["orderSysID"], d["insertTime"], d["insertDate"], d["acceptTime"], d["cancelTime"], |
| | | d["limitPrice"], d["turnover"], d["volume"], d["volumeTraded"], d["orderStatus"], |
| | | d["orderSubmitStatus"], d["statusMsg"], tool.get_now_datetime_str(), |
| | | tool.get_now_datetime_str(), d["accountID"])) |
| | | else: |
| | | # 修改数据 |
| | | updateDict = {} |
| | | if result[5] != d['orderSysID']: |
| | | updateDict['orderSysID'] = d['orderSysID'] |
| | | if result[8] != d['acceptTime']: |
| | | updateDict['acceptTime'] = d['acceptTime'] |
| | | if result[9] != d['cancelTime']: |
| | | updateDict['cancelTime'] = d['cancelTime'] |
| | | if result[11] != str(d['turnover']): |
| | | updateDict['turnover'] = d['turnover'] |
| | | if result[13] != d['volumeTraded']: |
| | | updateDict['volumeTraded'] = d['volumeTraded'] |
| | | if result[14] != int(d['orderStatus']): |
| | | updateDict['orderStatus'] = d['orderStatus'] |
| | | if result[15] != int(d['orderSubmitStatus']): |
| | | updateDict['orderSubmitStatus'] = d['orderSubmitStatus'] |
| | | if result[16] != d['statusMsg']: |
| | | updateDict['statusMsg'] = d['statusMsg'] |
| | | if updateDict: |
| | | # 有更新数据 |
| | | updateDict['updateTime'] = tool.get_now_datetime_str() |
| | | where_list = [] |
| | | for k in updateDict: |
| | | if type(updateDict[k]) == str: |
| | | where_list.append(f"{k}='{updateDict[k]}'") |
| | | else: |
| | | where_list.append(f"{k}={updateDict[k]}") |
| | | cls.mysqldb.execute( |
| | | f"update hx_trade_delegate_record set {','.join(where_list)} where id='{result[0]}'") |
| | | |
| | | @classmethod |
| | | def list_by_day(cls, day, min_update_time, orderStatus=[]): |
| | |
| | | results, update_time = DelegateRecordManager.list_by_day( |
| | | tool.get_now_date_str("%Y%m%d"), update_time) |
| | | print(results) |
| | | |