returns infos about open orders accounts(position size + asks&bids on the book)
get all balances for the account (adjusts usdc balance for realized pnl and funding)
get the USD value of the collateral tied in Borrows & Lending
Get Borrow Position Notional Value
Get collateral Initial Margin Fraction Information
Get Collateral MMF info
returns the total unrealized pnl for all positions
Collateral of the free value
get total funding amount from all the markets
Is Bankrupt
Is Liquidatable
Should account liquidate perp or spot(based on the weight of the position)
Largest balance
Largest borrow by weight
Largest position by weight
Maintenance Margin Fraction
Margin Fraction
Open Margin Fraction
Value of the collateral tied in positions
returns total realized pnl in case it hasn't been cranked
Tied collateral value
Total open position notional
Total position Notional
Account value(with unweighted collateral)
get deposited collateral value in USD terms
Account value(with weighted collateral, lower than the actual account value)
get WEIGHTED collateral value in USD terms
Cancels an order on the orderbook for a given market either by orderId or by clientId.
/** Withdrawable collateral without borrow
Withdrawable collateral with borrow
User must create a perp OpenOrders account for every perpetual market(future and or options) they intend to trade on.
The market symbol. Ex: ("BTC-PERP")
Deposits a given amount of collateral into the Margin account from the associated token account.
The amount of tokens to deposit, in big units. (ex: 1.5 SOL, or 0.5 BTC)
If true, will only deposit up to the amount borrowed. If true, amount parameter can be set to an arbitrarily large number to ensure that any outstanding borrow is fully repaid.
optional param to provide the token account to use it for deposits
Deposits a given amount of collateral into the Margin account. Raw implementation of the instruction.
The user's token account where tokens will be subtracted from.
The state vault where tokens will be deposited into.
The amount of tokens to deposit, in native quantity. (ex: lamports for SOL, satoshis for BTC)
If true, will only deposit up to the amount borrowed. If true, amount parameter can be set to an arbitrarily large number to ensure that any outstanding borrow is fully repaid.
Deposits a given amount of SOL collateral into the Margin account. Raw implementation of the instruction.
The state vault where tokens will be deposited into.
The amount of tokens to deposit, in native quantity. (ex: lamports for SOL, satoshis for BTC)
If true, will only deposit up to the amount borrowed. If true, amount parameter can be set to an arbitrarily large number to ensure that any outstanding borrow is fully repaid.
Value of the collateral tied in positions
The market symbol. Ex: ("BTC-PERP")
If true, creates the OpenOrders account if it doesn't exist.
The OpenOrdersInfo for the given market.
The market symbol. Ex: ("BTC-PERP")
The OpenOrders account key for the given market.
Get the value of the weighted borrow
Initial Margin Fraction
Initial Margin Fraction
Is Liquidatable with tolerance(mmf*tolerance>mf)
load all active orders across all markets
Creates the instruction for cancelling a perp order.
Creates the instruction for placing a perp order on the orderbook. Creates an Open orders account if does not exist, in the same transaction.
Max Collateral Purchaseable for the trade
Max Contracts Purchaseable for the trade
Places a perp order on the orderbook. Creates an Open orders account if does not exist, in the same transaction.
Raw implementation of the instruction rpc call. Places an order on the orderbook for a given market, using lot sizes for limit and base quantity, and native units for quote quantity. Assumes an open orders account has been created already.
returns the position info for the specific market key
get funding for the position
returns unrealized pnl for the position
returns unrealized pnl for the position
Position weighted
Refreshes the data on the Margin, state, cache and control accounts.
Settles unrealized funding and realized PnL into the margin account for a given market.
Market symbol (ex: BTC-PERP).
Refreshes the data on the Margin, state, cache and control accounts.
use a backup confirmed
listener
minimum time between state updates
minimum time between cache updates
Swaps between USDC and a given Token B (or vice versa) on the Serum Spot DEX. This is a direct IOC trade that instantly settles. Note that the token B needs to be swappable, as enabled by the 01 program.
Withdraws a given amount of collateral from the Margin account to a specified token account. If withdrawing more than the amount deposited, then account will be borrowing.
The amount of tokens to withdraw, in big units. (ex: 1.5 SOL, or 0.5 BTC)
If false, will only be able to withdraw up to the amount deposited. If false, amount parameter can be set to an arbitrarily large number to ensure that all deposits are fully withdrawn.
Withdraws a given amount of collateral from the Margin account to a specified token account. If withdrawing more than the amount deposited, then account will be borrowing. Raw implementation of the instruction.
The user's token account where tokens will be withdrawn to.
The state vault where tokens will be withdrawn from.
The amount of tokens to withdraw, in native quantity. (ex: lamports for SOL, satoshis for BTC)
If false, will only be able to withdraw up to the amount deposited. If false, amount parameter can be set to an arbitrarily large number to ensure that all deposits are fully withdrawn.
instructions executed before withdrawal
Withdraws a given amount of collateral from the Margin account to a specified token account. If withdrawing more than the amount deposited, then account will be borrowing. Raw implementation of the instruction.
The state vault where tokens will be withdrawn from.
The amount of tokens to withdraw, in native quantity. (ex: lamports for SOL, satoshis for BTC)
If false, will only be able to withdraw up to the amount deposited. If false, amount parameter can be set to an arbitrarily large number to ensure that all deposits are fully withdrawn.
Gets the Margin account's PDA and bump.
An array consisting of [PDA, bump]
Loads a new Margin object from prefetched schema;
Generated using TypeDoc
The margin account is a PDA generated using
javascript seeds=[userWalletKey, stateKey, "marginv1"]
.