futu-stock-mcp-server 0.1.4__py3-none-any.whl → 0.1.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of futu-stock-mcp-server might be problematic. Click here for more details.

@@ -569,87 +569,50 @@ def init_futu_connection() -> bool:
569
569
  # Log to file only
570
570
  logger.info(f"Initializing Futu connection to {host}:{port}")
571
571
 
572
- # Temporarily redirect stderr to capture any futu library output
573
- original_stderr = None
574
- futu_log_file = None
575
- futu_log_fd = None
576
-
577
- if os.getenv('MCP_MODE') == '1' and _stderr_redirected:
578
- try:
579
- # Create a special log file for futu connection logs
580
- home_dir = os.path.expanduser("~")
581
- log_dir = os.path.join(home_dir, "logs")
582
- os.makedirs(log_dir, exist_ok=True)
583
- futu_log_file = os.path.join(log_dir, "futu_connection.log")
584
-
585
- # Save current stderr (should be devnull)
586
- original_stderr = sys.stderr
587
-
588
- # Redirect stderr to futu log file temporarily
589
- futu_log_fd = open(futu_log_file, 'a')
590
- sys.stderr = futu_log_fd
591
- except Exception as e:
592
- logger.debug(f"Could not redirect stderr for futu connection: {e}")
572
+ # Initialize quote context
573
+ quote_ctx = OpenQuoteContext(host=host, port=port)
574
+
575
+ # Initialize trade context if needed
576
+ if os.getenv('FUTU_ENABLE_TRADING', '0') == '1':
577
+ # Get trading parameters
578
+ trade_env = os.getenv('FUTU_TRADE_ENV', 'SIMULATE')
579
+ security_firm = os.getenv('FUTU_SECURITY_FIRM', 'FUTUSECURITIES')
580
+ trd_market = os.getenv('FUTU_TRD_MARKET', 'HK')
581
+
582
+ # Map environment strings to Futu enums
583
+ trade_env_enum = {
584
+ 'REAL': TrdMarket.REAL,
585
+ 'SIMULATE': TrdMarket.SIMULATE
586
+ }.get(trade_env, TrdMarket.SIMULATE)
587
+
588
+ security_firm_enum = {
589
+ 'FUTUSECURITIES': SecurityFirm.FUTUSECURITIES,
590
+ 'FUTUINC': SecurityFirm.FUTUINC
591
+ }.get(security_firm, SecurityFirm.FUTUSECURITIES)
592
+
593
+ trd_market_enum = {
594
+ 'HK': TrdMarket.HK,
595
+ 'US': TrdMarket.US,
596
+ 'CN': TrdMarket.CN,
597
+ 'HKCC': TrdMarket.HKCC,
598
+ 'AU': TrdMarket.AU
599
+ }.get(trd_market, TrdMarket.HK)
600
+
601
+ # Initialize trade context
602
+ trade_ctx = OpenSecTradeContext(
603
+ host=host,
604
+ port=port,
605
+ security_firm=security_firm_enum
606
+ )
607
+ _is_trade_initialized = True
608
+ logger.info("Trade context initialized successfully")
593
609
 
594
- try:
595
- # Initialize quote context
596
- quote_ctx = OpenQuoteContext(host=host, port=port)
597
-
598
- # Initialize trade context if needed
599
- if os.getenv('FUTU_ENABLE_TRADING', '0') == '1':
600
- # Get trading parameters
601
- trade_env = os.getenv('FUTU_TRADE_ENV', 'SIMULATE')
602
- security_firm = os.getenv('FUTU_SECURITY_FIRM', 'FUTUSECURITIES')
603
- trd_market = os.getenv('FUTU_TRD_MARKET', 'HK')
604
-
605
- # Map environment strings to Futu enums
606
- trade_env_enum = {
607
- 'REAL': TrdMarket.REAL,
608
- 'SIMULATE': TrdMarket.SIMULATE
609
- }.get(trade_env, TrdMarket.SIMULATE)
610
-
611
- security_firm_enum = {
612
- 'FUTUSECURITIES': SecurityFirm.FUTUSECURITIES,
613
- 'FUTUINC': SecurityFirm.FUTUINC
614
- }.get(security_firm, SecurityFirm.FUTUSECURITIES)
615
-
616
- trd_market_enum = {
617
- 'HK': TrdMarket.HK,
618
- 'US': TrdMarket.US,
619
- 'CN': TrdMarket.CN,
620
- 'HKCC': TrdMarket.HKCC,
621
- 'AU': TrdMarket.AU
622
- }.get(trd_market, TrdMarket.HK)
623
-
624
- # Initialize trade context
625
- trade_ctx = OpenSecTradeContext(
626
- host=host,
627
- port=port,
628
- security_firm=security_firm_enum
629
- )
630
- _is_trade_initialized = True
631
- logger.info("Trade context initialized successfully")
632
-
633
- logger.info("Futu connection initialized successfully")
634
- return True
635
-
636
- finally:
637
- # Restore stderr redirection
638
- if futu_log_fd:
639
- try:
640
- futu_log_fd.close()
641
- except:
642
- pass
643
- # Restore original stderr (should be devnull)
644
- if original_stderr:
645
- sys.stderr = original_stderr
610
+ logger.info("Futu connection initialized successfully")
611
+ return True
646
612
 
647
613
  except Exception as e:
648
614
  error_msg = f"Failed to initialize Futu connection: {str(e)}"
649
615
  logger.error(error_msg)
650
- # Make sure we restore stderr even in case of errors
651
- if _stderr_redirected and _stderr_backup:
652
- sys.stderr = _stderr_backup
653
616
  return False
654
617
 
655
618
  @asynccontextmanager
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: futu-stock-mcp-server
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: A Model Context Protocol (MCP) server for accessing Futu OpenAPI functionality
5
5
  Project-URL: Homepage, https://github.com/shuizhengqi1/futu-stock-mcp-server
6
6
  Project-URL: Documentation, https://github.com/shuizhengqi1/futu-stock-mcp-server#readme
@@ -0,0 +1,7 @@
1
+ futu_stock_mcp_server/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ futu_stock_mcp_server/server.py,sha256=oMD3yHyBmECzqxQa7LU-QuPSDLkLo0RsluXACNeLKM0,65035
3
+ futu_stock_mcp_server-0.1.5.dist-info/METADATA,sha256=04hyGftEjBkbcpdA-zSJ3YoZmzUKGf6HtTSQJ76IMww,21041
4
+ futu_stock_mcp_server-0.1.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
+ futu_stock_mcp_server-0.1.5.dist-info/entry_points.txt,sha256=GAdKqPJD9dJ_fRA3e3m0NRia0elN5OcjEeAI30vOcIM,70
6
+ futu_stock_mcp_server-0.1.5.dist-info/licenses/LICENSE,sha256=XQBSQkjjpkymu_uLdyis4oNynV60VH1X7nS16uwM6g0,1069
7
+ futu_stock_mcp_server-0.1.5.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- futu_stock_mcp_server/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- futu_stock_mcp_server/server.py,sha256=SokGZ3seYN1KwNozJqpbAmRsjcoYVSJ8v_wvMHu3pcs,66611
3
- futu_stock_mcp_server-0.1.4.dist-info/METADATA,sha256=V8KxUH0ehGGfS7FtOGMH6t-kk1NYkKHhFLi3Vg84FO4,21041
4
- futu_stock_mcp_server-0.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
- futu_stock_mcp_server-0.1.4.dist-info/entry_points.txt,sha256=GAdKqPJD9dJ_fRA3e3m0NRia0elN5OcjEeAI30vOcIM,70
6
- futu_stock_mcp_server-0.1.4.dist-info/licenses/LICENSE,sha256=XQBSQkjjpkymu_uLdyis4oNynV60VH1X7nS16uwM6g0,1069
7
- futu_stock_mcp_server-0.1.4.dist-info/RECORD,,