From 7d7653d13ff86e0990b82430f11fc764bd542580 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 29 十一月 2023 15:59:51 +0800
Subject: [PATCH] bug修复

---
 middle_api_server.py |   60 ++++++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/middle_api_server.py b/middle_api_server.py
index 2528835..c0fc0b2 100644
--- a/middle_api_server.py
+++ b/middle_api_server.py
@@ -6,6 +6,7 @@
 import threading
 import time
 
+import constant
 import socket_manager
 import trade_manager
 from db import mysql_data, redis_manager
@@ -130,26 +131,35 @@
                         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妗d环鍗�
-                            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"]
@@ -278,6 +288,28 @@
                     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:
@@ -433,7 +465,7 @@
 
 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()

--
Gitblit v1.8.0