Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/profiler-dex-trades.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nansen-cli": minor
---

Add `nansen research profiler dex-trades` command for DEX trade history
119 changes: 117 additions & 2 deletions src/__tests__/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,33 @@ const MOCK_RESPONSES = {
{ token: 'ETH', side: 'short', pnl_usd: 5000 }
]
},
addressDexTrades: {
data: [
{
chain: 'ethereum',
block_timestamp: '2024-01-15T10:30:00',
transaction_hash: '0xabc123',
trader_address: '0x28c6c06298d514db089934071355e5743bf21d60',
trader_address_label: 'Smart Trader',
token_bought_address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
token_sold_address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
token_bought_amount: 1000.0,
token_sold_amount: 1.5,
token_bought_symbol: 'USDC',
token_sold_symbol: 'ETH',
token_bought_age_days: 365,
token_sold_age_days: 730,
token_bought_market_cap: 50000000000.0,
token_sold_market_cap: 200000000000.0,
token_bought_fdv: 55000000000.0,
token_sold_fdv: 220000000000.0,
trade_value_usd: 3000.0
}
],
page: 1,
per_page: 100,
total: 1
},
tokenIndicators: {
token_address: '0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9',
chain: 'ethereum',
Expand Down Expand Up @@ -1058,19 +1085,107 @@ describe('NansenAPI', () => {

it('should calculate correct date range for custom days', async () => {
setupMock(MOCK_RESPONSES.addressPerpTrades);

await api.addressPerpTrades({
address: TEST_DATA.ethereum.address,
days: 7
});

const body = expectFetchCalledWith('/api/v1/profiler/perp-trades');
const from = new Date(body.date.from);
const to = new Date(body.date.to);
const diffDays = Math.round((to - from) / (1000 * 60 * 60 * 24));
expect(diffDays).toBe(7);
});
});

describe('addressDexTrades', () => {
it('should fetch dex trades with correct endpoint', async () => {
setupMock(MOCK_RESPONSES.addressDexTrades);

const result = await api.addressDexTrades({
address: TEST_DATA.ethereum.address,
chain: 'ethereum'
});

const body = expectFetchCalledWith('/api/v1/profiler/dex-trades');
expect(body.address).toBe(TEST_DATA.ethereum.address);
expect(body.chain).toBe('ethereum');

expect(result.data).toBeInstanceOf(Array);
expect(result.data[0]).toHaveProperty('token_bought_symbol', 'USDC');
expect(result.data[0]).toHaveProperty('trade_value_usd', 3000.0);
});

it('should pass orderBy to API', async () => {
setupMock(MOCK_RESPONSES.addressDexTrades);

await api.addressDexTrades({
address: TEST_DATA.ethereum.address,
chain: 'ethereum',
orderBy: [{ column: 'block_timestamp', order: 'desc' }]
});

const body = expectFetchCalledWith('/api/v1/profiler/dex-trades');
expect(body.order_by).toEqual([{ column: 'block_timestamp', order: 'desc' }]);
});

it('should include date range with default days', async () => {
setupMock(MOCK_RESPONSES.addressDexTrades);

await api.addressDexTrades({
address: TEST_DATA.ethereum.address,
chain: 'ethereum'
});

const body = expectFetchCalledWith('/api/v1/profiler/dex-trades');
expect(body.date).toBeDefined();
expect(body.date.from).toBeDefined();
expect(body.date.to).toBeDefined();
});

it('should calculate correct date range for custom days', async () => {
setupMock(MOCK_RESPONSES.addressDexTrades);

await api.addressDexTrades({
address: TEST_DATA.ethereum.address,
chain: 'ethereum',
days: 14
});

const body = expectFetchCalledWith('/api/v1/profiler/dex-trades');
const from = new Date(body.date.from);
const to = new Date(body.date.to);
const diffDays = Math.round((to - from) / (1000 * 60 * 60 * 24));
expect(diffDays).toBe(14);
});

it('should pass filters through', async () => {
setupMock(MOCK_RESPONSES.addressDexTrades);

await api.addressDexTrades({
address: TEST_DATA.ethereum.address,
chain: 'ethereum',
filters: { min_trade_value_usd: 1000 }
});

const body = expectFetchCalledWith('/api/v1/profiler/dex-trades');
expect(body.filters.min_trade_value_usd).toBe(1000);
});

it('should work with solana address', async () => {
setupMock(MOCK_RESPONSES.addressDexTrades);

await api.addressDexTrades({
address: TEST_DATA.solana.address,
chain: 'solana'
});

const body = expectFetchCalledWith('/api/v1/profiler/dex-trades');
expect(body.address).toBe(TEST_DATA.solana.address);
expect(body.chain).toBe('solana');
});
});
});

// =================== Token God Mode Endpoints ===================
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/coverage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const DOCUMENTED_ENDPOINTS = {
{ name: 'pnl-summary', method: 'addressPnlSummary', endpoint: '/api/v1/profiler/address/pnl-summary' },
{ name: 'perp-positions', method: 'addressPerpPositions', endpoint: '/api/v1/profiler/perp-positions' },
{ name: 'perp-trades', method: 'addressPerpTrades', endpoint: '/api/v1/profiler/perp-trades' },
{ name: 'dex-trades', method: 'addressDexTrades', endpoint: '/api/v1/profiler/dex-trades' },
],
tokenGodMode: [
{ name: 'indicators', method: 'tokenIndicators', endpoint: '/api/v1/tgm/indicators' },
Expand Down
14 changes: 14 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,20 @@ export class NansenAPI {
});
}

async addressDexTrades(params = {}) {
const { address, chain = 'ethereum', filters = {}, orderBy, pagination, days = 30, date } = params;
if (address) requireValidAddress(address, chain);
const dateRange = date || buildDateRange(days);
return this.request('/api/v1/profiler/dex-trades', {
address,
chain,
date: dateRange,
filters,
order_by: orderBy,
pagination
});
}

// ============= Token God Mode Endpoints =============

async tokenScreener(params = {}) {
Expand Down
6 changes: 5 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,10 @@ export function buildCommands(deps = {}) {
'pnl-summary': () => apiInstance.addressPnlSummary({ address, chain, orderBy, pagination, days }),
'perp-positions': () => apiInstance.addressPerpPositions({ address, filters, orderBy, pagination }),
'perp-trades': () => apiInstance.addressPerpTrades({ address, filters, orderBy, pagination, days }),
'dex-trades': () => {
const date = parseDateOption(options.date, days);
return apiInstance.addressDexTrades({ address, chain, filters, orderBy, pagination, days, date });
},
'batch': () => {
let addresses = [];
if (options.addresses) {
Expand Down Expand Up @@ -1186,7 +1190,7 @@ export function buildCommands(deps = {}) {
return compareWallets(apiInstance, { addresses: addrs, chain, days });
},
'help': () => ({
commands: ['balance', 'labels', 'transactions', 'pnl', 'search', 'historical-balances', 'related-wallets', 'counterparties', 'pnl-summary', 'perp-positions', 'perp-trades', 'batch', 'trace', 'compare'],
commands: ['balance', 'labels', 'transactions', 'pnl', 'search', 'historical-balances', 'related-wallets', 'counterparties', 'pnl-summary', 'perp-positions', 'perp-trades', 'dex-trades', 'batch', 'trace', 'compare'],
description: 'Wallet profiling endpoints',
example: 'nansen research profiler compare --addresses "0xABC...,0xDEF..." --chain ethereum'
})
Expand Down
15 changes: 15 additions & 0 deletions src/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@
}
}
},
"dex-trades": {
"endpoint": "/api/v1/profiler/dex-trades",
"description": "DEX trade history for a wallet",
"options": {
"address": {
"required": true
},
"chain": {
"default": "ethereum"
},
"days": {
"default": 30
}
}
},
"search": {
"endpoint": "/api/v1/search/entity-name",
"description": "Search for entities by name",
Expand Down
Loading