Skip to main content

Library for trading on Tristero

Project description

Tristero

PyPI version Python Support

This repository is home to Tristero's trading library.

Installation

pip install tristero

Quick Start

Execute a cross-chain swap in just a few lines:

import os
from tristero.client import TokenSpec, execute_swap
from eth_account import Account
from web3 import AsyncWeb3
from tristero.api import ChainID

private_key = os.getenv("EVM_PRIVATE_KEY")
account = Account.from_key(private_key)
w3 = AsyncWeb3(AsyncWeb3.AsyncHTTPProvider("https://arbitrum-one-rpc.publicnode.com"))

result = await execute_swap(
    w3=w3,
    account=account,
    src_t=TokenSpec(chain_id=ChainID.arbitrum, token_address="0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9"),  # USDT
    dst_t=TokenSpec(chain_id=ChainID.base, token_address="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"),  # USDC
    raw_amount=10000000  # Raw token amount (multiply by 10^decimals)
)

How it works

Tristero swaps happen in two steps:

  1. Quote & Sign - Request a quote from the server and sign it with your private key
  2. Submit & Fill - Submit the signed order to be filled at a later date

This library provides both high-level convenience functions and lower-level components for precise control.

API Reference

Execute Full Swap

execute_swap handles the entire workflow automatically: quoting, signing, submitting, and monitoring.

from tristero.swap import execute_swap, TokenSpec
from web3 import AsyncWeb3
from eth_account.signers.local import LocalAccount

w3 = AsyncWeb3(...)  # Your Web3 provider
account: LocalAccount = ...  # Your account

result = await execute_swap(
    w3=w3,
    account=account,
    src_t=TokenSpec(chain_id=ChainID.ethereum, token_address="0xA0b8..."),
    dst_t=TokenSpec(chain_id=ChainID.arbitrum, token_address="0xaf88..."),
    raw_amount=10*(10**18),
    retry=True,
    timeout=300.0  # 5 minutes
)

Requesting a quote

get_quote requests a quote for a particular swap, letting you see output amounts and gas fees.

from tristero.api import get_quote, ChainID

quote = await get_quote(
    from_wallet="0x1234...",           # Source wallet address
    to_wallet="0x5678...",             # Destination wallet address
    from_chain_id=ChainID.ethereum,    # Source chain
    from_address="0xA0b8...",          # Source token address (or "native")
    to_chain_id=ChainID.arbitrum,      # Destination chain
    to_address="0xaf88...",            # Destination token address (or "native")
    amount=10*(10**18),                # Amount in smallest unit (wei)
)

Creating a signed order

create_order creates and signs an order without submitting to be filled.

from tristero.api import get_quote, ChainID

w3 = AsyncWeb3(...)  # Your Web3 provider
account: LocalAccount = ...  # Your account

data, sig = await create_order(
    w3,
    account,
    from_chain_id=ChainID.ethereum,
    from_address="0xA0b8...",
    to_chain_id=ChainID.arbitrum,
    to_address="0xaf88...",
    raw_amount=10*(10**18),
)

Submit order

fill_order submits a signed order for execution.

from tristero.api import fill_order

data, sig = ... # from earlier

response = await fill_order(
    signature=str(sig.signature.to_0x_hex()),
    domain=data.domain.model_dump(by_alias=True, mode="json"),
    message=data.message.model_dump(by_alias=True, mode="json"),
)

order_id = response['id']

Subscribing for updates

Orders can be monitored for changes and status live

from tristero.api import poll_updates
import json

ws = await poll_updates(order_id)

async for msg in ws:
    update = json.loads(msg)
    print(f"Completed: {update['completed']}")
    print(f"Failed: {update['failed']}")

    if update["completed"] or update["failed"]:
        await ws.close()
        break

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

tristero-0.1.3.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

tristero-0.1.3-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file tristero-0.1.3.tar.gz.

File metadata

  • Download URL: tristero-0.1.3.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.8

File hashes

Hashes for tristero-0.1.3.tar.gz
Algorithm Hash digest
SHA256 5e5cbe5d0627b133668c3dbea591c92ed2669a801b5aa92ec8fefa135bc3e4a1
MD5 0bdfb9ed3a2d7fa62d36c92781654f63
BLAKE2b-256 7a41dee792d7688bff29f4c94710588843f07d1fb9f9c930439193779ed15bf7

See more details on using hashes here.

File details

Details for the file tristero-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: tristero-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.8

File hashes

Hashes for tristero-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c1764cb4592ad43e3b0a0c62dff968662ae499648aad3590a82806cb92ade5e0
MD5 543bf9b8258611640dbae535bb8cfd55
BLAKE2b-256 af19805a2f23f22dbc79f3ed565c8f22e0a5dcee08e65d5621fc1d6eb5728b58

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