Skip to content

idexio/idex-sdk-python

Repository files navigation

IDEX Python SDK

Discord GitHub npm GitHub issues

Twitter Follow

The official library for IDEX v3's REST and WebSocket APIs, featuring a real time order book implementation with support for hybrid liquidity.

Complete documentation for the IDEX v3 API is available at https://api-docs-v3.idex.io.

The IDEX Python SDK is currently in beta.

Installation

pip install idex-sdk

Getting Started

  • Sign up for API keys. Market data endpoints do not require an account.
  • In-depth usage documentation by endpoint is available here.

Usage Examples

Public REST API Client

from idex_sdk.client.rest.public import RestPublicClient

c = RestPublicClient()
exchange_info = c.get_exchange_info()
assets = c.get_assets()
markets = c.get_markets()
candles = c.get_candles({"market": "ETH-USDC", "interval": "1h"})
order_book_l2 = c.get_order_book_level2("ETH-USDC")

Authenticated REST API Client

from uuid import uuid1

from idex_sdk.client.rest.authenticated import RestAuthenticatedClient

def uuid() -> str:
    return str(uuid1())

c = RestAuthenticatedClient(
    api_key="<API key>",
    api_secret="<API secret>",
    wallet_private_key="<wallet private key>",
)
wallet_address = "<wallet address>"

get_balances = c.get_balances(
    {
        "nonce": uuid(),
        "wallet": wallet_address,
    }
)

new_order = c.create_order(
    {
        "nonce": uuid(),
        "wallet": wallet_address,
        "market": "ETH-USDC",
        "type": "limit",
        "side": "buy",
        "quantity": "1.00000000",
        "price": "1000.00000000",
    }
)

Real Time Order Book Client

import asyncio

from idex_sdk.client.order_book.real_time import OrderBookRealTimeClient

def update_l2_order_book(market: str) -> None:
    real_time_order_book = client.get_order_book_l2(market, 10)
    print(real_time_order_book)

def make_client() -> OrderBookRealTimeClient:
    client = OrderBookRealTimeClient()
    client.on("l2", update_l2_order_book)
    client.on("ready", update_l2_order_book)
    client.on("error", lambda error: print(f"error {error}"))
    return client

client = make_client()

async def test() -> None:
    task = asyncio.create_task(client.start(["IDEX-USDC"]))
    await task

if __name__ == "__main__":
    asyncio.run(test())

About the Python SDK

This is a python conversion of the IDEX Typescript SDK. There is a conversion of all functionality, including typing with mypy. There are some small differences in how the OrderBookRealTimeClient is run by external code due to differences in how Python's asyncio library handles asynchronous code compares to Javascript. See the example code below for more information.

Setup Repository

  • Ensure python3 and poetry are installed.
  • Clone repo
  • Cd into repo directory
  • Run poetry install

The project is now installed to a virtual environment at ./.venv. Use this environment in the terminal by running poetry shell, or by pointing your IDE to it. For example, loading the project directory in VSCode with the Python extension installed should automatically prompt to select the virtual environment.

The project includes configuration (in pyproject.toml) for type-checking wih mypy, debugging with debugpy (for IDEs like neovim), linting with flake8, auto-formatting with black, and sorting imports with isort. If you configure your IDE appropriately, all of this will be automatic. An example VSCode configuration is included.

Testing

Unit tests are available (using python unittest) for logic-heavy functionality. To run them, run make test.

Generating docs

pydoc-markdown -I idex_sdk --render-toc > docs.md

Contract ABIs

Included in the contracts/ directory contains the ABIs necessary for interacting with IDEX v3's smart contracts.

Getting Help

Please reach out in the #developers Discord for help, or open an issue to report bugs.

License

The IDEX Python SDK is released under the MIT License.

Releases

No releases published

Packages

No packages published

Languages