Python SDK for the noex cryptocurrency exchange
Project description
noex Python SDK
Official Python SDK for the noex cryptocurrency exchange platform.
Features
- 🔐 Authentication: Register and login with wallet-based authentication
- 💼 Wallet Management: View and manage multi-currency balances
- 📊 Trading: Place limit and market orders, view order history
- 📈 Market Data: Access orderbooks, prices, and recent trades
- 💸 Transactions: Deposit and withdraw cryptocurrencies
- 🔌 WebSocket: Real-time updates for wallet, orderbook, and prices
- ✅ Fully Typed: Complete type hints for better IDE support
- 🧪 Well Tested: Comprehensive unit tests
Installation
pip install noex-sdk
Or install from source:
git clone https://github.com/noex/noex-sdk-python.git
cd noex-sdk-python
pip install -e .
Quick Start
Basic Usage
from noex import Exchange
# Initialize the exchange client
exchange = Exchange(base_url="http://localhost:8000")
# Register a new account
exchange.register(
public_key="0x37F5260604F3c346E0037619C34c1Ed260206B55",
ens="user.eth",
password="securePassword123"
)
# Or login to existing account
exchange.login("user.eth", "securePassword123")
# Get wallet balances
wallets = exchange.get_wallets()
for wallet in wallets:
print(f"{wallet['s']}: {wallet['b']} (locked: {wallet['l']})")
# Get current price
price = exchange.get_price("BTC/USDT")
print(f"BTC/USDT: ${price['pr']}")
# Place a limit buy order
order = exchange.limit_buy("BTC/USDT", amount=0.01, price=45000.0)
print(f"Order placed: {order['id']}")
# Cancel an order
exchange.cancel_order(order['id'])
WebSocket Usage
from noex import Exchange
import time
# Initialize with WebSocket auto-connect
exchange = Exchange(base_url="http://localhost:8000", auto_connect_ws=True)
exchange.login("user.eth", "securePassword123")
# Define callback for price updates
def on_price_update(message):
prices = message['data']
for price in prices:
print(f"{price['p']}: ${price['pr']}")
# Subscribe to price updates
sub_id = exchange.subscribe_all_prices(on_price_update)
# Listen for updates
time.sleep(30)
# Unsubscribe
exchange.unsubscribe({"type": "allMids"}, sub_id)
exchange.disconnect_websocket()
API Reference
Exchange Client
The Exchange class is the main entry point for the SDK.
Initialization
Exchange(base_url=None, timeout=None, auto_connect_ws=False)
base_url: API base URL (default:http://localhost:8000)timeout: Request timeout in seconds (default: 30)auto_connect_ws: Auto-connect WebSocket on initialization
Authentication
register(public_key, ens, password)- Register new accountlogin(identifier, password)- Login to existing account
Wallet
get_wallets()- Get all wallet balances
Trading
create_order(pair, order_type, mode, amount, price=None)- Create ordermarket_buy(pair, amount)- Create market buy ordermarket_sell(pair, amount)- Create market sell orderlimit_buy(pair, amount, price)- Create limit buy orderlimit_sell(pair, amount, price)- Create limit sell orderget_orders()- Get all orderscancel_order(order_id)- Cancel an order
Market Data
l2Book(pair)- Get orderbookget_price(pair)- Get current priceget_all_prices()- Get all pricesget_pairs()- Get available trading pairsget_trades(pair)- Get recent trades
Transactions
deposit(symbol, amount, address=None)- Create depositwithdraw(symbol, amount, address)- Create withdrawalget_transactions()- Get transaction history
WebSocket
connect_websocket()- Connect WebSocket clientdisconnect_websocket()- Disconnect WebSocket clientsubscribe_wallet(ens, callback)- Subscribe to wallet updatessubscribe_orderbook(coin, callback)- Subscribe to orderbook updatessubscribe_all_prices(callback)- Subscribe to price updatessubscribe(subscription, callback)- Generic subscribe methodunsubscribe(subscription, subscription_id)- Unsubscribe from updates
Examples
The examples/ directory contains complete working examples:
basic_usage.py- Basic REST API operationswebsocket_example.py- WebSocket subscriptionstrading_bot.py- Simple trading bot implementation
Run an example:
cd examples
python basic_usage.py
Development
Setup Development Environment
# Clone the repository
git clone https://github.com/noex/noex-sdk-python.git
cd noex-sdk-python
# Install development dependencies
pip install -r requirements-dev.txt
# Install package in editable mode
pip install -e .
Run Tests
# Run all tests
python -m pytest tests/
# Run with coverage
python -m pytest tests/ --cov=noex --cov-report=html
# Run specific test file
python -m pytest tests/test_api_client.py
Code Formatting
# Format code with black
black noex/ tests/ examples/
# Check with flake8
flake8 noex/ tests/ examples/
# Type checking with mypy
mypy noex/
Data Types
The SDK uses abbreviated field names to match the API:
p- pair (e.g., "BTC/USDT")t- type (e.g., "buy", "sell", "deposit")m- mode (e.g., "limit", "market")pr- priceam- amountf- filled amountst- statuss- symbolb- balancel- lockedc- created_atad- address
See noex/utils/types.py for complete type definitions.
Error Handling
The SDK provides specific exception classes:
from noex import NoexError, ClientError, ServerError, AuthenticationError, WebSocketError
try:
exchange.login("user.eth", "wrong_password")
except AuthenticationError as e:
print(f"Authentication failed: {e}")
except ClientError as e:
print(f"Client error {e.status_code}: {e.error_message}")
except ServerError as e:
print(f"Server error {e.status_code}: {e.message}")
Configuration
Environment Variables
You can configure the SDK using environment variables:
export NOEX_API_URL="http://localhost:8000"
export NOEX_API_TIMEOUT="30"
API URLs
Predefined URL constants:
from noex import LOCAL_API_URL, TESTNET_API_URL, MAINNET_API_URL
# Use testnet
exchange = Exchange(base_url=TESTNET_API_URL)
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Run the test suite
- Submit a pull request
License
MIT License - see LICENSE file for details.
Support
- 📧 Email: dev@noex.io
- 💬 Discord: https://discord.gg/noex
- 📚 Documentation: https://docs.noex.io
Links
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
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 noex_sdk-1.0.0.tar.gz.
File metadata
- Download URL: noex_sdk-1.0.0.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92d79f21e8bd74fccf9106c12ea8ac15226d2fabfda0cd2fa210b1a562236dca
|
|
| MD5 |
fbb5acb150934e82bdb626df7e0f16b9
|
|
| BLAKE2b-256 |
117e312874b74034cbdab4a204c51452633e29f313d39c98582087d5e0bc5798
|
File details
Details for the file noex_sdk-1.0.0-py3-none-any.whl.
File metadata
- Download URL: noex_sdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2336091509a684668e2bcd85fb5ab8dfa5507698a66c1e4249395c820cc470f5
|
|
| MD5 |
f50f0fea335f6efbcbb5fd1044d9c53a
|
|
| BLAKE2b-256 |
4853631db45b80e2636aa6915a87b31bb909b00242f3fa87e428195f196dffc8
|