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
mexc: MEXCdydx: dYdXhyperliquid: Hyperliquid
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:
- Directly on the SDK:
await sdk.book('mexc:spot:BTCUSDT')
- By venue:
venue = await sdk.venue('mexc')
await venue.book('spot:BTCUSDT')
- By exchange:
exchange = await venue.exchange('spot')
await exchange.book('BTCUSDT')
- By market:
market = await exchange.market('BTCUSDT')
await market.depth()
Market Interface
- Public data:
depth() -> Book: order bookdepth_stream() -> Stream[Book]: real-time order book updatesrules() -> Rules: market rules (tick size, fees, etc.)
- User data:
query_order(id: str) -> OrderState | Noneopen_orders() -> Sequence[OrderState]trades_history(start: datetime, end: datetime) -> AsyncIterable[Sequence[Trade]]trades_stream() -> Stream[Trade]: real-time user tradesposition() -> Position: base-asset position
- Trading:
place_order(order: Order) -> OrderResponseplace_orders(orders: Sequence[Order]) -> Sequence[OrderResponse]cancel_order(id: str) -> Anycancel_orders(ids: Sequence[str])cancel_open_orders()
- Perpetual markets:
index() -> Decimal: index pricenext_funding() -> FundingRate: next funding ratefunding_history(start: datetime, end: datetime) -> AsyncIterable[Sequence[FundingRate]]: market funding rate historyfunding_payments(start: datetime, end: datetime) -> AsyncIterable[Sequence[FundingPayment]]: your funding payments historyposition() -> PerpPosition: open base-asset position, including the entry price
Metadata
Release files for trading-sdk 1.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| trading_sdk-1.0.6.tar.gz | 19.9 kB | Without provenance | Details for trading_sdk-1.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| trading_sdk-1.0.6-py3-none-any.whl | Python 3 | none | any | Details for trading_sdk-1.0.6-py3-none-any.whl |
Total release size: 47.8 kB
Release files / trading_sdk-1.0.6.tar.gz
| Download URL | trading_sdk-1.0.6.tar.gz |
|---|---|
| Size | 19.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fc2a2e26d41244dfe47605ba18a9883db7238be541a3d030958beb7b64e20d81
|
|
BLAKE2b-256 checksum How to use checksums |
9d0d9a908401dafa8c65e6668e73daa163475a247466af5c6be19c4a1bdbf3a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.10
|
Release files / trading_sdk-1.0.6-py3-none-any.whl
| Download URL | trading_sdk-1.0.6-py3-none-any.whl |
|---|---|
| Size | 27.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
032eab33535a772510b7a3f36b9a6a629a6bfb36458200dd40473771946ecb03
|
|
BLAKE2b-256 checksum How to use checksums |
a116cac7b207a47ae19a8334ae74e100e1689e75d7e624a0f12130590aa29e68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.10
|
Security for trading-sdk 1.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.