fix signal and get position during closing
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Globalization;
|
||||||
using Managing.Core;
|
using Managing.Core;
|
||||||
using Managing.Domain.Candles;
|
using Managing.Domain.Candles;
|
||||||
using Managing.Domain.Users;
|
using Managing.Domain.Users;
|
||||||
@@ -34,7 +35,7 @@ namespace Managing.Domain.Strategies
|
|||||||
StrategyType = strategyType;
|
StrategyType = strategyType;
|
||||||
User = user;
|
User = user;
|
||||||
|
|
||||||
Identifier = $"{StrategyType}-{direction}-{ticker}-{candle?.Close}-{date:yyyyMMdd-HHmmss}";
|
Identifier = $"{StrategyType}-{direction}-{ticker}-{candle?.Close.ToString(CultureInfo.InvariantCulture)}-{date:yyyyMMdd-HHmmss}";
|
||||||
SignalType = signalType;
|
SignalType = signalType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -660,7 +660,9 @@ public class EvmManager : IEvmManager
|
|||||||
{
|
{
|
||||||
account = account.Key,
|
account = account.Key,
|
||||||
ticker = ticker.ToString(),
|
ticker = ticker.ToString(),
|
||||||
direction = direction.ToString(),
|
direction = direction == TradeDirection.Long
|
||||||
|
? TradeDirection.Short.ToString()
|
||||||
|
: TradeDirection.Long.ToString(),
|
||||||
});
|
});
|
||||||
trade = new Trade(
|
trade = new Trade(
|
||||||
DateTime.UtcNow,
|
DateTime.UtcNow,
|
||||||
|
|||||||
@@ -24,12 +24,12 @@ export type PositionIncreaseParams = (
|
|||||||
| {
|
| {
|
||||||
/** Increase amounts will be calculated based on collateral amount */
|
/** Increase amounts will be calculated based on collateral amount */
|
||||||
payAmount: bigint;
|
payAmount: bigint;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
/** Increase amounts will be calculated based on position size amount */
|
/** Increase amounts will be calculated based on position size amount */
|
||||||
sizeAmount: bigint;
|
sizeAmount: bigint;
|
||||||
}
|
}
|
||||||
) & {
|
) & {
|
||||||
marketAddress: string;
|
marketAddress: string;
|
||||||
payTokenAddress: string;
|
payTokenAddress: string;
|
||||||
collateralTokenAddress: string;
|
collateralTokenAddress: string;
|
||||||
@@ -85,7 +85,7 @@ export async function increaseOrderHelper(
|
|||||||
isLong: boolean;
|
isLong: boolean;
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const { tokensData, marketsInfoData, uiFeeFactor } = await getAndValidateBaseParams(sdk, params);
|
const {tokensData, marketsInfoData, uiFeeFactor} = await getAndValidateBaseParams(sdk, params);
|
||||||
|
|
||||||
const isLimit = Boolean(params.limitPrice);
|
const isLimit = Boolean(params.limitPrice);
|
||||||
|
|
||||||
@@ -157,9 +157,7 @@ export async function increaseOrderHelper(
|
|||||||
externalSwapQuote: undefined,
|
externalSwapQuote: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
const createSltpEntries: SidecarSlTpOrderEntryValid[] = [
|
const createSltpEntries: SidecarSlTpOrderEntryValid[] = []
|
||||||
|
|
||||||
]
|
|
||||||
|
|
||||||
let stopLossDecreaseAmounts: DecreasePositionAmounts | undefined;
|
let stopLossDecreaseAmounts: DecreasePositionAmounts | undefined;
|
||||||
if (params.stopLossPrice) {
|
if (params.stopLossPrice) {
|
||||||
@@ -183,8 +181,8 @@ export async function increaseOrderHelper(
|
|||||||
indexPrice: params.stopLossPrice,
|
indexPrice: params.stopLossPrice,
|
||||||
collateralPrice: 0n,
|
collateralPrice: 0n,
|
||||||
acceptablePrice: params.isLong ? 2n ** 256n - 1n : 0n,
|
acceptablePrice: params.isLong ? 2n ** 256n - 1n : 0n,
|
||||||
acceptablePriceDeltaBps: acceptablePriceInfo.acceptablePriceDeltaBps,
|
acceptablePriceDeltaBps: acceptablePriceInfo.acceptablePriceDeltaBps + 50n,
|
||||||
recommendedAcceptablePriceDeltaBps: 0n,
|
recommendedAcceptablePriceDeltaBps: 50n,
|
||||||
estimatedPnl: 0n,
|
estimatedPnl: 0n,
|
||||||
estimatedPnlPercentage: 0n,
|
estimatedPnlPercentage: 0n,
|
||||||
realizedPnl: 0n,
|
realizedPnl: 0n,
|
||||||
@@ -257,8 +255,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,
|
acceptablePriceDeltaBps: acceptablePriceInfo.acceptablePriceDeltaBps + 50n, // Add 0.5% buffer to acceptable price impact
|
||||||
recommendedAcceptablePriceDeltaBps: 0n,
|
recommendedAcceptablePriceDeltaBps: 50n, // Set recommended buffer to 0.5%
|
||||||
estimatedPnl: 0n,
|
estimatedPnl: 0n,
|
||||||
estimatedPnlPercentage: 0n,
|
estimatedPnlPercentage: 0n,
|
||||||
realizedPnl: 0n,
|
realizedPnl: 0n,
|
||||||
@@ -336,7 +334,7 @@ function getTriggerRatio({
|
|||||||
toToken,
|
toToken,
|
||||||
fromToken,
|
fromToken,
|
||||||
triggerPrice,
|
triggerPrice,
|
||||||
}: {
|
}: {
|
||||||
toToken: TokenData;
|
toToken: TokenData;
|
||||||
fromToken: TokenData;
|
fromToken: TokenData;
|
||||||
triggerPrice: bigint;
|
triggerPrice: bigint;
|
||||||
@@ -363,11 +361,11 @@ function getTriggerRatio({
|
|||||||
export type SwapParams = (
|
export type SwapParams = (
|
||||||
| {
|
| {
|
||||||
fromAmount: bigint;
|
fromAmount: bigint;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
toAmount: bigint;
|
toAmount: bigint;
|
||||||
}
|
}
|
||||||
) & {
|
) & {
|
||||||
fromTokenAddress: string;
|
fromTokenAddress: string;
|
||||||
toTokenAddress: string;
|
toTokenAddress: string;
|
||||||
allowedSlippageBps?: number;
|
allowedSlippageBps?: number;
|
||||||
@@ -378,7 +376,7 @@ export type SwapParams = (
|
|||||||
} & BaseOptionalParams;
|
} & BaseOptionalParams;
|
||||||
|
|
||||||
export async function swap(sdk: GmxSdk, params: SwapParams) {
|
export async function swap(sdk: GmxSdk, params: SwapParams) {
|
||||||
const { tokensData, marketsInfoData, uiFeeFactor } = await getAndValidateBaseParams(sdk, params);
|
const {tokensData, marketsInfoData, uiFeeFactor} = await getAndValidateBaseParams(sdk, params);
|
||||||
|
|
||||||
const fromToken = tokensData[params.fromTokenAddress];
|
const fromToken = tokensData[params.fromTokenAddress];
|
||||||
const toToken = tokensData[params.toTokenAddress];
|
const toToken = tokensData[params.toTokenAddress];
|
||||||
|
|||||||
Reference in New Issue
Block a user