Fix close position

This commit is contained in:
2025-05-12 13:07:43 +07:00
parent 0cf523c144
commit 4b0e87d48e
7 changed files with 20 additions and 16 deletions

View File

@@ -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,

View File

@@ -1,7 +1,7 @@
import { test } from 'node:test'
import {test} from 'node:test'
import assert from 'node:assert'
import { getClientForAddress, closeGmxPositionImpl } from '../../src/plugins/custom/gmx'
import { TradeDirection } from '../../src/generated/ManagingApiTypes'
import {closeGmxPositionImpl, getClientForAddress} from '../../src/plugins/custom/gmx'
import {TradeDirection} from '../../src/generated/ManagingApiTypes'
test('GMX Position Closing', async (t) => {
await t.test('should close a long position for BTC', async () => {
@@ -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)