| | |
| | | from db import redis_manager_delegate as redis_manager |
| | | from db.mysql_data_delegate import Mysqldb |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from log_module import log_export |
| | | from log_module import log_export, async_log_util |
| | | from log_module.log import logger_pre_close_price, logger_debug |
| | | from trade import trade_record_log_util |
| | | from utils import tool |
| | |
| | | # 设置收盘价 |
| | | @classmethod |
| | | def set_price_pre(cls, code, price, force=False): |
| | | if float(price) > 1000: |
| | | async_log_util.info(logger_debug, f"获取昨日收盘价异常:{code}-{price}") |
| | | return |
| | | if code in cls.__price_pre_cache and not force: |
| | | return |
| | | price = round(float(price), 2) |
| | |
| | | "turnover": pOrderField.Turnover, "orderRef": pOrderField.OrderRef, |
| | | "volume": pOrderField.VolumeTotalOriginal, |
| | | "volumeTraded": pOrderField.VolumeTraded, "orderStatus": pOrderField.OrderStatus, |
| | | "orderSubmitStatus": pOrderField.OrderSubmitStatus, "statusMsg": pOrderField.StatusMsg}) |
| | | "orderSubmitStatus": pOrderField.OrderSubmitStatus, "statusMsg": pOrderField.StatusMsg,"sinfo": pOrderField.SInfo |
| | | }) |
| | | else: |
| | | # logger.info('查询报单结束[%d] ErrorID[%d] ErrorMsg[%s]' |
| | | # % (nRequestID, pRspInfoField.ErrorID, pRspInfoField.ErrorMsg)) |
| | |
| | | th_sell = BeforeSubDealBigOrderManager().get_big_sell_order_threshold(code) |
| | | except: |
| | | th_sell = 0 |
| | | |
| | | # (缺少的资金, 净成交金额, 要求的大单金额, 计算得到的大单阈值金额, 人为设置的大单) |
| | | deal_big_money_info = radical_buy_data_manager.get_total_deal_big_order_info( |
| | | code, gpcode_manager.get_limit_up_price_as_num(code)) |
| | | if deal_big_money_info[1] == 0 and len(codes) == 1: |
| | | # 总成交金额为0 |
| | | deal_big_money_info = list(deal_big_money_info) |
| | | # 没有订阅L2会出现没有值的情况,如果涨停过就拉取之前的涨停买/卖大单 |
| | | deal_big_orders_result = radical_buy_data_manager.request_deal_big_orders(code) |
| | |
| | | th_buy = threshold_money |
| | | buy_money = sum(limit_up_price_money_list) |
| | | sell_money = sum([x[0] for x in sell_datas if x[1] == limit_up_price]) |
| | | # 涨停大单净买入 |
| | | # 涨停买净成交金额净买额 |
| | | deal_big_money_info[1] = buy_money - sell_money |
| | | # 要求的大单累计金额 |
| | | deal_big_money_info[ |
| | | 2] = radical_buy_data_manager.compute_total_deal_big_order_threshold_money(code, |
| | | limit_up_price, |
| | | threshold_money) |
| | | logger_debug.info(f"{code}-累计大单阈值:{deal_big_money_info[2]}") |
| | | # logger_debug.info(f"{code}-累计大单阈值:{deal_big_money_info[2]}") |
| | | # logger_debug.info(f"{code}非订阅大单, buy_money-{buy_money}, sell_money-{sell_money}") |
| | | |
| | | big_money_rate = radical_buy_data_manager.TotalDealBigOrderInfoManager.get_big_order_rate( |
| | | code) |
| | |
| | | output_util.money_desc(deal_big_money_info[2]), |
| | | # 原累计大单阈值(非人为设置) |
| | | output_util.money_desc(deal_big_money_info[3]), |
| | | # 人为设置的大单 |
| | | output_util.money_desc(deal_big_money_info[4]) if deal_big_money_info[4] else '', |
| | | ] |
| | | if len(codes) == 1: |
| | | # 加载大单详情 |
| | | deal_big_order_detail_info = radical_buy_data_manager.get_l2_big_order_deal_info(code) |
| | | # 加载涨停大单详情 |
| | | # 买大单, 上板前买大单, 卖大单, 上板前卖大单 |
| | | limit_up_big_order_detail = radical_buy_data_manager.get_total_detal_big_order_details( |
| | | code) |
| | | deal_big_order_info.append( |
| | | output_util.money_desc(limit_up_big_order_detail[0] + limit_up_big_order_detail[1])) |
| | | deal_big_order_info.append( |
| | | output_util.money_desc(limit_up_big_order_detail[2] + limit_up_big_order_detail[3])) |
| | | # 累计涨停买金额 |
| | | buy_money = output_util.money_desc(limit_up_big_order_detail[0] + limit_up_big_order_detail[1]) |
| | | sell_money = output_util.money_desc(limit_up_big_order_detail[2] + limit_up_big_order_detail[3]) |
| | | deal_big_order_info.append(buy_money) |
| | | # 累计涨停卖金额 |
| | | deal_big_order_info.append(sell_money) |
| | | deal_big_order_info.append( |
| | | radical_buy_data_manager.TotalDealBigOrderInfoManager().get_big_order_rate(code)) |
| | | |
| | |
| | | from third_data import block_info, kpl_data_manager, history_k_data_manager, huaxin_l1_data_manager, kpl_api, kpl_util |
| | | from third_data.code_plate_key_manager import KPLCodeJXBlockManager, RealTimeKplMarketData, \ |
| | | KPLPlateForbiddenManager |
| | | from third_data.history_k_data_manager import HistoryKDataManager |
| | | from third_data.history_k_data_util import JueJinApi, HistoryKDatasUtils |
| | | from trade import l2_trade_util, \ |
| | | trade_data_manager, trade_constant, buy_open_limit_up_strategy |
| | |
| | | # 初始化数据 |
| | | BuyMoneyAndCountSetting() |
| | | gpcode_manager.WantBuyCodesManager() |
| | | # 加载历史K线数据 |
| | | HistoryKDataManager().load_data() |
| | | |
| | | |
| | | def run(queue_strategy_r_trade_w, queue_strategy_w_trade_r, queue_strategy_w_trade_r_for_read, trade_ipc_addr): |
| | |
| | | from huaxin_client import l1_subscript_codes_manager |
| | | from log_module.log import logger_debug |
| | | from third_data import history_k_data_util |
| | | from third_data.history_k_data_util import HistoryKDatasUtils |
| | | from utils import tool, init_data_util |
| | | |
| | | |
| | |
| | | |
| | | |
| | | def re_set_price_pres(codes, force=False): |
| | | day = tool.get_now_date_str() |
| | | # 通过历史数据缓存获取 |
| | | # 获取上一个交易日 |
| | | day = HistoryKDatasUtils.get_previous_trading_date_cache(tool.get_now_date_str()) |
| | | not_codes = [] |
| | | for code in codes: |
| | | if not tool.is_can_buy_code(code): |
| | | continue |
| | | pre_close = HistoryKDataManager().get_pre_close(code, day) |
| | | if pre_close is not None: |
| | | gpcode_manager.CodePrePriceManager.set_price_pre(code, pre_close, force) |
| | |
| | | return datas |
| | | return None |
| | | |
| | | def load_data(self): |
| | | """ |
| | | 加载数据 |
| | | @param day: |
| | | @return: |
| | | """ |
| | | day = HistoryKDatasUtils.get_previous_trading_date_cache(tool.get_now_date_str()) |
| | | cache_dir = self.__get_cache_dir() |
| | | if not os.path.exists(cache_dir): |
| | | return |
| | | fs = os.listdir(cache_dir) |
| | | for f in fs: |
| | | if f.find(day) < 0: |
| | | continue |
| | | with open(os.path.join(cache_dir, f), mode='r', encoding='utf-8') as fs: |
| | | line = fs.readline() |
| | | if line: |
| | | datas = eval(line) |
| | | # 将日期格式转为datetime |
| | | for d in datas: |
| | | for k in d: |
| | | if type(d[k]) == str and d[k].find("-") > 0 and d[k].find(":") > 0 and d[k].find(" ") > 0: |
| | | d[k] = datetime.datetime.strptime(d[k], "%Y-%m-%d %H:%M:%S") |
| | | if datas: |
| | | if day not in self.__history_k_day_datas: |
| | | self.__history_k_day_datas[day] = {} |
| | | self.__history_k_day_datas[day][datas[0]['sec_id']] = datas |
| | | |
| | | def get_pre_close(self, code, day): |
| | | """ |
| | | 获取之前的收盘价 |
| | |
| | | """ |
| | | 总成交大单啊是否足够 |
| | | @param code: |
| | | @return:(缺少的资金, 总成交金额, 要求的大单金额, 计算得到的大单阈值金额) |
| | | @return:(缺少的资金, 净成交金额, 要求的大单金额, 计算得到的大单阈值金额, 人为设置的大单) |
| | | """ |
| | | |
| | | THRESHOLD_MONEY, is_temp_threshold_money = BeforeSubDealBigOrderManager().get_big_order_threshold_info(code) |
| | |
| | | except Exception as e: |
| | | async_log_util.info(logger_l2_radical_buy, f"计算正在成交大单出错:{str(e)}") |
| | | total_lack_money = max(0, int(TOTAL_BIG_DEAL_MONEY_THRESHOLD_MONEY - deal_big_order_money)) |
| | | return total_lack_money, deal_big_order_money, TOTAL_BIG_DEAL_MONEY_THRESHOLD_MONEY, TOTAL_BIG_DEAL_MONEY_THRESHOLD_MONEY_WITH_COMPUTE |
| | | return total_lack_money, deal_big_order_money, TOTAL_BIG_DEAL_MONEY_THRESHOLD_MONEY, TOTAL_BIG_DEAL_MONEY_THRESHOLD_MONEY_WITH_COMPUTE, human_setting_money |
| | | |
| | | |
| | | def is_big_order_deal_enough(code, volume_rate, refer_total_sell_money, for_buy=False, is_almost_open_limit_up=False): |
| | |
| | | tool.get_buy_volume(limit_up_price), list(special_volumes))) |
| | | huaxin_target_codes_manager.HuaXinL2SubscriptCodesManager.push(add_datas, request_id) |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | logger_debug.exception(e) |
| | | else: |
| | | pass |
| | | |
| | |
| | | nameDict = HistoryKDatasUtils.get_gp_codes_names([d['securityID']]) |
| | | name = nameDict.get(d['securityID']) |
| | | 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', '%s')" % ( |
| | | "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', '%s', '%s')" % ( |
| | | _id, d["orderLocalID"], d["securityID"], name, d["direction"], |
| | | d["orderSysID"], d["insertTime"], d["insertDate"], d["acceptTime"], d["cancelTime"], |
| | | d["limitPrice"], d["turnover"], d["volume"], d["volumeTraded"], d["orderStatus"], |
| | | d["orderSubmitStatus"], d["statusMsg"], tool.get_now_datetime_str(), |
| | | tool.get_now_datetime_str(), d["accountID"],d["orderRef"])) |
| | | tool.get_now_datetime_str(), d["accountID"], d["orderRef"], d["sinfo"])) |
| | | else: |
| | | # 修改数据 |
| | | updateDict = {} |
| | |
| | | updateDict['statusMsg'] = d['statusMsg'] |
| | | if result[20] != d['orderRef']: |
| | | updateDict['orderRef'] = d['orderRef'] |
| | | if result[21] != d['sinfo']: |
| | | updateDict['sinfo'] = d['sinfo'] |
| | | if updateDict: |
| | | # 有更新数据 |
| | | updateDict['updateTime'] = tool.get_now_datetime_str() |
| | |
| | | # 转dict |
| | | key_list = ["id", "orderLocalID", "securityID", "securityName", "direction", "orderSysID", "insertTime", |
| | | "insertDate", "acceptTime", "cancelTime", "limitPrice", "turnover", "volume", "volumeTraded", |
| | | "orderStatus", "orderSubmitStatus", "statusMsg", "createTime", "updateTime", "accountID", "orderRef"] |
| | | "orderStatus", "orderSubmitStatus", "statusMsg", "createTime", "updateTime", "accountID", |
| | | "orderRef", "sinfo"] |
| | | fresults = [] |
| | | max_update_time = None |
| | | if results: |
| | |
| | | |
| | | def re_set_price_pres(codes, force=False): |
| | | # 通过历史数据缓存获取 |
| | | result = HistoryKDatasUtils.get_gp_latest_info(codes) |
| | | for item in result: |
| | | symbol = item['symbol'] |
| | | symbol = symbol.split(".")[1] |
| | | pre_close = tool.to_price(decimal.Decimal(str(item['pre_close']))) |
| | | gpcode_manager.CodePrePriceManager.set_price_pre(symbol, pre_close, force) |
| | | for code in codes: |
| | | result = HistoryKDatasUtils.get_history_tick_n(code, 1) |
| | | for item in result: |
| | | symbol = item['symbol'] |
| | | symbol = symbol.split(".")[1] |
| | | pre_close = tool.to_price(decimal.Decimal(str(item['close']))) |
| | | gpcode_manager.CodePrePriceManager.set_price_pre(symbol, pre_close, force) |
| | | |
| | | |
| | | # 获取近90天的最大量与最近的量 |