| | |
| | | import concurrent.futures |
| | | import copy |
| | | import hashlib |
| | | import http |
| | | import json |
| | |
| | | if url.path == "/get_position_list": |
| | | # 获取持仓列表 |
| | | results = PositionManager.get_position_cache() |
| | | results = copy.deepcopy(results) |
| | | for r in results: |
| | | r["auto_sell"] = 1 if r["securityID"] in data_cache.LIMIT_UP_SELL_CODES else 0 |
| | | response_data = json.dumps({"code": 0, "data": results}) |
| | | elif url.path == "/get_money": |
| | | # 获取资金信息 |
| | |
| | | if data: |
| | | fdatas.append(data) |
| | | response_data = json.dumps({"code": 0, "data": fdatas}) |
| | | elif url.path == "/get_buy_money": |
| | | # 获取每次买入的金额 |
| | | money = data_cache.BUY_MONEY_PER_CODE |
| | | response_data = json.dumps({"code": 0, "data": {"money": money}}) |
| | | |
| | | self.send_response(200) |
| | | # 发给请求客户端的响应数据 |
| | | self.send_header('Content-type', 'application/json') |
| | |
| | | price = round(params.get("price"), 2) # 价格 |
| | | result = huaxin_trade_api.order(2, code, volume, price, blocking=True) |
| | | result_str = json.dumps(result) |
| | | |
| | | elif url.path == "/set_buy_money": |
| | | # 设置每次买入的金额 |
| | | params = self.__parse_request() |
| | | # 签名验证 |
| | | if not self.__is_sign_right(params): |
| | | result_str = json.dumps({"code": 1001, "msg": "签名错误"}) |
| | | return |
| | | # 卖出 |
| | | print("每次买入的金额", params) |
| | | money = params.get("money") # 金额 |
| | | if money is None: |
| | | result_str = json.dumps({"code": 1, "msg": "未上传金额"}) |
| | | return |
| | | money = int(money) |
| | | data_cache.BUY_MONEY_PER_CODE = money |
| | | result_str = json.dumps({"code": 0}) |
| | | |
| | | elif url.path == "/set_limit_up_sell": |
| | | # 设置每次买入的金额 |
| | | params = self.__parse_request() |
| | | # 签名验证 |
| | | if not self.__is_sign_right(params): |
| | | result_str = json.dumps({"code": 1001, "msg": "签名错误"}) |
| | | return |
| | | # 卖出 |
| | | print("每次买入的金额", params) |
| | | code = params.get("code") #代码 |
| | | enable = params.get("enable") # 是否开启 |
| | | if code is None or enable is None: |
| | | result_str = json.dumps({"code": 1, "msg": "上传数据缺失"}) |
| | | return |
| | | enable = int(enable) |
| | | if enable: |
| | | data_cache.LIMIT_UP_SELL_CODES.add(code) |
| | | else: |
| | | data_cache.LIMIT_UP_SELL_CODES.discard(code) |
| | | result_str = json.dumps({"code": 0}) |
| | | |
| | | elif url.path == "/cancel_order": |
| | | params = self.__parse_request() |
| | | # 签名验证 |
| | |
| | | httpd.serve_forever() |
| | | except Exception as e: |
| | | pass |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | run() |
| | |
| | | with open(constant.K_BARS_PATH, 'r', |
| | | encoding='utf-8') as f: |
| | | data_cache.all_stocks_all_K_line_property_dict = json.load(f) |
| | | print( |
| | | f"data_cache.all_stocks_all_K_line_property_dict的个数{len(data_cache.all_stocks_all_K_line_property_dict)}") |
| | | # print( |
| | | # f"data_cache.all_stocks_all_K_line_property_dict的个数{len(data_cache.all_stocks_all_K_line_property_dict)}") |
| | | |
| | | else: |
| | | check_today_date = check_data_date(data_cache.DataCache().today_date) |
| | |
| | | with open(constant.K_BARS_PATH, 'r', |
| | | encoding='utf-8') as f: |
| | | data_cache.all_stocks_all_K_line_property_dict = json.load(f) |
| | | print( |
| | | f"data_cache.all_stocks_all_K_line_property_dict的个数{len(data_cache.all_stocks_all_K_line_property_dict)}") |
| | | # print( |
| | | # f"data_cache.all_stocks_all_K_line_property_dict的个数{len(data_cache.all_stocks_all_K_line_property_dict)}") |
| | | except Exception as error: |
| | | logger.exception(error) |
| | | print(f"实时检测是否拉取K线线程报错An error occurred: {error}") |
| | |
| | | L1_data_start_time = datetime.time(9, 15, 00).strftime("%H:%M:%S") # 定义9:15 |
| | | before_open_bidding_time = datetime.time(9, 20, 00).strftime("%H:%M:%S") # 定义9:20 |
| | | open_bidding_time = datetime.time(9, 25, 00).strftime("%H:%M:%S") # 定义 盘前 集合竞价 时间 |
| | | later_open_bidding_time = datetime.time(9, 25, 30).strftime("%H:%M:%S") # 定义 盘前 集合竞价 时间 |
| | | after_open_bidding_time = datetime.time(9, 26, 00).strftime("%H:%M:%S") # 定义 集合竞价 开始后 时间 |
| | | later_open_bidding_time = datetime.time(9, 25, 6).strftime("%H:%M:%S") # 定义 盘前 集合竞价 时间 |
| | | after_open_bidding_time = datetime.time(9, 25, 12).strftime("%H:%M:%S") # 定义 集合竞价 开始后 时间 |
| | | opening_time = datetime.time(9, 30, 00).strftime("%H:%M:%S") # 定义开盘时间 |
| | | morn_market_time = datetime.time(9, 35, 00).strftime("%H:%M:%S") # 定义早盘时间 |
| | | noon_market_time = datetime.time(13, 5, 00).strftime("%H:%M:%S") # 定义午盘时间 |
| | |
| | | # 创业板指 开盘涨幅 |
| | | TSXV_open_growth = 0 |
| | | |
| | | # 每次买入的金额 |
| | | BUY_MONEY_PER_CODE = -1 |
| | | |
| | | # 可以板上盯卖的代码 |
| | | LIMIT_UP_SELL_CODES = set() |
| | | |
| | | logging.info(f"全局初始化数据 完成《《《 - {os.getpid()}") |
| | | |
| | | |
| | |
| | | |
| | | # 在集合竞价时更新一下 各个指数的开盘涨幅 |
| | | now_time = datetime.datetime.now().strftime("%H:%M:%S") |
| | | # 9:25:30 < now_time < 9:26:00 |
| | | # 9:25:06 < now_time < 9:25:12 |
| | | if data_cache.later_open_bidding_time < now_time < data_cache.after_open_bidding_time: |
| | | data_cache.Shanghai_open_growth = data_cache.Shanghai_today_growth |
| | | data_cache.Shenzhen_open_growth = data_cache.Shenzhen_today_growth |
| | |
| | | # 判断三大指数开盘涨幅 预期 |
| | | if data_cache.Shanghai_open_growth > 0 and data_cache.Shenzhen_open_growth > 0 and data_cache.TSXV_open_growth > 0: |
| | | index_composite_open_increase = '三大指数:高开' |
| | | index_trend_expectation_score += 10 |
| | | index_trend_expectation_score += 5 |
| | | if data_cache.Shanghai_open_growth >= 1 and data_cache.Shenzhen_open_growth >= 1 and data_cache.TSXV_open_growth >= 1: |
| | | index_composite_open_increase = '三大指数:高开1% 以上' |
| | | index_trend_expectation_score += 10 |
| | | index_trend_expectation_score += 5 |
| | | elif data_cache.Shanghai_open_growth < 0 and data_cache.Shenzhen_open_growth < 0 and data_cache.TSXV_open_growth < 0: |
| | | index_composite_open_increase = '三大指数:低开' |
| | | index_trend_expectation_score -= 10 |
| | | index_trend_expectation_score -= 5 |
| | | if data_cache.Shanghai_open_growth <= 1 and data_cache.Shenzhen_open_growth <= 1 and data_cache.TSXV_open_growth <= 1: |
| | | index_composite_open_increase = '三大指数:低开1% 以下' |
| | | index_trend_expectation_score -= 10 |
| | | index_trend_expectation_score -= 5 |
| | | else: |
| | | index_composite_open_increase = '三大指数:涨跌不一' |
| | | logger.info(f"开盘指数开盘涨幅播报:{index_composite_open_increase}") |
| | |
| | | # 在data_cache中获取到推送过来的实时指数行情数据 |
| | | stock_index_dict = data_cache.stock_index_dict |
| | | now_time = datetime.datetime.now().strftime("%H:%M:%S") |
| | | if len(stock_index_dict) == 0 and data_cache.L1_data_start_time < now_time: |
| | | print(f"9:15后 实时指数数据为空=stock_index_dict===={stock_index_dict}") |
| | | if len(stock_index_dict) == 0 and data_cache.L1_data_start_time < now_time < data_cache.closing_time: |
| | | print(f"9:15--15:00 实时指数数据为空===={stock_index_dict}") |
| | | index_judge_thread_manager(stock_index_dict) |
| | | except Exception as error: |
| | | logging.exception(error) |
| | |
| | | pass |
| | | # 获取当前时间 |
| | | now_time = datetime.datetime.now().strftime("%H:%M:%S") |
| | | # 如果当前时间大于09:25:30才运行最高价和最低价的运算 |
| | | # 如果当前时间大于09:25:06才运行最高价和最低价的运算 |
| | | if data_cache.later_open_bidding_time < now_time: |
| | | # if data_cache.after_closing_time < now_time: |
| | | if now_time < data_cache.opening_time and data_cache.record_current_open_execution is False: |
| | |
| | | def get_all_stocks_current_high_and_low(current_infos): |
| | | # 获取当前时间 |
| | | now_time = datetime.datetime.now().strftime("%H:%M:%S") |
| | | # 如果当前时间大于09:25:30才运行最高价和最低价的运算 |
| | | # 如果当前时间大于09:25:06才运行最高价和最低价的运算 |
| | | if data_cache.later_open_bidding_time < now_time: |
| | | # if data_cache.after_closing_time < now_time: |
| | | if data_cache.Local_startup_time < data_cache.opening_time: |
| | |
| | | index_trend_expectation_score = index_trend_expectation() |
| | | logger.info(f"大盘指数情绪预期分数==={index_trend_expectation_score}分") |
| | | print(f"大盘指数情绪预期分数==={index_trend_expectation_score}分") |
| | | # 目前大盘指数情绪预期分数 尚不科学 强制设置为初始0值 |
| | | index_trend_expectation_score = 0 |
| | | |
| | | # 获取计算今天新增的持仓数量 |
| | | addition_position_number = len(data_cache.addition_position_symbols_set) |
| | | # 定义一个今日的剩余新增持仓数量的变量 |
| | | Unfinished_opening_plan_number = 3 - addition_position_number |
| | | if Unfinished_opening_plan_number != 0: |
| | | # 如果GUI看盘上没有手动设置具体的下单金额,就按照评分策略的金额下单,否则就按照GUI设置的金额下单。 |
| | | if data_cache.BUY_MONEY_PER_CODE < 0: |
| | | # 根据账户可用金额 计算今日计划下单金额 |
| | | # (账户可用金额/今日最大新增持仓票数) * (大盘综合强度分数 * 0.01) |
| | | data_cache.today_planned_order_amount = (usefulMoney * index_trend_expectation_score / Unfinished_opening_plan_number) * (data_cache.real_time_market_strong * 0.01) |
| | | # ((大盘综合强度分数 + 大盘指数情绪预期分数) * 0.01) * (账户可用金额 * 极端低迷情绪比例 / 今日最大新增持仓票数) |
| | | data_cache.today_planned_order_amount = ((data_cache.real_time_market_strong + index_trend_expectation_score) * 0.01) * (usefulMoney * low_emotion_mood_ratio / Unfinished_opening_plan_number) |
| | | else: |
| | | data_cache.today_planned_order_amount = data_cache.BUY_MONEY_PER_CODE |
| | | |
| | | except Exception as error: |
| | | logger.error(f"获取实时大盘行情情绪综合强度[分数] 函数报错: {error}") |
| | |
| | | |
| | | |
| | | # kpl_stocks_list_selected_blocks_process() #在 kpl_api.py中可以调用 |
| | | |
| | | # stocks_list_selected_blocks(min_stocks) #在 kpl_api.py中可以调用 |
| | | |
| | | # list = ['SHSE.600805','SHSE.600804'] |
| | | # |
| | | # all_stocks_plate_dict(list) |
| | |
| | | ''' |
| | | 集合竞价阶段决断(只判断一次) |
| | | ''' |
| | | if data_cache.after_open_bidding_time < now_time < data_cache.opening_time and data_cache.execution_times < len(data_cache.available_symbols_set): |
| | | # 09:25:06---09:30:00 |
| | | if data_cache.later_open_bidding_time < now_time < data_cache.opening_time and data_cache.execution_times < len(data_cache.available_symbols_set): |
| | | # 每进入该条件分支一次就把进入次数自加1 |
| | | data_cache.execution_times += 1 |
| | | logger.info(f"这个分支逻辑已经执行次数:{data_cache.execution_times}") |
| | |
| | | |
| | | # 当日涨停视界(板上盯 有时间限制 9:30:00 --- 14:36:00) |
| | | if data_cache.opening_time < now_time < data_cache.watch_disk_end_time: |
| | | # if symbol in data_cache.LIMIT_UP_SELL_CODES: |
| | | if today_limit_up_price == current_high: |
| | | logger.info( |
| | | f"【开盘临机】【{k_line_data[0]['sec_name']}】 触及涨停! 买一总金额:{round(current_quotes_buy[0][1] * current_quotes_buy[0][0] / 10000, 2)} 万,当日当时量:{current_volume}") |
| | |
| | | index) |
| | | else: |
| | | logger.info(f"【开盘临机】【{k_line_data[0]['sec_name']}】 涨停封板!!") |
| | | |
| | | ''' |
| | | 下面是目前看来更有效的板上盯卖 |
| | | ''' |
| | | # 如果 卖一 量 为零 |
| | | if current_quotes_sell[0][1] * current_quotes_sell[0][0] == 0: |
| | | logger.info( |
| | |
| | | index) |
| | | if current_volume < k_line_data[0]['volume'] * 0.8: |
| | | logger.info( |
| | | f"【开盘临机】【 炸板!!且当日量不足】【{k_line_data[0]['sec_name']}】 买盘小于1万 且 今日量小于昨日量的 0.8,设定委卖数量【全仓】,当日当时量:{current_volume}") |
| | | f"【开盘临机】【 炸板!!且当日量不足】【{k_line_data[0]['sec_name']}】 买盘小于1万 且 今日量小于昨日量的 0.8,当日当时量:{current_volume}") |
| | | # 该股加入到板上盯卖的集合中 所以设定卖出全仓 |
| | | if symbol in data_cache.LIMIT_UP_SELL_CODES: |
| | | logger.info( |
| | | f"【开盘临机】【 炸板!!且当日量不足】【{k_line_data[0]['sec_name']}】 板上盯卖 |开启| 设定委卖【全仓】") |
| | | order_methods.sell_order_by_part_volume(1, symbol, |
| | | position_volume_yesterday, |
| | | current_price, |
| | | k_line_data[0]['sec_name'], |
| | | index) |
| | | else: |
| | | logger.info( |
| | | f"【开盘临机】【 炸板!!且当日量不足】【{k_line_data[0]['sec_name']}】 板上盯卖 |关闭| 设定委卖【十分之一仓】") |
| | | order_methods.sell_order_by_part_volume(0.1, symbol, |
| | | position_volume_yesterday, |
| | | current_price, |
| | | k_line_data[0]['sec_name'], |
| | | index) |
| | | |
| | | # 当前时间超过午盘时间【午盘决策】 |
| | | if now_time > data_cache.noon_market_time: |