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
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
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
trading_sdk-1.0.4.tar.gz
(19.7 kB
view details)
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 trading_sdk-1.0.4.tar.gz.
File metadata
- Download URL: trading_sdk-1.0.4.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fcab0b3ff94a4a2fe00528f00bfdf15b2b78e76f493b61694d074a36cd90330
|
|
| MD5 |
138dc9e657bd9e8d68de60af85640897
|
|
| BLAKE2b-256 |
528ed15b55dfbeea60b4c79c6ab1bcd9f9bc3ccb446573e7c44b1101c78e2912
|
File details
Details for the file trading_sdk-1.0.4-py3-none-any.whl.
File metadata
- Download URL: trading_sdk-1.0.4-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d07dc51f1e935f7e524c0d59018e2b065b3fd430410c30a55f4d04143d482439
|
|
| MD5 |
45d80a6ec5ce021dcd82d1803bd5cffe
|
|
| BLAKE2b-256 |
93fc21d949a48cb74810c33b51effc8b21bd680839ee632d273303aedd4e05f4
|