Implement spot position history retrieval in SpotBot and related services

- Added CheckSpotPositionInExchangeHistory method to SpotBot for verifying closed positions against exchange history.
- Enhanced logging for Web3Proxy errors during position verification.
- Introduced GetSpotPositionHistory method in IEvmManager, IExchangeService, and IWeb3ProxyService interfaces.
- Implemented GetSpotPositionHistory in EvmManager and ExchangeService to fetch historical swap data.
- Updated GMX SDK integration to support fetching spot position history.
- Modified generated API types to include new trading type and position history structures.
This commit is contained in:
2025-12-07 19:20:47 +07:00
parent 15d8b38d8b
commit a2ed4edd32
17 changed files with 978 additions and 84 deletions

View File

@@ -0,0 +1,53 @@
import {test} from 'node:test'
import assert from 'node:assert'
import {getClientForAddress, getSpotPositionHistoryImpl} from '../../src/plugins/custom/gmx.js'
import {Ticker} from '../../src/generated/ManagingApiTypes.js'
test('GMX get spot position history - Market swaps', async (t) => {
await t.test('should get spot swap executions', async () => {
const sdk = await getClientForAddress('0x932167388dD9aad41149b3cA23eBD489E2E2DD78')
const result = await getSpotPositionHistoryImpl(
sdk,
0, // pageIndex
100, // pageSize
Ticker.BTC, // ticker
'2025-12-04T00:00:00.000Z', // fromDateTime
'2025-12-07T00:00:00.000Z' // toDateTime
)
console.log('\n📊 Spot Swap History Summary:')
console.log(`Total swaps: ${result.length}`)
console.log(`📊 Result:`, result);
assert.ok(result, 'Spot position history result should be defined')
assert.ok(Array.isArray(result), 'Spot position history should be an array')
})
await t.test('should get spot swaps within date range', async () => {
const sdk = await getClientForAddress('0x932167388dD9aad41149b3cA23eBD489E2E2DD78')
const toDate = new Date()
const fromDate = new Date(toDate.getTime() - (60 * 60 * 1000)) // last 1 hour
const fromDateTime = fromDate.toISOString()
const toDateTime = toDate.toISOString()
const result = await getSpotPositionHistoryImpl(
sdk,
0,
50,
Ticker.BTC,
fromDateTime,
toDateTime
)
console.log(`\n📅 Spot swaps in last 1 hour: ${result.length}`)
console.log(`From: ${fromDateTime}`)
console.log(`To: ${toDateTime}`)
assert.ok(result, 'Spot position history result should be defined')
assert.ok(Array.isArray(result), 'Spot position history should be an array')
})
})