A client library for accessing the Lattice Prediction Market API
Project description
Lattice Python SDK
A Python client for the Lattice Prediction Market API.
Install
pip install lattice-trading
Quickstart
from lattice import LatticeClient
from lattice.api.markets import get_api_v1_markets
client = LatticeClient(
tenant_id="tenant-id",
api_key="lat_example",
)
markets = client.call(get_api_v1_markets.sync_detailed, limit=25, offset=0)
print(markets.markets)
To point at staging, override base_url:
client = LatticeClient(
base_url="https://staging-api.lattice.market",
tenant_id="tenant-id",
api_key="lat_example",
)
Async usage
from lattice import AsyncLatticeClient
from lattice.api.orders import post_api_v1_orders
client = AsyncLatticeClient(
tenant_id="tenant-id",
api_key="lat_example",
)
order = await client.call_async(
post_api_v1_orders.asyncio_detailed,
market_id="market-id",
outcome_id="outcome-id",
side="buy",
type="limit",
price=55,
quantity=10,
idempotency_key="order-001",
)
print(order.id)
Validation and logging
The SDK validates request parameters against type hints before sending requests.
import logging
from lattice import LatticeClient
from lattice.api.markets import get_api_v1_markets
logger = logging.getLogger("lattice")
client = LatticeClient(
tenant_id="tenant-id",
api_key="lat_example",
logger=logger,
)
client.call(get_api_v1_markets.sync_detailed, limit=10, offset=0)
Disable validation if you need to bypass strict checks:
client = LatticeClient(
tenant_id="tenant-id",
api_key="lat_example",
validate=False,
)
Pagination helpers
from lattice.pagination import paginate_offset
from lattice.api.orders import get_api_v1_orders
client = LatticeClient(tenant_id="tenant-id", api_key="lat_example")
def fetch_page(limit: int, offset: int):
response = client.call(get_api_v1_orders.sync_detailed, limit=limit, offset=offset)
return response.orders, response.limit, response.offset, response.total
for order in paginate_offset(fetch_page, limit=50):
print(order.id)
Notes
- Generated endpoint modules live in
lattice.api.*. x_tenant_idis injected automatically byLatticeClient.- Use
idempotency_keyfor state-changing operations. priceandamountvalues are integers in cents.- See
docs/getting-started.mdanddocs/api-reference.mdfor more detail.
Advanced customization
You can still use the generated Client and AuthenticatedClient directly for full control over httpx settings.
from lattice import Client
def log_request(request):
print(f"Request event hook: {request.method} {request.url} - Waiting for response")
def log_response(response):
request = response.request
print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
client = Client(
base_url="https://api.lattice.market",
httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
)
# Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client()
You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url):
import httpx
from lattice import Client
client = Client(
base_url="https://api.lattice.market",
)
# Note that base_url needs to be re-set, as would any shared cookies, headers, etc.
client.set_httpx_client(httpx.Client(base_url="https://api.lattice.market", proxies="http://localhost:8030"))
Building / publishing this package
This project uses Poetry to manage dependencies and packaging. Here are the basics:
- Update the metadata in pyproject.toml (e.g. authors, version)
- If you're using a private repository, configure it with Poetry
poetry config repositories.<your-repository-name> <url-to-your-repository>poetry config http-basic.<your-repository-name> <username> <password>
- Publish the client with
poetry publish --build -r <your-repository-name>or, if for public PyPI, justpoetry publish --build
If you want to install this client into another project without publishing it (e.g. for development) then:
- If that project is using Poetry, you can simply do
poetry add <path-to-this-client>from that project - If that project is not using Poetry:
- Build a wheel with
poetry build -f wheel - Install that wheel from the other project
pip install <path-to-wheel>
- Build a wheel with
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lattice_trading-0.1.0.tar.gz.
File metadata
- Download URL: lattice_trading-0.1.0.tar.gz
- Upload date:
- Size: 75.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.9.6 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55f53ec5051d19bc3aa53357ff11c1c1d5fddcfcd7dfcb677dbdaf3e33b81291
|
|
| MD5 |
30c5c76a68ba63a5b187235a70f0a4aa
|
|
| BLAKE2b-256 |
8dadabdc0e235ca5ac534bb3f5d24d781f977aa851f3a29741eb20d695e43a40
|
File details
Details for the file lattice_trading-0.1.0-py3-none-any.whl.
File metadata
- Download URL: lattice_trading-0.1.0-py3-none-any.whl
- Upload date:
- Size: 309.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.9.6 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7383bffcfe240b51f04809e5da671ce3f9408914951b32b44ef452199a360aed
|
|
| MD5 |
dcd3514810b3340e8e4d848abe92b90c
|
|
| BLAKE2b-256 |
8b8f76f1b59e7194c5e7a06c43c84a179f855f5ec08be8c3e17581c5887d8b12
|