Skip to main content

Python SDK for DFlow on Solana - prediction markets and trading

Project description

DFlow Python SDK

PyPI version Python versions License: MIT

🐍 Python SDK for DFlow on Solana - prediction markets and trading

Installation

pip install dflow-sdk

Or with a package manager:

# Poetry
poetry add dflow-sdk

# UV
uv add dflow-sdk

# PDM
pdm add dflow-sdk

Quick Start

from dflow import DFlowClient

# Development environment (no API key required)
client = DFlowClient()

# Get active markets
response = client.markets.get_markets(status="active")
for market in response.markets:
    print(f"{market.ticker}: YES={market.yes_price}, NO={market.no_price}")

# Get a specific market
market = client.markets.get_market("BTCD-25DEC0313-T92749.99")
print(f"Volume: {market.volume}")

Production Usage

from dflow import DFlowClient

# Production environment (API key required)
client = DFlowClient(environment="production", api_key="your-api-key")

# Get a swap quote
quote = client.swap.get_quote(
    input_mint="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",  # USDC
    output_mint=market.accounts["usdc"].yes_mint,
    amount=1_000_000,  # 1 USDC
)
print(f"You'll receive: {quote.out_amount} tokens")

Trading with Solana

from solders.keypair import Keypair
from solana.rpc.api import Client
from dflow import DFlowClient, sign_send_and_confirm, USDC_MINT

# Setup
dflow = DFlowClient(environment="production", api_key="your-api-key")
connection = Client("https://api.mainnet-beta.solana.com")
keypair = Keypair.from_bytes(your_secret_key)

# Create a swap transaction
swap = dflow.swap.create_swap(
    input_mint=USDC_MINT,
    output_mint=yes_mint,
    amount=1_000_000,
    slippage_bps=50,
    user_public_key=str(keypair.pubkey()),
)

# Sign and send
result = sign_send_and_confirm(connection, swap.swap_transaction, keypair)
print(f"Transaction confirmed: {result.signature}")

WebSocket Streaming

import asyncio
from dflow import DFlowClient

async def main():
    client = DFlowClient()
    
    # Connect to WebSocket
    await client.ws.connect()
    
    # Subscribe to price updates
    await client.ws.subscribe_prices(["BTCD-25DEC0313-T92749.99"])
    
    # Handle updates
    def on_price(update):
        print(f"{update.ticker}: YES={update.yes_price}")
    
    client.ws.on_price(on_price)
    
    # Keep running
    await asyncio.sleep(60)
    client.ws.disconnect()

asyncio.run(main())

Features

  • Full API Coverage: Events, Markets, Orderbook, Trades, Series, Tags, Sports, Search
  • Trading APIs: Orders, Swap, Intent-based swaps, Prediction market initialization
  • Solana Integration: Transaction signing, token balances, position tracking
  • WebSocket Support: Real-time price, trade, and orderbook updates
  • Type Safety: Full Pydantic models for all API responses
  • Async Support: Both sync and async HTTP clients available

API Modules

Module Description
client.events Event discovery and queries
client.markets Market data, pricing, batch queries
client.orderbook Orderbook snapshots
client.trades Historical trade data
client.live_data Real-time milestone data
client.series Series/category information
client.tags Tag-based filtering
client.sports Sports-specific filters
client.search Full-text search
client.orders Order creation and status
client.swap Imperative swaps with route preview
client.intent Declarative intent-based swaps
client.prediction_market Market initialization
client.tokens Token information
client.venues Trading venue information
client.ws WebSocket for real-time updates

Documentation

See the full documentation for detailed API reference.

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

dflow_sdk-0.1.8.tar.gz (50.8 kB view details)

Uploaded Source

Built Distribution

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

dflow_sdk-0.1.8-py3-none-any.whl (58.8 kB view details)

Uploaded Python 3

File details

Details for the file dflow_sdk-0.1.8.tar.gz.

File metadata

  • Download URL: dflow_sdk-0.1.8.tar.gz
  • Upload date:
  • Size: 50.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for dflow_sdk-0.1.8.tar.gz
Algorithm Hash digest
SHA256 601ae7dc88f889791f4d463aea94ca27bfa5bb72fa90a1d1f5f41f555f18a729
MD5 170c90b3e802b1eb426f85de6337889c
BLAKE2b-256 45a26e80292536947c47e0b796251bebf5146d653b81d5d37e368c5cb2dd7b69

See more details on using hashes here.

File details

Details for the file dflow_sdk-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: dflow_sdk-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 58.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for dflow_sdk-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 571e0f2afc9db090037d2b7d65b579b7367cf62723c2ce7d1b1c5b8da3d750b3
MD5 90867d3c32461b316b2b43a96fc4fe2e
BLAKE2b-256 a29e305e0af1ad1ad04a805d5100c5d40b2dcd4c875f8c5cce6145316f822002

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