Documentation Index
Fetch the complete documentation index at: https://docs.simplefunctions.dev/llms.txt
Use this file to discover all available pages before exploring further.
This recipe shows the shape of a guarded SDK execution path. It is intentionally conservative: read runtime and portfolio state, enforce a local budget, require a limit price, then call execution.place.
Guard function
import { SimpleFunctions } from "@spfunctions/sdk"
const sf = new SimpleFunctions({
baseUrl: "https://simplefunctions.dev",
apiKey: process.env.SF_API_KEY,
})
type OrderPlan = {
venue?: "kalshi" | "polymarket"
ticker: string
tokenId?: string
title: string
quantity: number
limitPrice: number
rationale: string
jurisdiction?: string
}
async function placeGuarded(plan: OrderPlan) {
const maxOrderCostCents = 300
const cost = plan.quantity * plan.limitPrice
if (plan.quantity < 1) throw new Error("quantity must be positive")
if (plan.limitPrice < 1 || plan.limitPrice > 99) throw new Error("limitPrice must be 1-99 cents")
if (cost > maxOrderCostCents) throw new Error(`order cost ${cost}c exceeds ${maxOrderCostCents}c`)
if (!plan.rationale) throw new Error("rationale is required")
const runtime = await sf.runtime.ensure({
mode: "auto",
startIfNeeded: true,
timeoutMs: 90_000,
})
if (!runtime.ok) throw new Error("runtime did not become usable")
const portfolio = await sf.portfolio.state()
if (portfolio?.lastReconcileStatus && portfolio.lastReconcileStatus !== "ok") {
throw new Error(`portfolio reconcile status is ${portfolio.lastReconcileStatus}`)
}
const baseOrder = {
title: plan.title,
action: "buy" as const,
direction: "yes" as const,
quantity: plan.quantity,
limitPrice: plan.limitPrice,
rationale: plan.rationale,
runtime: { mode: "auto" as const, startIfNeeded: false },
}
if (plan.venue === "polymarket") {
return sf.execution.place({
...baseOrder,
venue: "polymarket",
tokenId: plan.tokenId ?? plan.ticker,
jurisdiction: plan.jurisdiction,
})
}
return sf.execution.place({
...baseOrder,
venue: "kalshi",
ticker: plan.ticker,
})
}
Call it
await placeGuarded({
ticker: "KXFED-27APR-T3.50",
title: "Fed target rate",
quantity: 1,
limitPrice: 32,
rationale: "operator-approved test order after manual review",
})
await placeGuarded({
venue: "polymarket",
ticker: "polymarket-event-outcome",
tokenId: "POLYMARKET_CLOB_TOKEN_ID",
title: "Polymarket event outcome",
quantity: 1,
limitPrice: 32,
rationale: "operator-approved test order after manual review",
jurisdiction: "CA",
})
Why this shape
runtime.ensure happens before order creation.
- The second
execution.place call uses startIfNeeded: false because the runtime was already checked.
- The local budget is independent from server risk gates.
- Kalshi and Polymarket execution stay explicit and limit-priced.
- Polymarket applications can require jurisdiction before calling this helper.
Next steps
Execution intents API
Server-side intent semantics.
Agent trader loop
Add Agent SDK policy gates.