dexteritysdk-0.2.8


توضیحات

Client for Dexterity - a modular derivatives decentralized exchange reference implementation
ویژگی مقدار
سیستم عامل -
نام فایل dexteritysdk-0.2.8
نام dexteritysdk
نسخه کتابخانه 0.2.8
نگهدارنده []
ایمیل نگهدارنده []
نویسنده Joe Howarth
ایمیل نویسنده josephehowarth@gmail.com
آدرس صفحه اصلی -
آدرس اینترنتی https://pypi.org/project/dexteritysdk/
مجوز -
# Dexterity client SDK **Dexterity** is a derivatives decentralized exchange running on Solana. This package provides the basic blocks in order to integrate and trade on Dexterity. You can learn more about Dexterity [here](https://docs.hxro.network/market-protocols/derivatives-protocol/dexterity). ## Prerequisites * [Solana.py](https://pypi.org/project/solana/) ## Creating the client First, an instance of a Solana client is required. ```python from dexteritysdk.dex.sdk_context import SDKContext, SDKTrader from solana.rpc.api import Client from solana.keypair import Keypair from solana.publickey import PublicKey def main(): # use "https://api.mainnet-beta.solana.com" for mainnet network = "https://api.devnet.solana.com" client = Client(network) ``` A Keypair for the payer has to also be provided. ```python keypair = Keypair.from_secret_key(keypair_bytes) ``` The SDK also requires the **Market Product Group (MPG)** that we're going to trade on. The public key of the default MPG is **`HiCy6vzuN3yLXD3z35D6nV7bzNLcyrvGLf3uSKuutSLo`** for mainnet or **`HyWxreWnng9ZBDPYpuYugAfpCMkRkJ1oz93oyoybDFLB`** for devnet. ```python # mainnet MPG mpg = PublicKey("HiCy6vzuN3yLXD3z35D6nV7bzNLcyrvGLf3uSKuutSLo") # ** OR ** # devnet MPG mpg = PublicKey("HyWxreWnng9ZBDPYpuYugAfpCMkRkJ1oz93oyoybDFLB") ``` Now, we're ready to get an instance of `SDKContext` for this MPG. ```python ctx = SDKContext.connect( client=client, market_product_group_key=mpg, payer=keypair, raise_on_error=True ) ``` ## Registering new trader / TRG If you're a new trader, creation of a trading account is required. ```python trader = ctx.register_trader(keypair) trg_key = trader.account ``` The **Trader Risk Group (TRG)** is your trading account, that you can now use. ## Using an existing TRG If you already have a trader set up, you need to provide the TRG public key for it. The SDK allows you to list all your registered TRGs. ```python # this will return a list of your all your TRG public keys # for example: [HeykeQWRh6DC2Tz5X3WBuWdMHicyECDEFGMjomV6LBye, HeyZNJ9gQVAEqHeCFFQ781E53d66DATKXHeynwnCFBye] trg_keys = ctx.list_trader_risk_groups() ``` After finding your TRG, you can initialise the `SDKTrader` instance. ```python from dexteritysdk.codegen.dex.types import TraderRiskGroup from dexteritysdk.program_ids import * from dexteritysdk.utils.solana import explore # ... trader = SDKTrader.connect(ctx, trg_pubkey, keypair) ``` ## Funding the TRG To start trading, you need to deposit funds. The tokens deposited have to be MPG vault mint tokens (e.g. USDC). The wallet you provided will be debited. ```python # this will deposit 733.1 USDC trader.deposit(ctx, 733.1) ``` You can also withdraw in a similar fashion. ```python # this will withdraw 0.1 USDC back to your wallet trader.withdraw(ctx, 0.1) ``` You can check your balance at any time. ```python trg, _ = trader.get_trader_risk_group() trg.cash_balance ``` ## Trading on Dexterity ### Listing trading products and order books The `products` field of a `SDKContext` instance, is a list of the available trading products (`SDKProduct`). Every `SDKProduct` has a `name` and a `get_orderbook(ctx)` function that will return its order book (`SDKOrderBook`). The `SDKOrderBook` contains all `SDKOrders` on each side of the book. Here's an example: ```python for product in ctx.products: book = product.get_orderbook(ctx, refresh=True) print(f"Printing the order book of {product.name}") for order in book.bids: print(f"Bid of size {order.qty} at {order.price}") for order in book.asks: print(f"Ask of size {order.qty} at {order.price}") ``` ### Placing an order Placing an order is straightforward. ```python from dexteritysdk.utils.aob import Side # ... order_summary = trader.place_order(ctx, product, Side.ASK, size, price) ``` The returned `SDKOrderSummary` contains the `order_id` of the new order, as well as the `remaining_qty` and `filled_qty` if your order has been filled. If the order is immediately fully filled, `order_id` will be `None`. If there's any error, an exception will be raised. ### Cancelling orders To cancel a previous order you can call `trader.cancel(ctx, product, order_id)`. Following the previous example: ```python trader.cancel(ctx, product, order_summary.order_id) ``` You can also cancel all your open orders for multiple products. ```python # products is a list of SDKProduct # if products list is empty or None, then all your open orders will be cancelled products = [ctx.products[0], ctx.products[2]] trader.cancel_all_orders(ctx, products) ``` If any cancel fails, an exception will be raised. ### Positions Positions can also be listed, by iterating the `trader_positions` array: ```python trg, _ = trader.get_trader_risk_group() trg.trader_positions ```


نیازمندی

مقدار نام
>=0.18.1,<0.19.0 pyrsistent
>=3.0.3,<4.0.0 Jinja2
>=2.0.1,<3.0.0 MarkupSafe
>=0.6.3,<0.7.0 OSlash
>=9.0.1,<10.0.0 Pillow
>=1.5.0,<2.0.0 PyNaCl
>=2.11.2,<3.0.0 Pygments
>=2.0.1,<3.0.0 QtPy
>=1.8.0,<2.0.0 Send2Trash
>=3.0.0,<4.0.0 aiodns
>=3.8.1,<4.0.0 aiohttp
>=1.2.0,<2.0.0 aiosignal
>=3.5.0,<4.0.0 anyio
>=0.1.2,<0.2.0 appnope
>=21.3.0,<22.0.0 argon2-cffi
>=1.4.0,<2.0.0 argparse
>=4.0.2,<5.0.0 async-timeout
>=21.4.0,<22.0.0 attrs
>=0.2.0,<0.3.0 backcall
>=1.11.1,<2.0.0 backoff
>=2.1.1,<3.0.0 base58
>=4.1.0,<5.0.0 bleach
>=0.1.0,<0.2.0 borsh-construct
>=2021.10.8,<2022.0.0 certifi
>=1.15.0,<2.0.0 cffi
>=2.0.12,<3.0.0 charset-normalizer
>=2.10.67,<3.0.0 construct
>=0.5.2,<0.6.0 construct-typing
>=36.0.1,<37.0.0 cryptography
>=0.11.0,<0.12.0 cycler
>=1.5.1,<2.0.0 debugpy
>=5.1.1,<6.0.0 decorator
>=0.7.1,<0.8.0 defusedxml
>=2.2.0,<3.0.0 dnspython
>=0.4,<0.5 entrypoints
>=4.0.1,<5.0.0 flake8
>=1.3.0,<2.0.0 frozenlist
==0.12.0 h11
>=3.3,<4.0 idna
>=6.9.0,<7.0.0 ipykernel
>=8.0.1,<9.0.0 ipython
>=0.2.0,<0.3.0 ipython_genutils
>=7.6.5,<8.0.0 ipywidgets
>=0.18.1,<0.19.0 jedi
>=4.0.2,<5.0.0 jsonrpcclient
>=5.0.6,<6.0.0 jsonrpcserver
==3.2.0 jsonschema
>=1.0.0,<2.0.0 jupyter
>=7.1.2,<8.0.0 jupyter-client
>=6.4.0,<7.0.0 jupyter-console
>=4.9.1,<5.0.0 jupyter-core
>=0.1.2,<0.2.0 jupyterlab-pygments
>=1.0.2,<2.0.0 jupyterlab-widgets
>=1.3.2,<2.0.0 kiwisolver
>=0.6.0,<0.7.0 loguru
>=3.5.1,<4.0.0 matplotlib
>=0.1.3,<0.2.0 matplotlib-inline
==0.6.1 mccabe
==0.8.4 mistune
>=6.0.2,<7.0.0 multidict
>=0.5.10,<0.6.0 nbclient
==6.2 nbconvert
>=5.1.3,<6.0.0 nbformat
>=1.5.4,<2.0.0 nest-asyncio
>=6.4.8,<7.0.0 notebook
>=1.22.2,<2.0.0 numpy
>=21.3,<22.0 packaging
>=1.4.1,<2.0.0 pandas
>=1.5.0,<2.0.0 pandocfilters
>=0.8.3,<0.9.0 parso
>=4.8.0,<5.0.0 pexpect
>=0.7.5,<0.8.0 pickleshare
==0.1.2 podite
>=0.13.1,<0.14.0 prometheus-client
>=3.0.28,<4.0.0 prompt-toolkit
>=0.7.0,<0.8.0 ptyprocess
>=4.1.2,<5.0.0 pycares
>=2.8.0,<3.0.0 pycodestyle
>=2.21,<3.0 pycparser
>=2.4.0,<3.0.0 pyflakes
>=3.0.7,<4.0.0 pyparsing
>=0.1.2,<0.2.0 pythclient
>=2.8.2,<3.0.0 python-dateutil
>=2022.1,<2023.0 pytz
>=22.3.0,<23.0.0 pyzmq
>=5.2.2,<6.0.0 qtconsole
>=2.27.1,<3.0.0 requests
==1.5 rfc3986
>=1.16.0,<2.0.0 six
>=1.2.0,<2.0.0 sniffio
>=0.28.0,<0.29.0 solana
>=0.13.1,<0.14.0 terminado
>=0.5.0,<0.6.0 testpath
>=6.1,<7.0 tornado
>=5.1.1,<6.0.0 traitlets
>=4.2.9,<5.0.0 types-cachetools
==4.2.0 typing-extensions
>=1.26.8,<2.0.0 urllib3
>=0.2.5,<0.3.0 wcwidth
>=0.5.1,<0.6.0 webencodings
>=10.1,<11.0 websockets
>=3.5.2,<4.0.0 widgetsnbextension
>=1.7.2,<2.0.0 yarl


زبان مورد نیاز

مقدار نام
>=3.9,<4.0 Python


نحوه نصب


نصب پکیج whl dexteritysdk-0.2.8:

    pip install dexteritysdk-0.2.8.whl


نصب پکیج tar.gz dexteritysdk-0.2.8:

    pip install dexteritysdk-0.2.8.tar.gz