hmx-v2-python-test


Namehmx-v2-python-test JSON
Version 1.2.3 PyPI version JSON
download
home_pagehttps://github.com/HMXOrg/v2-sdk-python
SummaryHMXv2 Python SDK
upload_time2024-05-03 06:59:03
maintainerNone
docs_urlNone
authorHMXOrg
requires_pythonNone
licenseMIT
keywords hmx exchange perp dex defi ethereum eth arbitrum
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://github.com/HMXOrg/v2-sdk-python/tree/main/examples) directory as well as the [tests](https://github.com/HMXOrg/v2-sdk-python/tree/main/tests).

### Public functions

```python
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

```python
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](https://github.com/HMXOrg/v2-sdk-python/blob/main/LICENSE).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/HMXOrg/v2-sdk-python",
    "name": "hmx-v2-python-test",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "hmx exchange perp dex defi ethereum eth arbitrum",
    "author": "HMXOrg",
    "author_email": "contact@hmx.org",
    "download_url": "https://files.pythonhosted.org/packages/06/ac/ac1275653b0e4a81da26d01b0da99f24d8b490ebee3084fa69816125a687/hmx_v2_python_test-1.2.3.tar.gz",
    "platform": null,
    "description": "# Python SDK for HMXv2\n\nThis library is tested against Python versions 2.7, 3.4, 3.5, 3.9, and 3.11.\n\n## Installation\n\nThis package is available on PyPI. To install run the command below:\n\n```\n$ pip install hmx-v2-python\n```\n\n## Getting Started\n\nThe `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](https://github.com/HMXOrg/v2-sdk-python/tree/main/examples) directory as well as the [tests](https://github.com/HMXOrg/v2-sdk-python/tree/main/tests).\n\n### Public functions\n\n```python\nfrom hmx2.hmx_client import Client\nfrom hmx2.constants.markets import MARKET_ETH_USD\nfrom hmx2.enum import Action\n\n#\n# Using publicly access functions\n#\nhmx_client = Client(\n    rpc_url=RPC_URL\n)\n# Get oracle price, adaptive price, and price impact of a new position\nhmx_client.public.get_price(MARKET_ETH_USD, Action.SELL, 1000)\n# Get market information\nhmx_client.public.get_market_info(MARKET_ETH_USD)\n# Get sub account in address format\nhmx_client.public.get_sub_account(1)\n# Get position ID\nhmx_client.public.get_position_id(some_account, some_sub_account_id, MARKET_ETH_USD)\n# Get position info\nhmx_client.public.get_position_info(some_account, some_sub_account_id, MARKET_ETH_USD)\n```\n\n### Private function\n\n```python\nfrom hmx2.hmx_client import Client\nfrom hmx2.constants.markets import MARKET_ETH_USD\nfrom hmx2.constants.tokens import COLLATERAL_USDCe\nfrom hmx2.enum import Action\n\n#\n# Initailized client with private key\n#\nhmx_client = Client(\n    eth_private_key=PRIVATE_KEY,\n    rpc_url=RPC_URL\n)\n# Get public address of the ethereum key\nhmx_client.private.get_public_address()\n# Deposit ETH as collateral\nhmx_client.private.deposit_eth_collateral(sub_account_id=0, amount=10.123)\n# Deposit ERC20 as collateral. This function will automatically\n# approve CrossMarginHandler if needed.\nhmx_client.private.deposit_erc20_collateral(sub_account_id=0, token_address=COLLATERAL_USDCe, amount=100.10)\n# Create a market order\ncreate_market_order = hmx_client.private.create_market_order(\n  sub_account_id=0, market_index=MARKET_ETH_USD, buy=Action.BUY, size=100, reduce_only=False\n)\nprint(create_market_order)\n# Create a trigger order\n# trigger_above_threshold = The current price must go above (if True) or below (if False)\n# the trigger price in order for the order to be executed\ncreate_order = hmx_client.private.create_trigger_order(\n  sub_account_id=0,\n  market_index=MARKET_ETH_USD,\n  buy=Action.BUY,\n  size=100,\n  trigger_price=1800,\n  trigger_above_threshold=True,\n  reduce_only=False)\nprint(create_order)\n# Update the order\nupdate_order = hmx_client.private.update_trigger_order(\n  0, create_order[\"order\"][\"orderIndex\"], Action.SELL, 50, 1700, True, False)\nprint(update_order)\n# Cancel the order\ncancel_order = hmx_client.private.cancel_trigger_order(\n  0, update_order[\"order\"][\"orderIndex\"])\n```\n\n## Running Tests\n\nTo run tests, you will need have to clone the repo, update .env, and run:\n\n```\n$ make test\n```\n\nPlease note that to run tests, Tenderly account is required.\n\n## License\n\nThe primary license for HMXOrg/v2-sdk-python is the MIT License, see [here](https://github.com/HMXOrg/v2-sdk-python/blob/main/LICENSE).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "HMXv2 Python SDK",
    "version": "1.2.3",
    "project_urls": {
        "Homepage": "https://github.com/HMXOrg/v2-sdk-python"
    },
    "split_keywords": [
        "hmx",
        "exchange",
        "perp",
        "dex",
        "defi",
        "ethereum",
        "eth",
        "arbitrum"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f794a2c639539adc546db38bcf5bc97ebe7526f91fc7f8cf5766eec6fe037127",
                "md5": "694790d95e4cbdedb4c9403a40c82e58",
                "sha256": "e7af9b6ce1f658b3880e723c332f53a59bb2aa95256cec32c09baa85a8f23d1b"
            },
            "downloads": -1,
            "filename": "hmx_v2_python_test-1.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "694790d95e4cbdedb4c9403a40c82e58",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 72706,
            "upload_time": "2024-05-03T06:59:00",
            "upload_time_iso_8601": "2024-05-03T06:59:00.188947Z",
            "url": "https://files.pythonhosted.org/packages/f7/94/a2c639539adc546db38bcf5bc97ebe7526f91fc7f8cf5766eec6fe037127/hmx_v2_python_test-1.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "06acac1275653b0e4a81da26d01b0da99f24d8b490ebee3084fa69816125a687",
                "md5": "8a6a845e6d7d3811de05e9d9618f214f",
                "sha256": "9187c65d229dbaeb3d8e7f7008813e12d0f6a076ff94633f7ec6f6464e34b663"
            },
            "downloads": -1,
            "filename": "hmx_v2_python_test-1.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "8a6a845e6d7d3811de05e9d9618f214f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 51619,
            "upload_time": "2024-05-03T06:59:03",
            "upload_time_iso_8601": "2024-05-03T06:59:03.219483Z",
            "url": "https://files.pythonhosted.org/packages/06/ac/ac1275653b0e4a81da26d01b0da99f24d8b490ebee3084fa69816125a687/hmx_v2_python_test-1.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-03 06:59:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "HMXOrg",
    "github_project": "v2-sdk-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "tox": true,
    "lcname": "hmx-v2-python-test"
}
        
Elapsed time: 0.28399s