Vertex Protocol SDK
Project description
Vertex Protocol Python SDK
This is the Python SDK for the Vertex Protocol API.
See SDK docs to get started.
Requirements
- Python 3.9 or above
Installation
You can install the SDK via pip:
pip install vertex-protocol
Basic usage
Import the necessary utilities:
from vertex_protocol.client import create_vertex_client, VertexClientMode
from vertex_protocol.contracts.types import DepositCollateralParams
from vertex_protocol.engine_client.types.execute import (
OrderParams,
PlaceOrderParams,
SubaccountParams
)
from vertex_protocol.utils.expiration import OrderType, get_expiration_timestamp
from vertex_protocol.utils.math import to_pow_10, to_x18
from vertex_protocol.utils.nonce import gen_order_nonce
Create the VertexClient providing your private key:
print("setting up vertex client...")
private_key = "xxx"
client = create_vertex_client(VertexClientMode.MAINNET, 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(OrderType.POST_ONLY, int(time.time()) + 40),
nonce=gen_order_nonce(),
)
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
-
Clone github repo
-
Install poetry
$ curl -sSL https://install.python-poetry.org | python3 -
- Setup a virtual environment and activate it
$ python3 -m venv venv
$ source ./venv/bin/activate
- Install dependencies via
poetry install
- Setup an
.env
file and set the following envvars
CLIENT_MODE='mainnet|sepolia-testnet|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 theengine-client
.poetry run indexer-sanity
: runs sanity checks for theindexer-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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
vertex_protocol-2.1.9.tar.gz
(62.3 kB
view details)
Built Distribution
File details
Details for the file vertex_protocol-2.1.9.tar.gz
.
File metadata
- Download URL: vertex_protocol-2.1.9.tar.gz
- Upload date:
- Size: 62.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.11.10 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f6b94f98125c9c904d6b0d7520fd3513d4a6df383c6652d7da15346fe7d19cb |
|
MD5 | 3741f1906bfb481c82435a1e1c995ee0 |
|
BLAKE2b-256 | fb8e85244b40cf7311f781ec10d6751293701e1c6a86a9d0294471d97f8808ca |
File details
Details for the file vertex_protocol-2.1.9-py3-none-any.whl
.
File metadata
- Download URL: vertex_protocol-2.1.9-py3-none-any.whl
- Upload date:
- Size: 91.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.11.10 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd9796dfbf5cedba432cb67df43ce6ea4fb74d0b312a73de294ac67323e9e261 |
|
MD5 | cd7aa3bb56ec70334d21224f990b8e7a |
|
BLAKE2b-256 | 7800e8a4ea45dd09d53a77666f66cd60d865a0f732d9310ec7166ebff8012cc8 |