Pārlūkot izejas kodu

支持识别开发模式。

skyffire 1 gadu atpakaļ
vecāks
revīzija
35f86556b9
2 mainītis faili ar 29 papildinājumiem un 17 dzēšanām
  1. 1 1
      kappa/rest_server.py
  2. 28 16
      kappa/ws_client.py

+ 1 - 1
kappa/rest_server.py

@@ -28,7 +28,7 @@ class MyRequestHandler(http.server.BaseHTTPRequestHandler):
         pass
 
 
-PORT = 8000
+PORT = 9999
 
 
 def start_http_server():

+ 28 - 16
kappa/ws_client.py

@@ -1,3 +1,4 @@
+import os
 import traceback
 
 import websocket
@@ -26,22 +27,33 @@ def on_open(_ws):
 ws_trade = websocket.WebSocketApp(SOCKET_TRADE, on_message=on_message_trade, on_error=on_error, on_open=on_open)
 ws_depth = websocket.WebSocketApp(SOCKET_DEPTH, on_message=on_message_depth, on_error=on_error, on_open=on_open)
 
-# 定义要传递给 run_forever 的参数
-http_proxy_host = "127.0.0.1"
-http_proxy_port = 7890
-proxy_type = "http"
-
-# Run the WebSocket with proxy settings
-trade_thread = threading.Thread(target=ws_trade.run_forever, kwargs={
-    'http_proxy_host': http_proxy_host,
-    'http_proxy_port': http_proxy_port,
-    'proxy_type': proxy_type
-})
-depth_thread = threading.Thread(target=ws_depth.run_forever, kwargs={
-    'http_proxy_host': http_proxy_host,
-    'http_proxy_port': http_proxy_port,
-    'proxy_type': proxy_type
-})
+# 识别开发模式
+app_mode = os.getenv('APP_MODE', 'production')
+
+if app_mode == 'development':
+    # 在开发模式下执行的代码
+    # 定义要传递给 run_forever 的参数
+    http_proxy_host = "127.0.0.1"
+    http_proxy_port = 7890
+    proxy_type = "http"
+
+    # Run the WebSocket with proxy settings
+    trade_thread = threading.Thread(target=ws_trade.run_forever, kwargs={
+        'http_proxy_host': http_proxy_host,
+        'http_proxy_port': http_proxy_port,
+        'proxy_type': proxy_type
+    })
+    depth_thread = threading.Thread(target=ws_depth.run_forever, kwargs={
+        'http_proxy_host': http_proxy_host,
+        'http_proxy_port': http_proxy_port,
+        'proxy_type': proxy_type
+    })
+
+# 在生产模式下执行的代码
+else:
+    # Run the WebSocket with proxy settings
+    trade_thread = threading.Thread(target=ws_trade.run_forever)
+    depth_thread = threading.Thread(target=ws_depth.run_forever)
 
 
 def start_ws_clients():