l2/l2_data_manager_new.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/l2_trade_test.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
third_data/code_plate_key_manager.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
third_data/kpl_api.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
trade/huaxin/huaxin_trade_server.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
l2/l2_data_manager_new.py
@@ -633,6 +633,11 @@ try: jx_blocks, jx_blocks_by = KPLCodeJXBlockManager().get_jx_blocks_cache( code), KPLCodeJXBlockManager().get_jx_blocks_cache(code, by=True) if jx_blocks: jx_blocks = jx_blocks[0] if jx_blocks_by: jx_blocks_by = jx_blocks_by[0] info = cls.__trade_log_placr_order_info_dict[code] info.mode = order_begin_pos.mode info.set_buy_index(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) @@ -935,7 +940,7 @@ # 获取当前票的涨停原因 if code in LimitUpCodesPlateKeyManager.today_total_limit_up_reason_dict: limit_up_reason = kpl_data_manager.KPLLimitUpDataRecordManager.get_current_block(code) if limit_up_reason not in constant.KPL_INVALID_BLOCKS: if limit_up_reason and limit_up_reason not in constant.KPL_INVALID_BLOCKS: # 判断是否是独苗 codes = kpl_data_manager.KPLLimitUpDataRecordManager.get_current_codes_by_block(limit_up_reason) if codes: @@ -1009,7 +1014,7 @@ return False, True, "尚未获取到板块信息" if can_buy_result[1]: if cls.volume_rate_info[code][0] < 0.6: if code in cls.volume_rate_info and cls.volume_rate_info[code][0] < 0.6: return False, True, f"独苗:量比({cls.volume_rate_info[code][0]})未达到60%" # 获取K线形态,判断是否近2天是否为10天内最大量 test/l2_trade_test.py
@@ -216,8 +216,8 @@ # @unittest.skip("跳过此单元测试") def test_block(self): code = "000903" KPLCodeJXBlockManager().load_jx_blocks(code, 2.9, 2.9) code = "002962" KPLCodeJXBlockManager().load_jx_blocks(code, 14.99, 14.99) block_info.init_code(code) kpl_data_manager.KPLLimitUpDataRecordManager.load_total_datas() yesterday_codes = kpl_data_manager.get_yesterday_limit_up_codes() third_data/code_plate_key_manager.py
@@ -3,7 +3,9 @@ """ # 涨停代码关键词板块管理 import copy import json import time import constant from db.redis_manager_delegate import RedisUtils @@ -35,19 +37,28 @@ def __get_redis(self): return self.__redisManager.getRedis() def save_jx_blocks(self, code, blocks, by=False): if blocks is None: def save_jx_blocks(self, code, blocks: list, by=False): if not blocks: return final_blocks = copy.deepcopy(blocks) if len(blocks) > 2: blocks = blocks[:2] final_blocks.clear() # 根据涨幅排序 blocks.sort(key=lambda x: x[2]) blocks.reverse() for b in blocks: if b[2] > 0 and b[1] not in constant.KPL_INVALID_BLOCKS: final_blocks.append(b) if len(final_blocks) < 2: final_blocks = blocks # 保存前2条数据 if by: RedisUtils.setex_async(self.__db, f"kpl_jx_blocks_by-{code}", tool.get_expire(), json.dumps(blocks)) self.__code_by_blocks[code] = blocks RedisUtils.setex_async(self.__db, f"kpl_jx_blocks_by-{code}", tool.get_expire(), json.dumps(final_blocks)) self.__code_by_blocks[code] = (final_blocks, time.time()) else: RedisUtils.setex_async(self.__db, f"kpl_jx_blocks-{code}", tool.get_expire(), json.dumps(blocks)) self.__code_blocks[code] = blocks RedisUtils.setex_async(self.__db, f"kpl_jx_blocks-{code}", tool.get_expire(), json.dumps(final_blocks)) self.__code_blocks[code] = (final_blocks, time.time()) # 获取精选板块 def get_jx_blocks(self, code, by=False): @@ -86,10 +97,29 @@ # 如果涨幅大于7%就读取板块 price_rate = (buy_1_price - pre_close_price) / pre_close_price if price_rate > 0.07: if not self.get_jx_blocks_cache(code): jx_blocks_info = self.get_jx_blocks_cache(code) if not jx_blocks_info: blocks = kpl_api.getCodeJingXuanBlocks(code) self.save_jx_blocks(code, blocks) async_log_util.info(logger_kpl_block_can_buy, f"{code}:获取到精选板块-{blocks}") else: # 还没涨停的需要更新精选板块 更新精选板块 if abs(float(buy_1_price) - float(limit_up_price)) >= 0.001: # 非涨停状态 UPDATE_TIME_SPACE = 5 * 60 time_diff = tool.trade_time_sub(tool.get_now_time_str(), "09:30:00") if time_diff < 0: UPDATE_TIME_SPACE = 60 * 60 else: UPDATE_TIME_SPACE = int(time_diff / 30) + 60 if UPDATE_TIME_SPACE > 5 * 60: UPDATE_TIME_SPACE = 5 * 60 if time.time() - jx_blocks_info[1] > UPDATE_TIME_SPACE: # 距离上次更新时间过去了5分钟 blocks = kpl_api.getCodeJingXuanBlocks(code) self.save_jx_blocks(code, blocks) elif price_rate > 0.03: # 添加备用板块 if not self.get_jx_blocks_cache(code, by=True): @@ -410,11 +440,11 @@ k3 = {industry} k4 = set() jingxuan_blocks = self.__KPLCodeJXBlockManager.get_jx_blocks_cache(code) if not jingxuan_blocks: jingxuan_blocks = self.__KPLCodeJXBlockManager.get_jx_blocks_cache(code, by=True) if jingxuan_blocks: jingxuan_blocks = jingxuan_blocks[:2] jingxuan_block_info = self.__KPLCodeJXBlockManager.get_jx_blocks_cache(code) if not jingxuan_block_info: jingxuan_block_info = self.__KPLCodeJXBlockManager.get_jx_blocks_cache(code, by=True) if jingxuan_block_info: jingxuan_blocks = jingxuan_block_info[0] k4 |= set([x[1] for x in jingxuan_blocks]) for k in [k1, k11, k2, k3, k4]: keys |= k third_data/kpl_api.py
@@ -3,6 +3,7 @@ import requests import constant from utils import middle_api_protocol # 竞价 @@ -135,6 +136,13 @@ if __name__ == "__main__": limit_up_infos = getLimitUpInfo() limit_up_infos = json.loads(limit_up_infos) print(limit_up_infos) blocks = getCodeJingXuanBlocks("002362") if len(blocks) > 2: # 根据涨幅排序 blocks.sort(key=lambda x: x[2]) blocks.reverse() datas = [] for b in blocks: if b[2] > 0 and b[1] not in constant.KPL_INVALID_BLOCKS: datas.append(b) print(datas) trade/huaxin/huaxin_trade_server.py
@@ -571,6 +571,7 @@ async_log_util.info(logger_trade, f"API卖: 单价-{price}") result = huaxin_trade_api.order(direction, code, volume, price, sinfo=sinfo, blocking=True, request_id=request_id) logger_debug.info(f"卖接口返回数据:{result}") order_ref = result.get("order_ref") # 如果是在正常交易时间提交的2s之内还未成交的需要撤单 if int("092958") <= int(tool.get_now_time_str().replace(":", "")) <= int("150000"):