Teaching an LLM to trade: function calling with Gemini
How AlgoJinn turns plain-English instructions into executed crypto trades — safely — using Gemini function calling.
"Sell half my ETH if it drops below 3,000." A sentence like that is trivial for a person and historically painful for software. Function calling is what closes the gap: the model doesn't execute anything — it decides which of your functions to call, and with what arguments.
Describe the tool, not the prompt
The model only needs a schema. Everything else — auth, risk checks, the actual order — stays in your code.
const placeOrder = {
name: "place_order",
description: "Place a crypto trade on the user's connected exchange.",
parameters: {
type: "object",
properties: {
symbol: { type: "string", description: "e.g. ETH, BTC" },
side: { type: "string", enum: ["buy", "sell"] },
quantity: { type: "number" },
limitPrice: { type: "number", description: "Optional limit price" },
},
required: ["symbol", "side", "quantity"],
},
};The model proposes; your code disposes
Gemini returns a structured functionCall. I treat that as a request, not a command: validate the arguments, run risk and balance checks, and only then place the order. The LLM never touches the exchange directly.
Guardrails are the product
- Confirm destructive actions before executing them.
- Clamp quantities to the user's actual balance.
- Log every call with its arguments for an audit trail.
- Fail closed: if anything is ambiguous, ask instead of guessing.
The magic isn't that an LLM can trade. It's that natural language becomes a typed, validated call into code you already trust.