zeno-python-sdk


Namezeno-python-sdk JSON
Version 0.0.3 PyPI version JSON
download
home_pagehttps://github.com/Zeno-Exchange/zeno-sdk
SummaryZeno Python SDK
upload_time2024-08-16 09:05:28
maintainerNone
docs_urlNone
authorZenoExchange
requires_pythonNone
licenseMIT
keywords zeno exchange perp dex defi ethereum eth metis
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Python SDK for Zeno

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

## 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/ZenoExchange/zeno-sdk/tree/main/examples) directory as well as the [tests](https://github.com/ZenoExchange/zeno-sdk/tree/main/tests).

### Public functions

```python
from zeno.zeno_client import Client
from zeno.constants.markets import (
  MARKET_ETH_USD,
  MARKET_METIS_USD
)

#
# Using publicly access functions
#
client = Client(
    rpc_url=RPC_URL
)
# Get oracle price, adaptive price, and price impact of a new position
# `buy` and `size` is optional
client.public.get_price(market_index=MARKET_ETH_USD, buy=Action.SELL, size=1000)
# Get market information
client.public.get_market_info(market_index=MARKET_ETH_USD)
# Get every market information
client.public.get_all_market_info()
# Get sub account in address format
client.public.get_sub_account(1)
# Get position ID
client.public.get_position_id(
  account=some_account,
  sub_account_id=some_sub_account_id,
  market_index=MARKET_ETH_USD
)
# Get position info
client.public.get_position_info(
  account=some_account,
  sub_account_id=some_sub_account_id,
  market_index=MARKET_ETH_USD
)
# Get collateral info
client.public.get_collaterals(
    account=some_account,
    sub_account_id=some_account_id
  )
# Get all position info
client.public.get_all_position_info(
  account=some_account,
  sub_account_id=[some_account_id] # optional
)
# Get active limit order info
client.public.get_active_limit_orders(
  account=some_account,
  sub_account_ids=[sub_account_id] # optional
)
# Get portfolio value
client.public.get_portfolio_value(
  account=some_account,
  sub_account_id=sub_account_id
)
# Get Equity value
client.public.get_equity(
  account=some_account,
  sub_account_id=sub_account_id
)
# Get leverage
client.public.get_leverage(
  account=some_account,
  sub_account_id=sub_account_id
)
```

### Private function

```python
from zeno.client import Client
from zeno.constants.markets import MARKET_ETH_USD
from zeno.constants.tokens import COLLATERAL_mUSDC
from zeno.enum import Action

#
# Initailized client with private key
#
client = Client(
    eth_private_key=PRIVATE_KEY,
    rpc_url=RPC_URL
)
# Get public address of the ethereum key
client.private.get_public_address()
# Deposit ETH as collateral
client.private.deposit_eth_collateral(sub_account_id=0, amount=10.123)
# Deposit ERC20 as collateral. This function will automatically
# approve CrossMarginHandler if needed.
client.private.deposit_erc20_collateral(sub_account_id=0, token_address=COLLATERAL_mUSDC, amount=100.10)
# Withdraw Collateral
client.private.withdraw_collateral(
    sub_account_id=0,
    token_address=COLLATERAL_mUSDT,
    amount=1
  )
# Create a market order
create_market_order = 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 = client.private.create_trigger_order(
    sub_account_id=0,
    market_index=MARKET_ETH_USD,
    buy=Action.BUY,
    size=100,
    trigger_price=3000,
    trigger_above_threshold=False,
    reduce_only=False,
    tp_token=COLLATERAL_mUSDC,
  )
print(create_order)
# Cancel the order
cancel_order = client.private.cancel_trigger_order(
  0, create_order["data"]["intentTradeOrders"][0]["id"])
print(cancel_order)
```

## 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 ZenoExchange/zeno-sdk is the MIT License, see [here](https://github.com/ZenoExchange/zeno-sdk/blob/main/LICENSE).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Zeno-Exchange/zeno-sdk",
    "name": "zeno-python-sdk",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "zeno exchange perp dex defi ethereum eth metis",
    "author": "ZenoExchange",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/ed/64/445453306b9371c8d30857d0cf4e845b694fd36274415cf49879e2efd0ba/zeno-python-sdk-0.0.3.tar.gz",
    "platform": null,
    "description": "# Python SDK for Zeno\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 zeno-python-sdk\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/ZenoExchange/zeno-sdk/tree/main/examples) directory as well as the [tests](https://github.com/ZenoExchange/zeno-sdk/tree/main/tests).\n\n### Public functions\n\n```python\nfrom zeno.zeno_client import Client\nfrom zeno.constants.markets import (\n  MARKET_ETH_USD,\n  MARKET_METIS_USD\n)\n\n#\n# Using publicly access functions\n#\nclient = Client(\n    rpc_url=RPC_URL\n)\n# Get oracle price, adaptive price, and price impact of a new position\n# `buy` and `size` is optional\nclient.public.get_price(market_index=MARKET_ETH_USD, buy=Action.SELL, size=1000)\n# Get market information\nclient.public.get_market_info(market_index=MARKET_ETH_USD)\n# Get every market information\nclient.public.get_all_market_info()\n# Get sub account in address format\nclient.public.get_sub_account(1)\n# Get position ID\nclient.public.get_position_id(\n  account=some_account,\n  sub_account_id=some_sub_account_id,\n  market_index=MARKET_ETH_USD\n)\n# Get position info\nclient.public.get_position_info(\n  account=some_account,\n  sub_account_id=some_sub_account_id,\n  market_index=MARKET_ETH_USD\n)\n# Get collateral info\nclient.public.get_collaterals(\n    account=some_account,\n    sub_account_id=some_account_id\n  )\n# Get all position info\nclient.public.get_all_position_info(\n  account=some_account,\n  sub_account_id=[some_account_id] # optional\n)\n# Get active limit order info\nclient.public.get_active_limit_orders(\n  account=some_account,\n  sub_account_ids=[sub_account_id] # optional\n)\n# Get portfolio value\nclient.public.get_portfolio_value(\n  account=some_account,\n  sub_account_id=sub_account_id\n)\n# Get Equity value\nclient.public.get_equity(\n  account=some_account,\n  sub_account_id=sub_account_id\n)\n# Get leverage\nclient.public.get_leverage(\n  account=some_account,\n  sub_account_id=sub_account_id\n)\n```\n\n### Private function\n\n```python\nfrom zeno.client import Client\nfrom zeno.constants.markets import MARKET_ETH_USD\nfrom zeno.constants.tokens import COLLATERAL_mUSDC\nfrom zeno.enum import Action\n\n#\n# Initailized client with private key\n#\nclient = Client(\n    eth_private_key=PRIVATE_KEY,\n    rpc_url=RPC_URL\n)\n# Get public address of the ethereum key\nclient.private.get_public_address()\n# Deposit ETH as collateral\nclient.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.\nclient.private.deposit_erc20_collateral(sub_account_id=0, token_address=COLLATERAL_mUSDC, amount=100.10)\n# Withdraw Collateral\nclient.private.withdraw_collateral(\n    sub_account_id=0,\n    token_address=COLLATERAL_mUSDT,\n    amount=1\n  )\n# Create a market order\ncreate_market_order = client.private.create_market_order(\n  sub_account_id=0,\n  market_index=MARKET_ETH_USD,\n  buy=Action.BUY,\n  size=100,\n  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 = 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=3000,\n    trigger_above_threshold=False,\n    reduce_only=False,\n    tp_token=COLLATERAL_mUSDC,\n  )\nprint(create_order)\n# Cancel the order\ncancel_order = client.private.cancel_trigger_order(\n  0, create_order[\"data\"][\"intentTradeOrders\"][0][\"id\"])\nprint(cancel_order)\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 ZenoExchange/zeno-sdk is the MIT License, see [here](https://github.com/ZenoExchange/zeno-sdk/blob/main/LICENSE).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Zeno Python SDK",
    "version": "0.0.3",
    "project_urls": {
        "Homepage": "https://github.com/Zeno-Exchange/zeno-sdk"
    },
    "split_keywords": [
        "zeno",
        "exchange",
        "perp",
        "dex",
        "defi",
        "ethereum",
        "eth",
        "metis"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ed64445453306b9371c8d30857d0cf4e845b694fd36274415cf49879e2efd0ba",
                "md5": "92a3431cc8080caad24339fc0fd874b2",
                "sha256": "9535c927dc17d1c39c8a9f9cad4df190779d7d2b1987beb5de5c728a1b5a05c7"
            },
            "downloads": -1,
            "filename": "zeno-python-sdk-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "92a3431cc8080caad24339fc0fd874b2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 43253,
            "upload_time": "2024-08-16T09:05:28",
            "upload_time_iso_8601": "2024-08-16T09:05:28.126561Z",
            "url": "https://files.pythonhosted.org/packages/ed/64/445453306b9371c8d30857d0cf4e845b694fd36274415cf49879e2efd0ba/zeno-python-sdk-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-16 09:05:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Zeno-Exchange",
    "github_project": "zeno-sdk",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "zeno-python-sdk"
}
        
Elapsed time: 0.36123s