| | |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | |
| | | |
| | | def OnRspSubMarketData(self, pSpecificSecurity, pRspInfo, nRequestID, bIsLast): |
| | | if pRspInfo["ErrorID"] == 0: |
| | | self.subscripted_market_codes.add(pSpecificSecurity['SecurityID']) |
| | |
| | | (pTick['SecurityID'], pTick['Price'], pTick['TickTime'])) |
| | | except Exception as e: |
| | | logger_local_huaxin_l2_error.exception(e) |
| | | |
| | | |
| | | |
| | | def OnRtnMarketData(self, pDepthMarketData, FirstLevelBuyNum, FirstLevelBuyOrderVolumes, FirstLevelSellNum, |
| | | FirstLevelSellOrderVolumes): |
| | |
| | | filter=lambda record: record["extra"].get("name") == "kpl_open_limit_up", |
| | | rotation="00:00", compression="zip", enqueue=True) |
| | | |
| | | logger.add(self.get_path("kpl", "kpl_blocks"), |
| | | filter=lambda record: record["extra"].get("name") == "kpl_blocks", |
| | | rotation="00:00", compression="zip", enqueue=True) |
| | | |
| | | # 看盘日志 |
| | | logger.add(self.get_path("kp", "kp_msg"), |
| | | filter=lambda record: record["extra"].get("name") == "kp_msg", |
| | |
| | | |
| | | logger_kpl_open_limit_up = __mylogger.get_logger("kpl_open_limit_up") |
| | | |
| | | logger_kpl_blocks = __mylogger.get_logger("kpl_blocks") |
| | | |
| | | |
| | | logger_kp_msg = __mylogger.get_logger("kp_msg") |
| | | |
| | | logger_redis_debug = __mylogger.get_logger("redis_debug") |
| | |
| | | return fdatas |
| | | |
| | | |
| | | def load_kpl_blocks(date=tool.get_now_date_str()): |
| | | fdatas = {} |
| | | path = f"{constant.LOG_DIR}/gp/kpl/kpl_blocks.{date}.log" |
| | | with open(path, 'r', encoding='utf-8') as file: |
| | | lines = file.readlines() |
| | | for line in lines: |
| | | content = line[line.find(']') + 1:] |
| | | ds = content.split("#") |
| | | code = ds[0].strip() |
| | | data_str = ds[1].strip() |
| | | blocks = eval(data_str) |
| | | fdatas[code] = blocks |
| | | return fdatas |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | fdatas = load_big_buy_order() |
| | | print(fdatas) |
| | |
| | | # print("下单:", huaxin_trade_api.order(1, "127075", 10, 140.5, blocking=True)) |
| | | |
| | | |
| | | def __get_buy_money(): |
| | | time_str = tool.get_now_time_str().replace(":","") |
| | | if int(time_str) < int("103000"): |
| | | return 40000 |
| | | elif int(time_str) < int("113000"): |
| | | return 30000 |
| | | elif int(time_str) < int("140000"): |
| | | return 20000 |
| | | else: |
| | | return 10000 |
| | | |
| | | |
| | | def read_l2_results(trade_call_back_queue): |
| | | while True: |
| | | try: |
| | |
| | | market_info = code_market_manager.get_market_info(cb_code) |
| | | limit_up_price = target_codes_manager.get_limit_up_price(cb_code) |
| | | if market_info: |
| | | volume = int(20000 / float(limit_up_price)) |
| | | volume = int(__get_buy_money()/ float(limit_up_price)) |
| | | volume = (volume // 10) * 10 |
| | | buy_price = round(min(float(market_info.price * 1.02), float(limit_up_price)), 3) |
| | | async_log_util.info(logger_trade, f"准备下单:{cb_code}-{buy_price}") |
New file |
| | |
| | | from third_data.code_block_manager import CodeKPLBlockManager |
| | | |
| | | if __name__ == "__main__": |
| | | CodeKPLBlockManager().request_block(["300696"]) |
| | | |
| | | pass |
New file |
| | |
| | | """ |
| | | 代码板块管理 |
| | | """ |
| | | from code_attribute.history_k_data_util import JueJinApi |
| | | from log_module import log_export, async_log_util |
| | | from log_module.log import printlog, logger_kpl_blocks |
| | | from third_data import kpl_api, kpl_util |
| | | from utils import tool, constant |
| | | |
| | | |
| | | class CodeKPLBlockManager: |
| | | __instance = None |
| | | # 代码板块管理 |
| | | __code_block_cache_dict = {} |
| | | # 上一个交易日的板块 |
| | | __code_before_block_cache_dict = {} |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | | if not cls.__instance: |
| | | cls.__instance = super(CodeKPLBlockManager, cls).__new__(cls, *args, **kwargs) |
| | | cls.__load_datas() |
| | | return cls.__instance |
| | | |
| | | @classmethod |
| | | def __load_datas(cls): |
| | | # 加载今日和上个交易日的数据 |
| | | today = tool.get_now_date_str() |
| | | last_day = JueJinApi().get_previous_trading_date(today) |
| | | printlog("获取上个交易日", last_day) |
| | | block_dict = log_export.load_kpl_blocks(today) |
| | | for code in block_dict: |
| | | cls.__code_block_cache_dict[code] = block_dict[code] |
| | | |
| | | block_dict = log_export.load_kpl_blocks(last_day) |
| | | for code in block_dict: |
| | | cls.__code_before_block_cache_dict[code] = block_dict[code] |
| | | |
| | | def get_blocks(self, code): |
| | | """ |
| | | 获取代码的板块,优先今日获取到的板块 |
| | | :param code: |
| | | :return: |
| | | """ |
| | | blocks = self.__code_block_cache_dict.get(code) |
| | | if blocks: |
| | | return blocks |
| | | blocks = self.__code_before_block_cache_dict.get(code) |
| | | return blocks |
| | | |
| | | def get_codes_count_info(self): |
| | | """ |
| | | 获取代码数量信息 |
| | | :return:(当日板块的代码数量,上个交易日的代码数量) |
| | | """ |
| | | return len(self.__code_block_cache_dict), len(self.__code_before_block_cache_dict) |
| | | |
| | | def __request_block(self, code, force=False): |
| | | if code in self.__code_block_cache_dict and not force: |
| | | return |
| | | blocks = kpl_api.getCodeBlocks(code) |
| | | fblocks = set() |
| | | if blocks: |
| | | for b in blocks: |
| | | if b not in constant.KPL_INVALID_BLOCKS: |
| | | fblocks.add(kpl_util.filter_block(b)) |
| | | self.__code_block_cache_dict[code] = fblocks |
| | | async_log_util.info(logger_kpl_blocks, f"{code}#{fblocks}") |
| | | |
| | | def request_block(self, codes, force=False): |
| | | """ |
| | | 请求板块 |
| | | :param codes: 代码集合 |
| | | :param force: 是否强制求情 |
| | | :return: |
| | | """ |
| | | if type(codes) == str: |
| | | self.__request_block(codes, force) |
| | | else: |
| | | for code in codes: |
| | | self.__request_block(code, force) |
| | |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | print(getZYLTAmount("300198")) |
| | | print(getCodeBlocks("300198")) |
| | |
| | | |
| | | @classmethod |
| | | def get_current_codes_by_block(cls, block): |
| | | return cls.__current_reason_codes_dict.get(block) |
| | | try: |
| | | return cls.__current_reason_codes_dict.get(block) |
| | | except Exception as e: |
| | | logger_debug.info(f"{cls.__current_reason_codes_dict}") |
| | | return set() |
| | | |
| | | @classmethod |
| | | def get_current_reason_codes_dict(cls): |
| | |
| | | """ |
| | | import decimal |
| | | |
| | | from third_data.kpl_data_manager import KPLLimitUpDataRecordManager |
| | | from trade.l2_transaction_data_manager import HuaXinBuyOrderManager |
| | | from utils import tool |
| | | |
| | |
| | | finally: |
| | | self.__latest_trade_price_dict[code] = info["TradePrice"] |
| | | return False |
| | | |
| | | def process(self, underlying_code, underlying_transaction_info, underlying_market_info, cb_code, cb_market_info): |
| | | """ |
| | | 处理数据 |
| | | :param underlying_code: 正股代码 |
| | | :param underlying_transaction_info:正股成交信息 |
| | | :param underlying_market_info: 正股行情 |
| | | :param cb_code: 可转债代码 |
| | | :param cb_market_info: 可转债行情 |
| | | :return: 是否可以买, 买入信息 |
| | | """ |
| | | pass |
| | | # 是否开1 |
| | | limit_up_datas = KPLLimitUpDataRecordManager.latest_origin_datas |
| | | for item in limit_up_datas: |
| | | pass |
| | | |
| | | |
| | | |
| | | |
| | | |