Skip to content
Automation
Skill

/portfolio-sync

Sync portfolio positions from Polymarket, Kalshi, and Manifold

From plugin
cloddsbot
3.1k121 skills

Claude Code

$ npx -y skills add alsk1992/CloddsBot --skill portfolio-sync --agent claude-code

SKILL.md

portfolio-sync.SKILL.md
name: portfolio-sync
description: "Sync portfolio positions from Polymarket, Kalshi, and Manifold"
emoji: "📁"

Portfolio Sync Skill

Real methods to fetch and sync positions from each prediction market platform.

Polymarket Position Sync

Polymarket positions are held as ERC-1155 tokens on Polygon. Query on-chain balances.

import os
import requests

WALLET = os.getenv("POLY_FUNDER_ADDRESS")
CTF_CONTRACT = "0x4D97DCd97eC945f40cF65F87097ACe5EA0476045"  # Conditional Token Framework

def get_polymarket_positions(token_ids: list[str]) -> dict:
    """
    Get balances for specific token IDs

    Args:
        token_ids: List of token IDs to check (from market data)

    Returns:
        Dict of token_id -> balance in shares
    """
    positions = {}

    for token_id in token_ids:
        token_int = int(token_id)

        # ERC-1155 balanceOf call
        data = f"0x00fdd58e000000000000000000000000{WALLET[2:].lower()}{token_int:064x}"

        r = requests.post("https://polygon-rpc.com/", json={
            "jsonrpc": "2.0",
            "method": "eth_call",
            "params": [{"to": CTF_CONTRACT, "data": data}, "latest"],
            "id": 1
        })

        result = r.json().get("result", "0x0")
        balance = int(result, 16) / 1e6  # Raw to shares

        if balance > 0:
            positions[token_id] = balance

    return positions

# Example: Check positions for BTC 15-min market
btc_tokens = [
    "21742633143463906290569050155826241533067272736897614950488156847949938836455",  # YES
    "48331043336612883890938759509493159234755048973500640148014422747788308965745"   # NO
]

positions = get_polymarket_positions(btc_tokens)
for token_id, balance in positions.items():
    print(f"Token {token_id[:20]}...: {balance} shares")

Get All Polymarket Positions (via Gamma API)

def get_all_polymarket_positions(wallet: str):
    """Get all positions for a wallet via Gamma API"""
    url = f"https://gamma-api.polymarket.com/positions?user={wallet.lower()}"
    r = requests.get(url)

    if r.status_code != 200:
        return []

    positions = r.json()

    result = []
    for p in positions:
        result.append({
            "market_id": p.get("conditionId"),
            "market_question": p.get("title", "Unknown"),
            "token_id": p.get("tokenId"),
            "outcome": p.get("outcome"),
            "size": float(p.get("size", 0)),
            "avg_price": float(p.get("avgPrice", 0)),
            "current_price": float(p.get("currentPrice", 0)),
            "pnl": float(p.get("pnl", 0)),
            "value": float(p.get("value", 0))
        })

    return result

positions = get_all_polymarket_positions(WALLET)
for p in positions:
    print(f"{p['market_question'][:40]}")
    print(f"  {p['outcome']}: {p['size']} shares @ {p['avg_price']:.2f} -> {p['current_price']:.2f}")
    print(f"  PnL: ${p['pnl']:.2f}")

Get USDC Balance

def get_usdc_balance(wallet: str) -> float:
    """Get USDC balance on Polygon"""
    USDC = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"  # USDC on Polygon

    # ERC-20 balanceOf
    data = f"0x70a08231000000000000000000000000{wallet[2:].lower()}"

    r = requests.post("https://polygon-rpc.com/", json={
        "jsonrpc": "2.0",
        "method": "eth_call",
        "params": [{"to": USDC, "data": data}, "latest"],
        "id": 1
    })

    result = r.json().get("result", "0x0")
    balance = int(result, 16) / 1e6  # USDC has 6 decimals

    return balance

usdc = get_usdc_balance(WALLET)
print(f"USDC Balance: ${usdc:.2f}")

Kalshi Position Sync

import requests
import time

BASE_URL = "https://trading-api.kalshi.com/trade-api/v2"

class KalshiSync:
    def __init__(self, email: str, password: str):
        self.email = email
        self.password = password
        self.token = None
        self.token_expiry = 0

    def _auth(self):
        if time.time() > self.token_expiry - 60:
            r = requests.post(f"{BASE_URL}/login", json={
                "email": self.email,
                "password": self.password
            })
            r.raise_for_status()
            self.token = r.json()["token"]
            self.token_expiry = time.time() + 29 * 60

    def _headers(self):
        self._auth()
        return {"Authorization": f"Bearer {self.token}"}

    def get_positions(self):
        """Get all Kalshi positions"""
        r = requests.get(f"{BASE_URL}/portfolio/positions", headers=self._headers())
        r.raise_for_status()

        positions = []
        for p in r.json().get("market_positions", []):
            # Get market details
            market = requests.get(
                f"{BASE_URL}/markets/{p['ticker']}",
                headers=self._headers()
            ).json().get("market", {})

            positions.append({
                "market_id": p["ticker"],
                "market_question": market.get("title", p["ticker"]),
                "side": "YES" if p.get("position", 0) > 0 else "NO",
                "size": abs(p.get("position", 0)),
                "avg_price": p.get("average_price", 0) / 100,
                "current_price": market.get("yes_bid", 50) / 100,
                "value": abs(p.get("position", 0)) * market.get("yes_bid", 50) / 100,
                "pnl": p.get("realized_pnl", 0) / 100
            })

        return positions

    def get_balance(self):
        """Get Kalshi balance"""
        r = requests.get(f"{BASE_URL}/portfolio/balance", headers=self._headers())
        r.raise_for_status()
        data = r.json()
        return {
            "available": data.get("balance", 0) / 100,
            "portfolio_value": data.get("portfolio_value", 0) / 100
        }

# Usage
sync = KalshiSync(os.getenv("KALSHI_EMAIL"), os.getenv("KALSHI_PASSWORD"))

positions = sync.get_positions()
for p in positions:
    print(f"{p['market_question'][:40]}")
    print(f"  {p['side']}: {p['size']} @ {p['avg_price']:.2f} -> {p['curre
Read more
@alsk1992
Ships withcloddsbot

Open Source AI trading agent that operates autonomously across 1000+ markets - Polymarket, Kalshi, Binance, Hyperliquid, Solana DEXs, 5 EVM chains. Scans for edge, executes instantly, manages risk while you sleep. Agent commerce protocol for machine-to-machine payments. Self-hosted. Built on Claude.

3.1k121 skills
Get the whole plugin

Stars on GitHub

Momentum

stars in total
3.1k
Star history of alsk1992/CloddsBot on GitHub, a chart by star-history.com

Other skills on cloddsbot.

acp

acp

Enable agent-to-agent commerce with on-chain escrow, cryptographic agreements, and service discovery.

@alsk1992@alsk1992Install Skill

More skills from other plugins.

agent-builder

agent-builder

Load immediately after an Agent intent, before the first agent_builder_* call. Governs how you create, configure, test, and…

n8n2w209k
@n8n-io@n8n-ioInstall Skill
browser-use

browser-use

Direct browser control via CDP for web interaction: automation, scraping, testing, screenshots, and site/app work. Also covers…

@browser-use@browser-useInstall Skill
add-anydoc

add-anydoc

Add local office-document-to-Markdown conversion to NanoClaw agent containers with the pinned Firecrawl AnyDoc CLI. Use when…

@nanocoai@nanocoaiInstall Skill

Questions about portfolio-sync.

Which coding agents can use portfolio-sync?
portfolio-sync installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.