Skip to main content

Connector library for Pionex REST and WS API with enhanced error handling and performance.

Project description

Pionex to Python

Python connector for the Pionex API — REST, WebSocket, bots, dual investment and high-level portfolio helpers in one package. Tracks the official OpenAPI spec (pionex-official/pionex-open-api).

Installation

pip install pionex_py

What's included

Module Coverage Auth
Common Symbol metadata (/api/v1/common/symbols) no
Markets Trades, depth, tickers, book tickers, klines (+ paging) no
Account Balances + per-coin / portfolio helpers yes
Orders Spot orders: new, mass, cancel, lookup, fills, market/limit helpers, wait_for_order yes
Trade High-level façade: portfolio value/weights, daily rebalancer with dry-run yes
Bot Spot Grid, Futures Grid, Smart Copy, custom signal listener yes
EarnDual Dual Investment — products, prices, invest/revoke/collect mixed
PublicStream / PrivateStream Trade / Depth / Order / Fill / Balance WebSocket mixed

Implements every endpoint exposed by the official 1.x OpenAPI spec for the Trade, Bot, Earn-Dual and WebSocket APIs (Futures and Partner APIs are invite-only and not included).

30-second tour

from pionex_python import Common, Markets, Account, Orders, Trade, Bot, EarnDual

# Public
print(Markets().get_price('BTC_USDT'))
print(Common().list_symbols(market_type='SPOT')[:5])

# Authenticated trading
orders = Orders('KEY', 'SECRET')
orders.market_buy('BTC_USDT', amount=20)             # spend 20 USDT
orders.limit_sell('BTC_USDT', price=80000, size=0.0002)

# Portfolio rebalance — what the daily rebalancer is built on
trade = Trade('KEY', 'SECRET', quote='USDT')
trade.execute_rebalance({'BTC': 0.5, 'ETH': 0.3, 'USDT': 0.2}, dry_run=True)

# Spot-grid bot
bot = Bot('KEY', 'SECRET')
print(bot.get_spot_grid_ai_strategy('BTC', 'USDT'))   # AI suggestion

For a full walkthrough of every module — including bot creation, custom signal pushing, dual-investment subscriptions and a daily rebalancer skeleton — see EXAMPLES.md.

Daily portfolio rebalancer

from pionex_python import Trade

trade = Trade(api_key, api_secret, quote='USDT')

# 1. From your TA + sentiment pipeline
target = {'BTC': 0.50, 'ETH': 0.30, 'USDT': 0.20}

# 2. Compute the diff between current and target weights
plan = trade.compute_rebalance_orders(target, threshold=0.01)

# 3. Always preview first
print(trade.execute_rebalance(plan, dry_run=True))

# 4. When ready
# trade.execute_rebalance(plan, dry_run=False)

execute_rebalance automatically:

  • sells overweight positions before buying underweight ones (so quote cash is available)
  • rounds sizes/amounts to each symbol's basePrecision / quotePrecision
  • skips orders below minNotional / minTradeSize
  • supports dry_run=True so you can iterate safely

API key

  1. Create the key at https://www.pionex.com/en/apiKey.

  2. For a rebalancer enable Read + Trade only — never Withdraw.

  3. Restrict the key to your server's IP.

  4. Export it:

    export PIONEX_KEY=...
    export PIONEX_SECRET=...
    

Versioning

Tracks the published Pionex Open API spec. The library is in pionex_python.__version__.

TODO

  • WebSocket auto-reconnect
  • Retry/backoff on REST 5xx
  • CLI for ad-hoc trading
  • Futures REST coverage (gated by Pionex invite-only access)

Contributing

PRs welcome — issues and feature requests at https://github.com/alejandrorodm/pionex_py/issues.

License

MIT — see LICENSE.

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

pionex_py-1.2.0.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

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

pionex_py-1.2.0-py3-none-any.whl (25.7 kB view details)

Uploaded Python 3

File details

Details for the file pionex_py-1.2.0.tar.gz.

File metadata

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

File hashes

Hashes for pionex_py-1.2.0.tar.gz
Algorithm Hash digest
SHA256 b2c672dee9bbd947d25a14f87f47800647dc51be3181d5d3a764ec30c9c9d4ff
MD5 e551e2ee81f8a59a85a45a968dd8f585
BLAKE2b-256 06c324787b0f8ae107296a8edb7a497116f2f8b06a340e074e3d24ca98bc71ec

See more details on using hashes here.

File details

Details for the file pionex_py-1.2.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pionex_py-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53f22c5ea208d0f4b5185686868f60f2ccb68dd312c0ec4f482bd4b78a0d71bc
MD5 6eaf562df85bb06aa60d9c17a7cef974
BLAKE2b-256 2b0edd30c13b9259f7550ec626ed97e7015b197fadc377af2b5deb85ffa3accc

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