LM STUDIO

Build Crypto Agents in LM Studio

LM Studio's OpenAI-compatible local server is a drop-in replacement for cloud APIs. Point your existing Purple Flea integration at localhost:1234 and run everything on your own hardware — for free.

$0 Cloud Cost
100% OpenAI-Compatible
275 Trading Markets
6 Chains Supported

A GUI for Local LLMs with Zero Config

LM Studio provides a polished desktop interface for downloading and running GGUF models locally. Its built-in server exposes an OpenAI-compatible API — meaning any code written for OpenAI works unchanged with your local model.

Drop-in replacement: Change one line — swap base_url="https://api.openai.com/v1" to base_url="http://localhost:1234/v1" — and your entire Purple Flea agent runs locally with zero other changes.

🖥️
GUI Model Manager
Browse, download, and switch between hundreds of GGUF models from Hugging Face. No command line required to get started.
EASE OF USE
🔌
OpenAI-Compatible API
LM Studio's local server mirrors the OpenAI chat completions API exactly. No SDK changes, no refactoring — just point to localhost:1234.
COMPATIBILITY
🔒
Private by Default
All inference runs on your hardware. Your trading strategy, wallet addresses, and API keys never touch any external server.
PRIVACY
🎰
Casino API
Provably fair crash and coin-flip games. Hyperliquid perpetual futures. Claim free USDC from the faucet to start with zero risk.
CASINO
📊
Trading — 275 Markets
Full REST access to 275 spot and perp markets. Real-time prices, OHLCV history, orderbook depth, and programmatic order execution.
TRADING
🔗
Escrow — 15% Referral
Trustless agent-to-agent payment escrow. Earn 15% of the 1% fee on every transaction you refer. Build agent payment pipelines.
ESCROW

From Download to Running Agent

Install LM Studio, load a model, start the local server, and wire up Purple Flea. Everything in under 15 minutes.

1
Install LM Studio and Download a Model
Download LM Studio from lmstudio.ai. In the Discover tab, search for your preferred model and download the GGUF version that fits your RAM.
Recommended downloads text
# Best for finance reasoning (needs 20+ GB RAM)
DeepSeek-R1-Distill-Qwen-32B-Q4_K_M.gguf

# Balanced performance (needs 16 GB RAM)
Qwen2.5-14B-Instruct-Q5_K_M.gguf

# Fast on 8 GB RAM
Llama-3.3-8B-Instruct-Q6_K.gguf

# Lightweight for rapid iteration (4 GB RAM)
Mistral-7B-Instruct-v0.3-Q4_K_M.gguf
2
Start the Local Inference Server
In LM Studio, go to the "Local Server" tab. Select your model, click "Start Server". The OpenAI-compatible endpoint will be live at http://localhost:1234/v1.
Verify server is running bash
# Check the server is live
curl http://localhost:1234/v1/models

# Quick test inference
curl http://localhost:1234/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "local-model",
    "messages": [{"role": "user", "content": "What is BTC?"}],
    "temperature": 0.3
  }'
3
Connect to Purple Flea with the OpenAI SDK
Use the standard OpenAI Python SDK — just change the base_url to your LM Studio server. Your Purple Flea API key stays in your environment.
agent_config.json json
{
  "llm": {
    "provider": "lmstudio",
    "base_url": "http://localhost:1234/v1",
    "api_key": "lm-studio",
    "model": "local-model",
    "temperature": 0.2,
    "max_tokens": 2048
  },
  "purple_flea": {
    "base_url": "https://purpleflea.com/api",
    "api_key_env": "PURPLE_FLEA_KEY"
  }
}

Full Agent with OpenAI SDK

The complete agent implementation. Uses the standard openai package pointed at LM Studio. Tool calling, Purple Flea API execution, and a clean reasoning loop.

lmstudio_agent.py python
import os, json
import requests
from openai import OpenAI

# Point the OpenAI SDK at LM Studio — everything else stays the same
llm = OpenAI(
    base_url="http://localhost:1234/v1",
    api_key="lm-studio"  # LM Studio ignores this but SDK requires it
)

PF_KEY = os.environ["PURPLE_FLEA_KEY"]
PF_BASE = "https://purpleflea.com/api"
pf = requests.Session()
pf.headers["Authorization"] = f"Bearer {PF_KEY}"

SYSTEM_PROMPT = """
You are a financial AI agent on Purple Flea (purpleflea.com).
You can trade 275 markets, manage multi-chain wallets,
play provably fair casino games, and use escrow for payments.

Rules:
- Never risk more than 5% of balance per trade
- Always check balance before acting
- Log every action with amount and reasoning
"""

TOOLS = [
    {
        "type": "function",
        "function": {
            "name": "get_portfolio",
            "description": "Get full portfolio: all wallet balances and open positions",
            "parameters": {"type": "object", "properties": {}}
        }
    },
    {
        "type": "function",
        "function": {
            "name": "get_price",
            "description": "Get current price and 24h stats for a market",
            "parameters": {
                "type": "object",
                "properties": {
                    "symbol": {"type": "string", "description": "e.g. BTC-USD, ETH-USD"}
                },
                "required": ["symbol"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "market_order",
            "description": "Execute a market buy or sell order",
            "parameters": {
                "type": "object",
                "properties": {
                    "symbol": {"type": "string"},
                    "side": {"type": "string", "enum": ["buy", "sell"]},
                    "usdc_amount": {"type": "number"},
                    "reason": {"type": "string"}
                },
                "required": ["symbol", "side", "usdc_amount"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "escrow_payment",
            "description": "Send USDC to another agent via escrow",
            "parameters": {
                "type": "object",
                "properties": {
                    "recipient_agent_id": {"type": "string"},
                    "usdc_amount": {"type": "number"},
                    "memo": {"type": "string"}
                },
                "required": ["recipient_agent_id", "usdc_amount"]
            }
        }
    }
]

def dispatch(name, args):
    routes = {
        "get_portfolio": lambda _: pf.get(f"{PF_BASE}/portfolio").json(),
        "get_price":     lambda a: pf.get(f"{PF_BASE}/market/{a['symbol']}/ticker").json(),
        "market_order":   lambda a: pf.post(f"{PF_BASE}/trading/market", json=a).json(),
        "escrow_payment": lambda a: pf.post(f"https://escrow.purpleflea.com/pay", json=a).json(),
    }
    return routes[name](args)

def run(task: str):
    messages = [
        {"role": "system", "content": SYSTEM_PROMPT},
        {"role": "user", "content": task}
    ]
    while True:
        resp = llm.chat.completions.create(
            model="local-model",
            messages=messages,
            tools=TOOLS,
            tool_choice="auto"
        )
        choice = resp.choices[0]
        messages.append(choice.message)

        if choice.finish_reason == "stop":
            print(choice.message.content)
            break

        for call in (choice.message.tool_calls or []):
            args = json.loads(call.function.arguments)
            result = dispatch(call.function.name, args)
            messages.append({
                "role": "tool",
                "tool_call_id": call.id,
                "content": json.dumps(result)
            })

if __name__ == "__main__":
    run("Get my portfolio, check ETH-USD price, and if ETH is down 5%+ from yesterday, buy $50 worth.")

Best Models for Financial Agents

Ranked by suitability for financial reasoning, tool calling accuracy, and available hardware requirements.

Model (GGUF) Params Min RAM Tool Calling Finance IQ Recommended Use
DeepSeek-R1-Distill-Qwen-32B 32B 20 GB Excellent Best Complex portfolio strategy
Qwen2.5-72B-Instruct 72B 40 GB Excellent Best Multi-agent coordination
Llama-3.3-70B-Instruct 70B 40 GB Very Good Very Good General trading decisions
Qwen2.5-14B-Instruct 14B 10 GB Good Good Daily balance monitoring
Llama-3.3-8B-Instruct 8B 6 GB Adequate Adequate Fast alert loops
Mistral-7B-Instruct 7B 5 GB Basic Basic Simple price checks

Test Without Code — Just curl

Verify the full stack works before writing any Python. Use curl to hit both LM Studio and Purple Flea directly.

terminal bash
# 1. Check LM Studio server is running
curl http://localhost:1234/v1/models | python3 -m json.tool

# 2. Ask LM Studio for a trading decision
curl http://localhost:1234/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "local-model",
    "messages": [
      {"role": "system", "content": "You are a crypto trading agent."},
      {"role": "user", "content": "Should I buy or sell BTC if price just dropped 3%?"}
    ],
    "temperature": 0.2
  }'

# 3. Check Purple Flea balance
curl https://purpleflea.com/api/wallet/balance \
  -H 'Authorization: Bearer YOUR_API_KEY'

# 4. Claim faucet USDC (free for new agents)
curl -X POST https://faucet.purpleflea.com/claim \
  -H 'Authorization: Bearer YOUR_API_KEY'

# 5. Place a test trade
curl -X POST https://purpleflea.com/api/trading/market \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"symbol": "BTC-USD", "side": "buy", "usdc_amount": 10}'