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.2.tar.gz (11.6 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.2-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: talarion-0.1.2.tar.gz
  • Upload date:
  • Size: 11.6 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.2.tar.gz
Algorithm Hash digest
SHA256 085e42a37a8c98c5300250dae4ab80f9c8b1ff68a29f39936e5fcf3d51a052cc
MD5 e072fb2207e88f1a1fa9069832583ff2
BLAKE2b-256 f2efa9ce65a4f47e64582f2b83983e9c7c70a31032b1ce544d65271de782be8b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: talarion-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.0 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bbfeb284a9c4d779623fb77e11ebfde42136f9ff9fe3c010ba72ac3b7a465f1b
MD5 c0bf4708cc35a6d1e43bc85ad15aca56
BLAKE2b-256 9c675222cefcc437aee6cf544de212afd26ddbac8b855a407e25ba0121d86f73

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