marginpy.client module

class MarginfiClient(config: MarginfiConfig, program: Program, group: MarginfiGroup)

Bases: object

Entrypoint to interact with the marginfi contract.

async classmethod fetch(config: MarginfiConfig, wallet: Wallet, rpc_client: AsyncClient, opts: Optional[TxOpts] = None) MarginfiClient

MarginfiClient factory.

Fetches account data according to the config and instantiate the corresponding MarginfiAccount.

Parameters
  • config (MarginfiConfig) – marginfi config

  • wallet (Wallet) – User wallet (used to pay fees and sign transations)

  • rpc_client (AsyncClient) – RPC client

  • opts (types.TxOpts, optional) – Transaction/commitment options. Defaults to DEFAULT_OPTIONS.

Returns

marginfi client

Return type

MarginfiClient

async classmethod from_env(overrides: Optional[Dict[Literal['env', 'connection', 'program_id', 'group_pk'], Any]] = None) MarginfiClient

MarginfiClient environment factory.

Fetches account data according to the ENV variables provided (falling back to default config when possible), and instantiate the corresponding MarginfiAccount.

Parameters

overrides (Dict[str, Any], optional) – override to environment variables. Defaults to {}.

Returns

marginfi client

Return type

MarginfiClient

property program: Program
property provider: Provider
property group: MarginfiGroup
property config: MarginfiConfig
property program_id: PublicKey
async create_marginfi_account() Tuple[MarginfiAccount, TransactionSignature]

Creates a new marginfi account under the authority of the user.

Returns

new marginfi account and creation tx signature

Return type

Tuple[MarginfiAccount, TransactionSignature]

async load_own_marginfi_accounts() List[MarginfiAccount]

Retrieves all marginfi accounts under the authority of the user.

async load_all_marginfi_account_addresses() List[PublicKey]

Retrieves the addresses of all marginfi accounts in the underlying group.

Raises

Exception – RPC call errors out

async load_all_marginfi_accounts() List[MarginfiAccount]

Retrieves all marginfi accounts in the underlying group.

async load_marginfi_account(address: Union[str, PublicKey], observe_utps: bool = True) MarginfiAccount

Retrieves specified marginfi account.

async load_all_program_account_addresses(account_type: AccountType) List[PublicKey]

Retrieves the addresses of all accounts of the spcified type, owned by the marginfi program.

Raises

Exception – RPC call errors out

async terminate() None

Cleans up connections.