Fix price impact
This commit is contained in:
@@ -429,7 +429,7 @@ public class DataController : ControllerBase
|
|||||||
return new UserStrategyDetailsViewModel
|
return new UserStrategyDetailsViewModel
|
||||||
{
|
{
|
||||||
Name = strategy.Name,
|
Name = strategy.Name,
|
||||||
StrategyName = strategy.Config.ScenarioName,
|
ScenarioName = strategy.Config.ScenarioName,
|
||||||
State = strategy.GetStatus() == BotStatus.Up.ToString() ? "RUNNING" :
|
State = strategy.GetStatus() == BotStatus.Up.ToString() ? "RUNNING" :
|
||||||
strategy.GetStatus() == BotStatus.Down.ToString() ? "STOPPED" : "UNUSED",
|
strategy.GetStatus() == BotStatus.Down.ToString() ? "STOPPED" : "UNUSED",
|
||||||
PnL = pnl,
|
PnL = pnl,
|
||||||
|
|||||||
@@ -12,11 +12,6 @@ namespace Managing.Api.Models.Responses
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Strategy identifier
|
|
||||||
/// </summary>
|
|
||||||
public string StrategyName { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Current state of the strategy (RUNNING, STOPPED, UNUSED)
|
/// Current state of the strategy (RUNNING, STOPPED, UNUSED)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -73,5 +68,6 @@ namespace Managing.Api.Models.Responses
|
|||||||
public List<Position> Positions { get; set; } = new List<Position>();
|
public List<Position> Positions { get; set; } = new List<Position>();
|
||||||
|
|
||||||
public string Identifier { get; set; }
|
public string Identifier { get; set; }
|
||||||
|
public string ScenarioName { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,6 +72,11 @@ public static class WorkersBootstrap
|
|||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IServiceCollection AddWorkers(this IServiceCollection services, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
private static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
|
private static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
// Database
|
// Database
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ 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, getOrderThresholdType} from "../../utils/prices.js";
|
import {getAcceptablePriceInfo, getDefaultAcceptablePriceImpactBps, 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";
|
||||||
@@ -164,13 +164,24 @@ export async function increaseOrderHelper(
|
|||||||
if (params.stopLossPrice) {
|
if (params.stopLossPrice) {
|
||||||
const stopLossCollateralDeltaUsd = convertToUsd(increaseAmounts.collateralDeltaAmount, collateralToken.decimals, params.stopLossPrice);
|
const stopLossCollateralDeltaUsd = convertToUsd(increaseAmounts.collateralDeltaAmount, collateralToken.decimals, params.stopLossPrice);
|
||||||
|
|
||||||
|
// Use a higher acceptable price impact buffer for stop loss orders to ensure execution
|
||||||
|
const stopLossAcceptablePriceImpactBps = params.fixedAcceptablePriceImpactBps ??
|
||||||
|
getDefaultAcceptablePriceImpactBps({
|
||||||
|
isIncrease: false,
|
||||||
|
isLong: params.isLong,
|
||||||
|
indexPrice: params.stopLossPrice,
|
||||||
|
sizeDeltaUsd: increaseAmounts.sizeDeltaUsd,
|
||||||
|
priceImpactDeltaUsd: 0n, // We'll calculate this based on current market conditions
|
||||||
|
acceptablePriceImapctBuffer: params.acceptablePriceImpactBuffer ?? 100, // Default 1% buffer for SL orders
|
||||||
|
});
|
||||||
|
|
||||||
const acceptablePriceInfo = getAcceptablePriceInfo({
|
const acceptablePriceInfo = getAcceptablePriceInfo({
|
||||||
marketInfo,
|
marketInfo,
|
||||||
isIncrease: false,
|
isIncrease: false,
|
||||||
isLong: params.isLong,
|
isLong: params.isLong,
|
||||||
indexPrice: params.stopLossPrice,
|
indexPrice: params.stopLossPrice,
|
||||||
sizeDeltaUsd: increaseAmounts.sizeDeltaUsd,
|
sizeDeltaUsd: increaseAmounts.sizeDeltaUsd,
|
||||||
maxNegativePriceImpactBps: marketInfo.maxPositionImpactFactorForLiquidations,
|
maxNegativePriceImpactBps: stopLossAcceptablePriceImpactBps,
|
||||||
});
|
});
|
||||||
|
|
||||||
stopLossDecreaseAmounts = {
|
stopLossDecreaseAmounts = {
|
||||||
@@ -241,13 +252,24 @@ export async function increaseOrderHelper(
|
|||||||
if (params.takeProfitPrice) {
|
if (params.takeProfitPrice) {
|
||||||
const takeProfitCollateralDeltaUsd = convertToUsd(increaseAmounts.collateralDeltaAmount, collateralToken.decimals, params.takeProfitPrice);
|
const takeProfitCollateralDeltaUsd = convertToUsd(increaseAmounts.collateralDeltaAmount, collateralToken.decimals, params.takeProfitPrice);
|
||||||
|
|
||||||
|
// Use a higher acceptable price impact buffer for take profit orders to ensure execution
|
||||||
|
const takeProfitAcceptablePriceImpactBps = params.fixedAcceptablePriceImpactBps ??
|
||||||
|
getDefaultAcceptablePriceImpactBps({
|
||||||
|
isIncrease: false,
|
||||||
|
isLong: params.isLong,
|
||||||
|
indexPrice: params.takeProfitPrice,
|
||||||
|
sizeDeltaUsd: increaseAmounts.sizeDeltaUsd,
|
||||||
|
priceImpactDeltaUsd: 0n, // We'll calculate this based on current market conditions
|
||||||
|
acceptablePriceImapctBuffer: params.acceptablePriceImpactBuffer ?? 100, // Default 1% buffer for TP orders
|
||||||
|
});
|
||||||
|
|
||||||
const acceptablePriceInfo = getAcceptablePriceInfo({
|
const acceptablePriceInfo = getAcceptablePriceInfo({
|
||||||
marketInfo,
|
marketInfo,
|
||||||
isIncrease: false,
|
isIncrease: false,
|
||||||
isLong: params.isLong,
|
isLong: params.isLong,
|
||||||
indexPrice: params.takeProfitPrice,
|
indexPrice: params.takeProfitPrice,
|
||||||
sizeDeltaUsd: increaseAmounts.sizeDeltaUsd,
|
sizeDeltaUsd: increaseAmounts.sizeDeltaUsd,
|
||||||
maxNegativePriceImpactBps: marketInfo.maxPositionImpactFactorForLiquidations,
|
maxNegativePriceImpactBps: takeProfitAcceptablePriceImpactBps,
|
||||||
});
|
});
|
||||||
|
|
||||||
takeProfitDecreaseAmounts = {
|
takeProfitDecreaseAmounts = {
|
||||||
|
|||||||
@@ -212,12 +212,13 @@ export const openGmxPositionImpl = async (
|
|||||||
marketAddress: marketInfo.marketTokenAddress,
|
marketAddress: marketInfo.marketTokenAddress,
|
||||||
payTokenAddress: collateralToken.address,
|
payTokenAddress: collateralToken.address,
|
||||||
collateralTokenAddress: collateralToken.address,
|
collateralTokenAddress: collateralToken.address,
|
||||||
allowedSlippageBps: 50, // 0.5% slippage
|
allowedSlippageBps: 100, // 0.5% slippage
|
||||||
leverage: leverageBps,
|
leverage: leverageBps,
|
||||||
skipSimulation: true,
|
skipSimulation: true,
|
||||||
referralCodeForTxn: encodeReferralCode("kaigen_ai"),
|
referralCodeForTxn: encodeReferralCode("kaigen_ai"),
|
||||||
stopLossPrice: stopLossPrice ? numberToBigint(stopLossPrice, 30) : undefined,
|
stopLossPrice: stopLossPrice ? numberToBigint(stopLossPrice, 30) : undefined,
|
||||||
takeProfitPrice: takeProfitPrice ? numberToBigint(takeProfitPrice, 30) : undefined
|
takeProfitPrice: takeProfitPrice ? numberToBigint(takeProfitPrice, 30) : undefined,
|
||||||
|
acceptablePriceImpactBuffer: 150,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (direction === TradeDirection.Long) {
|
if (direction === TradeDirection.Long) {
|
||||||
|
|||||||
@@ -1132,7 +1132,7 @@ export class DataClient extends AuthorizedApiBase {
|
|||||||
return Promise.resolve<PlatformSummaryViewModel>(null as any);
|
return Promise.resolve<PlatformSummaryViewModel>(null as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
data_GetAgentBalances(agentName: string | null | undefined, startDate: Date | undefined, endDate: Date | null | undefined): Promise<AgentBalance[]> {
|
data_GetAgentBalances(agentName: string | null | undefined, startDate: Date | undefined, endDate: Date | null | undefined): Promise<AgentBalanceHistory> {
|
||||||
let url_ = this.baseUrl + "/Data/GetAgentBalances?";
|
let url_ = this.baseUrl + "/Data/GetAgentBalances?";
|
||||||
if (agentName !== undefined && agentName !== null)
|
if (agentName !== undefined && agentName !== null)
|
||||||
url_ += "agentName=" + encodeURIComponent("" + agentName) + "&";
|
url_ += "agentName=" + encodeURIComponent("" + agentName) + "&";
|
||||||
@@ -1158,13 +1158,13 @@ export class DataClient extends AuthorizedApiBase {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected processData_GetAgentBalances(response: Response): Promise<AgentBalance[]> {
|
protected processData_GetAgentBalances(response: Response): Promise<AgentBalanceHistory> {
|
||||||
const status = response.status;
|
const status = response.status;
|
||||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||||
if (status === 200) {
|
if (status === 200) {
|
||||||
return response.text().then((_responseText) => {
|
return response.text().then((_responseText) => {
|
||||||
let result200: any = null;
|
let result200: any = null;
|
||||||
result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as AgentBalance[];
|
result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as AgentBalanceHistory;
|
||||||
return result200;
|
return result200;
|
||||||
});
|
});
|
||||||
} else if (status !== 200 && status !== 204) {
|
} else if (status !== 200 && status !== 204) {
|
||||||
@@ -1172,7 +1172,7 @@ export class DataClient extends AuthorizedApiBase {
|
|||||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return Promise.resolve<AgentBalance[]>(null as any);
|
return Promise.resolve<AgentBalanceHistory>(null as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
data_GetBestAgents(startDate: Date | undefined, endDate: Date | null | undefined, page: number | undefined, pageSize: number | undefined): Promise<BestAgentsResponse> {
|
data_GetBestAgents(startDate: Date | undefined, endDate: Date | null | undefined, page: number | undefined, pageSize: number | undefined): Promise<BestAgentsResponse> {
|
||||||
@@ -3212,7 +3212,6 @@ export interface StrategyPerformance {
|
|||||||
|
|
||||||
export interface UserStrategyDetailsViewModel {
|
export interface UserStrategyDetailsViewModel {
|
||||||
name?: string | null;
|
name?: string | null;
|
||||||
strategyName?: string | null;
|
|
||||||
state?: string | null;
|
state?: string | null;
|
||||||
pnL?: number;
|
pnL?: number;
|
||||||
roiPercentage?: number;
|
roiPercentage?: number;
|
||||||
@@ -3225,6 +3224,7 @@ export interface UserStrategyDetailsViewModel {
|
|||||||
losses?: number;
|
losses?: number;
|
||||||
positions?: Position[] | null;
|
positions?: Position[] | null;
|
||||||
identifier?: string | null;
|
identifier?: string | null;
|
||||||
|
scenarioName?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PlatformSummaryViewModel {
|
export interface PlatformSummaryViewModel {
|
||||||
@@ -3251,6 +3251,11 @@ export interface AgentSummaryViewModel {
|
|||||||
volumeLast24h?: number;
|
volumeLast24h?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AgentBalanceHistory {
|
||||||
|
agentName?: string | null;
|
||||||
|
agentBalances?: AgentBalance[] | null;
|
||||||
|
}
|
||||||
|
|
||||||
export interface AgentBalance {
|
export interface AgentBalance {
|
||||||
agentName?: string | null;
|
agentName?: string | null;
|
||||||
totalValue?: number;
|
totalValue?: number;
|
||||||
@@ -3268,21 +3273,6 @@ export interface BestAgentsResponse {
|
|||||||
totalPages?: number;
|
totalPages?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AgentBalanceHistory {
|
|
||||||
agentName?: string | null;
|
|
||||||
totalValue?: number;
|
|
||||||
totalAccountUsdValue?: number;
|
|
||||||
botsAllocationUsdValue?: number;
|
|
||||||
pnL?: number;
|
|
||||||
time?: Date;
|
|
||||||
pnLHistory?: PnLPoint[] | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PnLPoint {
|
|
||||||
time?: Date;
|
|
||||||
value?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum RiskLevel {
|
export enum RiskLevel {
|
||||||
Low = "Low",
|
Low = "Low",
|
||||||
Medium = "Medium",
|
Medium = "Medium",
|
||||||
|
|||||||
Reference in New Issue
Block a user