repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | export function deterministicDecision(obs) { |
| #2 | const candles = obs.candles; |
| #3 | const latest = candles.at(-1); |
| #4 | const previous = candles.at(-2); |
| #5 | if (!latest || !previous || candles.length < 3) { |
| #6 | return { action: "hold", reason: "insufficient candles for a legal devnet paper decision" }; |
| #7 | } |
| #8 | const openPosition = obs.book.positions[0]; |
| #9 | const momentum = latest.c - previous.c; |
| #10 | const momentumPct = momentum / previous.c; |
| #11 | const whaleBias = obs.whale_activity.bias; |
| #12 | const confidence = Math.min(1, Math.abs(momentumPct) * 80 + (whaleBias !== "neutral" ? 0.25 : 0)); |
| #13 | const desiredSide = momentum >= 0 ? "long" : "short"; |
| #14 | const whaleAgainst = whaleBias !== "neutral" && whaleBias !== desiredSide; |
| #15 | const oneAwayFromKill = obs.last_decisions.at(-1)?.consecutive_losses === obs.config.loss_killswitch_consecutive - 1; |
| #16 | if (openPosition) { |
| #17 | const shouldClose = (openPosition.side === "long" && momentum < 0 && !whaleAgainst) || |
| #18 | (openPosition.side === "short" && momentum > 0 && !whaleAgainst) || |
| #19 | oneAwayFromKill; |
| #20 | if (shouldClose) { |
| #21 | return { |
| #22 | action: "close", |
| #23 | position_id: openPosition.id, |
| #24 | reason: `paper signal reversed or risk tightened; closing ${openPosition.side} before the shell cracks`, |
| #25 | }; |
| #26 | } |
| #27 | return { action: "hold", reason: "position already open and signal is not strong enough to churn" }; |
| #28 | } |
| #29 | const threshold = obs.config.goblin ? 0.5 : 0.7; |
| #30 | if (confidence >= threshold && !whaleAgainst) { |
| #31 | return { |
| #32 | action: "open", |
| #33 | side: desiredSide, |
| #34 | size_lamports: obs.config.max_position_size_lamports, |
| #35 | reason: `${desiredSide} momentum plus ${whaleBias} whale flow clears goblin paper threshold`, |
| #36 | }; |
| #37 | } |
| #38 | return { action: "hold", reason: "signal exists but whale flow or confidence blocks a safe paper entry" }; |
| #39 | } |
| #40 | export async function claudeDecision(obs, systemPrompt) { |
| #41 | const apiKey = process.env["ANTHROPIC_API_KEY"]; |
| #42 | if (!apiKey) |
| #43 | return deterministicDecision(obs); |
| #44 | const response = await fetch("https://api.anthropic.com/v1/messages", { |
| #45 | method: "POST", |
| #46 | headers: { |
| #47 | "anthropic-version": "2023-06-01", |
| #48 | "content-type": "application/json", |
| #49 | "x-api-key": apiKey, |
| #50 | }, |
| #51 | body: JSON.stringify({ |
| #52 | model: process.env["GOBLIN_MODEL"] || obs.config.model || "claude-opus-4-7", |
| #53 | max_tokens: 220, |
| #54 | temperature: obs.config.goblin ? 0.55 : 0.2, |
| #55 | system: systemPrompt, |
| #56 | messages: [ |
| #57 | { |
| #58 | role: "user", |
| #59 | content: `OBSERVATIONS AT TICK ${obs.tick}\n${JSON.stringify(obs, null, 2)}\n\nReturn only one JSON object.`, |
| #60 | }, |
| #61 | ], |
| #62 | }), |
| #63 | }); |
| #64 | if (!response.ok) { |
| #65 | return { |
| #66 | action: "hold", |
| #67 | reason: `decision API error ${response.status}; holding paper position safely`, |
| #68 | }; |
| #69 | } |
| #70 | const payload = (await response.json()); |
| #71 | const text = payload.content?.find((part) => part.type === "text")?.text?.trim() ?? ""; |
| #72 | const match = text.match(/\{[\s\S]*\}/); |
| #73 | if (!match) |
| #74 | return { action: "hold", reason: "model returned no JSON object; paper hold enforced" }; |
| #75 | try { |
| #76 | return JSON.parse(match[0]); |
| #77 | } |
| #78 | catch { |
| #79 | return { action: "hold", reason: "model returned invalid JSON; paper hold enforced" }; |
| #80 | } |
| #81 | } |
| #82 | //# sourceMappingURL=claude-decision.js.map |