Administrator
2024-09-04 cd5863943c5c207601df5c91ec1159c41fb044fb
小群撤参数修改
4个文件已修改
137 ■■■■■ 已修改文件
huaxin_client/l1_api_client.py 105 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
servers/data_server.py 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/buy_strategy_util.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/data_export_util.py 27 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/l1_api_client.py
@@ -3,7 +3,7 @@
import time
import qcvalueaddproapi
import sys
from utils import tool
global g_userid, g_passwd, g_address, g_port, g_seqnum
g_seqnum = 100000
@@ -29,10 +29,15 @@
    def queryTradeCalendar(self):
        try:
            queryField = qcvalueaddproapi.CQCVDReqQryShareCalendarField()
            queryField.BegDate = "20240701"
            queryField.EndDate = "20240801"
            queryField.PageCount = 100
            # queryField.BegDate = "20240704"
            queryField.EndDate = "20240904"
            queryField.PageCount = 10
            queryField.PageLocate = 1
            if queryField.BegDate:
                queryField.OrderType = qcvalueaddproapi.QCVD_ORDST_ASC
            if queryField.EndDate:
                queryField.OrderType = qcvalueaddproapi.QCVD_ORDST_DESC
            request_id = self.__create_request_id()
            results = self.m_api.ReqReqQryShareCalendar(queryField, request_id)
            for i in range(0, 1000):
@@ -40,6 +45,57 @@
                    return self.__result_cache
                time.sleep(0.002)
            print("ReqReqQryShareCalendar:", results)
        except Exception as e:
            logging.exception(e)
    def queryBars(self, code, begin_date, end_date):
        try:
            queryField = qcvalueaddproapi.CQCVDReqQryStockDayQuotationField()
            queryField.BegDate = begin_date.replace("-", "")
            queryField.EndDate = end_date.replace("-", "")
            if tool.is_sh_code(code):
                queryField.ExchangeID = qcvalueaddproapi.QCVD_EXD_SSE
            else:
                queryField.ExchangeID = qcvalueaddproapi.QCVD_EXD_SZSE
            queryField.SecurityID = code
            # queryField.PageCount = 10
            queryField.PageLocate = 1
            queryField.OrderType = qcvalueaddproapi.QCVD_ORDST_DESC
            request_id = self.__create_request_id()
            results = self.m_api.ReqReqQryStockDayQuotation(queryField, request_id)
            for i in range(0, 1000):
                if request_id in self.__result_cache:
                    results = self.__result_cache[request_id]
                    # 最新的复权因子
                    start_adjust_factor = None
                    for i in range(0, len(results)):
                        d = results[i]
                        if not start_adjust_factor:
                            start_adjust_factor = d["AdjustFactor"]
                        # 复权价格
                        if start_adjust_factor != d["AdjustFactor"]:
                            # 开始复权
                            d["PreClosePrice"] = round(d["AdjustFactor"] * d["PreClosePrice"] / start_adjust_factor, 4)
                            d["OpenPrice"] = round(d["AdjustFactor"] * d["OpenPrice"] / start_adjust_factor, 4)
                            d["HighPrice"] = round(d["AdjustFactor"] * d["HighPrice"] / start_adjust_factor, 4)
                            d["LowPrice"] = round(d["AdjustFactor"] * d["LowPrice"] / start_adjust_factor, 4)
                            d["ClosePrice"] = round(d["AdjustFactor"] * d["ClosePrice"] / start_adjust_factor, 4)
                    fresults = []
                    for r in results:
                        fresults.append({"sec_id": r["SecurityID"],
                                         "open": r["TradingDay"],
                                         "high": r["HighPrice"],
                                         "low": r["LowPrice"],
                                         "close": r["ClosePrice"],
                                         "volume": r["Volume"],
                                         "pre_close": r["PreClosePrice"],
                                         "bob": f"{r['TradingDay'][:4]}-{r['TradingDay'][4:6]}-{r['TradingDay'][6:]} 00:00:00",
                                         "amount": r["Turnover"]
                                         })
                    return fresults
                time.sleep(0.002)
            print("ReqReqQryStockDayQuotation:", results)
        except Exception as e:
            logging.exception(e)
@@ -66,7 +122,8 @@
        if (pRspInfo.ErrorID == 0):
            # 登录成功后直接查询
            # self.ReqInquiryHistoryDelivery()
            threading.Thread(target=lambda : print("交易日历:", self.queryTradeCalendar())).start()
            # threading.Thread(target=lambda : print("交易日历:", self.queryTradeCalendar())).start()
            threading.Thread(target=lambda: print("日K:", self.queryBars())).start()
    def ReqQryGGTEODPrices(self):
        QryField = qcvalueaddproapi.CQCVDQryGGTEODPricesField()
@@ -77,6 +134,15 @@
        self.m_api.ReqQryInvestor(QryField, new_seqnum())
    def OnRspInquiryShareCalendar(self, pShareCalendar, pRspInfo, nRequestID, bIsPageLast, bIsTotalLast):
        """
        交易日历响应
        @param pShareCalendar:
        @param pRspInfo:
        @param nRequestID:
        @param bIsPageLast:
        @param bIsTotalLast:
        @return:
        """
        if nRequestID not in self.__temp_cache:
            self.__temp_cache[nRequestID] = []
@@ -87,6 +153,35 @@
            self.__temp_cache.pop(nRequestID)
            print("OnRspInquiryShareCalendar:", self.__result_cache[nRequestID])
    def OnRspInquiryStockDayQuotation(self, pStockDayQuotation, pRspInfo, nRequestID, bIsPageLast, bIsTotalLast):
        """
       日K响应
       @param pStockDayQuotation:
       @param pRspInfo:
       @param nRequestID:
       @param bIsPageLast:
       @param bIsTotalLast:
       @return:
       """
        if nRequestID not in self.__temp_cache:
            self.__temp_cache[nRequestID] = []
        print("是否本页查询完毕:", bIsPageLast)
        if not bIsPageLast:
            self.__temp_cache[nRequestID].append({
                "SecurityID": pStockDayQuotation.SecurityID, "TradingDay": pStockDayQuotation.TradingDay,
                "AdjustFactor": pStockDayQuotation.AdjustFactor, "PreClosePrice": pStockDayQuotation.PreClosePrice,
                "OpenPrice": pStockDayQuotation.OpenPrice, "HighPrice": pStockDayQuotation.HighPrice,
                "LowPrice": pStockDayQuotation.LowPrice,
                "ClosePrice": pStockDayQuotation.ClosePrice, "Volume": int(pStockDayQuotation.Volume * 100),
                "Turnover": int(pStockDayQuotation.Turnover * 1000)
            })
        else:
            self.__result_cache[nRequestID] = self.__temp_cache[nRequestID]
            self.__temp_cache.pop(nRequestID)
            print("OnRspInquiryStockDayQuotation:", len(self.__result_cache[nRequestID]))
def main():
    # if (len(sys.argv)< 5):
servers/data_server.py
@@ -361,6 +361,7 @@
                code = ps_dict['code']
                date = ps_dict.get('date')
                time_str = ps_dict.get('time')
                end_index = ps_dict.get('end_index')
                total_datas = l2_data_util.local_today_datas.get(code)
                if not total_datas:
                    total_datas = []
@@ -368,7 +369,7 @@
                    total_datas = None
                else:
                    date = tool.get_now_date_str()
                delegate_datas = data_export_util.get_l2_datas(code, total_datas, date=date)
                delegate_datas = data_export_util.get_l2_datas(code, total_datas, date=date, end_index=end_index)
                transaction_datas = data_export_util.get_l2_transaction_datas(code, date=date)
                code_name = gpcode_manager.get_code_name(code)
                response_data = json.dumps({"code": 0, "data": {"code": code, "code_name": code_name,
utils/buy_strategy_util.py
@@ -45,7 +45,7 @@
                        break
            continue
        # 与当前时间相差3s的结束
        if tool.trade_time_sub_with_ms(end_time_with_ms, l2_data_util.L2DataUtil.get_time_with_ms(val)) > 6000:
        if tool.trade_time_sub_with_ms(end_time_with_ms, l2_data_util.L2DataUtil.get_time_with_ms(val)) > 10000:
            break
        cancel_count += 1
utils/data_export_util.py
@@ -1,6 +1,7 @@
"""
数据导出工具
"""
import copy
import json
import logging
import os
@@ -13,7 +14,7 @@
import l2.l2_data_util
from l2.huaxin import l2_huaxin_util
from log_module import log, log_export
from l2 import l2_data_source_util
from l2 import l2_data_source_util, l2_data_util
from log_module.log import logger_debug
from trade import deal_big_money_manager
from utils import tool
@@ -29,7 +30,7 @@
# 获取L2的数据
def get_l2_datas(code, today_datas=None, date=None, max_time=None):
def get_l2_datas(code, today_datas=None, date=None, end_index=None):
    __start_time = time.time()
    if date is None:
        date = tool.get_now_date_str()
@@ -66,6 +67,14 @@
    active_sell_set = active_sell_map.get(code)
    if not active_sell_set:
        active_sell_set = set()
    # 如果有截至位置
    if end_index:
        datas = copy.deepcopy(datas)
        for i in range(len(datas)):
            if datas[i]["index"] == end_index:
                datas = datas[:i]
                break
    fdatas = export_l2_data(code, datas, process_indexs, trade_indexs, real_position_indexes, deal_list_dict, sell_nos,
                            active_sell_set, cancel_reasons)
    return fdatas
@@ -93,6 +102,11 @@
            if trade_indexs[i][1] == index:
                return trade_indexs[i]
        return None
    # 最新的一条数据
    latest_data = datas[-1]
    latest_time_str_with_ms = l2.l2_data_util.L2DataUtil.get_time_with_ms(latest_data["val"])
    # 数据预处理
    num_operate_map = {}
@@ -200,7 +214,8 @@
        if int(data["val"]["operateType"]) == 0:
            cancel_data = l2.l2_data_util.local_today_canceled_buyno_map.get(code).get(str(data["val"]["orderNo"]))
            # 买
            if cancel_data:
            if cancel_data and latest_data["index"] >= cancel_data["index"]:
                # 如果撤单索引不能比最近数据索引还大
                try:
                    left_num = data["val"]["num"] - cancel_data["val"]["num"]
                    if left_num > 0:
@@ -213,8 +228,10 @@
            else:
                deal_info = deal_list_dict.get(str(data["val"].get("orderNo")))
                if deal_info and len(deal_info) >= 5:
                    cancel_info = l2_huaxin_util.convert_time(deal_info[4],
                                                              with_ms=True)
                    # 成交时间不能比当前索引时间大
                    if tool.trade_time_sub_with_ms(cancel_info , latest_time_str_with_ms) <= 0:
                        cancel_info = l2_huaxin_util.convert_time(deal_info[4],
                                                                  with_ms=True)
        format_data.append(cancel_info)
        cancel_order_info = None
        if trade_info: