Fix a bit the sdk and trades

This commit is contained in:
2025-05-27 13:47:07 +07:00
parent ebcaff6b5b
commit f743436634
3 changed files with 32 additions and 12 deletions

View File

@@ -963,14 +963,29 @@ public class TradingBot : Bot, ITradingBot
private async Task LogInformation(string message) private async Task LogInformation(string message)
{ {
Logger.LogInformation(message); Logger.LogInformation(message);
await SendTradeMessage(message); try
{
await SendTradeMessage(message);
}
catch (Exception e)
{
Console.WriteLine(e);
}
} }
private async Task LogWarning(string message) private async Task LogWarning(string message)
{ {
message = $"[{Identifier}] {message}"; message = $"[{Identifier}] {message}";
SentrySdk.CaptureException(new Exception(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) private async Task SendTradeMessage(string message, bool isBadBehavior = false)

View File

@@ -6,12 +6,13 @@ import {getByKey} from "../../utils/objects.js";
import {createFindSwapPath, findAllSwapPaths, getWrappedAddress} from "../../utils/swap/swapPath.js"; import {createFindSwapPath, findAllSwapPaths, getWrappedAddress} from "../../utils/swap/swapPath.js";
import {convertToUsd, getIsUnwrap, getIsWrap, getTokensRatioByPrice} from "../../utils/tokens.js"; import {convertToUsd, getIsUnwrap, getIsWrap, getTokensRatioByPrice} from "../../utils/tokens.js";
import {getIncreasePositionAmounts} from "../../utils/trade/amounts.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 type {GmxSdk} from "../..";
import {createSwapEstimator, getMarketsGraph} from "../../utils/swap/swapRouting.js"; import {createSwapEstimator, getMarketsGraph} from "../../utils/swap/swapRouting.js";
import {getSwapAmountsByFromValue, getSwapAmountsByToValue} from "../../utils/swap/index.js"; import {getSwapAmountsByFromValue, getSwapAmountsByToValue} from "../../utils/swap/index.js";
import {EntryField, SidecarSlTpOrderEntryValid} from "../../types/sidecarOrders.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 */ /** Base Optional params for helpers, allows to avoid calling markets, tokens and uiFeeFactor methods if they are already passed */
interface BaseOptionalParams { interface BaseOptionalParams {
@@ -180,9 +181,9 @@ export async function increaseOrderHelper(
collateralDeltaAmount: increaseAmounts.collateralDeltaAmount, collateralDeltaAmount: increaseAmounts.collateralDeltaAmount,
indexPrice: params.stopLossPrice, indexPrice: params.stopLossPrice,
collateralPrice: 0n, collateralPrice: 0n,
acceptablePrice: params.isLong ? 2n ** 256n - 1n : 0n, acceptablePrice: params.isLong ? 0n : ethers.MaxUint256,
acceptablePriceDeltaBps: acceptablePriceInfo.acceptablePriceDeltaBps + 50n, acceptablePriceDeltaBps: acceptablePriceInfo.acceptablePriceDeltaBps,
recommendedAcceptablePriceDeltaBps: 50n, recommendedAcceptablePriceDeltaBps: 30n,
estimatedPnl: 0n, estimatedPnl: 0n,
estimatedPnlPercentage: 0n, estimatedPnlPercentage: 0n,
realizedPnl: 0n, realizedPnl: 0n,
@@ -195,7 +196,7 @@ export async function increaseOrderHelper(
fundingFeeUsd: 0n, fundingFeeUsd: 0n,
swapProfitFeeUsd: 0n, swapProfitFeeUsd: 0n,
positionPriceImpactDeltaUsd: 0n, positionPriceImpactDeltaUsd: 0n,
priceImpactDiffUsd: 0n, priceImpactDiffUsd: acceptablePriceInfo.priceImpactDeltaUsd,
payedRemainingCollateralAmount: 0n, payedRemainingCollateralAmount: 0n,
payedOutputUsd: 0n, payedOutputUsd: 0n,
payedRemainingCollateralUsd: 0n, payedRemainingCollateralUsd: 0n,
@@ -204,8 +205,11 @@ export async function increaseOrderHelper(
decreaseSwapType: DecreasePositionSwapType.SwapPnlTokenToCollateralToken, decreaseSwapType: DecreasePositionSwapType.SwapPnlTokenToCollateralToken,
triggerOrderType: OrderType.StopLossDecrease, triggerOrderType: OrderType.StopLossDecrease,
triggerPrice: params.stopLossPrice, triggerPrice: params.stopLossPrice,
triggerThresholdType: getOrderThresholdType(OrderType.StopLossDecrease, params.isLong),
} }
console.log(stopLossDecreaseAmounts);
const stopLossEntry: SidecarSlTpOrderEntryValid = { const stopLossEntry: SidecarSlTpOrderEntryValid = {
decreaseAmounts: stopLossDecreaseAmounts, decreaseAmounts: stopLossDecreaseAmounts,
id: "sl-order", id: "sl-order",
@@ -255,8 +259,8 @@ export async function increaseOrderHelper(
indexPrice: params.takeProfitPrice, // Keep original trigger price for indexPrice indexPrice: params.takeProfitPrice, // Keep original trigger price for indexPrice
collateralPrice: 0n, // Consider if this needs calculation collateralPrice: 0n, // Consider if this needs calculation
acceptablePrice: acceptablePriceInfo.acceptablePrice, acceptablePrice: acceptablePriceInfo.acceptablePrice,
acceptablePriceDeltaBps: acceptablePriceInfo.acceptablePriceDeltaBps + 50n, // Add 0.5% buffer to acceptable price impact acceptablePriceDeltaBps: acceptablePriceInfo.acceptablePriceDeltaBps, // Add 0.5% buffer to acceptable price impact
recommendedAcceptablePriceDeltaBps: 50n, // Set recommended buffer to 0.5% recommendedAcceptablePriceDeltaBps: 30n, // Set recommended buffer to 0.5%
estimatedPnl: 0n, estimatedPnl: 0n,
estimatedPnlPercentage: 0n, estimatedPnlPercentage: 0n,
realizedPnl: 0n, realizedPnl: 0n,
@@ -269,7 +273,7 @@ export async function increaseOrderHelper(
fundingFeeUsd: 0n, fundingFeeUsd: 0n,
swapProfitFeeUsd: 0n, swapProfitFeeUsd: 0n,
positionPriceImpactDeltaUsd: 0n, positionPriceImpactDeltaUsd: 0n,
priceImpactDiffUsd: 0n, priceImpactDiffUsd: acceptablePriceInfo.priceImpactDeltaUsd,
payedRemainingCollateralAmount: 0n, payedRemainingCollateralAmount: 0n,
payedOutputUsd: 0n, payedOutputUsd: 0n,
payedRemainingCollateralUsd: 0n, payedRemainingCollateralUsd: 0n,
@@ -278,6 +282,7 @@ export async function increaseOrderHelper(
decreaseSwapType: DecreasePositionSwapType.SwapPnlTokenToCollateralToken, decreaseSwapType: DecreasePositionSwapType.SwapPnlTokenToCollateralToken,
triggerOrderType: OrderType.LimitDecrease, triggerOrderType: OrderType.LimitDecrease,
triggerPrice: params.takeProfitPrice, triggerPrice: params.takeProfitPrice,
triggerThresholdType: getOrderThresholdType(OrderType.LimitDecrease, params.isLong),
} }
const takeProfitEntry: SidecarSlTpOrderEntryValid = { const takeProfitEntry: SidecarSlTpOrderEntryValid = {

View File

@@ -138,7 +138,7 @@ export async function getClientForAddress(
account: account, account: account,
oracleUrl: "https://arbitrum-api.gmxinfra.io", oracleUrl: "https://arbitrum-api.gmxinfra.io",
rpcUrl: "https://arb1.arbitrum.io/rpc", 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", subgraphUrl: "https://subgraph.satsuma-prod.com/3b2ced13c8d9/gmx/synthetics-arbitrum-stats/api",
settings: { settings: {
uiFeeReceiverAccount: "0xF9f04a745Db54B25bB8B345a1da74D4E3c38c8aB" uiFeeReceiverAccount: "0xF9f04a745Db54B25bB8B345a1da74D4E3c38c8aB"
@@ -212,7 +212,7 @@ export const openGmxPositionImpl = async (
marketAddress: marketInfo.marketTokenAddress, marketAddress: marketInfo.marketTokenAddress,
payTokenAddress: collateralToken.address, payTokenAddress: collateralToken.address,
collateralTokenAddress: collateralToken.address, collateralTokenAddress: collateralToken.address,
allowedSlippageBps: 100, // 1% slippage allowedSlippageBps: 50, // 0.5% slippage
leverage: leverageBps, leverage: leverageBps,
skipSimulation: true, skipSimulation: true,
referralCodeForTxn: encodeReferralCode("kaigen_ai"), referralCodeForTxn: encodeReferralCode("kaigen_ai"),