Fix close position
This commit is contained in:
@@ -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,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)
|
||||
|
||||
Reference in New Issue
Block a user