Python SDK

Introduction

HXRO Network provides a Python SDK that closely resembles the REST API for traders & developers who wish to write trading bots or build on top of the protocol directly from their Python applications.

How to get it

The SDK is currently available on Test Pypi for Linux only at https://test.pypi.org/project/parimutuelsdk. A MacOS version will follow soon, as well as moving to main Pypi.

How to instantiate it

Start by creating a virtualenv and installing the SDK
pip install partimutuelsdk
Then instantiate the SDK, passing in a validator URL (public or private), the parimutuel program id (the current program id on devnet is 3kjK4HA6A4K86NgNB93gGhSt257wtN4QAqXMNPQ4fVTm) and the private key for the owner of the system account that will be used to pay for transactions and which owns the ATAs holding the settlement token (USDC) and any HXRO tokens. Note you can get an airdrop for both using our devnet UI, see How to Trade Parimutuels (Devnet Version) for more information.
import parimutuelsdk as psdk
url = "https://api.devnet.solana.com"
private_key_bytes = bytes(json.load(open(in_file, 'rb')))
private_key = base58.b58encode(private_key_bytes).decode("ascii")
program_id = "3kjK4HA6A4K86NgNB93gGhSt257wtN4QAqXMNPQ4fVTm"
sdk = psdk.SDKClientImpl(url, private_key, program_id)

Example usage

The SDK attempts to replicate the existing hxro.trade API described here at https://hxroapi.readme.io/docs/getting-started. We recommend wrapping the SDK in a user defined class that allows adding type hints, for example:
class ParimutuelSDK(ParimutuelClient):
def __init__(self, url: str, private_key: str, program_id: str):
self._sdk = psdk.SDKClientImpl(
url, private_key, program_id)
def get_series_ids(self) -> List[psdk.Series]:
series = self._sdk.get_series_ids_py()
return series
def get_contest_ids(self, series_id: str) -> List[psdk.Contest]:
contests = self._sdk.get_contest_ids_py(series_id)
return contests
def enter_contest(
self,
user_id: str,
contest_id: str,
contest_type: str,
direction: str,
wager: float,
) -> psdk.ContestEntry:
contest_entry = self._sdk.enter_contest_py(
user_id,
contest_id,
contest_type,
direction,
wager
)
return contest_entry
def get_contest_entry(
self,
user_id,
contest_entry_id,
) -> psdk.ContestEntry:
contest_entry = self._sdk.get_contest_entry_py(user_id, contest_entry_id)
return contest_entry
def get_contest_history(
self,
user_id,
) -> List[psdk.ContestEntry]:
contest_entries = self._sdk.get_contest_history_py(user_id)
return contest_entries
def get_account_info(
self,
user_id: str,
) -> List[psdk.AccountBalance]:
account_balances = self._sdk.get_account_info_py(user_id)
return account_balances

Comments, Feedback, Suggestions

Please find us on the #dev-chat channel on Discord at https://discord.com/channels/740983228134981793/980287738819538974