| | |
| | | __big_num_deal_rate_dict = {} |
| | | __MustBuyCodesManager = gpcode_manager.MustBuyCodesManager() |
| | | |
| | | # 获取撤单比例 |
| | | # 获取撤单比例,返回(撤单比例,是否必买) |
| | | @classmethod |
| | | def get_cancel_rate(cls, code, is_up=False): |
| | | try: |
| | | must_buy_cancel_rate = cls.__MustBuyCodesManager.get_cancel_rate_cache(code) |
| | | if must_buy_cancel_rate is not None: |
| | | return must_buy_cancel_rate |
| | | return must_buy_cancel_rate, True |
| | | except Exception as e: |
| | | async_log_util.error(logger_l2_l_cancel, str(e)) |
| | | |
| | |
| | | base_rate += deal_rate |
| | | except Exception as e: |
| | | l2_log.l_cancel_debug(code, f"计算撤单比例出错:{e}") |
| | | return round(base_rate, 2) |
| | | return round(base_rate, 2), False |
| | | |
| | | # 设置板块涨停数量(除开自己) |
| | | @classmethod |
| | |
| | | # return True, total_data[-1] |
| | | |
| | | rate = round(canceled_num / total_num, 3) |
| | | thresh_hold_rate = LCancelRateManager.get_cancel_rate(code) |
| | | thresh_hold_rate, must_buy = LCancelRateManager.get_cancel_rate(code) |
| | | # 除开最大单的影响权重 |
| | | temp_thresh_hold_rate = round((total_num - max_num)*0.9/total_num, 2) |
| | | thresh_hold_rate = min(thresh_hold_rate, temp_thresh_hold_rate) |
| | | if not must_buy: |
| | | temp_thresh_hold_rate = round((total_num - max_num) * 0.9 / total_num, 2) |
| | | thresh_hold_rate = min(thresh_hold_rate, temp_thresh_hold_rate) |
| | | l2_log.l_cancel_debug(code, f"计算范围:{start_index}-{end_index},已撤单比例:{rate}/{thresh_hold_rate}") |
| | | if rate >= thresh_hold_rate: |
| | | canceled_indexes.sort() |
| | |
| | | else: |
| | | canceled_count_weight += WATCH_INDEX_WEIGHTS[-1] |
| | | rate = round(canceled_count_weight / total_count_weight, 3) |
| | | thresh_cancel_rate = LCancelRateManager.get_cancel_rate(code, is_up=True) |
| | | thresh_cancel_rate, must_buy = LCancelRateManager.get_cancel_rate(code, is_up=True) |
| | | l2_log.l_cancel_debug(code, f"计算范围:{start_index}-{end_index},成交位临近已撤单比例:{rate}/{thresh_cancel_rate}") |
| | | if rate >= thresh_cancel_rate: |
| | | # 计算成交进度位置到当前下单位置的纯买额 |
| | |
| | | total_nums += val["num"] |
| | | if left_count > 0 and index < trade_index: |
| | | total_deal_nums += val["num"] |
| | | thresh_hold_rate = LCancelRateManager.get_cancel_rate(code) |
| | | thresh_hold_rate, must_buy = LCancelRateManager.get_cancel_rate(code) |
| | | if total_deal_nums / total_nums > 1 - thresh_hold_rate - 0.05: |
| | | return False |
| | | return True |
| | |
| | | from log_module import async_log_util, log_export |
| | | from third_data import kpl_data_manager, block_info, history_k_data_util |
| | | from third_data.history_k_data_util import HistoryKDatasUtils |
| | | from utils import global_util, ths_industry_util, tool |
| | | from utils import global_util, ths_industry_util, tool, buy_condition_util |
| | | import l2_data_util |
| | | from db import redis_manager_delegate as redis_manager |
| | | from third_data.code_plate_key_manager import CodePlateKeyBuyManager, KPLCodeJXBlockManager, LimitUpCodesPlateKeyManager |
| | |
| | | |
| | | from trade.trade_data_manager import CodeActualPriceProcessor, PlaceOrderCountManager |
| | | |
| | | from trade.trade_manager import TradeTargetCodeModeManager, AccountAvailableMoneyManager |
| | | from trade.trade_manager import TradeTargetCodeModeManager, AccountAvailableMoneyManager, MarketSituationManager |
| | | |
| | | |
| | | class L2DataManager: |
| | |
| | | __L2LimitUpSellManager = L2LimitUpSellManager() |
| | | __PlaceOrderCountManager = PlaceOrderCountManager() |
| | | __CodeNatureRecordManager = code_nature_analyse.CodeNatureRecordManager() |
| | | __MarketSituationManager=MarketSituationManager() |
| | | |
| | | # 获取代码评分 |
| | | @classmethod |
| | |
| | | if day in HistoryKDatasUtils.get_latest_trading_date_cache(5): |
| | | if code in cls.volume_rate_info and cls.volume_rate_info[code][0] < 0.6: |
| | | return False, True, f"参考量在最近5天,量未达到60%({cls.volume_rate_info[code][0]})" |
| | | |
| | | # 获取市场行情 |
| | | situation = cls.__MarketSituationManager.get_situation_cache() |
| | | zylt_threshold = buy_condition_util.get_zyltgb_threshold(situation) |
| | | zyltgb = global_util.zyltgb_map.get(code) |
| | | if k_format and k_format[8][0]: |
| | | # 具有辨识度 |
| | | zyltgb = 15 * 100000000 |
| | | zyltgb = zylt_threshold[1] + 1 |
| | | |
| | | if zyltgb >= 40 * 100000000: |
| | | return False, True, f"40亿以上的都不买({zyltgb})" |
| | | if zyltgb >= zylt_threshold[0]: |
| | | return False, True, f"{zylt_threshold[0]//100000000}亿以上的都不买({zyltgb})" |
| | | |
| | | if HighIncreaseCodeManager().is_in(code): |
| | | if code in cls.volume_rate_info and cls.volume_rate_info[code][0] < 0.8: |
| | |
| | | # 独苗 |
| | | if not can_buy_result[0] and can_buy_result[1]: |
| | | msg_list.append("独苗") |
| | | if zyltgb < 10 * 100000000 or zyltgb > 20 * 100000000: |
| | | if zyltgb < zylt_threshold[1] or zyltgb > zylt_threshold[2]: |
| | | return False, True, f"强势10分钟,独苗({can_buy_result[4]})不下单({can_buy_result[4]})自由流通市值({zyltgb})不满足条件" |
| | | if k_format and (k_format[1][0] or k_format[3][0]): |
| | | msg_list.append("股价创新高或者逼近前高") |
| | |
| | | return False, True, f"强势10分钟,独苗({can_buy_result[4]}),当日量比({cls.volume_rate_info[code][0]})小于0.3" |
| | | else: |
| | | msg_list.append("非独苗") |
| | | if zyltgb < 10 * 100000000 or zyltgb > 20 * 100000000: |
| | | if zyltgb < zylt_threshold[1] or zyltgb > zylt_threshold[2]: |
| | | msg_list.append("不满足自由流通") |
| | | if k_format and (k_format[1][0] or k_format[3][0]): |
| | | # 股价创新高或者逼近前高 |
| | |
| | | return False, True, f"非强势10分钟,独苗({can_buy_result[4]})不下单" |
| | | if can_buy_result[3]: |
| | | # 强势主线 |
| | | if zyltgb < 10 * 100000000 or zyltgb > 20 * 100000000: |
| | | if zyltgb < zylt_threshold[1] or zyltgb > zylt_threshold[2]: |
| | | if k_format and (k_format[1][0] or k_format[3][0]): |
| | | # 股价创新高或者逼近前高 |
| | | if code in cls.volume_rate_info and cls.volume_rate_info[code][0] < 0.6: |
| | |
| | | return False, True, f"非强势10分钟,强势主线后排,满足自由市值,股价创新高或者逼近前高, 当日量比({cls.volume_rate_info[code][0]})小于0.3" |
| | | else: |
| | | # 非强势主线 |
| | | if zyltgb < 10 * 100000000 or zyltgb > 20 * 100000000: |
| | | if zyltgb < zylt_threshold[1] or zyltgb > zylt_threshold[2]: |
| | | if code in cls.volume_rate_info and cls.volume_rate_info[code][0] < 0.6: |
| | | return False, True, f"非强势10分钟,非强势主线后排,不满足自由市值, 当日量比({cls.volume_rate_info[code][0]})小于0.6" |
| | | else: |
| | |
| | | except: |
| | | pass |
| | | |
| | | # 获取是否 |
| | | k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code) |
| | | if k_format: |
| | | params["trade_data"]["special_info"] = k_format[8] |
| | | |
| | | __base_L2PlaceOrderParamsManager = l2_trade_factor.L2PlaceOrderParamsManager(code, False, volume_rate, |
| | | code_volumn_manager.get_volume_rate_index( |
| | | volume_rate), |
| | |
| | | API_TYPE_COMMON_REQUEST = "common_request" # 通用请求 |
| | | |
| | | |
| | | |
| | | class ActionCallback(object): |
| | | # 交易 |
| | | def OnTrade(self, client_id, request_id, data): |
| | |
| | | |
| | | # @unittest.skip("跳过此单元测试") |
| | | def test_block(self): |
| | | code = "603825" |
| | | code = "603778" |
| | | # KPLCodeJXBlockManager().load_jx_blocks(code, 23.52,23.62, |
| | | # kpl_data_manager.KPLLimitUpDataRecordManager.get_current_reasons()) |
| | | # |
| | |
| | | from code_attribute import code_nature_analyse |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from third_data import kpl_block_util, kpl_api, kpl_util |
| | | from utils import global_util, tool |
| | | from trade.trade_manager import MarketSituationManager |
| | | from utils import global_util, tool, buy_condition_util |
| | | from log_module import log, async_log_util |
| | | from db import redis_manager_delegate as redis_manager |
| | | |
| | |
| | | |
| | | # 返回内容(是否可买, 是否为独苗, 描述信息) |
| | | @classmethod |
| | | def __is_block_can_buy(cls, code, block, current_limit_up_datas, code_limit_up_reason_dict, |
| | | def __is_block_can_buy(cls, code, block, current_limit_up_datas, code_limit_up_reasons_dict, |
| | | yesterday_current_limit_up_codes, limit_up_record_datas, current_limit_up_block_codes_dict, |
| | | high_level_code_blocks=None, high_level_block_codes=None): |
| | | # 独苗判断 |
| | |
| | | # ---------------------------判断强势主线------------------------- |
| | | is_strong_block = False |
| | | for d in current_limit_up_datas: |
| | | if d[5] != block: |
| | | bs = kpl_util.get_current_limit_up_reasons(d) |
| | | if block not in bs: |
| | | general_blocks = high_level_code_blocks.get(d[0]) |
| | | if not general_blocks or block not in general_blocks: |
| | | # 没在泛化板块中 |
| | |
| | | # 获取主板实时身位,剔除高位板 |
| | | current_shsz_rank, front_current_shsz_rank_codes = kpl_block_util.get_code_current_rank(code, block, |
| | | current_limit_up_datas, |
| | | code_limit_up_reason_dict, |
| | | code_limit_up_reasons_dict, |
| | | yesterday_current_limit_up_codes, |
| | | exclude_first_codes, |
| | | len( |
| | |
| | | # 看自由流通市值是否小于20亿 |
| | | if is_strong_block and current_shsz_rank < len(current_open_limit_up_codes) + max_rank + 1: |
| | | zyltgb = global_util.zyltgb_map.get(code) |
| | | if zyltgb and zyltgb < 20 * 100000000: |
| | | return True, False, f"【{block}】强势板块 自由流通市值({zyltgb})小于20亿", is_strong_block |
| | | situation = MarketSituationManager().get_situation_cache() |
| | | zylt_threshold = buy_condition_util.get_zyltgb_threshold(situation) |
| | | if zyltgb and zylt_threshold[1] <= zyltgb <= zylt_threshold[2]: |
| | | return True, False, f"【{block}】强势板块 自由流通市值({zyltgb})大于{zylt_threshold[1]//100000000}亿 小于{zylt_threshold[2]//100000000}亿", is_strong_block |
| | | return False, False, f"【{block}】前排代码:{front_current_shsz_rank_codes} 超过{len(current_open_limit_up_codes) + max_rank}个", is_strong_block |
| | | |
| | | # 过时的代码 |
| | |
| | | if limit_up_record_datas: |
| | | for d in limit_up_record_datas: |
| | | if d[2] in constant.KPL_INVALID_BLOCKS and d[3] in before_blocks_dict: |
| | | code_limit_up_reason_dict[d[3]] = list(before_blocks_dict.get(d[3]))[0] |
| | | code_limit_up_reasons_dict[d[3]] = {list(before_blocks_dict.get(d[3]))[0]} |
| | | else: |
| | | code_limit_up_reason_dict[d[3]] = d[2] |
| | | return code_limit_up_reason_dict |
| | | code_limit_up_reasons_dict[d[3]] = {d[2]} |
| | | if d[6]: |
| | | code_limit_up_reasons_dict[d[3]] |= set(d[6].split("、")) |
| | | return code_limit_up_reasons_dict |
| | | |
| | | if current_limit_up_datas is None: |
| | | current_limit_up_datas = [] |
| | |
| | | fresults = [] |
| | | if not keys: |
| | | return fresults, set() |
| | | code_limit_up_reason_dict = {} |
| | | code_limit_up_reasons_dict = {} |
| | | load_code_block() |
| | | for block in keys: |
| | | can_buy, unique, msg, is_strong = cls.__is_block_can_buy(code, block, current_limit_up_datas, |
| | | code_limit_up_reason_dict, |
| | | code_limit_up_reasons_dict, |
| | | yesterday_current_limit_up_codes, |
| | | limit_up_record_datas, |
| | | current_limit_up_block_codes_dict, |
| | |
| | | |
| | | # 获取当日实时身位 |
| | | # before_blocks_dict格式位{"代码":set("板块")} |
| | | def get_code_current_rank(code, block, current_limit_up_datas, code_limit_up_reason_dict, |
| | | yesterday_current_limit_up_codes, exclude_codes, open_limit_up_count, shsz=False, limit_up_time = time.time()): |
| | | def get_code_current_rank(code, block, current_limit_up_datas, code_limit_up_reasons_dict, |
| | | yesterday_current_limit_up_codes, exclude_codes, open_limit_up_count, shsz=False, |
| | | limit_up_time=time.time()): |
| | | block_codes_infos = [] |
| | | for k in current_limit_up_datas: |
| | | if k[0] == code: |
| | |
| | | # 剔除高位板 |
| | | if k[0] in yesterday_current_limit_up_codes: |
| | | continue |
| | | if code_limit_up_reason_dict.get(k[0]) == block: |
| | | if code_limit_up_reasons_dict.get(k[0]) and block in code_limit_up_reasons_dict.get(k[0]): |
| | | if k[0] != code: |
| | | # 代码.涨停时间 |
| | | block_codes_infos.append((k[0], int(k[2]))) |
| | |
| | | __kplPlatManager = KPLPlatManager() |
| | | __LimitUpCodesPlateKeyManager = LimitUpCodesPlateKeyManager() |
| | | __CodesPlateKeysManager = CodesHisReasonAndBlocksManager() |
| | | __current_code_reason_dict = {} |
| | | __current_code_reasons_dict = {} |
| | | __current_reason_codes_dict = {} |
| | | __records_cache = {} |
| | | |
| | |
| | | cls.latest_origin_datas = records |
| | | cls.__LimitUpCodesPlateKeyManager.set_today_limit_up([(r[0], r[5]) for r in records]) |
| | | |
| | | code_reason_dict = {} |
| | | reason_code_dict = {} |
| | | code_reasons_dict = {} |
| | | reason_codes_dict = {} |
| | | for d in records: |
| | | code_reason_dict[d[0]] = d[5] |
| | | if d[5] not in reason_code_dict: |
| | | reason_code_dict[d[5]] = set() |
| | | reason_code_dict[d[5]].add(d[0]) |
| | | cls.__current_code_reason_dict = code_reason_dict |
| | | cls.__current_reason_codes_dict = reason_code_dict |
| | | # 涨停原因 + 推荐原因 |
| | | bs = {d[5]} |
| | | if d[6]: |
| | | bs |= set(d[6].split("、")) |
| | | code_reasons_dict[d[0]] = bs |
| | | for b in bs: |
| | | if b not in reason_codes_dict: |
| | | reason_codes_dict[b] = set() |
| | | reason_codes_dict[b].add(d[0]) |
| | | cls.__current_code_reasons_dict = code_reasons_dict |
| | | cls.__current_reason_codes_dict = reason_codes_dict |
| | | |
| | | # 涨停数据记录 |
| | | mysqldb = mysql_data.Mysqldb() |
| | |
| | | return bs |
| | | |
| | | @classmethod |
| | | def get_current_block(cls, code): |
| | | return cls.__current_code_reason_dict.get(code) |
| | | def get_current_blocks(cls, code): |
| | | return cls.__current_code_reasons_dict.get(code) |
| | | |
| | | @classmethod |
| | | def get_current_codes_by_block(cls, block): |
| | |
| | | return 1 |
| | | |
| | | |
| | | # 获取实时涨停列表中的涨停原因 |
| | | def get_current_limit_up_reasons(item) -> set: |
| | | b = {item[5]} |
| | | if item[6]: |
| | | b |= set(item[6].split("、")) |
| | | return b |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | print(get_high_level_count("首板")) |
| | | print(get_high_level_count("5天4板")) |
| | |
| | | |
| | | # 成交记录 |
| | | class DealRecordManager: |
| | | __latest_deal_trade_id_dict = {} |
| | | |
| | | __instance = None |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | | if not cls.__instance: |
| | | cls.__instance = super(DealRecordManager, cls).__new__(cls, *args, **kwargs) |
| | | cls.__load_data() |
| | | return cls.__instance |
| | | |
| | | @classmethod |
| | | def __load_data(cls): |
| | | # fresults = cls.list_by_day(tool.get_now_date_str("%Y%m%d")) |
| | | fresults = cls.list_by_day(tool.get_now_date_str("20231227")) |
| | | if fresults: |
| | | for r in fresults: |
| | | cls.__latest_deal_trade_id_dict[r["tradeID"]] = r |
| | | |
| | | def list_sell_by_code_cache(self, code): |
| | | fresults = [] |
| | | for k in self.__latest_deal_trade_id_dict: |
| | | d = self.__latest_deal_trade_id_dict[k] |
| | | if d["securityID"] != code: |
| | | continue |
| | | if int(d["direction"]) != 1: |
| | | continue |
| | | fresults.append(d) |
| | | return fresults |
| | | |
| | | @classmethod |
| | | def add(cls, datas): |
| | | mysqldb = mysql_data.Mysqldb() |
| | | try: |
| | | if datas: |
| | | for d in datas: |
| | | cls.__latest_deal_trade_id_dict[d['tradeID']] = d |
| | | # 查询是否有数据 |
| | | result = mysqldb.select_one( |
| | | f"select * from hx_trade_deal_record where tradeID='{d['tradeID']}'") |
| | |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | update_time = None |
| | | results, update_time = DelegateRecordManager.list_by_day( |
| | | tool.get_now_date_str("%Y%m%d"), update_time) |
| | | print(results) |
| | | deal_list = DealRecordManager().list_sell_by_code_cache("603759") |
| | | deal_order_system_id_infos = {} |
| | | if deal_list: |
| | | for d in deal_list: |
| | | if d["orderSysID"] not in deal_order_system_id_infos: |
| | | deal_order_system_id_infos[d["orderSysID"]] = [d["volume"], d["tradeTime"]] |
| | | else: |
| | | deal_order_system_id_infos[d["orderSysID"]][0] += d["volume"] |
| | | deal_list = [deal_order_system_id_infos[k] for k in deal_order_system_id_infos] |
| | | deal_list.sort(key=lambda x: x[1]) |
| | | print([k[0] for k in deal_list]) |
| | |
| | | |
| | | from trade.huaxin import huaxin_trade_api as trade_api, huaxin_trade_api, huaxin_trade_data_update, \ |
| | | huaxin_trade_record_manager, huaxin_trade_order_processor |
| | | from trade.huaxin.huaxin_trade_record_manager import PositionManager |
| | | from trade.huaxin.huaxin_trade_record_manager import PositionManager, DealRecordManager |
| | | from trade.l2_trade_factor import L2PlaceOrderParamsManager |
| | | from trade.sell import sell_manager |
| | | from trade.sell.sell_rule_manager import SellRuleManager, SellRule |
| | | from trade.trade_manager import TradeTargetCodeModeManager |
| | | from trade.trade_manager import TradeTargetCodeModeManager, MarketSituationManager |
| | | from utils import socket_util, data_export_util, middle_api_protocol, tool, huaxin_util, output_util, sell_util |
| | | |
| | | trade_data_request_queue = queue.Queue() |
| | |
| | | |
| | | class OutsideApiCommandCallback(outside_api_command_manager.ActionCallback): |
| | | __cancel_sell_thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=8) |
| | | __DealRecordManager = DealRecordManager() |
| | | |
| | | @classmethod |
| | | def __send_response(cls, data_bytes): |
| | |
| | | # 获取持仓 |
| | | positions = PositionManager.latest_positions |
| | | sell_rules_count = len(SellRuleManager().list_can_excut_rules_cache()) |
| | | fdata = {"code": code, "total": 0, "available": 0, "sell_rules_count": sell_rules_count, |
| | | |
| | | fdata = {"code": code, "total": 0, "available": 0, "sell_orders": [], "sell_rules_count": sell_rules_count, |
| | | "code_info": (code, code_name), "desc": "".join(desc_list)} |
| | | if positions: |
| | | for d in positions: |
| | |
| | | continue |
| | | fdata["total"] = d["prePosition"] |
| | | fdata["available"] = d["availablePosition"] |
| | | deal_order_system_id_infos = {} |
| | | # 获取已经卖的单数 |
| | | deal_list = self.__DealRecordManager.list_sell_by_code_cache(code) |
| | | if deal_list: |
| | | for d in deal_list: |
| | | if d["orderSysID"] not in deal_order_system_id_infos: |
| | | deal_order_system_id_infos[d["orderSysID"]] = [d["volume"], d["tradeTime"]] |
| | | else: |
| | | deal_order_system_id_infos[d["orderSysID"]][0] += d["volume"] |
| | | deal_list = [deal_order_system_id_infos[k] for k in deal_order_system_id_infos] |
| | | deal_list.sort(key=lambda x: x[1]) |
| | | fdata["sell_orders"] =[k[0] for k in deal_list] |
| | | break |
| | | result = {"code": 0, "data": fdata} |
| | | self.send_response(result, client_id, request_id) |
| | |
| | | result = {"code": 0, |
| | | "data": codes} |
| | | self.send_response(result, client_id, request_id) |
| | | elif ctype == "market_situation": |
| | | try: |
| | | operate = data["operate"] |
| | | if operate == outside_api_command_manager.OPERRATE_SET: |
| | | situation = data["situation"] |
| | | MarketSituationManager().set_situation(situation) |
| | | self.send_response({"code": 0, "data": {"situation": situation}}, client_id, request_id) |
| | | elif operate == outside_api_command_manager.OPERRATE_GET: |
| | | situation = MarketSituationManager().get_situation_cache() |
| | | self.send_response({"code": 0, "data": {"situation": situation}}, client_id, request_id) |
| | | except Exception as e: |
| | | self.send_response({"code": 1, "msg": str(e)}, client_id, request_id) |
| | | |
| | | except Exception as e: |
| | | logging.exception(e) |
| | |
| | | huaxin_trade_record_manager.DelegateRecordManager.add([data]) |
| | | if huaxin_util.is_deal(order_status): |
| | | if int(str(data["direction"])) == huaxin_util.TORA_TSTP_D_Buy: |
| | | l2_trade_util.forbidden_trade(data["securityID"], msg="已成交", force = True) |
| | | l2_trade_util.forbidden_trade(data["securityID"], msg="已成交", force=True) |
| | | # 成交,更新成交列表与资金列表 |
| | | huaxin_trade_data_update.add_deal_list() |
| | | huaxin_trade_data_update.add_money_list() |
| | |
| | | return self.__trade_buy_mode_cache |
| | | |
| | | |
| | | # 市场行情等级管理 |
| | | class MarketSituationManager: |
| | | # 差 |
| | | SITUATION_BAD = 0 |
| | | # 一般 |
| | | SITUATION_COMMON = 1 |
| | | # 好 |
| | | SITUATION_GOOD = 2 |
| | | |
| | | __db = 2 |
| | | redisManager = redis_manager.RedisManager(2) |
| | | __situation_cache = SITUATION_BAD |
| | | __instance = None |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | | if not cls.__instance: |
| | | cls.__instance = super(MarketSituationManager, cls).__new__(cls, *args, **kwargs) |
| | | # 初始化设置 |
| | | # 获取交易窗口的锁 |
| | | cls.__instance.__situation_cache = cls.get_situation() |
| | | return cls.__instance |
| | | |
| | | @classmethod |
| | | def __get_redis(cls): |
| | | return cls.redisManager.getRedis() |
| | | |
| | | def set_situation(self, situation): |
| | | if situation not in [self.SITUATION_BAD, self.SITUATION_COMMON, self.SITUATION_GOOD]: |
| | | raise Exception("situation参数值错误") |
| | | self.__situation_cache = situation |
| | | RedisUtils.setex_async(self.__db, "market_situation", tool.get_expire(), situation) |
| | | |
| | | # 是否可以下单 |
| | | @classmethod |
| | | def get_situation(cls): |
| | | # 默认设置为可交易 |
| | | val = RedisUtils.get(cls.__get_redis(), "market_situation") |
| | | if val is None: |
| | | return cls.SITUATION_BAD |
| | | return int(val) |
| | | |
| | | def get_situation_cache(self): |
| | | return self.__situation_cache |
| | | |
| | | |
| | | # 根据分数禁止买的票管理 |
| | | class ForbiddenBuyCodeByScoreManager: |
| | | __instance = None |
| | |
| | | __db = 2 |
| | | __redis_manager = redis_manager.RedisManager(2) |
| | | __instance = None |
| | | |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | | if not cls.__instance: |
| | |
| | | continue |
| | | # 买入成功 |
| | | if code is not None and int(data["type"]) == 0: |
| | | l2_trade_util.forbidden_trade(code, msg="交易成功",force = True) |
| | | l2_trade_util.forbidden_trade(code, msg="交易成功", force=True) |
| | | state = CodesTradeStateManager().get_trade_state_cache(code) |
| | | if state != TRADE_STATE_BUY_SUCCESS: |
| | | CodesTradeStateManager().set_trade_state(code, TRADE_STATE_BUY_SUCCESS) |
| | |
| | | def buy_success(code): |
| | | # 加入黑名单 |
| | | if not l2_trade_util.is_in_forbidden_trade_codes(code): |
| | | l2_trade_util.forbidden_trade(code, "buy success",force=True) |
| | | l2_trade_util.forbidden_trade(code, "buy success", force=True) |
| | | # 取s消所有的挂单 |
| | | if constant.API_TRADE_ENABLE: |
| | | if constant.TRADE_WAY == constant.TRADE_WAY_JUEJIN: |