Skip to main content

Official Python SDK for the Merx TRON resource exchange

Project description

merx-sdk

Python SDK for the Merx TRON energy exchange.

Installation

pip install merx-sdk

Requires Python 3.11+. No external dependencies (uses stdlib urllib and json).

Quickstart

from merx import MerxClient

client = MerxClient(api_key="sk_live_...")

# Check prices
prices = client.prices.list()
best = client.prices.best("ENERGY")

# Preview cost
preview = client.prices.preview(
    resource="ENERGY",
    amount=65000,
    duration=3600,
)

# Create order
order = client.orders.create(
    resource_type="ENERGY",
    amount=65000,
    duration_sec=3600,
    target_address="TYourAddress...",
)

API Reference

Constructor

client = MerxClient(
    api_key: str,                              # Required
    base_url: str = "https://merx.exchange",   # Optional
)

client.prices

Method Returns Description
list() list[ProviderPrice] All current prices from all providers
best(resource, amount=None) PriceHistoryEntry Cheapest available provider (server-side)
history(provider=None, resource=None, period="24h") list[PriceHistoryEntry] Historical price snapshots
stats() PriceStats Market statistics
preview(resource, amount, duration, max_price_sun=None) OrderPreview Preview order cost

client.orders

Method Returns Description
create(resource_type, amount, duration_sec, target_address, ...) Order Place a new order
list(limit=30, offset=0, status=None) tuple[list[Order], int] Orders with total count
get(order_id) OrderWithFills Order details with fills

create parameters:

Parameter Type Required Description
resource_type str Yes "ENERGY" or "BANDWIDTH"
amount int Yes Min 65000 for ENERGY, 300 for BANDWIDTH
duration_sec int Yes Duration in seconds (3600 = 1h, 86400 = 1d)
target_address str Yes TRON address to receive resources
order_type str No "MARKET" (default), "LIMIT", "PERIODIC", "BROADCAST"
max_price_sun int No Maximum price per unit in SUN
idempotency_key str No Prevent duplicate orders

client.balance

Method Returns Description
get() Balance TRX, USDT, locked amounts
deposit_info() DepositInfo Deposit address and memo
withdraw(address, amount, currency="TRX", idempotency_key=None) Withdrawal Withdraw TRX or USDT
history(period="30D") list[HistoryEntry] Transaction history
summary() HistorySummary Aggregated stats

client.webhooks

Method Returns Description
create(url, events) Webhook Register webhook (secret shown once)
list() list[Webhook] List all webhooks
delete(webhook_id) bool Delete a webhook

Error Handling

All API errors raise MerxError:

from merx import MerxClient, MerxError

try:
    order = client.orders.create(...)
except MerxError as e:
    print(e.code, str(e))

Types

All responses are dataclasses: ProviderPrice, PricePoint, PriceHistoryEntry, PriceStats, OrderPreview, PreviewMatch, Balance, DepositInfo, Order, OrderWithFills, Fill, HistoryEntry, HistorySummary, Withdrawal, Webhook.

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

merx_sdk-1.0.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

merx_sdk-1.0.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file merx_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: merx_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for merx_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 03970f4e62d86e4cf55accd2f874e5816bc6dcaea20e08db3f0f1d92f1560dbf
MD5 eaab61ef96cf5cb182157ed9c4a60539
BLAKE2b-256 5e19911cf26fb0b0eb6e85724077d826364b16449c69db534747da4458947b62

See more details on using hashes here.

File details

Details for the file merx_sdk-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: merx_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for merx_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 39c678e7ffd4117e25923b3a2d1539e38139a00771d2b6ef81a400f15e5f83e6
MD5 49f0bd8783db9f5e1f2db31b21150f0c
BLAKE2b-256 aa91f6c238fc0c29b325bfd6984584f9cb792bdd2178f275cb006fca693b3db2

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