Skip to main content

Python client for X10 API

Project description

X10

Python client for X10 API.

Minimum Python version required to use this library is 3.9 (you can use pyenv to manage your Python versions easily).

Installation

pip install x10-python-trading

Our SDK makes use of a Rust Library to accelerate signing and hashing of stark components. Currently this library supports the following environments

3.9 3.10 3.11 3.12
linux (glibc) - x86
linux (musl) - x86
linux (glibc) - arm64
linux (musl) - arm64
OSX - arm64
windows - x86 ⚠️ ⚠️ ⚠️ ⚠️
windows - arm64 ⚠️ ⚠️ ⚠️ ⚠️

TLDR:

Register at x10 testnet by connecting a supported Ethereum Wallet.

Navigate to Api Management

  1. Generate an API key
  2. Show API details (You will need these details to initialise a trading client)

Instantiate a Trading Account

from x10.perpetual.accounts import StarkPerpetualAccount
api_key:str = "<api>" #from api-management
public_key:str = "<public>" #from api-management
private_key:str = "<private>" #from api-management
vault:int = <vault> #from api-management

stark_account = StarkPerpetualAccount(
    vault=vault,
    private_key=private_key,
    public_key=public_key,
    api_key=api_key,
)

Instantiate a Trading Client

from x10.perpetual.accounts import StarkPerpetualAccount
from x10.perpetual.configuration import TESTNET_CONFIG
from x10.perpetual.orders import OrderSide
from x10.perpetual.trading_client import PerpetualTradingClient

trading_client = PerpetualTradingClient.create(TESTNET_CONFIG, stark_account)
placed_order = await trading_client.place_order(
    market_name="BTC-USD",
    amount_of_synthetic=Decimal("1"),
    price=Decimal("63000.1"),
    side=OrderSide.SELL,
)
await trading_client.orders.cancel_order(order_id=placed_order.id)
print(placed_order)

for more information see placing an order example

Modules

The SDK currently provides functionality across three main modules

Order Management Module

The order module is accessed using the orders property of the trading client

trading_client.orders

TODO

Account Module

The account module is accessed using the account property of the trading client

trading_client.account

it exposes functionality related to managing an active trading account

get_balance

Fetches the balance of the user's account.

    logger = logging.getLogger("demo_logger")
    balance = await trading_client.account.get_balance()
    logger.info("Balance: %s", balance.to_pretty_json())

get_positions

Fetches the current positions of the user's account. It can filter the positions based on market names and position side.

    logger = logging.getLogger("demo_logger")
    positions = await trading_client.account.get_positions()
    logger.info("Positions: %s", positions.to_pretty_json())

get_positions_history

Fetches the historical positions of the user's account. It can filter the positions based on market names and position side.

pass

get_open_orders

Fetches the open orders of the user's account. It can filter the orders based on market names, order type, and order side.

    open_orders = await trading_client.account.get_open_orders()
    await trading_client.orders.mass_cancel(order_ids=[order.id for order in open_orders.data])

get_orders_history

Fetches the historical orders of the user's account. It can filter the orders based on market names, order type, and order side.

pass

get_trades

Fetches the trades of the user's account. It can filter the trades based on market names, trade side, and trade type.

pass

get_fees

Fetches the trading fees for the specified markets.

pass

get_leverage

Fetches the leverage for the specified markets.

   leverage = await trading_client.account.get_leverage(market_names=list("BTC-USD"))
   print(leverage)

update_leverage

Updates the leverage for a specific market.

    await trading_client.account.update_leverage(market_name="BTC-USD", leverage=Decimal("20.0"))

Markets Info Module

The markets module is accessed using the markets_info property of the trading client

trading_client.markets_info

TODO

Contribution

Make sure you have poetry installed.

  • Clone the repository: git@github.com:x10xchange/python-trading.git
  • Navigate to the project directory: cd python-trading
  • Create a virtual environment: poetry shell
  • Install dependencies: poetry install
  • Update examples/placed_order_example.py with your credentials
  • Run it: python -m examples.placed_order_example

Custom commands:

  • make format - format code with black
  • make lint - run safety, black, flake8 and mypy checks
  • make test - run tests

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

x10_python_trading-0.1.3.tar.gz (136.8 kB view hashes)

Uploaded Source

Built Distribution

x10_python_trading-0.1.3-py3-none-any.whl (153.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page