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