-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
201 lines (172 loc) · 5.85 KB
/
Copy pathsetup.py
File metadata and controls
201 lines (172 loc) · 5.85 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
"""Interactive setup for Mirofish API keys and configuration.
Run: python setup.py
Creates: config/local.yaml (gitignored, never committed)
"""
import os
import sys
from pathlib import Path
QUANT_ROOT = Path(__file__).parent
CONFIG_DIR = QUANT_ROOT / "config"
LOCAL_YAML = CONFIG_DIR / "local.yaml"
ENV_FILE = QUANT_ROOT / ".env"
def prompt_key(name: str, env_var: str, required: bool = True) -> str:
"""Prompt user for an API key, checking environment first."""
existing = os.environ.get(env_var, "")
if existing:
masked = existing[:8] + "..." + existing[-4:]
print(f" {name}: Found in environment ({masked})")
return existing
hint = " (REQUIRED)" if required else " (optional, press Enter to skip)"
value = input(f" Enter {name}{hint}: ").strip()
if required and not value:
print(f" WARNING: {name} is required for core functionality.")
return value
def write_local_yaml(keys: dict) -> None:
"""Write config/local.yaml with API keys."""
content = f"""# Mirofish Local Configuration
# AUTO-GENERATED by setup.py — DO NOT COMMIT
# This file is gitignored.
api_keys:
anthropic: "{keys.get('anthropic', '')}"
openai: "{keys.get('openai', '')}"
polymarket_api_key: "{keys.get('polymarket_api_key', '')}"
polymarket_secret: "{keys.get('polymarket_secret', '')}"
polymarket_passphrase: "{keys.get('polymarket_passphrase', '')}"
news_api: "{keys.get('news_api', '')}"
# Override any default.yaml settings below:
risk:
paper_trading: true # SAFETY: always start with paper trading
"""
LOCAL_YAML.write_text(content, encoding="utf-8")
print(f"\n Config written to: {LOCAL_YAML}")
def write_env_file(keys: dict) -> None:
"""Write .env file for environment variable loading."""
lines = []
env_map = {
"anthropic": "ANTHROPIC_API_KEY",
"openai": "OPENAI_API_KEY",
"polymarket_api_key": "POLYMARKET_API_KEY",
"polymarket_secret": "POLYMARKET_SECRET",
"polymarket_passphrase": "POLYMARKET_PASSPHRASE",
"news_api": "NEWS_API_KEY",
}
for key_name, env_var in env_map.items():
value = keys.get(key_name, "")
if value:
lines.append(f"{env_var}={value}")
ENV_FILE.write_text("\n".join(lines) + "\n", encoding="utf-8")
print(f" .env written to: {ENV_FILE}")
def test_anthropic(key: str) -> bool:
"""Test Anthropic API connection."""
if not key:
return False
try:
import anthropic
client = anthropic.Anthropic(api_key=key)
response = client.messages.create(
model="claude-haiku-4-5-20251001",
max_tokens=50,
messages=[{"role": "user", "content": "Say 'Mirofish online' in 3 words."}],
)
text = response.content[0].text
print(f" Claude API: OK — \"{text.strip()}\"")
return True
except Exception as e:
print(f" Claude API: FAILED — {e}")
return False
def test_polymarket() -> bool:
"""Test Polymarket Gamma API (no auth needed)."""
try:
import httpx
r = httpx.get(
"https://gamma-api.polymarket.com/markets",
params={"limit": 1, "active": "true"},
timeout=15,
)
r.raise_for_status()
markets = r.json()
if markets:
q = markets[0].get("question", "N/A")[:60]
print(f" Polymarket API: OK — \"{q}...\"")
return True
print(" Polymarket API: OK (no active markets returned)")
return True
except Exception as e:
print(f" Polymarket API: FAILED — {e}")
return False
def main():
print("=" * 60)
print(" MIROFISH SETUP")
print(" Configuring API keys and connections")
print("=" * 60)
print()
# Step 1: Collect API keys
print("[1/3] API Keys")
print("-" * 40)
keys = {}
keys["anthropic"] = prompt_key(
"Anthropic API Key",
"ANTHROPIC_API_KEY",
required=True,
)
keys["openai"] = prompt_key(
"OpenAI API Key",
"OPENAI_API_KEY",
required=False,
)
print()
print(" Polymarket CLOB API (for trading — optional for now):")
print(" Get keys at: https://docs.polymarket.com")
keys["polymarket_api_key"] = prompt_key(
"Polymarket API Key",
"POLYMARKET_API_KEY",
required=False,
)
keys["polymarket_secret"] = prompt_key(
"Polymarket Secret",
"POLYMARKET_SECRET",
required=False,
)
keys["polymarket_passphrase"] = prompt_key(
"Polymarket Passphrase",
"POLYMARKET_PASSPHRASE",
required=False,
)
keys["news_api"] = prompt_key(
"News API Key (Tavily/Serper)",
"NEWS_API_KEY",
required=False,
)
# Step 2: Write config files
print()
print("[2/3] Writing Configuration")
print("-" * 40)
write_local_yaml(keys)
write_env_file(keys)
# Step 3: Test connections
print()
print("[3/3] Testing Connections")
print("-" * 40)
anthropic_ok = test_anthropic(keys.get("anthropic", ""))
polymarket_ok = test_polymarket()
# Summary
print()
print("=" * 60)
print(" SETUP COMPLETE")
print("=" * 60)
print(f" Claude API: {'READY' if anthropic_ok else 'NOT CONFIGURED'}")
print(f" Polymarket API: {'READY' if polymarket_ok else 'FAILED'}")
print(f" Config: {LOCAL_YAML}")
print(f" .env: {ENV_FILE}")
print()
if anthropic_ok and polymarket_ok:
print(" Next: Run the demo!")
print(" python demo_live.py")
elif not anthropic_ok:
print(" To add your Anthropic key later:")
print(" 1. Edit config/local.yaml")
print(" 2. Or set ANTHROPIC_API_KEY environment variable")
print(" 3. Get a key at: https://console.anthropic.com/settings/keys")
print()
if __name__ == "__main__":
main()