交易者交互

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' // 可以从 triton 获得
)

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

// 替代方案请参见 https://docs.pyth.network/price-feeds/use-real-time-data/off-chain

从 Pyth 获取价格:

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

// POOL_CONFIG 如前所示

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(`未找到 ${token.symbol} 的 priceData`)
        }

        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

注意:

  • 止损:

    • 对于做多必须高于清算价格并低于当前价格

    • 对于做空必须低于清算价格并高于当前价格

  • 止盈:

    • 对于做多必须高于当前价格

    • 对于做空必须低于当前价格

  • 虚拟代币* 做多的止盈必须低于最大利润价格*

获取当前活跃仓位的清算价格

最后更新于

这有帮助吗?