zetamarkets_py package#

Subpackages#

Submodules#

zetamarkets_py.client module#

class zetamarkets_py.client.Client(provider: ~anchorpy.provider.Provider, network: ~zetamarkets_py.types.Network, connection: ~solana.rpc.async_api.AsyncClient, endpoint: str, ws_endpoint: str, exchange: ~zetamarkets_py.exchange.Exchange, margin_account: ~zetamarkets_py.zeta_client.accounts.cross_margin_account.CrossMarginAccount | None, _margin_account_address: ~solders.pubkey.Pubkey | None, _open_orders_addresses: dict[~zetamarkets_py.types.Asset, ~solders.pubkey.Pubkey] | None, _margin_account_manager_address: ~solders.pubkey.Pubkey | None, _user_usdc_address: ~solders.pubkey.Pubkey | None, _combined_vault_address: ~solders.pubkey.Pubkey, _combined_socialized_loss_address: ~solders.pubkey.Pubkey, _logger: ~logging.Logger, _account_exists_cache: dict[~solders.pubkey.Pubkey, bool] = <factory>)#

Bases: object

This class represents the Zeta Client. It contains all the necessary attributes and methods for interacting with the Zeta Exchange from the user side, including loading the client, fetching state and pricing, and handling various market assets.

Note

Loading the client is asynchronous, so it is recommended to use load() to initialize the client.

async cancel_order(asset: Asset, order_id: int, side: Side)#

Cancel an order.

Parameters:
  • asset (Asset) – The asset for which to cancel the order.

  • order_id (int) – The ID of the order to cancel.

  • side (Side) – The side of the order (buy or sell).

Returns:

The transaction of the cancelled order.

Return type:

Transaction

async cancel_orders_for_market(asset: Asset, pre_instructions: list[Instruction] | None = None, post_instructions: list[Instruction] | None = None, priority_fee: int = 0)#

Cancel all orders for a market.

Parameters:
  • asset (Asset) – The asset for which to cancel all orders.

  • pre_instructions (Optional[list[Instruction]], optional) – The list of instructions to execute before cancelling the orders. Defaults to None.

  • post_instructions (Optional[list[Instruction]], optional) – The list of instructions to execute after cancelling the orders. Defaults to None.

  • priority_fee (int) – Additional priority fee, in microlamports per CU. Defaults to 0.

Returns:

The transaction of the cancelled orders.

Return type:

Transaction

connection: AsyncClient#

The connection to the Solana network.

async deposit(amount: float, subaccount_index: int = 0)#

This method is used to deposit a specified amount into the user’s margin account.

Parameters:
  • amount (float) – The amount to be deposited.

  • subaccount_index (int, optional) – The index of the subaccount. Defaults to 0.

Raises:

Exception – If the user does not have a USDC account.

Returns:

The transaction object of the deposit operation.

Return type:

Transaction

endpoint: str#

The http(s) RPC endpoint.

exchange: Exchange#

The Zeta Exchange object.

async fetch_clock()#

Fetch the Solana clock.

Raises:

Exception – If the clock is not found.

Returns:

The clock.

Return type:

Clock

async fetch_margin_state()#

Fetch the state of the margin account.

Raises:

Exception – If the margin account is not loaded or not found.

Returns:

The balance and positions of the margin account.

Return type:

Tuple[Decimal, Dict[Asset, zetamarkets_py.types.Position]]

async fetch_open_orders(asset: Asset)#

Fetch the open orders for a specific asset.

Parameters:

asset (Asset) – The asset for which to fetch the open orders.

Raises:

Exception – If the open orders accounts are not loaded.

Returns:

The open orders for the asset.

Return type:

List[Order]

async get_account_risk_summary()#

Get the risk summary of the account.

This method fetches the margin state of the account, calculates the equity, margin parameters, margin usage, and leverage, and returns an AccountRiskSummary object.

Returns:

The risk summary of the account.

Return type:

AccountRiskSummary

async liquidate()#

Liquidate method.

Raises:

NotImplementedError – This method is not implemented yet.

async classmethod load(endpoint: str | None = None, ws_endpoint: str | None = None, commitment: Commitment = 'confirmed', wallet: Wallet | None = None, assets: list[Asset] = [Asset.SOL, Asset.BTC, Asset.ETH, Asset.APT, Asset.ARB, Asset.BNB, Asset.PYTH, Asset.TIA, Asset.JTO, Asset.ONEMBONK, Asset.SEI, Asset.JUP, Asset.DYM, Asset.STRK], tx_opts: TxOpts = (False, False, 'processed', None, None), network: Network = Network.MAINNET, log_level: int = 30, blockhash_cache: BlockhashCache | bool = False, delegator_pubkey: Pubkey | None = None)#

Asynchronously load the Zeta Client.

Parameters:
  • endpoint (str, optional) – The http(s) RPC endpoint. Defaults to None.

  • ws_endpoint (str, optional) – The websocket RPC endpoint. Defaults to None.

  • commitment (Commitment, optional) – The commitment level of the Solana network. Defaults to Confirmed.

  • wallet (Wallet, optional) – The wallet used for transactions. Defaults to None.

  • assets (list[Asset], optional) – The list of assets to be used. Defaults to all available assets.

  • tx_opts (TxOpts, optional) – Transaction options. Defaults to DEFAULT_OPTIONS.

  • network (Network, optional) – The network of the Zeta program. Defaults to Network.MAINNET.

  • log_level (int, optional) – The level of logging. Defaults to logging.CRITICAL.

  • blockhash_cache (Union[BlockhashCache, bool], optional) – The blockhash cache. Disabled by default.

  • delegator_pubkey (Pubkey, optional) – If passing in a delegated wallet in the ‘wallet’ param, this

  • positions/orders/balance/etc (is the delegator account itself so you can load) –

Returns:

An instance of the Client class.

Return type:

Client

margin_account: CrossMarginAccount | None#

The margin account of the Zeta program.

network: Network#

The Solana network identifier (i.e. mainnet_beta, devnet etc.).

async place_orders_for_market(asset: Asset, orders: list[OrderArgs], pre_instructions: list[Instruction] | None = None, post_instructions: list[Instruction] | None = None, tif_buffer: int = 0, priority_fee: int = 0)#

Place orders for a market.

Parameters:
  • asset (Asset) – The asset for which to place the orders.

  • orders (list[OrderArgs]) – The list of orders to place.

  • pre_instructions (Optional[list[Instruction]], optional) – The list of instructions to execute before placing the orders. Defaults to None.

  • post_instructions (Optional[list[Instruction]], optional) – The list of instructions to execute after placing the orders. Defaults to None.

  • tif_buffer (int) – Extra value to add to tif_expiry at epoch rollover to aid a smooth transition. Defaults to 0.

  • priority_fee (int) – Additional priority fee, in microlamports per CU. Defaults to 0.

Returns:

The transaction of the placed orders.

Return type:

Transaction

provider: Provider#

The network and wallet context to send transactions paid for and signed by the provider.

async replace_orders_for_market(asset: Asset, orders: list[OrderArgs], priority_fee: int = 0)#

Replace orders for a market (atomically cancel all orders and replace them).

Parameters:
  • asset (Asset) – The asset for which to replace the orders.

  • orders (list[OrderArgs]) – The list of new orders to place.

  • priority_fee (int) – Additional priority fee, in microlamports per CU. Defaults to 0.

Returns:

The transaction of the replaced orders.

Return type:

Transaction

async subscribe_clock(commitment: Commitment | None = None) AsyncIterator[Tuple[Clock, int]]#

Subscribe to a clock and yield clock data and slot.

Parameters:

commitment (Commitment, optional) – The commitment level to use for the subscription. Defaults to None.

Yields:

AsyncIterator[Tuple[Clock, int]] – An async iterator that yields tuples of clock data and slot.

async subscribe_events(commitment: Commitment | None = None) AsyncIterator[Tuple[List[PlaceOrderEvent | TradeEvent | CancelOrderEvent | LiquidationEvent | ApplyFundingEvent], EventMeta]]#

Subscribe to events and yield event data and slot.

Parameters:

commitment (Commitment, optional) – The commitment level to use for the subscription. Defaults to None.

Yields:

AsyncIterator[Tuple[List[ZetaEvent], int]] – An async iterator that yields tuples of event data and slot.

async subscribe_orderbook(asset: Asset, side: Side, commitment: Commitment | None = None) AsyncIterator[Tuple[Orderbook, int]]#

Subscribe to an orderbook and yield orderbook data and slot.

Parameters:
  • asset (Asset) – The asset for which to subscribe to the orderbook.

  • side (Side) – The side of the orderbook to subscribe to.

  • commitment (Commitment, optional) – The commitment level to use for the subscription. Defaults to None.

Yields:

AsyncIterator[Tuple[Orderbook, int]] – An async iterator that yields tuples of orderbook data and slot.

async subscribe_transactions(commitment: Commitment | None = None, ignore_truncation: bool = False) AsyncIterator[Tuple[List[PlaceOrderEventWithArgs | TradeEvent | CancelOrderEvent | LiquidationEvent | ApplyFundingEvent], EventMeta]]#

This method is used to subscribe to transactions.

Parameters:
  • commitment (Optional[Commitment], optional) – The commitment level to use for the subscription. Defaults to None.

  • ignore_truncation (bool) – Bool to ignore the “Logs truncated, missing event data” warning. Defaults to False.

Yields:

List[ZetaEvent] – A list of ZetaEvents that are yielded as they are received.

Warning

This method is experimental and requires a Triton RPC node.

async withdraw()#

Withdraw method.

Raises:

NotImplementedError – This method is not implemented yet.

ws_endpoint: str#

The websocket RPC endpoint.

zetamarkets_py.constants module#

zetamarkets_py.events module#

class zetamarkets_py.events.ApplyFundingEvent(margin_account: Pubkey, authority: Pubkey, asset: Asset, balance_change: float, remaining_balance: float, funding_rate: float, oracle_price: float, position_size: float)#

Bases: object

Program event for funding being applied to a position.

asset: Asset#
authority: Pubkey#
balance_change: float#
classmethod from_event(event: Event)#
funding_rate: float#
margin_account: Pubkey#
oracle_price: float#
position_size: float#
remaining_balance: float#
class zetamarkets_py.events.CancelOrderEvent(margin_account: Pubkey, authority: Pubkey, asset: Asset, side: Side, unfilled_size: float, order_id: int, client_order_id: int)#

Bases: object

Event for cancelling an order.

Note: This event is emitted when an order is cancelled, including auto-cancels like TIF.

asset: Asset#
authority: Pubkey#
client_order_id: int#
classmethod from_order_complete_event(event: OrderCompleteEvent)#
margin_account: Pubkey#
order_id: int#
side: Side#
unfilled_size: float#
class zetamarkets_py.events.EventMeta(slot: int, error: Any | None)#

Bases: object

error: Any | None#
property is_successful: bool#
slot: int#
class zetamarkets_py.events.LiquidationEvent(liquidator_reward: float, insurance_reward: float, side: Side, liquidation_price: float, liquidation_size: float, remaining_liquidatee_balance: float, remaining_liquidator_balance: float, mark_price: float, oracle_price: float, liquidatee: Pubkey, liquidator: Pubkey, asset: Asset, liquidatee_margin_account: Pubkey, liquidator_margin_account: Pubkey)#

Bases: object

Program event for a liquidation.

asset: Asset#
classmethod from_event(event: Event)#
insurance_reward: float#
liquidatee: Pubkey#
liquidatee_margin_account: Pubkey#
liquidation_price: float#
liquidation_size: float#
liquidator: Pubkey#
liquidator_margin_account: Pubkey#
liquidator_reward: float#
mark_price: float#
oracle_price: float#
remaining_liquidatee_balance: float#
remaining_liquidator_balance: float#
side: Side#
class zetamarkets_py.events.OrderCompleteEvent(margin_account: Pubkey, authority: Pubkey, asset: Asset, side: Side, unfilled_size: float, order_id: int, client_order_id: int, order_complete_type: OrderCompleteType)#

Bases: object

Program event for an order being completed.

Note: This event is emitted when an order is either fully filled, cancelled or booted (i.e. TIF expiry).

asset: Asset#
authority: Pubkey#
client_order_id: int#
classmethod from_event(event: Event)#
margin_account: Pubkey#
order_complete_type: OrderCompleteType#
order_id: int#
side: Side#
unfilled_size: float#
class zetamarkets_py.events.PlaceOrderEvent(fee: float, oracle_price: float, order_id: int, asset: Asset, margin_account: Pubkey, client_order_id: int)#

Bases: object

Program event for placing an order.

asset: Asset#
client_order_id: int#
fee: float#
classmethod from_event(event: Event)#
margin_account: Pubkey#
oracle_price: float#
order_id: int#
class zetamarkets_py.events.PlaceOrderEventWithArgs(price: float, size: float, side: Side, fee: float, oracle_price: float, order_id: int, asset: Asset, margin_account: Pubkey, client_order_id: int)#

Bases: object

Program event for placing an order.

Note

This class is an extension of the PlaceOrderEvent class. It includes additional arguments from the PlaceOrder instruction.

asset: Asset#
client_order_id: int#
fee: float#
classmethod from_event_and_args(event: Event, args: Container)#
margin_account: Pubkey#
oracle_price: float#
order_id: int#
price: float#
side: Side#
size: float#
class zetamarkets_py.events.TradeEvent(margin_account: Pubkey, price: float, size: float, cost_of_trades: float, side: Side, client_order_id: int, order_id: int, asset: Asset, authority: Pubkey, is_taker: bool, sequence_number: int, fee: float, pnl: float)#

Bases: object

Program event for a trade.

asset: Asset#
authority: Pubkey#
client_order_id: int#
cost_of_trades: float#
fee: float#
classmethod from_event(event: Event)#
is_taker: bool#
margin_account: Pubkey#
order_id: int#
pnl: float#
price: float#
sequence_number: int#
side: Side#
size: float#

zetamarkets_py.exchange module#

class zetamarkets_py.exchange.Exchange(connection: AsyncClient, program_id: Pubkey, program: Program, state: State, pricing: Pricing, markets: dict[Asset, Market], _event_parser: EventParser, _state_address: Pubkey, _pricing_address: Pubkey, _serum_authority_address: Pubkey, _mint_authority_address: Pubkey, _logger: Logger)#

Bases: object

This class represents the Zeta Exchange. It contains all the necessary attributes and methods for interacting with the Zeta Exchange, including loading the exchange, fetching state and pricing, and handling various market assets.

Note

Loading the exchange is asynchronous, so it is recommended to use load() to initialize the exchange.

property assets: list[Asset]#

Returns a list of keys from the markets dictionary.

Returns:

A list of Asset objects.

Return type:

list[Asset]

connection: AsyncClient#

The connection to the Solana network.

property endpoint: str#

Returns the RPC endpoint.

Returns:

The endpoint URI.

Return type:

str

async classmethod load(network: Network, connection: AsyncClient, assets: list[Asset] = [Asset.SOL, Asset.BTC, Asset.ETH, Asset.APT, Asset.ARB, Asset.BNB, Asset.PYTH, Asset.TIA, Asset.JTO, Asset.ONEMBONK, Asset.SEI, Asset.JUP, Asset.DYM, Asset.STRK], log_level: int = 50) Exchange#

Asynchronously load the Zeta Exchange.

Parameters:
  • network (Network) – The network to connect to.

  • connection (AsyncClient) – The connection to the Solana network.

  • assets (list[Asset], optional) – The list of assets to load. Defaults to all assets.

  • log_level (int, optional) – The logging level. Defaults to logging.CRITICAL.

Returns:

The loaded Zeta Exchange.

Return type:

Exchange

Raises:

Exception – If the state or pricing is not found at their respective addresses.

markets: dict[Asset, Market]#

A dictionary mapping assets to their respective markets.

pricing: Pricing#

The pricing account of the Zeta program. Stores mark prices, funding rates etc.

program: Program#

The Zeta program.

program_id: Pubkey#

The public key of the Zeta program.

state: State#

The state account of the Zeta program.

zetamarkets_py.market module#

class zetamarkets_py.market.Market(connection: AsyncClient, zeta_program_id: Pubkey, matching_engine_program_id: Pubkey, asset: Asset, _market_state: MarketState, _base_zeta_vault_address: Pubkey, _quote_zeta_vault_address: Pubkey, _logger: Logger, _bids_subscription_task: Task | None = None, _asks_subscription_task: Task | None = None, _bids_last_update_slot: int | None = None, _asks_last_update_slot: int | None = None)#

Bases: object

This class represents a Market on Zeta. It wraps the matching engine interface with useful metadata and helper methods.

Note

Loading the market is asynchronous, so it is recommended to use load() to initialize the market.

property address: Pubkey#

Market state account address.

Returns:

The public key of the market state.

Return type:

Pubkey

asset: Asset#

The asset being traded on the market.

connection: AsyncClient#

The connection to the Solana network.

async get_l2(side: Side, depth: int = 1000, clock_ts: int = 1708682351) list[OrderInfo] | None#

Get the Level 2 market information.

Parameters:
  • side (Side) – The side of the market to get information for.

  • depth (int, optional) – The depth of the market to get information for. Defaults to 1000.

  • clock_ts (int, optional) – The timestamp of the clock. Defaults to the current time.

Returns:

A list of order information if it exists, None otherwise.

Return type:

Optional[list[OrderInfo]]

async classmethod load(network: Network, connection: AsyncClient, asset: Asset, market_state_address: Pubkey, log_level: int = 50)#

Asynchronously load the Market.

Parameters:
  • network (Network) – The network to connect to.

  • connection (AsyncClient) – The connection to the Solana network.

  • asset (Asset) – The asset being traded on the market.

  • market_state_address (Pubkey) – The public key of the market state.

  • log_level (int, optional) – The logging level. Defaults to logging.CRITICAL.

Raises:

Exception – If the market state is not found at the provided address.

Returns:

An instance of the Market class.

Return type:

Market

async load_asks() Orderbook | None#

Load the ask order book.

Returns:

The ask order book if it exists, None otherwise.

Return type:

Optional[Orderbook]

async load_bids() Orderbook | None#

Load the bid order book.

Returns:

The bid order book if it exists, None otherwise.

Return type:

Optional[Orderbook]

async load_bids_and_asks() Tuple[Orderbook | None, Orderbook | None]#

Load the bid and ask orderbooks.

Returns:

A tuple containing the bid and ask orderbooks. If either

does not exist, its value will be None.

Return type:

Tuple[Optional[Orderbook], Optional[Orderbook]]

async load_event_queue() EventQueue | None#

Load the event queue which contains matching engine events that are yet to be processed.

Returns:

The event queue if it exists, None otherwise.

Return type:

Optional[EventQueue]

async load_fills(limit=100) list[FilledOrder] | None#

Load the filled orders.

Warning: this method may not work since we’ve modified our event queue to only include fills.

Parameters:

limit (int, optional) – The maximum number of filled orders to load. Defaults to 100.

Returns:

A list of filled orders if they exist, None otherwise.

Return type:

Optional[list[FilledOrder]]

async load_orders_for_owner(open_orders_account_address: Pubkey) list[Order] | None#

Load orders for a specific owner.

Parameters:

open_orders_account_address (Pubkey) – The public key of the owner’s open orders account.

Returns:

A list of orders for the owner if they exist, None otherwise.

Return type:

Optional[list[Order]]

matching_engine_program_id: Pubkey#

The public key of the matching engine program.

async print_orderbook(depth: int = 10) None#

Prints the order book up to a specified depth.

Parameters:

depth (int, optional) – The depth of the order book to print. Defaults to 10.

zeta_program_id: Pubkey#

The public key of the Zeta program.

zetamarkets_py.orderbook module#

class zetamarkets_py.orderbook.Orderbook(side: Side, orderbook: OrderbookAccount, market_state: MarketState)#

Bases: object

Represents an order book.

side#

The side of the order book.

Type:

Side

async classmethod load(conn: AsyncClient, address: Pubkey, commitment: Commitment, side: Side, market_state: MarketState, program_id: Pubkey = Pubkey(zDEXqXEG7gAyxb1Kg9mK5fPnUdENCGKzWrM21RMdWRq)) Orderbook | None#

Loads the order book.

Parameters:
  • conn (AsyncClient) – The connection.

  • address (Pubkey) – The address.

  • commitment (Commitment) – The commitment.

  • side (Side) – The side.

  • market_state (MarketState) – The market state.

  • program_id (Pubkey, optional) – The program ID. Defaults to constants.MATCHING_ENGINE_PID[Network.MAINNET].

Returns:

The order book if it exists, None otherwise.

Return type:

Optional[Orderbook]

orders() Iterable[Order]#

Yields the orders.

Yields:

Order – The order.

zetamarkets_py.pda module#

zetamarkets_py.pda.get_associated_token_address(authority: Pubkey, mint: Pubkey) Pubkey#
zetamarkets_py.pda.get_combined_socialized_loss_address(program_id: Pubkey) Pubkey#
zetamarkets_py.pda.get_combined_vault_address(program_id: Pubkey) Pubkey#
zetamarkets_py.pda.get_cross_margin_account_manager_address(program_id: Pubkey, authority: Pubkey) Pubkey#
zetamarkets_py.pda.get_margin_account_address(program_id: Pubkey, authority: Pubkey, subaccount_index: int = 0) Pubkey#
zetamarkets_py.pda.get_mint_authority_address(program_id: Pubkey) Pubkey#
zetamarkets_py.pda.get_open_orders_address(program_id: Pubkey, dex_program_id: Pubkey, market: Pubkey, margin_account: Pubkey) Pubkey#
zetamarkets_py.pda.get_open_orders_map_address(program_id: Pubkey, open_orders: Pubkey) Pubkey#
zetamarkets_py.pda.get_perp_sync_queue_address(program_id: Pubkey, zeta_group: Pubkey) Pubkey#
zetamarkets_py.pda.get_pricing_address(program_id: Pubkey) Pubkey#
zetamarkets_py.pda.get_serum_authority_address(program_id: Pubkey) Pubkey#
zetamarkets_py.pda.get_state_address(program_id: Pubkey) Pubkey#
zetamarkets_py.pda.get_underlying_mint_address(asset: Asset, network: Network) Pubkey#
zetamarkets_py.pda.get_zeta_group_address(program_id: Pubkey, mint: Pubkey) Pubkey#
zetamarkets_py.pda.get_zeta_vault_address(program_id: Pubkey, mint: Pubkey) Pubkey#

zetamarkets_py.types module#

class zetamarkets_py.types.Asset(value)#

Bases: Enum

Enum class for different types of assets.

APT = 'APT'#
ARB = 'ARB'#
BNB = 'BNB'#
BTC = 'BTC'#
DYM = 'DYM'#
ETH = 'ETH'#
JTO = 'JTO'#
JUP = 'JUP'#
ONEMBONK = 'ONEMBONK'#
PYTH = 'PYTH'#
SEI = 'SEI'#
SOL = 'SOL'#
STRK = 'STRK'#
TIA = 'TIA'#
static all()#

Returns a list of all assets.

classmethod from_index(index: int)#

Returns the asset corresponding to the given index.

to_index()#

Converts the asset to its corresponding index.

to_program_type()#

Converts the asset to its corresponding program type.

class zetamarkets_py.types.FilledOrder(order_id: int, side: Side, price: float, size: float, fee_cost: int)#

Bases: object

Data class for filled order details.

fee_cost: int#
order_id: int#
price: float#
side: Side#
size: float#
class zetamarkets_py.types.Network(value)#

Bases: Enum

Enum class for different types of networks.

DEVNET = 'devnet'#
MAINNET = 'mainnet_beta'#
TESTNET = 'testnet'#
class zetamarkets_py.types.Order(order_id: int, client_id: int, open_order_address: Pubkey, open_order_slot: int, fee_tier: int, info: OrderInfo, side: Side, tif_offset: int)#

Bases: object

Data class for order details.

client_id: int#
fee_tier: int#
info: OrderInfo#
open_order_address: Pubkey#
open_order_slot: int#
order_id: int#
side: Side#
tif_offset: int#
class zetamarkets_py.types.OrderArgs(price: float, size: float, side: ~zetamarkets_py.types.Side, order_opts: ~zetamarkets_py.types.OrderOptions = <factory>)#

Bases: object

Data class for order arguments.

order_opts: OrderOptions#
price: float#
side: Side#
size: float#
class zetamarkets_py.types.OrderCompleteType(value)#

Bases: Enum

Enum class for different types of order completion statuses.

Booted = 2#
Cancel = 0#
Fill = 1#
classmethod from_index(index: int)#

Returns the order completion status corresponding to the given index.

class zetamarkets_py.types.OrderInfo(price: float, size: float)#

Bases: object

Data class for order information.

price: float#
size: float#
class zetamarkets_py.types.OrderOptions(expiry_ts: int | None = None, client_order_id: int | None = None, blockhash: Hash | None = None, order_type: OrderType = OrderType.Limit, tag: str = 'SDK')#

Bases: object

Data class for order options.

blockhash: Hash | None = None#
client_order_id: int | None = None#
expiry_ts: int | None = None#
order_type: OrderType = 0#
tag: str = 'SDK'#
class zetamarkets_py.types.OrderType(value)#

Bases: IntEnum

Enum class for different types of orders.

FillOrKill = 2#
ImmediateOrCancel = 3#
Limit = 0#
PostOnly = 1#
PostOnlySlide = 4#
classmethod from_index(index: int)#

Returns the order type corresponding to the given index.

to_program_type()#

Converts the order type to its corresponding program type.

class zetamarkets_py.types.SelfTradeBehavior(value)#

Bases: Enum

Enum class for different types of self trade behaviors.

AbortTransaction = 2#
CancelProvide = 1#
DecrementTake = 0#
class zetamarkets_py.types.Side(value)#

Bases: Enum

Enum class for different sides of the orderbook to trade.

Ask = 2#
Bid = 1#
Uninitialized = 0#
classmethod from_index(index: int)#

Returns the side corresponding to the given index.

to_program_type() Uninitialized | Bid | Ask#

Converts the side to its corresponding program type.

class zetamarkets_py.types.TIFOptions(expiry_offset: int | None = None, expiry_ts: int | None = None)#

Bases: object

Data class for Time in Force options.

expiry_offset: int | None = None#
expiry_ts: int | None = None#

zetamarkets_py.utils module#

zetamarkets_py.utils.cluster_endpoint(network: Network, tls: bool = True, ws: bool = False) str#

Retrieve the RPC API URL for the specified cluster.

Parameters:
  • network (Network) – The network to use.

  • tls (bool, optional) – If True, use https. Defaults to True.

  • ws (bool, optional) – If True, use WebSocket. Defaults to False.

Returns:

The RPC API URL.

Return type:

str

zetamarkets_py.utils.convert_decimal_to_fixed_int(amount: float, tick_size: int) int#

Converts a decimal to a fixed integer number.

Parameters:

amount (float) – The decimal to be converted.

Returns:

The converted fixed integer.

Return type:

int

zetamarkets_py.utils.convert_decimal_to_fixed_lot(amount: float, min_lot_size: int) int#

Converts a decimal to a fixed integer lot size.

Parameters:

amount (float) – The decimal to be converted.

Returns:

The converted fixed lot.

Return type:

int

zetamarkets_py.utils.convert_fixed_int_to_decimal(amount: int) float#

Converts a fixed integer number to a decimal.

Parameters:

amount (int) – The fixed integer to be converted.

Returns:

The converted decimal.

Return type:

float

zetamarkets_py.utils.convert_fixed_lot_to_decimal(amount: int) float#

Converts a fixed integer lot size to a decimal.

Parameters:

amount (int) – The fixed lot to be converted.

Returns:

The converted decimal.

Return type:

float

zetamarkets_py.utils.create_logger(name: str, log_level: int = 50, file_name: str | None = None) Logger#

Create a logger.

Parameters:
  • name (str) – The name of the logger.

  • log_level (int, optional) – The log level. Defaults to logging.CRITICAL.

  • file_name (str, optional) – The file name. If provided, logs will be written to this file. Defaults to None.

Returns:

The created logger.

Return type:

logging.Logger

zetamarkets_py.utils.get_fixed_min_lot_size(state: State, asset: Asset) int#
zetamarkets_py.utils.get_fixed_tick_size(state: State, asset: Asset) int#
zetamarkets_py.utils.get_recent_prio_fees(url: str, accounts: [<class 'str'>], lookback_slots: int = 20, use_max: bool = False) int#
zetamarkets_py.utils.get_tif_offset(expiry_ts: int, epoch_length: int, current_ts: int, tif_buffer: int = 0) int#

Get the Time in Force (TIF) offset.

Parameters:
  • expiry_ts (int) – The expiry timestamp.

  • epoch_length (int) – The length of the epoch.

  • current_ts (int) – The current timestamp.

Returns:

The Time in Force offset.

Return type:

int

Raises:

Exception – If the expiry timestamp is less than the current timestamp.

zetamarkets_py.utils.http_to_ws(endpoint: str) str#

Converts an HTTP endpoint to a WebSocket endpoint.

Parameters:

endpoint (str) – The HTTP endpoint.

Returns:

The WebSocket endpoint.

Return type:

str

Module contents#