Skip to main content

Nado Protocol SDK

Project description

Nado Protocol Python SDK

This is the Python SDK for the Nado Protocol API.

See SDK docs to get started.

Requirements

  • Python 3.9 or above

Installation

You can install the SDK via pip:

pip install nado-protocol

Basic usage

Import the necessary utilities:

from nado_protocol.client import create_nado_client, NadoClientMode
from nado_protocol.contracts.types import DepositCollateralParams
from nado_protocol.engine_client.types.execute import (
    OrderParams,
    PlaceOrderParams,
    SubaccountParams
)
from nado_protocol.utils.expiration import OrderType, get_expiration_timestamp
from nado_protocol.utils.math import to_pow_10, to_x18
from nado_protocol.utils.nonce import gen_order_nonce
from nado_protocol.utils.order import build_appendix

Create the NadoClient providing your private key:

print("setting up nado client...")
private_key = "xxx"
client = create_nado_client(NadoClientMode.DEVNET, private_key)

Perform basic operations:

# Depositing collaterals
print("approving allowance...")
approve_allowance_tx_hash = client.spot.approve_allowance(0, to_pow_10(100000, 6))
print("approve allowance tx hash:", approve_allowance_tx_hash)

print("querying my allowance...")
token_allowance = client.spot.get_token_allowance(0, client.context.signer.address)
print("token allowance:", token_allowance)

print("depositing collateral...")
deposit_tx_hash = client.spot.deposit(
   DepositCollateralParams(
      subaccount_name="default", product_id=0, amount=to_pow_10(100000, 6)
   )
)
print("deposit collateral tx hash:", deposit_tx_hash)

# Placing orders
print("placing order...")
owner = client.context.engine_client.signer.address
product_id = 1
order = OrderParams(
   sender=SubaccountParams(
      subaccount_owner=owner,
      subaccount_name="default",
   ),
   priceX18=to_x18(20000),
   amount=to_pow_10(1, 17),
   expiration=get_expiration_timestamp(40),
   nonce=gen_order_nonce(),
   appendix=build_appendix(order_type=OrderType.POST_ONLY)
)
res = client.market.place_order({"product_id": product_id, "order": order})
print("order result:", res.json(indent=2))

See Getting Started for more.

Running locally

  1. Clone github repo

  2. Install poetry


$ curl -sSL https://install.python-poetry.org | python3 -

  1. Setup a virtual environment and activate it

$ python3 -m venv venv
$ source ./venv/bin/activate

  1. Install dependencies via poetry install
  2. Setup an .env file and set the following envvars
CLIENT_MODE='devnet'
SIGNER_PRIVATE_KEY="0x..."
LINKED_SIGNER_PRIVATE_KEY="0x..." # not required

Run tests

$ poetry run test

Run sanity checks

  • poetry run client-sanity: runs sanity checks for the top-level client.
  • poetry run engine-sanity: runs sanity checks for the engine-client.
  • poetry run indexer-sanity: runs sanity checks for the indexer-client.
  • poetry run contracts-sanity: runs sanity checks for the contracts module.

Build Docs

To build the docs locally run:

$ poetry run sphinx-build docs/source docs/build

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

nado_protocol-0.1.3.tar.gz (60.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nado_protocol-0.1.3-py3-none-any.whl (91.4 kB view details)

Uploaded Python 3

File details

Details for the file nado_protocol-0.1.3.tar.gz.

File metadata

  • Download URL: nado_protocol-0.1.3.tar.gz
  • Upload date:
  • Size: 60.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.11.13 Linux/6.11.0-1018-azure

File hashes

Hashes for nado_protocol-0.1.3.tar.gz
Algorithm Hash digest
SHA256 52edbf9b9fb19e5a159d81916352a491f6467877fc24a599bc09b0b35dd877c0
MD5 73aeb4aefebf6a1617d7c7ac4e34d786
BLAKE2b-256 1a4e928704f5a652bc86dee02d8ec174a3e3dca6c6d17d2b670be7f0f29ac74c

See more details on using hashes here.

File details

Details for the file nado_protocol-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: nado_protocol-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 91.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.11.13 Linux/6.11.0-1018-azure

File hashes

Hashes for nado_protocol-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b3f5a778f5260516108ec2065c176cc4a248d8714968157d4933f82074bceb3d
MD5 86b732d074e9255f615cbe1afe9e1f3a
BLAKE2b-256 36e37e94003db000615e1fdd590d4f49ffc87a8485404d0a686a79bd9cc538aa

See more details on using hashes here.

Supported by

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