KREX - A Lightweight Python Package for Low-Latency and Cross-Exchange Trading
A high-performance and lightweight Python library for interacting with cryptocurrency exchanges. KREX offers full synchronous and asynchronous support across major exchanges, designed for speed, modularity, and ease of use.
📦 Installation
pip install krex
🚀 Quick Start
Synchronous Usage
import krex
import os
# Initialize client for any supported exchange
client = krex.binance(
api_key="your_api_key",
api_secret="your_api_secret"
)
# Get account balance
balance = client.get_account_balance()
print(balance)
# Get market data
klines = client.get_klines(symbol="BTCUSDT", interval="1h")
print(klines)
Asynchronous Usage
import asyncio
import krex.async_support as krex
import os
async def main():
# Initialize async client
client = await krex.binance(
api_key="your_api_key",
api_secret="your_api_secret"
)
try:
# Get account balance
balance = await client.get_account_balance()
print(balance)
# Get market data
klines = await client.get_klines(symbol="BTCUSDT", interval="1h")
print(klines)
finally:
await client.close()
if __name__ == "__main__":
asyncio.run(main())
📚 Supported Exchanges
| Exchange | Sync Support | Async Support |
|---|---|---|
| Binance | ✅ | ✅ |
| Bybit | ✅ | ✅ |
| OKX | ✅ | ✅ |
| BitMart | ✅ | ✅ |
| Gate.io | ✅ | ✅ |
| Hyperliquid | ✅ | ✅ |
| BitMEX | ✅ | ✅ |
| BingX | Developing | Developing |
| AscendEX | Developing | Developing |
| KuCoin | Developing | Developing |
🔍 Key Features
- 📘 Product Table Manager for unifying trading instruments in different exchanges
- 🔁 Sync & Async API clients with identical interfaces
- ⚡ Optimized for low-latency, high-frequency trading
What is Product Table Manager(ptm)?
Ptm is a utility that standardizes and unifies trading instrument metadata across different exchanges, making cross-exchange strategy development easier.
It is a table that contains the following columns:
| Column | Description |
|---|---|
| exchange | The exchange name |
| product_symbol | The symbol we use to identify the product, it will be the same in different exchanges. For example, BTC-USDT-SWAP is the same product in Binance and Bybit, which named BTCUSDT in Binance and BTC-USDT-SWAP in OKX. |
| exchange_symbol | The symbol that the exchange will actually used |
| product_type | The type we will use, e.g. spot, inverse, swap, futures |
| exchange_type | The type the exchange will actually used, e.g. linear, INVERSE, perp... different exchanges have different types, pretty annoying... |
| base_symbol | The base symbol, e.g. BTC |
| quote_symbol | The quote symbol, e.g. USDT |
| price_precision | The price precision, e.g. 0.000001 |
| size_precision | The size precision, e.g. 0.000001 |
| min_size | The minimum size, e.g. 0.000001 |
| min_notional | The minimum notional, e.g. 0.000001 |
| multiplier | The multiplier of the product, such symbol like 1000BONKUSDT in Bybit will need to be multiplied by 1000 to get the actual size, if you are trading across spot and swap, you will need this |
| size_per_contract | The size per contract. Sometimes 1 contract is not the same as 1 unit in exchanges like OKX. |
How to use Product Table Manager?
In most cases, we have handled the case, but if you have any specific use cases, you can use the ptm to get the information you want.
import krex
binance = krex.binance()
btcusdt_product_symbol = binance.ptm.get_product_symbol(
exchange="binance",
exchange_symbol="BTCUSDT",
product_type="swap",
)
print(btcusdt_product_symbol)
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
# Clone the repository
git clone https://github.com/kairosresearchio/krex.git
cd krex
# We use `uv` to manage the project, you can install it with `pip install uv`
# Create a virtual environment
uv venv
# Install the dependencies
uv sync
Contributors
📄 License
This project is licensed under the MIT License.
🆘 Support
- Issues: Report bugs and request features on GitHub Issues
📜 Disclaimer
Cryptocurrency trading involves significant risk. This library is provided as-is without any warranty. Users are responsible for their own trading decisions and risk management.
Metadata
Release files for krex 0.21.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| krex-0.21.0.tar.gz | 123.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| krex-0.21.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 304.6 kB
Release files / krex-0.21.0.tar.gz
| Download URL | krex-0.21.0.tar.gz |
|---|---|
| Size | 123.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e8212f4ccc78850bf2af6f3e0ca2afd1e7c42af2df4997c183b405520283356e
|
|
BLAKE2b-256 checksum How to use checksums |
229dff9ac0e9f335d838dfa332db3014ab6c95dcae3ef26e647d80c784c3509d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.23
|
Release files / krex-0.21.0-py3-none-any.whl
| Download URL | krex-0.21.0-py3-none-any.whl |
|---|---|
| Size | 181.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dde902ddfe4bc5de81b59f9cb515f9d7f41401b6704b6ff8a9efb26e3078e518
|
|
BLAKE2b-256 checksum How to use checksums |
b4effe3b46d4f4f3686f08c9557a9d6762be22abf8500b2255d60a643ef53c4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.23
|