admin
2025-03-10 a21cbb2a3e01e088c9cebc7c38c02e7e5d614cbe
data_server.py
@@ -1,4 +1,5 @@
import concurrent.futures
import copy
import hashlib
import http
import json
@@ -32,6 +33,9 @@
        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":
            # 获取资金信息
@@ -87,6 +91,11 @@
                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')
@@ -144,7 +153,7 @@
                    pre_price = data[1]
                    current_price = data[2] if data[2] else data[5][0][0]
                    price = tool.get_buy_max_price(current_price)
                    price = min(price, tool.get_limit_up_price(code,pre_price))
                    price = min(price, tool.get_limit_up_price(code, pre_price))
                else:
                    price = round(float(params.get("price")), 2)  # 价格
                result = huaxin_trade_api.order(1, code, volume, price, blocking=True)
@@ -173,6 +182,45 @@
                    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()
                # 签名验证
@@ -229,3 +277,7 @@
        httpd.serve_forever()
    except Exception as e:
        pass
if __name__ == "__main__":
    run()