Skip to main content

An abstract, fully-typed, async Python SDK for automated crypto trading. By Tribulnation.

Project description

Trading SDK

An abstract, fully-typed, async Python SDK for automated crypto trading.

Quick Start

from trading_sdk import TradingSDK

sdk = TradingSDK()
mexc = await sdk.market('mexc:spot:BTCUSDT')
dydx = await sdk.market('dydx:perp:BTC-USD')

async for my_trade in mexc.trades_stream():
  print(f'Hedging {my_trade}')
  await dydx.place_order({
    'type': 'LIMIT',
    'qty': -my_trade.qty,
    'price': my_trade.price,
  })

Installation

pip install trading-sdk[mexc, dydx, hyperliquid]

Supported Venues

Enumerating Venues/Exchanges/Markets

venues = await sdk.venues()

venue = await sdk.venue(venues[0])

exchanges = await venue.exchanges()
exchange = await venue.exchange(exchanges[0])

markets = await exchange.markets()
market = await exchange.market(markets[0])

Market IDs

Market IDs have this form: <venue_id>:<exchange_id>:<market_id>.

You can also scope. These are equivalent:

  1. Directly on the SDK:
await sdk.book('mexc:spot:BTCUSDT')
  1. By venue:
venue = await sdk.venue('mexc')
await venue.book('spot:BTCUSDT')
  1. By exchange:
exchange = await venue.exchange('spot')
await exchange.book('BTCUSDT')
  1. By market:
market = await exchange.market('BTCUSDT')
await market.depth()

Market Interface

  • Public data:
    • depth() -> Book: order book
    • depth_stream() -> Stream[Book]: real-time order book updates
    • rules() -> Rules: market rules (tick size, fees, etc.)
  • User data:
    • query_order(id: str) -> OrderState | None
    • open_orders() -> Sequence[OrderState]
    • trades_history(start: datetime, end: datetime) -> AsyncIterable[Sequence[Trade]]
    • trades_stream() -> Stream[Trade]: real-time user trades
    • position() -> Position: base-asset position
  • Trading:
    • place_order(order: Order) -> OrderResponse
    • place_orders(orders: Sequence[Order]) -> Sequence[OrderResponse]
    • cancel_order(id: str) -> Any
    • cancel_orders(ids: Sequence[str])
    • cancel_open_orders()
  • Perpetual markets:
    • index() -> Decimal: index price
    • next_funding() -> FundingRate: next funding rate
    • funding_history(start: datetime, end: datetime) -> AsyncIterable[Sequence[FundingRate]]: market funding rate history
    • funding_payments(start: datetime, end: datetime) -> AsyncIterable[Sequence[FundingPayment]]: your funding payments history
    • position() -> PerpPosition: open base-asset position, including the entry price

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

trading_sdk-1.0.5.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

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

trading_sdk-1.0.5-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

Details for the file trading_sdk-1.0.5.tar.gz.

File metadata

  • Download URL: trading_sdk-1.0.5.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.10

File hashes

Hashes for trading_sdk-1.0.5.tar.gz
Algorithm Hash digest
SHA256 fbebc6f68fea59f84f6e365a868396e7591179b59600417728bba59d98d7f05b
MD5 fea4c66fcb228c0ea4a334224e35ce2b
BLAKE2b-256 d2495470c47d5905d4b79b1bf5bc226587b605a9a7101896e5b02f4dc740c30f

See more details on using hashes here.

File details

Details for the file trading_sdk-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: trading_sdk-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 27.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.10

File hashes

Hashes for trading_sdk-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7de149baa34bb0f45b672be47de13499ebae97b2b2c4f63158fb34b314974ea2
MD5 e969acfcc0bec6dd6286bc897bc543a4
BLAKE2b-256 1730691d30d14c1d37731580d51afe9bd6f359f457d6febc2944aab54e8b3ec4

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