diff --git a/src/Managing.Application/Bots/TradingBot.cs b/src/Managing.Application/Bots/TradingBot.cs index 9816578..7174489 100644 --- a/src/Managing.Application/Bots/TradingBot.cs +++ b/src/Managing.Application/Bots/TradingBot.cs @@ -963,14 +963,29 @@ public class TradingBot : Bot, ITradingBot private async Task LogInformation(string message) { Logger.LogInformation(message); - await SendTradeMessage(message); + try + { + await SendTradeMessage(message); + } + catch (Exception e) + { + Console.WriteLine(e); + } } private async Task LogWarning(string message) { message = $"[{Identifier}] {message}"; SentrySdk.CaptureException(new Exception(message)); - await SendTradeMessage(message, true); + + try + { + await SendTradeMessage(message, true); + } + catch (Exception e) + { + Console.WriteLine(e); + } } private async Task SendTradeMessage(string message, bool isBadBehavior = false) diff --git a/src/Managing.Web3Proxy/src/generated/gmxsdk/modules/orders/helpers.ts b/src/Managing.Web3Proxy/src/generated/gmxsdk/modules/orders/helpers.ts index b2aad76..11bdc45 100644 --- a/src/Managing.Web3Proxy/src/generated/gmxsdk/modules/orders/helpers.ts +++ b/src/Managing.Web3Proxy/src/generated/gmxsdk/modules/orders/helpers.ts @@ -6,12 +6,13 @@ 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 {getAcceptablePriceInfo, getOrderThresholdType} from "../../utils/prices.js"; import type {GmxSdk} from "../.."; import {createSwapEstimator, getMarketsGraph} from "../../utils/swap/swapRouting.js"; import {getSwapAmountsByFromValue, getSwapAmountsByToValue} from "../../utils/swap/index.js"; import {EntryField, SidecarSlTpOrderEntryValid} from "../../types/sidecarOrders.js"; +import {ethers} from "ethers"; /** Base Optional params for helpers, allows to avoid calling markets, tokens and uiFeeFactor methods if they are already passed */ interface BaseOptionalParams { @@ -180,9 +181,9 @@ export async function increaseOrderHelper( collateralDeltaAmount: increaseAmounts.collateralDeltaAmount, indexPrice: params.stopLossPrice, collateralPrice: 0n, - acceptablePrice: params.isLong ? 2n ** 256n - 1n : 0n, - acceptablePriceDeltaBps: acceptablePriceInfo.acceptablePriceDeltaBps + 50n, - recommendedAcceptablePriceDeltaBps: 50n, + acceptablePrice: params.isLong ? 0n : ethers.MaxUint256, + acceptablePriceDeltaBps: acceptablePriceInfo.acceptablePriceDeltaBps, + recommendedAcceptablePriceDeltaBps: 30n, estimatedPnl: 0n, estimatedPnlPercentage: 0n, realizedPnl: 0n, @@ -195,7 +196,7 @@ export async function increaseOrderHelper( fundingFeeUsd: 0n, swapProfitFeeUsd: 0n, positionPriceImpactDeltaUsd: 0n, - priceImpactDiffUsd: 0n, + priceImpactDiffUsd: acceptablePriceInfo.priceImpactDeltaUsd, payedRemainingCollateralAmount: 0n, payedOutputUsd: 0n, payedRemainingCollateralUsd: 0n, @@ -204,8 +205,11 @@ export async function increaseOrderHelper( decreaseSwapType: DecreasePositionSwapType.SwapPnlTokenToCollateralToken, triggerOrderType: OrderType.StopLossDecrease, triggerPrice: params.stopLossPrice, + triggerThresholdType: getOrderThresholdType(OrderType.StopLossDecrease, params.isLong), } + console.log(stopLossDecreaseAmounts); + const stopLossEntry: SidecarSlTpOrderEntryValid = { decreaseAmounts: stopLossDecreaseAmounts, id: "sl-order", @@ -255,8 +259,8 @@ export async function increaseOrderHelper( indexPrice: params.takeProfitPrice, // Keep original trigger price for indexPrice collateralPrice: 0n, // Consider if this needs calculation acceptablePrice: acceptablePriceInfo.acceptablePrice, - acceptablePriceDeltaBps: acceptablePriceInfo.acceptablePriceDeltaBps + 50n, // Add 0.5% buffer to acceptable price impact - recommendedAcceptablePriceDeltaBps: 50n, // Set recommended buffer to 0.5% + acceptablePriceDeltaBps: acceptablePriceInfo.acceptablePriceDeltaBps, // Add 0.5% buffer to acceptable price impact + recommendedAcceptablePriceDeltaBps: 30n, // Set recommended buffer to 0.5% estimatedPnl: 0n, estimatedPnlPercentage: 0n, realizedPnl: 0n, @@ -269,7 +273,7 @@ export async function increaseOrderHelper( fundingFeeUsd: 0n, swapProfitFeeUsd: 0n, positionPriceImpactDeltaUsd: 0n, - priceImpactDiffUsd: 0n, + priceImpactDiffUsd: acceptablePriceInfo.priceImpactDeltaUsd, payedRemainingCollateralAmount: 0n, payedOutputUsd: 0n, payedRemainingCollateralUsd: 0n, @@ -278,6 +282,7 @@ export async function increaseOrderHelper( decreaseSwapType: DecreasePositionSwapType.SwapPnlTokenToCollateralToken, triggerOrderType: OrderType.LimitDecrease, triggerPrice: params.takeProfitPrice, + triggerThresholdType: getOrderThresholdType(OrderType.LimitDecrease, params.isLong), } const takeProfitEntry: SidecarSlTpOrderEntryValid = { diff --git a/src/Managing.Web3Proxy/src/plugins/custom/gmx.ts b/src/Managing.Web3Proxy/src/plugins/custom/gmx.ts index 712175e..f3faf97 100644 --- a/src/Managing.Web3Proxy/src/plugins/custom/gmx.ts +++ b/src/Managing.Web3Proxy/src/plugins/custom/gmx.ts @@ -138,7 +138,7 @@ export async function getClientForAddress( account: account, oracleUrl: "https://arbitrum-api.gmxinfra.io", rpcUrl: "https://arb1.arbitrum.io/rpc", - subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum:live/api/graphql", + subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum:prod/api/graphql", subgraphUrl: "https://subgraph.satsuma-prod.com/3b2ced13c8d9/gmx/synthetics-arbitrum-stats/api", settings: { uiFeeReceiverAccount: "0xF9f04a745Db54B25bB8B345a1da74D4E3c38c8aB" @@ -212,7 +212,7 @@ export const openGmxPositionImpl = async ( marketAddress: marketInfo.marketTokenAddress, payTokenAddress: collateralToken.address, collateralTokenAddress: collateralToken.address, - allowedSlippageBps: 100, // 1% slippage + allowedSlippageBps: 50, // 0.5% slippage leverage: leverageBps, skipSimulation: true, referralCodeForTxn: encodeReferralCode("kaigen_ai"),