Fix close position
This commit is contained in:
@@ -10,7 +10,6 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using static Managing.Common.Enums;
|
||||
using ApplicationTradingBot = Managing.Application.Bots.TradingBot;
|
||||
using ApiTradingBot = Managing.Api.Models.Responses.TradingBot;
|
||||
|
||||
namespace Managing.Api.Controllers;
|
||||
@@ -454,7 +453,7 @@ public class BotController : BaseController
|
||||
}
|
||||
|
||||
var activeBots = _botService.GetActiveBots();
|
||||
var bot = activeBots.FirstOrDefault(b => b.Identifier == request.Identifier) as ApplicationTradingBot;
|
||||
var bot = activeBots.FirstOrDefault(b => b.Identifier == request.Identifier);
|
||||
|
||||
if (bot == null)
|
||||
{
|
||||
@@ -498,7 +497,7 @@ public class BotController : BaseController
|
||||
}
|
||||
|
||||
var activeBots = _botService.GetActiveBots();
|
||||
var bot = activeBots.FirstOrDefault(b => b.Identifier == request.Identifier) as ApplicationTradingBot;
|
||||
var bot = activeBots.FirstOrDefault(b => b.Identifier == request.Identifier);
|
||||
|
||||
if (bot == null)
|
||||
{
|
||||
|
||||
@@ -37,5 +37,6 @@
|
||||
"RequestsChannelId": 1018589494968078356,
|
||||
"ButtonExpirationMinutes": 2
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"EnableBotManager": true
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using Managing.Application.Bots;
|
||||
using Managing.Core.FixedSizedQueue;
|
||||
using Managing.Core.FixedSizedQueue;
|
||||
using Managing.Domain.Accounts;
|
||||
using Managing.Domain.Bots;
|
||||
using Managing.Domain.Candles;
|
||||
@@ -38,5 +37,8 @@ namespace Managing.Application.Abstractions
|
||||
void UpdateStrategiesValues();
|
||||
Task LoadAccount();
|
||||
Task<Position> OpenPositionManually(TradeDirection direction);
|
||||
|
||||
Task CloseTrade(Signal signal, Position position, Trade tradeToClose, decimal lastPrice,
|
||||
bool tradeClosingPosition = false);
|
||||
}
|
||||
}
|
||||
@@ -456,9 +456,11 @@ export const closeGmxPositionImpl = async (
|
||||
// Find the specific position to close
|
||||
const positionKey = Object.keys(positionsInfo).find(key => {
|
||||
const position = positionsInfo[key];
|
||||
return position.marketInfo.indexToken.symbol === ticker && position.isLong === (direction === TradeDirection.Short);
|
||||
return position.marketInfo.indexToken.symbol === ticker && position.isLong === (direction === TradeDirection.Long);
|
||||
});
|
||||
|
||||
console.log("positionsInfo", positionsInfo);
|
||||
|
||||
if (!positionKey) {
|
||||
throw new Error(`No open ${direction} position found for ${ticker}`);
|
||||
}
|
||||
@@ -503,7 +505,7 @@ export const closeGmxPositionImpl = async (
|
||||
marketInfo,
|
||||
marketsInfoData,
|
||||
tokensData,
|
||||
isLong: direction === TradeDirection.Short,
|
||||
isLong: direction === TradeDirection.Long,
|
||||
allowedSlippage: 30,
|
||||
decreaseAmounts,
|
||||
collateralToken: position.marketInfo.shortToken,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {test} from 'node:test'
|
||||
import assert from 'node:assert'
|
||||
import { getClientForAddress, closeGmxPositionImpl } from '../../src/plugins/custom/gmx'
|
||||
import {closeGmxPositionImpl, getClientForAddress} from '../../src/plugins/custom/gmx'
|
||||
import {TradeDirection} from '../../src/generated/ManagingApiTypes'
|
||||
|
||||
test('GMX Position Closing', async (t) => {
|
||||
@@ -9,7 +9,7 @@ test('GMX Position Closing', async (t) => {
|
||||
|
||||
const result = await closeGmxPositionImpl(
|
||||
sdk,
|
||||
'BTC',
|
||||
'BNB',
|
||||
TradeDirection.Long
|
||||
)
|
||||
console.log('Position closing result:', result)
|
||||
|
||||
@@ -33,7 +33,7 @@ function ManualPositionModal({ showModal, botName, onClose }: ManualPositionModa
|
||||
const t = new Toast('Opening position...')
|
||||
try {
|
||||
await client.bot_OpenPositionManually({
|
||||
botName: botName,
|
||||
identifier: botName,
|
||||
direction: data.direction,
|
||||
})
|
||||
t.update('success', 'Position opened successfully')
|
||||
|
||||
@@ -60,7 +60,7 @@ const TradesModal: React.FC<TradesModalProps> = ({
|
||||
// Use BotClient instead of fetch
|
||||
const botClient = new BotClient({}, apiUrl)
|
||||
const request: ClosePositionRequest = {
|
||||
identifier: agentName,
|
||||
identifier: strategyName,
|
||||
positionId: position.identifier
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user