トレーダーインタラクション

circle-check

依存関係をインストール:

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

// setup the flashClient as show previously

価格設定のためのPythのセットアップ:

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

PythからPrice取得:

import { BN } from "@coral-xyz/anchor";
import { OraclePrice } from 'flash-sdk';

// POOL_CONFIG as show previously

const getPrices = async () => { 
    const pythHttpClientResult = await pythClient.getData()
    
    const priceMap = new Map<string, { price: OraclePrice; emaPrice: OraclePrice }>();

    for (let token of POOL_CONFIG.tokens) {
        const priceData: PriceData = pythHttpClientResult.productPrice.get(token.pythTicker)!
        if (!priceData) {
            throw new Error(`priceData not found for ${token.symbol}`)
        }
        const priceOracle = new OraclePrice({
            price: new BN(priceData?.aggregate.priceComponent.toString()),
            exponent: new BN(priceData?.exponent),
            confidence: new BN(priceData?.confidence!),
            timestamp: new BN(priceData?.timestamp.toString()),
        })

        const emaPriceOracle = new OraclePrice({
            price: new BN(priceData?.emaPrice.valueComponent.toString()),
            exponent: new BN(priceData?.exponent),
            confidence: new BN(priceData?.emaConfidence.valueComponent.toString()),
            timestamp: new BN(priceData?.timestamp.toString()),
        })
        priceMap.set(token.symbol, { price: priceOracle, emaPrice: emaPriceOracle })
    }

    return priceMap;
 }

同じ担保でポジションを開く:

ポジションを閉じて同じトークンで担保を受け取る:

異なる担保でポジションを開く:

ポジションを閉じて異なるトークンで担保を受け取る:

既存のポジションに完全または部分的な利確・損切りを設定:

circle-info

注意:

  • ストップロス:

    • ロングの場合、清算価格より上で現在価格より下である必要があります

    • ショートの場合、清算価格より下で現在価格より上である必要があります

  • 利確:

    • ロングの場合、現在価格より上である必要があります

    • ショートの場合、現在価格より下である必要があります

  • バーチャルトークン* ロングの場合、利確は最大利益価格より下である必要があります*

最終更新

役に立ちましたか?