| | |
| | | import platform |
| | | |
| | | TEST = True |
| | | IS_A = False |
| | | |
| | | ##B类## |
| | | MIDDLE_SERVER_PORT = 10008 |
| | | MIDDLE_API_SERVER_PORT = 11008 |
| | | DATA_SERVER_PORT = 9004 |
| | | |
| | | ##A类## |
| | | if IS_A: |
| | | MIDDLE_SERVER_PORT = 10009 |
| | | MIDDLE_API_SERVER_PORT = 11009 |
| | | DATA_SERVER_PORT = 9005 |
| | | |
| | | # 买入分数分档 |
| | | BUY_SCORE_RANK_0 = 150 |
| | |
| | | # "pwd": "123456" |
| | | } |
| | | |
| | | if IS_A: |
| | | REDIS_CONFIG = { |
| | | "host": "172.16.32.8", |
| | | "port": 6379, |
| | | "db": 0, |
| | | "pwd": "Yeshi2016@" |
| | | } |
| | | |
| | | MYSQL_CONFIG = { |
| | | "host": "192.168.3.252", |
| | | "port": 3306, |
| | |
| | | "passwd": "Yeshi2016@" |
| | | } |
| | | |
| | | if IS_A: |
| | | MYSQL_CONFIG = { |
| | | "host": "172.16.16.17", |
| | | "port": 3306, |
| | | "database": "gp_a", |
| | | "charset": "utf8", |
| | | "user": "root", |
| | | "passwd": "Yeshi2016@" |
| | | } |
| | | |
| | | |
| | | # 获取根路径 |
| | | def get_path_prefix(): |
| | |
| | | (k, len(limit_up_reason_dict[k]), limit_up_reason_want_count_dict.get(k), limit_up_reason_dict[k][0][5]) for |
| | | k in |
| | | limit_up_reason_dict] |
| | | limit_up_reason_statistic_info.sort(key=lambda x: int(x[3])) |
| | | limit_up_reason_statistic_info.sort(key=lambda x: int(x[1])) |
| | | limit_up_reason_statistic_info.reverse() |
| | | |
| | | codes_set = set([d[3] for d in total_datas]) |
| | | # 判断是龙几,判断是否涨停,判断是否炸板,加载分数 |
| | |
| | | import threading |
| | | |
| | | import constant |
| | | import data_server |
| | | import middle_api_server |
| | | import middle_server |
| | |
| | | if __name__ == "__main__": |
| | | t1 = threading.Thread(target=lambda: middle_api_server.run(), daemon=True) |
| | | t1.start() |
| | | t1 = threading.Thread(target=lambda: data_server.run("0.0.0.0", 9004), daemon=True) |
| | | t1 = threading.Thread(target=lambda: data_server.run("0.0.0.0", constant.DATA_SERVER_PORT), daemon=True) |
| | | t1.start() |
| | | middle_server.run() |
| | |
| | | import threading |
| | | import time |
| | | |
| | | import constant |
| | | import socket_manager |
| | | import trade_manager |
| | | from db import mysql_data, redis_manager |
| | |
| | | codes_data = data_json["data"] |
| | | code = codes_data["code"] |
| | | volume = codes_data["volume"] |
| | | price = codes_data["price"] |
| | | # 是否强制卖0/1 |
| | | force_sell = codes_data["force"] |
| | | if not price: |
| | | # 获取现价 |
| | | prices = HistoryKDatasUtils.get_now_price([code]) |
| | | if not prices: |
| | | raise Exception("现价获取失败") |
| | | # 已现价的5档价卖 |
| | | price = prices[0][1] - 0.04 |
| | | |
| | | price_type = codes_data["price_type"] |
| | | result = hosting_api_util.trade_order(hosting_api_util.TRADE_DIRECTION_SELL, code, volume, |
| | | price) |
| | | '',price_type=price_type) |
| | | if result["code"] == 0: |
| | | return_str = json.dumps({"code": 0, "msg": ""}) |
| | | return_str = json.dumps(result) |
| | | else: |
| | | raise Exception(result["msg"]) |
| | | print("---卖出结果----") |
| | | print(result) |
| | | break |
| | | elif type_ == 'get_code_position_info': |
| | | # 验证签名 |
| | | if not is_sign_right: |
| | | raise Exception("签名错误") |
| | | codes_data = data_json["data"] |
| | | code = codes_data["code"] |
| | | result = hosting_api_util.get_code_position_info(code) |
| | | return_str = json.dumps(result) |
| | | break |
| | | |
| | | elif type_ == 'common': |
| | | # 验证签名 |
| | | if not is_sign_right: |
| | | raise Exception("签名错误") |
| | | params = data_json["data"] |
| | | result = hosting_api_util.common_request(params) |
| | | return_str = json.dumps(result) |
| | | break |
| | | |
| | | elif type_ == 'get_cost_price': |
| | | # 获取成本价 |
| | | codes_data = data_json["data"] |
| | |
| | | elif type_ == "trade_server_channels": |
| | | channels = socket_manager.ClientSocketManager.list_client() |
| | | return_str = json.dumps({"code": 0, "data": channels}) |
| | | elif type_ == "save_running_data": |
| | | result = hosting_api_util.save_running_data() |
| | | return_str = json.dumps(result) |
| | | elif type_ == "add_sell_rule": |
| | | result = hosting_api_util.sell_rule(hosting_api_util.OPERRATE_ADD, data=data_json["data"]) |
| | | return_str = json.dumps(result) |
| | | elif type_ == "del_sell_rule": |
| | | id_ = data_json["data"]["id"] |
| | | result = hosting_api_util.sell_rule(hosting_api_util.OPERRATE_DELETE, data={"id": id_}) |
| | | return_str = json.dumps(result) |
| | | elif type_ == "list_sell_rule": |
| | | result = hosting_api_util.sell_rule(hosting_api_util.OPERRATE_GET, data={}) |
| | | return_str = json.dumps(result) |
| | | elif type_ == "get_code_position_info": |
| | | code = data_json["data"]["code"] |
| | | result = hosting_api_util.get_code_position_info(code) |
| | | return_str = json.dumps(result) |
| | | elif type_ == "common": |
| | | params = data_json["data"] |
| | | result = hosting_api_util.common_request(params) |
| | | return_str = json.dumps(result) |
| | | |
| | | break |
| | | # sk.close() |
| | | except Exception as e: |
| | |
| | | |
| | | def run(): |
| | | print("create middle_api_server") |
| | | laddr = "0.0.0.0", 10009 |
| | | laddr = "0.0.0.0", constant.MIDDLE_API_SERVER_PORT |
| | | print("middle_api_server is at: http://%s:%d/" % (laddr)) |
| | | tcpserver = MyThreadingTCPServer(laddr, MyBaseRequestHandle) # 注意:参数是MyBaseRequestHandle |
| | | tcpserver.serve_forever() |
| | |
| | | import threading |
| | | import time |
| | | |
| | | import constant |
| | | import socket_manager |
| | | from db import mysql_data |
| | | from db.redis_manager import RedisUtils, RedisManager |
| | |
| | | t1 = threading.Thread(target=lambda: clear_invalid_client(), daemon=True) |
| | | t1.start() |
| | | |
| | | laddr = "0.0.0.0", 10008 |
| | | laddr = "0.0.0.0", constant.MIDDLE_SERVER_PORT |
| | | print("MiddleServer is at: http://%s:%d/" % (laddr)) |
| | | tcpserver = MyThreadingTCPServer(laddr, MyBaseRequestHandle) # 注意:参数是MyBaseRequestHandle |
| | | tcpserver.serve_forever() |
| | |
| | | OPERRATE_SET = 1 # 设置 |
| | | OPERRATE_DELETE = 2 # 删除 |
| | | OPERRATE_GET = 3 # 获取 |
| | | OPERRATE_ADD = 4 # 添加 |
| | | |
| | | # 代码名单类型 |
| | | CODE_LIST_WHITE = "white" |
| | |
| | | API_TYPE_TRADE = "trade" # 交易 |
| | | API_TYPE_TRADE_STATE = "trade_state" # 交易状态 |
| | | API_TYPE_TRADE_MODE = "trade_mode" # 交易模式 |
| | | API_TYPE_SELL_RULE = "sell_rule" # 卖出规则 |
| | | API_TYPE_CODE_LIST = "code_list" # 代码名单 |
| | | API_TYPE_EXPORT_L2 = "export_l2" # 导出L2数据 |
| | | API_TYPE_INIT = "init" # 初始化 |
| | |
| | | API_TYPE_GET_FROM_DATA_SERVER = "get_from_data_server" # 从数据服务器拉取数据 |
| | | API_TYPE_CODE_TRADE_INFO = "code_trade_info" # 代码交易信息 |
| | | API_TYPE_CODE_L2_LISTEN_ACTIVE_COUNT = "l2_listen_active_count" # L2有效监听数量 |
| | | API_TYPE_SAVE_RUNNING_DATA = "save_running_data" # 保存运行时数据 |
| | | API_TYPE_GET_CODE_POSITION_INFO = "get_code_position_info" # 获取代码持仓信息 |
| | | API_TYPE_COMMON_REQUEST = "common_request" # 通用请求 |
| | | # 超时时间2s |
| | | TIMEOUT = 5.0 |
| | | |
| | |
| | | return __read_response(client, request_id, blocking, timeout=30) |
| | | |
| | | |
| | | # 保存正在运行的数据 |
| | | def save_running_data(blocking=True): |
| | | request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE, |
| | | {"type": API_TYPE_SAVE_RUNNING_DATA, |
| | | "sinfo": f"cb_{API_TYPE_SAVE_RUNNING_DATA}_{round(time.time() * 1000)}"}) |
| | | return __read_response(client, request_id, blocking, timeout=30) |
| | | |
| | | |
| | | # 保存正在运行的数据 |
| | | def sell_rule(operate, data={}, blocking=True): |
| | | request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE, |
| | | {"type": API_TYPE_SELL_RULE, "operate": operate, "data": data, |
| | | "sinfo": f"cb_{API_TYPE_SELL_RULE}_{round(time.time() * 1000)}"}) |
| | | return __read_response(client, request_id, blocking, timeout=30) |
| | | |
| | | |
| | | # 获取代码持仓信息 |
| | | def get_code_position_info(code, blocking=True): |
| | | request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE, |
| | | {"type": API_TYPE_GET_CODE_POSITION_INFO, "code": code, |
| | | "sinfo": f"cb_{API_TYPE_GET_CODE_POSITION_INFO}_{round(time.time() * 1000)}"}) |
| | | return __read_response(client, request_id, blocking, timeout=30) |
| | | |
| | | |
| | | def common_request(params={}, blocking=True): |
| | | data = {"type": API_TYPE_COMMON_REQUEST, |
| | | "sinfo": f"cb_{API_TYPE_COMMON_REQUEST}_{round(time.time() * 1000)}"} |
| | | if params: |
| | | for k in params: |
| | | data[k] = params[k] |
| | | request_id, client = __request(ClientSocketManager.CLIENT_TYPE_TRADE, data) |
| | | return __read_response(client, request_id, blocking, timeout=30) |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | d = {"id": "123123"} |
| | | print(d.pop("id")) |