cnhkmcp 1.1.9__tar.gz → 1.2.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cnhkmcp
3
- Version: 1.1.9
3
+ Version: 1.2.1
4
4
  Summary: A comprehensive Model Context Protocol (MCP) server for quantitative trading platform integration
5
5
  Home-page: https://github.com/cnhk/cnhkmcp
6
6
  Author: CNHK
@@ -50,7 +50,7 @@ from .untracked.forum_functions import (
50
50
  read_full_forum_post
51
51
  )
52
52
 
53
- __version__ = "1.1.9"
53
+ __version__ = "1.2.1"
54
54
  __author__ = "CNHK"
55
55
  __email__ = "cnhk@example.com"
56
56
 
@@ -436,22 +436,53 @@ class BrainApiClient:
436
436
  try:
437
437
  response = self.session.get(f"{self.base_url}/alphas/{alpha_id}/recordsets/pnl")
438
438
  response.raise_for_status()
439
- return response.json()
439
+ # Some alphas may return 204 No Content or an empty body
440
+ text = (response.text or "").strip()
441
+ if not text:
442
+ return {}
443
+ try:
444
+ return response.json()
445
+ except Exception as parse_err:
446
+ self.log(f"PnL JSON parse failed for {alpha_id}: {parse_err}", "WARNING")
447
+ return {}
440
448
  except Exception as e:
441
449
  self.log(f"Failed to get alpha PnL: {str(e)}", "ERROR")
442
450
  raise
443
451
 
444
- async def get_user_alphas(self, stage: str = "IS", limit: int = 100, offset: int = 0) -> Dict[str, Any]:
445
- """Get user's alphas."""
452
+ async def get_user_alphas(
453
+ self,
454
+ stage: str = "OS",
455
+ limit: int = 30,
456
+ offset: int = 0,
457
+ start_date: Optional[str] = None,
458
+ end_date: Optional[str] = None,
459
+ submission_start_date: Optional[str] = None,
460
+ submission_end_date: Optional[str] = None,
461
+ order: Optional[str] = None,
462
+ hidden: Optional[bool] = None,
463
+ ) -> Dict[str, Any]:
464
+ """Get user's alphas with advanced filtering."""
446
465
  await self.ensure_authenticated()
447
466
 
448
467
  try:
449
468
  params = {
450
- 'stage': stage,
451
- 'limit': limit,
452
- 'offset': offset
469
+ "stage": stage,
470
+ "limit": limit,
471
+ "offset": offset,
453
472
  }
454
-
473
+ if start_date:
474
+ params["dateCreated>"] = start_date
475
+ if end_date:
476
+ params["dateCreated<"] = end_date
477
+ if submission_start_date:
478
+ params["dateSubmitted>"] = submission_start_date
479
+ if submission_end_date:
480
+ params["dateSubmitted<"] = submission_end_date
481
+ if order:
482
+ params["order"] = order
483
+ if hidden is not None:
484
+ params["hidden"] = str(hidden).lower()
485
+
455
486
  response = self.session.get(f"{self.base_url}/users/self/alphas", params=params)
456
487
  response.raise_for_status()
457
488
  return response.json()
@@ -763,9 +794,11 @@ class BrainApiClient:
763
794
  await self.ensure_authenticated()
764
795
 
765
796
  try:
766
- response = self.session.get(f"{self.base_url}/alphas/{alpha_id}/recordsets/production-correlation")
797
+ response = self.session.get(f"{self.base_url}/alphas/{alpha_id}/correlations/prod")
767
798
  response.raise_for_status()
768
- return response.json()
799
+ if response.text:
800
+ return response.json()
801
+ return {} # Return empty dict for empty response
769
802
  except Exception as e:
770
803
  self.log(f"Failed to get production correlation: {str(e)}", "ERROR")
771
804
  raise
@@ -775,9 +808,11 @@ class BrainApiClient:
775
808
  await self.ensure_authenticated()
776
809
 
777
810
  try:
778
- response = self.session.get(f"{self.base_url}/alphas/{alpha_id}/recordsets/self-correlation")
811
+ response = self.session.get(f"{self.base_url}/alphas/{alpha_id}/correlations/self")
779
812
  response.raise_for_status()
780
- return response.json()
813
+ if response.text:
814
+ return response.json()
815
+ return {} # Return empty dict for empty response
781
816
  except Exception as e:
782
817
  self.log(f"Failed to get self correlation: {str(e)}", "ERROR")
783
818
  raise
@@ -1473,20 +1508,69 @@ async def get_alpha_pnl(alpha_id: str) -> Dict[str, Any]:
1473
1508
  return {"error": str(e)}
1474
1509
 
1475
1510
  @mcp.tool()
1476
- async def get_user_alphas(stage: str = "IS", limit: int = 100, offset: int = 0) -> Dict[str, Any]:
1511
+ async def get_user_alphas(
1512
+ stage: str = "IS",
1513
+ limit: int = 30,
1514
+ offset: int = 0,
1515
+ start_date: Optional[str] = None,
1516
+ end_date: Optional[str] = None,
1517
+ submission_start_date: Optional[str] = None,
1518
+ submission_end_date: Optional[str] = None,
1519
+ order: Optional[str] = None,
1520
+ hidden: Optional[bool] = None,
1521
+ ) -> Dict[str, Any]:
1477
1522
  """
1478
- 👤 Get user's alphas.
1479
-
1523
+ 👤 Get user's alphas with advanced filtering, pagination, and sorting.
1524
+
1525
+ This tool retrieves a list of your alphas, allowing for detailed filtering based on stage,
1526
+ creation date, submission date, and visibility. It also supports pagination and custom sorting.
1527
+
1480
1528
  Args:
1481
- stage: Alpha stage ("IS" for in-sample, "OS" for out-of-sample)
1482
- limit: Maximum number of alphas to return
1483
- offset: Offset for pagination, if the desired total number is larger than 100. then it is useful, every page, the load max is 100 alphas.
1529
+ stage (str): The stage of the alphas to retrieve.
1530
+ - "IS": In-Sample (alphas that have not been submitted).
1531
+ - "OS": Out-of-Sample (alphas that have been submitted).
1532
+ Defaults to "IS".
1533
+ limit (int): The maximum number of alphas to return in a single request.
1534
+ For example, `limit=50` will return at most 50 alphas. Defaults to 30.
1535
+ offset (int): The number of alphas to skip from the beginning of the list.
1536
+ Used for pagination. For example, `limit=50, offset=50` will retrieve alphas 51-100.
1537
+ Defaults to 0.
1538
+ start_date (Optional[str]): The earliest creation date for the alphas to be included.
1539
+ Filters for alphas created on or after this date.
1540
+ Example format: "2023-01-01T00:00:00Z".
1541
+ end_date (Optional[str]): The latest creation date for the alphas to be included.
1542
+ Filters for alphas created before this date.
1543
+ Example format: "2023-12-31T23:59:59Z".
1544
+ submission_start_date (Optional[str]): The earliest submission date for the alphas.
1545
+ Only applies to "OS" alphas. Filters for alphas submitted on or after this date.
1546
+ Example format: "2024-01-01T00:00:00Z".
1547
+ submission_end_date (Optional[str]): The latest submission date for the alphas.
1548
+ Only applies to "OS" alphas. Filters for alphas submitted before this date.
1549
+ Example format: "2024-06-30T23:59:59Z".
1550
+ order (Optional[str]): The sorting order for the returned alphas.
1551
+ Prefix with a hyphen (-) for descending order.
1552
+ Examples: "name" (sort by name ascending), "-dateSubmitted" (sort by submission date descending).
1553
+ hidden (Optional[bool]): Filter alphas based on their visibility.
1554
+ - `True`: Only return hidden alphas.
1555
+ - `False`: Only return non-hidden alphas.
1556
+ If not provided, both hidden and non-hidden alphas are returned.
1484
1557
 
1485
1558
  Returns:
1486
- User's alphas
1559
+ Dict[str, Any]: A dictionary containing a list of alpha details under the 'results' key,
1560
+ along with pagination information. If an error occurs, it returns a dictionary with an 'error' key.
1487
1561
  """
1488
1562
  try:
1489
- return await brain_client.get_user_alphas(stage, limit, offset)
1563
+ return await brain_client.get_user_alphas(
1564
+ stage=stage,
1565
+ limit=limit,
1566
+ offset=offset,
1567
+ start_date=start_date,
1568
+ end_date=end_date,
1569
+ submission_start_date=submission_start_date,
1570
+ submission_end_date=submission_end_date,
1571
+ order=order,
1572
+ hidden=hidden,
1573
+ )
1490
1574
  except Exception as e:
1491
1575
  return {"error": str(e)}
1492
1576
 
@@ -1564,35 +1648,7 @@ async def save_simulation_data(simulation_id: str, filename: str) -> Dict[str, A
1564
1648
  except Exception as e:
1565
1649
  return {"error": str(e)}
1566
1650
 
1567
- @mcp.tool()
1568
- async def analyze_alpha_performance(alpha_id: str) -> Dict[str, Any]:
1569
- """
1570
- 📊 Comprehensive alpha performance analysis.
1571
-
1572
- Args:
1573
- alpha_id: The alpha ID to analyze
1574
-
1575
- Returns:
1576
- Comprehensive performance analysis
1577
- """
1578
- try:
1579
- # Get alpha details
1580
- alpha_details = await brain_client.get_alpha_details(alpha_id)
1581
-
1582
- # Get PnL data
1583
- pnl_data = await brain_client.get_alpha_pnl(alpha_id)
1584
-
1585
- # Get yearly stats if available
1586
- yearly_stats = await brain_client.get_alpha_yearly_stats(alpha_id)
1587
-
1588
- return {
1589
- "alpha_details": alpha_details,
1590
- "pnl_data": pnl_data,
1591
- "yearly_stats": yearly_stats,
1592
- "analysis_timestamp": datetime.now().isoformat()
1593
- }
1594
- except Exception as e:
1595
- return {"error": str(e)}
1651
+
1596
1652
 
1597
1653
  @mcp.tool()
1598
1654
  async def get_operators() -> Dict[str, Any]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cnhkmcp
3
- Version: 1.1.9
3
+ Version: 1.2.1
4
4
  Summary: A comprehensive Model Context Protocol (MCP) server for quantitative trading platform integration
5
5
  Home-page: https://github.com/cnhk/cnhkmcp
6
6
  Author: CNHK
@@ -13,7 +13,7 @@ def read_requirements():
13
13
 
14
14
  setup(
15
15
  name="cnhkmcp",
16
- version="1.1.9",
16
+ version="1.2.1",
17
17
  author="CNHK",
18
18
  author_email="cnhk@example.com",
19
19
  description="A comprehensive Model Context Protocol (MCP) server for quantitative trading platform integration",
File without changes
File without changes
File without changes
File without changes
File without changes