Fix bots + positions managements
This commit is contained in:
@@ -6,6 +6,7 @@ import { getByKey } from "../../utils/objects.js";
|
||||
import { createFindSwapPath, findAllSwapPaths, getWrappedAddress } from "../../utils/swap/swapPath.js";
|
||||
import { convertToUsd, getIsUnwrap, getIsWrap, getTokensRatioByPrice } from "../../utils/tokens.js";
|
||||
import { getIncreasePositionAmounts } from "../../utils/trade/amounts.js";
|
||||
import { getAcceptablePriceInfo } from "../../utils/prices.js";
|
||||
|
||||
import type { GmxSdk } from "../..";
|
||||
import { createSwapEstimator, getMarketsGraph } from "../../utils/swap/swapRouting.js";
|
||||
@@ -13,7 +14,6 @@ import { getSwapAmountsByFromValue, getSwapAmountsByToValue } from "../../utils/
|
||||
import { EntryField, SidecarSlTpOrderEntryValid } from "../../types/sidecarOrders.js";
|
||||
import { bigMath } from "../../utils/bigmath.js";
|
||||
|
||||
const ALLOWED_SLIPPAGE_BPS = BigInt(100);
|
||||
/** Base Optional params for helpers, allows to avoid calling markets, tokens and uiFeeFactor methods if they are already passed */
|
||||
interface BaseOptionalParams {
|
||||
marketsInfoData?: MarketsInfoData;
|
||||
@@ -166,16 +166,25 @@ export async function increaseOrderHelper(
|
||||
if (params.stopLossPrice) {
|
||||
const stopLossCollateralDeltaUsd = convertToUsd(increaseAmounts.collateralDeltaAmount, collateralToken.decimals, params.stopLossPrice);
|
||||
|
||||
const acceptablePriceInfo = getAcceptablePriceInfo({
|
||||
marketInfo,
|
||||
isIncrease: false,
|
||||
isLong: params.isLong,
|
||||
indexPrice: params.stopLossPrice,
|
||||
sizeDeltaUsd: increaseAmounts.sizeDeltaUsd,
|
||||
maxNegativePriceImpactBps: marketInfo.maxPositionImpactFactorForLiquidations,
|
||||
});
|
||||
|
||||
stopLossDecreaseAmounts = {
|
||||
isFullClose: true,
|
||||
sizeDeltaUsd: increaseAmounts.sizeDeltaUsd,
|
||||
sizeDeltaInTokens: increaseAmounts.sizeDeltaInTokens,
|
||||
collateralDeltaUsd: stopLossCollateralDeltaUsd,
|
||||
collateralDeltaAmount: increaseAmounts.collateralDeltaAmount,
|
||||
indexPrice: 0n,
|
||||
indexPrice: params.stopLossPrice,
|
||||
collateralPrice: 0n,
|
||||
acceptablePrice: params.stopLossPrice,
|
||||
acceptablePriceDeltaBps: ALLOWED_SLIPPAGE_BPS,
|
||||
acceptablePrice: acceptablePriceInfo.acceptablePrice,
|
||||
acceptablePriceDeltaBps: acceptablePriceInfo.acceptablePriceDeltaBps,
|
||||
recommendedAcceptablePriceDeltaBps: 0n,
|
||||
estimatedPnl: 0n,
|
||||
estimatedPnlPercentage: 0n,
|
||||
@@ -231,16 +240,25 @@ export async function increaseOrderHelper(
|
||||
if (params.takeProfitPrice) {
|
||||
const takeProfitCollateralDeltaUsd = convertToUsd(increaseAmounts.collateralDeltaAmount, collateralToken.decimals, params.takeProfitPrice);
|
||||
|
||||
const acceptablePriceInfo = getAcceptablePriceInfo({
|
||||
marketInfo,
|
||||
isIncrease: false,
|
||||
isLong: params.isLong,
|
||||
indexPrice: params.takeProfitPrice,
|
||||
sizeDeltaUsd: increaseAmounts.sizeDeltaUsd,
|
||||
maxNegativePriceImpactBps: marketInfo.maxPositionImpactFactorForLiquidations,
|
||||
});
|
||||
|
||||
takeProfitDecreaseAmounts = {
|
||||
isFullClose: true,
|
||||
sizeDeltaUsd: increaseAmounts.sizeDeltaUsd,
|
||||
sizeDeltaInTokens: increaseAmounts.sizeDeltaInTokens,
|
||||
collateralDeltaUsd: takeProfitCollateralDeltaUsd,
|
||||
collateralDeltaAmount: increaseAmounts.collateralDeltaAmount,
|
||||
indexPrice: 0n,
|
||||
collateralPrice: 0n,
|
||||
acceptablePrice: params.takeProfitPrice,
|
||||
acceptablePriceDeltaBps: ALLOWED_SLIPPAGE_BPS,
|
||||
indexPrice: params.takeProfitPrice, // Keep original trigger price for indexPrice
|
||||
collateralPrice: 0n, // Consider if this needs calculation
|
||||
acceptablePrice: acceptablePriceInfo.acceptablePrice,
|
||||
acceptablePriceDeltaBps: acceptablePriceInfo.acceptablePriceDeltaBps,
|
||||
recommendedAcceptablePriceDeltaBps: 0n,
|
||||
estimatedPnl: 0n,
|
||||
estimatedPnlPercentage: 0n,
|
||||
|
||||
@@ -140,6 +140,8 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
|
||||
account,
|
||||
ticker
|
||||
)
|
||||
|
||||
console.log('result', result)
|
||||
|
||||
return result
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user