ai newsDo., 15. Okt.
EilmeldungMeta and Apple team up to make Muse AI models run better on Macs

KI-Agenten auf Polymarket-Trades aufsetzen: Claude Code, Codex und MCP

Ein KI-Agent soll Trades verfolgter Polymarket-Haendler lesen, den Markt analysieren und ueber Reaktionen entscheiden. Tools wie Claude Code und Codex koennen das zwar, scheitern aber als dauerhafte Listener, weil sie ihre Arbeit beenden, sobald eine Aufgabe erledigt ist.

dev.toMittwoch 17:39 · 14.10.DE6 Min. Lesezeit
Bild: dev.to

Ich wollte einen KI-Agenten, der einen Fill liest, sobald ein Polymarket-Trader, dem ich folge, kauft, sich den Markt anschaut und entscheidet, ob etwas zu tun ist.

Agenten wie Claude Code oder Codex können einen Fill lesen und über einen Markt nachdenken, aber sie eignen sich nicht gut als langlebige Listener. Sie beenden sich, wenn ihre Aufgabe erledigt ist. In diesem Aufbau hält ein kleiner Prozess die Live-Verbindung und reiht Fills in eine Warteschlange. Er startet den Agenten einmal pro Batch mit den Fills auf stdin; der Agent bearbeitet den Batch und beendet sich.

Alles hier verwendet zwei Kommandozeilen-Tools, die JSON ausgeben, und beide lassen sich auch als MCP-Server betreiben:

npm i -g pmwallets pmwallets-copytrade # Node.js 20+ # oder pip install pmwallets pmwallets-copytrade # gleiche Befehle Enter fullscreen mode Exit fullscreen mode Man benötigt einen PMWallets API-Schlüssel (erstellt unter pmwallets.com/keys):

export PMW_API_KEY = pmw_... Enter fullscreen mode Exit fullscreen mode Trader zum Folgen auswählen pmwallets leaderboard --period 30d --minWinLo 0.55 --category politics --limit 20 pmwallets entity 7KQ2MF9X4B1C # Statistiken eines Traders, per Handle Enter fullscreen mode Exit fullscreen mode minWinLo ist die Untergrenze des 95-Prozent-Konfidenzintervalls der Gewinnquote eines Traders. Ein Trader, der 3 von 3 Wetten gewonnen hat, hat eine Gewinnquote von 100 Prozent und eine Untergrenze deutlich unter 0,5, weil drei Trades sehr wenig aussagen. Die Filterung nach der Untergrenze schiebt Glückstränen nach unten in der Liste.

pmwallets subscribe 7KQ2MF9X4B1C # abrechnung pro Stunde während des Abonnements pmwallets subscriptions Enter fullscreen mode Exit fullscreen mode Fills zum Agenten bringen Es gibt zwei Wege, je nachdem, ob man einen Prozess dauerhaft laufen lassen kann.

Wenn der Agent nach einem Zeitplan läuft (ein Cron-Job, eine Schleife im Agenten, ein Chat-Agent, den man gelegentlich anstößt), ruft man auf:

pmwallets new-fills Enter fullscreen mode Exit fullscreen mode Er liefert die Fills seit dem vorherigen Aufruf zurück, jeden genau einmal. Die Position wird in ~/.pmwallets/mcp-cursor.json gespeichert, oder dort, worauf PMW_MCP_STATE zeigt. Ein Leser pro Datei: Wenn zwei Agenten pollen, gibt man jedem sein eigenes PMW_MCP_STATE, sonst teilen sie sich die Fills auf.

Wenn man einen Prozess dauerhaft laufen lassen kann, hält watch eine Live-Verbindung und führt den Befehl für jeden Batch von Fills aus:

pmwallets watch --batch-sec 30 --exec 'claude -p "Fills from traders I follow are on stdin. For each BUY above $1000 in a market ending after 2026-12-31, read the market with pmwallets-copytrade market, then buy $5 with --key <eventId> if the price is below 0.6. One line per fill: what you did." --allowedTools "Bash(pmwallets-copytrade:*)"' Enter fullscreen mode Exit fullscreen mode Die Fills kommen auf der Standardeingabe des Befehls als JSON-Zeilen an, und dieselben Zeilen stehen in einer Datei, die über $PMW_BATCH_FILE benannt wird. Fills, die eintreffen, während der Agent noch läuft, landen im nächsten Batch. --batch-sec 30 wartet 30 Sekunden nach dem ersten Fill, sodass ein Schub zu einem einzigen Agenten-Lauf wird statt zu zehn.

--allowedTools "Bash(pmwallets-copytrade:*)" erlaubt dem headless Claude, das Trading-CLI auszuführen. Ohne diese Option kann Claude entweder gar nichts ausführen, oder man gewährt ihm am Ende weit mehr, als es braucht.

Bei anderen Agenten sieht der Befehl ähnlich aus:

# Codex: dessen Standard-Sandbox hat kein Netzwerk, daher kann das Trading-CLI Polymarket nicht erreichen --exec 'codex exec --sandbox danger-full-access "...same instructions..."' # Gemini CLI --exec 'gemini -p "..." --yolo' Enter fullscreen mode Exit fullscreen mode Ohne --exec gibt watch einfach eine JSON-Zeile pro Fill aus, was sich gut zum Weiterleiten in ein eigenes Skript eignet.

{ "eventId": "137:78012345:0x…:0x…:212", "side": "BUY", "role": "taker", "price": "0.570000", "tokenId": "1043…", "usdcAmount": "1824.000000", "sharesAmount": "3200.000000", "market": { "question": "…", "outcome": "Yes", "endDate": "2026-11-03T00:00:00Z" }, "source": "ws", "receivedAt": "2026-10-14T09:12:03.417Z" } Enter fullscreen mode Exit fullscreen mode Die rohen usdc- und shares-Felder sind Ganzzahlen in Millionsteln. Die *Amount-Felder enthalten dieselben Werte als Dezimalzahlen, damit der Agent nicht durch eine Million teilen muss (Modelle machen dabei durchaus Fehler). Die Marktfrage und das Ergebnis sind angehängt, damit der Agent erkennen kann, was gekauft wurde, ohne nachschlagen zu müssen.

Ein Batch wird an den Befehl höchstens einmal übergeben. Wenn der Agent abstürzt, ein Timeout auftritt oder die Maschine mitten im Lauf neu startet, landet dieser Batch in pmw-watch/failed/ und wird nie erneut ausgeführt, weil der Agent möglicherweise bereits eine Order platziert hat. Diese Batches müssen von Hand geprüft werden. Ein Neustart setzt den Stream dort fort, wo er aufgehört hat.

Zuerst schreibt man eine Konfiguration. Sie startet im dry-run-Modus:

pmwallets-copytrade init # schreibt config.yaml, mode: dry-run pmwallets-copytrade check # prüft Schlüssel und Konto, platziert nichts Enter fullscreen mode Exit fullscreen mode Im dry-run-Modus wird jede Order gegen das live Orderbuch simuliert und nichts wird gesendet. Das ist der Modus, in dem man den Agenten eine Weile lassen sollte.

pmwallets-copytrade market <tokenId> # Frage, Outcomes, Preise, Orderbuch pmwallets-copytrade balance pmwallets-copytrade positions pmwallets-copytrade order buy <tokenId> --usdc 5 --max-price 0.45 --key <eventId> pmwallets-copytrade order sell <tokenId> --all --min-price 0.40 --key <eventId>:exit Enter fullscreen mode Exit fullscreen mode Die Order-Befehle folgen diesen Regeln:

Ich verlange --key ausdrücklich im Prompt, da Agenten nach einer langsamen Antwort einen erneuten Versuch starten können. Ohne einen Schlüssel sendet dieser erneute Versuch eine zweite Order.

Wenn man die Konfiguration auf mode: live umstellt, sollte man ihm ein eigenes Polymarket-Konto geben, das nur das Geld enthält, dessen Verlust man bereit ist zu tragen. Polymarket akzeptiert keine Orders aus einigen Ländern (einschließlich der USA und Großbritannien); pmwallets-copytrade check sagt einem, ob der Standort der eigenen Maschine handeln darf.

Für Claude Desktop, Cursor, Windsurf, Cline und Ähnliches sind dieselben Tools als MCP-Server verfügbar:

{ "mcpServers": { "pmwallets": { "command": "npx", "args": [ "-y", "pmwallets", "mcp" ], "env": { "PMW_API_KEY": "pmw_..." } }, "copytrade": { "command": "npx", "args": [ "-y", "pmwallets-copytrade", "mcp", "--config", "/abs/path/config.yaml" ] } } } Enter fullscreen mode Exit fullscreen Mode Das new_fills-Tool teilt sich seine Position mit pmwallets new-fills, sodass man beides mischen kann, aber die Regel eines Lesers pro Datei gilt weiterhin.

Der Trading-MCP-Server lehnt Argumente ab, die er nicht kennt. Wenn ein Modell max_price statt maxPrice sendet, schlägt der Aufruf mit einem Fehler fehl, der die erlaubten Namen auflistet, statt das Limit stillschweigend zu verwerfen und zu jedem beliebigen Ask-Preis zu kaufen.

Für Dify, Coze, n8n oder einen custom GPT importiert man die OpenAPI-Spezifikation unter https://pmwallets.com/openapi.json und ruft die REST-API mit einem x-api-key-Header auf. Fills können auch als signierte Webhooks eintreffen. Das Platzieren von Orders von dort aus liegt bei einem selbst; das Trading-CLI braucht eine Maschine, auf der es laufen kann.

Der Großteil der Verzögerung kommt vom Agenten. Wenn es einem darum geht, denselben Preis zu bekommen wie der Trader, dem man folgt, macht es einen Unterschied, 10 bis 30 Sekunden auf ein Modell zu warten: In schnellen Märkten wird sich der Preis bewegt haben. Für diesen Fall würde ich einen Bot mit festen Regeln verwenden (pmwallets-copytrade run). Der Agenten-Aufbau ist nützlicher, wenn eine Aufgabe Lesen erfordert, etwa Sport auszulassen oder nur dann zu handeln, wenn die Frage ein bestimmtes Ereignis erwähnt. Er kann auch zusammenfassen, was die Personen, denen man folgt, heute getan haben.

Nichts davon ist Finanzberatung, und das Kopieren eines Traders ist nicht dasselbe wie dieser Trader zu sein: Man kauft später, zu einem anderen Preis, und zahlt Gebühren.

Die Anleitung, die man seinem Agenten geben kann, wird von npx pmwallets skill ausgegeben. Paketversionen zum Zeitpunkt des Verfassens: pmwallets 0.6.5 und pmwallets-copytrade 0.4.1.

Automatisch übersetzt. Das Original auf Englisch ist unten aufklappbar.

Original (Englisch) anzeigen

I wanted an AI agent to read a fill when a Polymarket trader I follow buys, look at the market, and decide whether to do anything about it.

Agents like Claude Code or Codex can read a fill and reason about a market, but they don't work well as long-running listeners. They exit when their task is done. In this setup, a small process holds the live connection and queues fills. It starts the agent once per batch with the fills on stdin; the agent handles the batch and exits.

Everything here uses two command-line tools that print JSON, and both also run as MCP servers:

npm i -g pmwallets pmwallets-copytrade # Node.js 20+ # or pip install pmwallets pmwallets-copytrade # same commands Enter fullscreen mode Exit fullscreen mode You need a PMWallets API key (created on pmwallets.com/keys):

export PMW_API_KEY = pmw_... Enter fullscreen mode Exit fullscreen mode Pick traders to follow pmwallets leaderboard --period 30d --minWinLo 0.55 --category politics --limit 20 pmwallets entity 7KQ2MF9X4B1C # one trader's stats, by handle Enter fullscreen mode Exit fullscreen mode minWinLo is the lower bound of the 95% confidence interval on a trader's win rate. A trader who won 3 bets out of 3 has a 100% win rate and a lower bound well under 0.5, because three trades say very little. Filtering on the lower bound pushes lucky streaks down the list.

pmwallets subscribe 7KQ2MF9X4B1C # billed per hour while subscribed pmwallets subscriptions Enter fullscreen mode Exit fullscreen mode Getting fills to the agent There are two ways, depending on whether you can keep a process running.

If your agent runs on a schedule (a cron job, a loop inside the agent, a chat agent you poke now and then), call:

pmwallets new-fills Enter fullscreen mode Exit fullscreen mode It returns the fills since the previous call, each one once. The position is kept in ~/.pmwallets/mcp-cursor.json, or wherever PMW_MCP_STATE points. One reader per file: if two agents poll, give each its own PMW_MCP_STATE, or they will split the fills between them.

If you can keep a process up, watch holds a live connection and runs your command for each batch of fills:

pmwallets watch --batch-sec 30 --exec 'claude -p "Fills from traders I follow are on stdin. For each BUY above $1000 in a market ending after 2026-12-31, read the market with pmwallets-copytrade market, then buy $5 with --key <eventId> if the price is below 0.6. One line per fill: what you did." --allowedTools "Bash(pmwallets-copytrade:*)"' Enter fullscreen mode Exit fullscreen mode The fills arrive on the command's stdin as JSON lines, and the same lines are in a file named by $PMW_BATCH_FILE. Fills that come in while the agent is still running go into the next batch. --batch-sec 30 waits 30 seconds after the first fill so that a burst becomes one agent run instead of ten.

--allowedTools "Bash(pmwallets-copytrade:*)" lets headless Claude run the trading CLI. Without it, Claude either can't run anything or you end up granting far more than it needs.

For other agents, the command looks similar:

# Codex: its default sandbox has no network, so the trading CLI can't reach Polymarket --exec 'codex exec --sandbox danger-full-access "...same instructions..."' # Gemini CLI --exec 'gemini -p "..." --yolo' Enter fullscreen mode Exit fullscreen mode Without --exec, watch just prints one JSON line per fill, which is handy for piping into your own script.

{ "eventId": "137:78012345:0x…:0x…:212", "side": "BUY", "role": "taker", "price": "0.570000", "tokenId": "1043…", "usdcAmount": "1824.000000", "sharesAmount": "3200.000000", "market": { "question": "…", "outcome": "Yes", "endDate": "2026-11-03T00:00:00Z" }, "source": "ws", "receivedAt": "2026-10-14T09:12:03.417Z" } Enter fullscreen mode Exit fullscreen mode The raw usdc and shares fields are integers in millionths. The *Amount fields are the same values as decimals, so the agent doesn't have to divide by a million (models do get this wrong). The market question and outcome are attached, so the agent can tell what was bought without looking it up.

A batch is handed to the command at most once. If the agent crashes, times out, or the machine reboots mid-run, that batch goes to pmw-watch/failed/ and is never run again, because the agent may already have placed an order. Those batches need to be checked by hand. A restart picks up the stream where it stopped.

First write a config. It starts in dry-run:

pmwallets-copytrade init # writes config.yaml, mode: dry-run pmwallets-copytrade check # checks keys and account, places nothing Enter fullscreen mode Exit fullscreen mode In dry-run, every order is simulated against the live order book and nothing is sent. That is the mode to leave the agent in for a while.

pmwallets-copytrade market <tokenId> # question, outcomes, prices, order book pmwallets-copytrade balance pmwallets-copytrade positions pmwallets-copytrade order buy <tokenId> --usdc 5 --max-price 0.45 --key <eventId> pmwallets-copytrade order sell <tokenId> --all --min-price 0.40 --key <eventId>:exit Enter fullscreen mode Exit fullscreen mode The order commands follow these rules:

I'd explicitly require --key in the prompt, since agents may retry after a slow response. Without a key, that retry sends a second order.

When you switch the config to mode: live, give it a Polymarket account of its own with only what you're willing to lose in it. Polymarket doesn't accept orders from some countries (including the US and the UK); pmwallets-copytrade check tells you whether your machine's location can trade.

For Claude Desktop, Cursor, Windsurf, Cline and similar, the same tools are available as MCP servers:

{ "mcpServers": { "pmwallets": { "command": "npx", "args": [ "-y", "pmwallets", "mcp" ], "env": { "PMW_API_KEY": "pmw_..." } }, "copytrade": { "command": "npx", "args": [ "-y", "pmwallets-copytrade", "mcp", "--config", "/abs/path/config.yaml" ] } } } Enter fullscreen mode Exit fullscreen mode The new_fills tool shares its position with pmwallets new-fills, so you can mix the two, but the one-reader-per-file rule still applies.

The trading MCP server rejects arguments it doesn't know. If a model sends max_price instead of maxPrice, the call fails with an error that lists the allowed names, rather than quietly dropping the limit and buying at whatever the ask is.

For Dify, Coze, n8n or a custom GPT, import the OpenAPI spec at https://pmwallets.com/openapi.json and call the REST API with an x-api-key header. Fills can also arrive as signed webhooks. Placing orders from there is up to you; the trading CLI needs a machine to run on.

Most of the delay comes from the agent. If you care about getting the same price as the trader you follow, waiting 10 to 30 seconds for a model matters: in fast markets the price will have moved. For that case I'd use a fixed-rule bot ( pmwallets-copytrade run ). The agent setup is more useful when a task needs reading, such as skipping sports or only acting if the question mentions a specific event. It can also summarise what the people you follow did today.

None of this is financial advice, and copying a trader is not the same as being that trader: you buy later, at a different price, and pay fees.

The guide to hand your agent is printed by npx pmwallets skill. Package versions at the time of writing: pmwallets 0.6.5 and pmwallets-copytrade 0.4.1.

Originaltitel: Let your AI agent follow Polymarket traders: Claude Code, Codex, Cursor and MCPQuelle: dev.to (dev.to). Original öffnen