| | |
| | | from db import redis_manager_delegate as redis_manager, mysql_data_delegate as mysql_data |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from log_module import log_export, async_log_util |
| | | from log_module.log import hx_logger_l2_transaction, logger_debug, logger_request_api |
| | | from log_module.log import hx_logger_l2_transaction, logger_debug, logger_request_api, logger_system |
| | | from strategy import data_cache |
| | | from strategy.kpl_data_manager import KPLStockOfMarketsPlateLogManager, KPLMarketStockHeatLogManager |
| | | from strategy.forbidden_plates_manager import ForbiddenPlatesManager |
| | | from strategy.kpl_data_manager import KPLMarketsSiftPlateLogManager, KPLMarketStockHeatLogManager |
| | | from strategy.trade_setting import TradeSetting |
| | | from trade import huaxin_trade_api, huaxin_trade_data_update |
| | | from trade.huaxin_trade_record_manager import DelegateRecordManager, DealRecordManager, MoneyManager, PositionManager |
| | |
| | | "auto_buy": TradeSetting().get_auto_buy()} |
| | | response_data = json.dumps({"code": 0, "data": fdata}) |
| | | |
| | | elif url.path == "/set_trade_settings": |
| | | running = params_dict.get("running") |
| | | auto_sell = params_dict.get("auto_sell") |
| | | auto_buy = params_dict.get("auto_buy") |
| | | if running is not None: |
| | | TradeSetting().set_running(int(running)) |
| | | if auto_sell is not None: |
| | | TradeSetting().set_auto_sell(int(auto_sell)) |
| | | if auto_buy is not None: |
| | | TradeSetting().set_auto_buy(int(auto_buy)) |
| | | response_data = json.dumps({"code": 0, "data": {}}) |
| | | |
| | | elif url.path == "/get_env": |
| | | request_id = params_dict.get("request_id") |
| | | use_time_list = [] |
| | |
| | | if use_time_list and use_time_list[-1][1] > 10: |
| | | logger_debug.warning(f"环境获取时间大于10s({request_id}):{use_time_list}") |
| | | # 获取板块强度数据 |
| | | elif url.path == "/load_get_kpl_market_sift_plate": |
| | | elif url.path == "/load_kpl_market_sift_plate": |
| | | # 加载数据 |
| | | KPLStockOfMarketsPlateLogManager().load_data() |
| | | KPLMarketsSiftPlateLogManager().load_data() |
| | | response_data = json.dumps({"code": 0, "msg": "暂无内容"}) |
| | | elif url.path == "/get_kpl_market_sift_plate": |
| | | # 获取开盘啦流入板块详细信息 |
| | |
| | | time_str = params_dict.get("time") |
| | | if not time_str: |
| | | time_str = tool.get_now_time_str() |
| | | fdatas = KPLStockOfMarketsPlateLogManager().get_filter_log_datas() |
| | | fdatas = KPLMarketsSiftPlateLogManager().get_filter_log_datas() |
| | | response_data = json.dumps({"code": 1, "msg": "暂无内容"}) |
| | | for i in range(len(fdatas) - 1, -1, -1): |
| | | if fdatas[i][0] <= time_str: |
| | |
| | | # (距离09:15:00的秒数, 时间, 强度) |
| | | fdatas.append((tool.trade_time_sub(data[0], "09:15:00"), data[0], data[1])) |
| | | response_data = json.dumps({"code": 0, "data": fdatas}) |
| | | elif url.path == "/get_place_order_records": |
| | | datas = data_cache.purchased_stocks_details_list |
| | | response_data = json.dumps({"code": 0, "data": datas}) |
| | | elif url.path == "/get_forbidden_plates": |
| | | datas = ForbiddenPlatesManager().list_plates() |
| | | # human 认为设置 fixed: 固定的 |
| | | response_data = json.dumps( |
| | | {"code": 0, "data": {"human": list(datas), "fixed": list(constant.check_plate_list)}}) |
| | | elif url.path == "/add_forbidden_plate": |
| | | plate = params_dict.get("plate") |
| | | ForbiddenPlatesManager().add_plate(plate) |
| | | response_data = json.dumps({"code": 0, "data": {}}) |
| | | elif url.path == "/remove_forbidden_plate": |
| | | plate = params_dict.get("plate") |
| | | ForbiddenPlatesManager().remove_plate(plate) |
| | | response_data = json.dumps({"code": 0, "data": {}}) |
| | | elif url.path == "/get_market_sift_plate_stock_dict": |
| | | # 获取开盘啦板块精选流入 |
| | | data = data_cache.market_sift_plates |
| | | response_data = json.dumps({"code": 0, "data": data}) |
| | | |
| | | self.send_response(200) |
| | | # 发给请求客户端的响应数据 |
| | |
| | | else: |
| | | huaxin_trade_api.add_trade_callback_data(body) |
| | | result_str = json.dumps({"code": 0}) |
| | | elif url.path == "/set_trade_settings": |
| | | params = self.__parse_request() |
| | | if not self.__is_sign_right(params): |
| | | result_str = json.dumps({"code": 1001, "msg": "签名错误"}) |
| | | return |
| | | logger_debug.info(f"set_trade_settings: {params}") |
| | | running = params.get("running") |
| | | auto_sell = params.get("auto_sell") |
| | | auto_buy = params.get("auto_buy") |
| | | if running is not None: |
| | | TradeSetting().set_running(int(running)) |
| | | if auto_sell is not None: |
| | | TradeSetting().set_auto_sell(int(auto_sell)) |
| | | if auto_buy is not None: |
| | | TradeSetting().set_auto_buy(int(auto_buy)) |
| | | result_str = json.dumps({"code": 0, "data": {}}) |
| | | |
| | | elif url.path == "/buy": |
| | | # 签名验证 |
| | | params = self.__parse_request() |
| | |
| | | print("HTTP server is at: http://%s:%d/" % (addr, port)) |
| | | httpd.serve_forever() |
| | | except Exception as e: |
| | | pass |
| | | logger_system.exception(e) |
| | | |
| | | |
| | | if __name__ == "__main__": |