Skip to main content

Zeno Python SDK

Project description

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 directory as well as the tests.

Public functions

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

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.

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

zeno-python-sdk-0.0.3.tar.gz (43.3 kB view details)

Uploaded Source

File details

Details for the file zeno-python-sdk-0.0.3.tar.gz.

File metadata

  • Download URL: zeno-python-sdk-0.0.3.tar.gz
  • Upload date:
  • Size: 43.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for zeno-python-sdk-0.0.3.tar.gz
Algorithm Hash digest
SHA256 9535c927dc17d1c39c8a9f9cad4df190779d7d2b1987beb5de5c728a1b5a05c7
MD5 92a3431cc8080caad24339fc0fd874b2
BLAKE2b-256 ed64445453306b9371c8d30857d0cf4e845b694fd36274415cf49879e2efd0ba

See more details on using hashes here.

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