Skip to main content

Python SDK for HMXv2

This library is tested against Python versions 2.7, 3.4, 3.5, 3.9, and 3.11.

Installation

This package is available on PyPI. To install run the command below:

$ pip install hmx-v2-python

Getting Started

The Client object contains two major attributes: Public and Private. As the names suggest, Public is for public functions that don't require an Ethereum private key, and Private is for functions specifically for the given key. For more comprehensive examples, please refer to the examples directory as well as the tests.

Public functions

from hmx2.hmx_client import Client
from hmx2.constants.markets import MARKET_ETH_USD
from hmx2.enum import Action

#
# Using publicly access functions
#
hmx_client = Client(
    rpc_url=RPC_URL
)
# Get oracle price, adaptive price, and price impact of a new position
hmx_client.public.get_price(MARKET_ETH_USD, Action.SELL, 1000)
# Get market information
hmx_client.public.get_market_info(MARKET_ETH_USD)
# Get sub account in address format
hmx_client.public.get_sub_account(1)
# Get position ID
hmx_client.public.get_position_id(some_account, some_sub_account_id, MARKET_ETH_USD)
# Get position info
hmx_client.public.get_position_info(some_account, some_sub_account_id, MARKET_ETH_USD)

Private function

from hmx2.hmx_client import Client
from hmx2.constants.markets import MARKET_ETH_USD
from hmx2.constants.tokens import COLLATERAL_USDCe
from hmx2.enum import Action

#
# Initailized client with private key
#
hmx_client = Client(
    eth_private_key=PRIVATE_KEY,
    rpc_url=RPC_URL
)
# Get public address of the ethereum key
hmx_client.private.get_public_address()
# Deposit ETH as collateral
hmx_client.private.deposit_eth_collateral(sub_account_id=0, amount=10.123)
# Deposit ERC20 as collateral. This function will automatically
# approve CrossMarginHandler if needed.
hmx_client.private.deposit_erc20_collateral(sub_account_id=0, token_address=COLLATERAL_USDCe, amount=100.10)
# Create a market order
create_market_order = hmx_client.private.create_market_order(
  sub_account_id=0, market_index=MARKET_ETH_USD, buy=Action.BUY, size=100, reduce_only=False
)
print(create_market_order)
# Create a trigger order
# trigger_above_threshold = The current price must go above (if True) or below (if False)
# the trigger price in order for the order to be executed
create_order = hmx_client.private.create_trigger_order(
  sub_account_id=0,
  market_index=MARKET_ETH_USD,
  buy=Action.BUY,
  size=100,
  trigger_price=1800,
  trigger_above_threshold=True,
  reduce_only=False)
print(create_order)
# Update the order
update_order = hmx_client.private.update_trigger_order(
  0, create_order["order"]["orderIndex"], Action.SELL, 50, 1700, True, False)
print(update_order)
# Cancel the order
cancel_order = hmx_client.private.cancel_trigger_order(
  0, update_order["order"]["orderIndex"])

Running Tests

To run tests, you will need have to clone the repo, update .env, and run:

$ make test

Please note that to run tests, Tenderly account is required.

License

The primary license for HMXOrg/v2-sdk-python is the MIT License, see here.

Metadata

Release files for hmx-v2-python-test 1.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hmx-v2-python-test 1.2.3
File Size Uploaded Provenance Actions
hmx_v2_python_test-1.2.3.tar.gz 51.6 kB Without provenance Details for hmx_v2_python_test-1.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hmx-v2-python-test 1.2.3
File Interpreter ABI Platform Actions
hmx_v2_python_test-1.2.3-py3-none-any.whl Python 3 none any Details for hmx_v2_python_test-1.2.3-py3-none-any.whl

Total release size: 124.3 kB

Release files / hmx_v2_python_test-1.2.3.tar.gz

Download URL hmx_v2_python_test-1.2.3.tar.gz
Size 51.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9187c65d229dbaeb3d8e7f7008813e12d0f6a076ff94633f7ec6f6464e34b663
BLAKE2b-256 checksum
How to use checksums
06acac1275653b0e4a81da26d01b0da99f24d8b490ebee3084fa69816125a687
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.8

Release files / hmx_v2_python_test-1.2.3-py3-none-any.whl

Download URL hmx_v2_python_test-1.2.3-py3-none-any.whl
Size 72.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e7af9b6ce1f658b3880e723c332f53a59bb2aa95256cec32c09baa85a8f23d1b
BLAKE2b-256 checksum
How to use checksums
f794a2c639539adc546db38bcf5bc97ebe7526f91fc7f8cf5766eec6fe037127
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.8

Security for hmx-v2-python-test 1.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page