Trader Interactions

circle-exclamation

Note

circle-check

Install Dependencies:

yarn add @solana/web3.js @pythnetwork/client @solana/spl-token @coral-xyz/anchor

// setup the flashClient as show previously

Setup Pyth for Pricing:

const connectionFromPyth = new Connection(
    'pythnet-provider-url' // can get it from triton
)

const pythClient = new PythHttpClient(connectionFromPyth, getPythProgramKeyForCluster('pythnet'))

// for alternatives see https://docs.pyth.network/price-feeds/use-real-time-data/off-chain

Fetch Prices From Pyth:

Open Position with Same Collateral:

Close a Position and Receive Collateral in the Same Token:

Open position with different Collateral:

Close Position and Receive Collateral in a Different Token:

Set Full or Partial Take Profit or Stop Loss on an Existing Position:

circle-info

NOTE :

  • Stop Loss:

    • Must be above Liquidation Price and below Current Price for LONG

    • Must be below Liquidation Price above Current Price for SHORT

  • Take Profit:

    • Must be above Current Price for LONG

    • Must be below Current Price for SHORT

  • Virtual tokens Take Profit must be below Max Profit Price for LONG

Getting Liquidation Price of Current Active Position

Last updated

Was this helpful?