-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgroup_config.py
More file actions
64 lines (47 loc) · 2.18 KB
/
Copy pathgroup_config.py
File metadata and controls
64 lines (47 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Build V2 analytics and colocated spot-group negotiation payloads."""
from typing import Dict, List
V2_HUB_PREFIX = "v2_"
ANALYTICS_GROUP_MARKERS = ("_classic_", "_state_", "_orderflow_")
def analytics_group_ticker(group: str) -> str:
"""Return the ticker from one unprefixed analytics group."""
normalized = group.strip()
if normalized.lower().endswith("_spot"):
raise ValueError(
"Configure analytics groups only; spot groups are added automatically."
)
for marker in ANALYTICS_GROUP_MARKERS:
marker_index = normalized.lower().find(marker)
if marker_index > 0:
return normalized[:marker_index]
raise ValueError(f"Cannot derive a ticker from analytics group: {group}")
def add_colocated_spot_groups(
analytics_group_config: Dict[str, List[str]],
) -> Dict[str, List[str]]:
"""Add one matching ticker spot group to each V2 analytics hub."""
group_config: Dict[str, List[str]] = {}
for hub, analytics_groups in analytics_group_config.items():
if not hub.startswith(V2_HUB_PREFIX):
raise ValueError(f"V2 group configuration requires a v2_* hub: {hub}")
tickers = list(
dict.fromkeys(analytics_group_ticker(group) for group in analytics_groups)
)
group_config[hub] = [
*analytics_groups,
*(f"{ticker}_spot" for ticker in tickers),
]
return group_config
def build_post_groups(group_config: Dict[str, List[str]]) -> List[str]:
"""Build the unqualified POST group list with duplicate spot names removed."""
return list(
dict.fromkeys(group for groups in group_config.values() for group in groups)
)
def build_patch_groups(group_config: Dict[str, List[str]]) -> List[Dict[str, str]]:
"""Build the hub-qualified full replacement list for PATCH negotiation."""
return [
{"hub": hub, "group": group}
for hub, groups in group_config.items()
for group in groups
]
def count_group_memberships(group_config: Dict[str, List[str]]) -> int:
"""Count the final hub-and-group memberships enforced by the backend limit."""
return sum(len(groups) for groups in group_config.values())