Interacciones de Trader

Instalar Dependencias:

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

// setup the flashClient as show previously

Configurar Pyth para Precios:

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

Obtener Precios de Pyth:

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;
 }

Abrir Posición con el Mismo Colateral:

Cerrar una Posición y Recibir Colateral en el Mismo Token:

Abrir posición con Colateral Diferente:

Cerrar Posición y Recibir Colateral en un Token Diferente:

Establecer Take Profit o Stop Loss Completo o Parcial en una Posición Existente:

NOTA:

  • Stop Loss:

    • Debe estar por encima del Precio de Liquidación y por debajo del Precio Actual para LONG

    • Debe estar por debajo del Precio de Liquidación y por encima del Precio Actual para SHORT

  • Take Profit:

    • Debe estar por encima del Precio Actual para LONG

    • Debe estar por debajo del Precio Actual para SHORT

  • Tokens virtuales* Take Profit debe estar por debajo del Precio de Ganancia Máxima para LONG*

Obteniendo Precio de Liquidación de la Posición Activa Actual

Última actualización

¿Te fue útil?