Skip to main content

Python SDK for the Talarion prediction market maker API

Project description

Talarion SDK

Python client for the Talarion prediction market maker API.

Installation

pip install talarion

For EOA (externally owned account) direct on-chain interaction:

pip install talarion[eoa]

Quick Start

import asyncio
from datetime import datetime, timezone, timedelta
from talarion import TalarionClient

async def main():
    async with TalarionClient(api_key="tlrn_...") as client:
        # Generate a prediction market
        instrument = await client.generate_instrument(
            query="Will BTC hit 100k?",
            resolution_time=datetime.now(timezone.utc) + timedelta(days=7),
        )

        # Get a price quote
        quote = await client.get_quote(
            instrument.instrument_id,
            buy_yes=True,
            amount=10.0,
            user_id="user-123",
        )
        print(f"Price: {quote.price}, Amount: {quote.amount}")

        # Submit an order (returns EIP-712 data to sign)
        result = await client.submit_order(
            instrument_id=instrument.instrument_id,
            user_id="user-123",
            caller_address="0xYourSafeAddress",
            amount=quote.amount,
            price=quote.price,
            buy_yes=True,
        )

        # Sign each operation's EIP-712 data with your wallet,
        # then relay the signed operations
        signatures = {}  # {operation_id: "0xSignature..."}
        for op in result.operation_sequence.operations:
            sig = sign_eip712(op.eip_712_tx)  # your signing logic
            signatures[op.operation_id] = sig

        relay = await client.relay(
            result.operation_sequence.sequence_id,
            signatures,
        )
        print(f"Relay successful: {relay.successful}")

asyncio.run(main())

EOA Direct Interaction

For EOA wallets that want to interact with the Escrow contract directly (bypassing the Safe/relay flow):

from talarion.eoa import (
    build_approve_usdc_tx,
    build_create_trade_tx,
    sign_and_send,
)

ESCROW = "0xEscrowContractAddress"
USDC = "0xUsdcContractAddress"
RPC = "https://tenderly.rpc.polygon.community/"
PK = "0xYourPrivateKey"

# 1. Approve USDC spending (one-time)
approve_tx = build_approve_usdc_tx(USDC, ESCROW)
sign_and_send(approve_tx, PK, RPC)

# 2. After calling client.submit_order(), build and send the trade tx
result = ...  # from client.submit_order()
trade_tx = build_create_trade_tx(result, ESCROW)
tx_hash = sign_and_send(trade_tx, PK, RPC)
print(f"Trade created: {tx_hash}")

API Reference

Client Methods

Method Description
generate_instrument(query, resolution_time) Create a new prediction market
get_instrument(instrument_id) Fetch instrument details
get_settlement(instrument_id) Get settlement value (0-1)
get_quote(instrument_id, buy_yes, *, amount, dollars, user_id) Request a price quote
submit_order(instrument_id, user_id, caller_address, amount, price, buy_yes) Submit a trade order
cancel_order(trade_id, caller_address) Cancel a pending trade
relay(sequence_id, signatures) Relay signed operations on-chain
get_trade(trade_id) Fetch a single trade
list_trades(*, status, user_id, instrument_id) List trades with filters
get_user_trades(user_id, *, status) List a user's trades
get_user_pnl(user_id) Get user's realized P&L

EOA Functions

Function Description
build_create_trade_tx(result, escrow_address) Build unsigned createTrade tx
build_cancel_trade_tx(trade_id, escrow_address) Build unsigned cancelPendingTrade tx
build_approve_usdc_tx(usdc_address, escrow_address) Build unsigned USDC approval tx
sign_and_send(tx, private_key, rpc_url) Sign and broadcast a transaction

Exceptions

Exception HTTP Status Description
TalarionError any Base exception
AuthenticationError 401 Invalid or missing API key
ValidationError 400 Invalid request parameters
NotFoundError 404 Resource not found
ConflictError 409 Duplicate order or already relayed
QuoteProcessingError 202 Quote still being generated
ServerError 5xx Server-side error

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

talarion-0.1.1.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

talarion-0.1.1-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file talarion-0.1.1.tar.gz.

File metadata

  • Download URL: talarion-0.1.1.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for talarion-0.1.1.tar.gz
Algorithm Hash digest
SHA256 701c5b4d3a6774eca1ccf2baade79e5673b4acc477995d2db11f9fca6b527575
MD5 a60ca23e4f614b6767b4e80fe93d2527
BLAKE2b-256 239cccba8c39ce7ec8ebec6bc59f3c244fe4e24bc15260c8bccefbb46a9b227a

See more details on using hashes here.

File details

Details for the file talarion-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: talarion-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for talarion-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5ce21610358d1ef11e941be8038eb71883cf9d25f2c577eab34071fc53076f8f
MD5 35b21abf537f308d064a34b9538cb909
BLAKE2b-256 2435c3d392359d0215efe31a3e3532f2fd7de72a59802fdc3ab11df3147e929e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page