Administrator
2023-10-16 c8ea1ff2ad99112d20f0cecd34508d030b3da4bb
委托优化
4个文件已修改
31 ■■■■ 已修改文件
code_attribute/gpcode_manager.py 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_api.py 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_data_update.py 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_record_manager.py 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
code_attribute/gpcode_manager.py
@@ -590,6 +590,8 @@
def get_limit_up_price_cache(code):
    if code in __limit_up_price_dict:
        return __limit_up_price_dict[code]
    return None
trade/huaxin/huaxin_trade_api.py
@@ -15,7 +15,7 @@
from log_module import async_log_util
from log_module.log import hx_logger_trade_debug, hx_logger_trade_loop, hx_logger_trade_callback, logger_trade, \
    logger_system
from trade.huaxin import huaxin_trade_data_update
from trade.huaxin import huaxin_trade_data_update, huaxin_trade_record_manager
from trade.huaxin.huaxin_trade_record_manager import TradeOrderIdManager
from trade.huaxin.huaxin_trade_order_processor import CancelOrderManager, HuaxinOrderEntity, TradeResultProcessor
from utils import socket_util, huaxin_util, tool
@@ -84,6 +84,10 @@
                                                          is_shadow_order=is_shadow_order)
                                TradeResultProcessor.process_order(order)
                                try:
                                    huaxin_trade_record_manager.DelegateRecordManager.add_one(data)
                                except:
                                    pass
                                if not is_shadow_order:
                                    # 订单相关回调
                                    # 重新请求委托列表与资金
trade/huaxin/huaxin_trade_data_update.py
@@ -58,12 +58,15 @@
                                    if limit_up_price and volume == huaxin_client_constant.SHADOW_ORDER_VOLUME and abs(
                                            float(limitPrice) - float(limit_up_price)) < 0.01:
                                        is_shadow_order = True
                                    if is_shadow_order:
                                        continue
                                    order = HuaxinOrderEntity(code, orderStatus, orderRef, accountID, orderSysID,
                                                              insertTime=insertTime, acceptTime=acceptTime,
                                                              insertDate=insertDate, direction=direction,
                                                              is_shadow_order=is_shadow_order)
                                    TradeResultProcessor.process_order(order)
                                    if not is_shadow_order and huaxin_util.is_can_cancel(orderStatus):
                                    if huaxin_util.is_can_cancel(orderStatus):
                                        codes.append(code)
                                if codes:
                                    try:
trade/huaxin/huaxin_trade_record_manager.py
@@ -14,21 +14,28 @@
# 委托列表
class DelegateRecordManager:
    mysqldb = mysql_data.Mysqldb()
    @classmethod
    def add(cls, datas):
        mysqldb = mysql_data.Mysqldb()
        try:
            if datas:
                for d in datas:
                    cls.add_one(d)
        finally:
            pass
    @classmethod
    def add_one(cls, d):
                    # 查询是否有数据
                    _id = f"{d['insertDate']}-{d['orderLocalID']}"
                    result = mysqldb.select_one(
        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'])
                        mysqldb.execute(
            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"],
@@ -63,10 +70,8 @@
                                    where_list.append(f"{k}='{updateDict[k]}'")
                                else:
                                    where_list.append(f"{k}={updateDict[k]}")
                            mysqldb.execute(
                cls.mysqldb.execute(
                                f"update hx_trade_delegate_record set {','.join(where_list)} where id='{result[0]}'")
        finally:
            pass
    @classmethod
    def list_by_day(cls, day, min_update_time, orderStatus=[]):
@@ -395,4 +400,3 @@
    results, update_time = DelegateRecordManager.list_by_day(
        tool.get_now_date_str("%Y%m%d"), update_time)
    print(results)