@builderz/maiker-analytics-sdk
v0.1.3
Published
TypeScript API client for Maiker Analytics
Maintainers
Readme
Maiker Analytics SDK
The Maiker Analytics SDK provides TypeScript clients for accessing Maiker Analytics data through multiple interfaces:
- HTTP API Client: Access analytics via REST API endpoints (recommended for client-side applications)
- Direct Database Client: Direct PostgreSQL access for server-side applications
- Strategy Client: On-chain Solana strategy data access
Installation
npm install @builderz/maiker-analytics-sdk
# or
yarn add @builderz/maiker-analytics-sdkHTTP API Client (Recommended)
The HTTP API client provides a clean interface to the Maiker Analytics API:
import { MaikerAnalyticsApiClient } from '@builderz/maiker-analytics-sdk';
// Initialize client
const client = new MaikerAnalyticsApiClient({
baseUrl: 'https://api.maiker.fun', // Optional, defaults to production
timeout: 30000, // Optional, defaults to 30 seconds
});
// Get all token pairs with statistics (includes volume, fees, TVL data)
const tokenMaps = await client.getPairTokenMaps();
// Get timeseries data (v2 endpoint optimized for charting)
const timeseries = await client.getLbPairTimeseries(
['lb_pair_1', 'lb_pair_2'],
{
start_timestamp: Math.floor(Date.now() / 1000) - 24 * 60 * 60, // Last 24 hours
},
'1h' // Hourly granularity
);
// Fee concentration analysis
const feeData = await client.getFeeConcentration('lb_pair_address');
// Position analytics
const positionPnL = await client.getPositionPnL('position_id');
const positionTimeseries = await client.getPositionTimeseries('position_id');
const userPositions = await client.getUserPositions('owner_address');
// Session analytics (all positions for owner/lb_pair)
const sessionPnL = await client.getSessionPnL('owner_address', 'lb_pair_address');
const sessionTimeseries = await client.getSessionTimeseries('owner_address', 'lb_pair_address');Available Endpoints
Pairs API
getPairTokenMaps(): Get all token pairs with LB pairs and statistics (volume, fees, TVL across multiple timeframes)getLbPairTimeseries(lbPairs, timeRange?, granularity?): Get timeseries data optimized for charting
Analysis API
getFeeConcentration(lbPair, startTimestamp?): Get fee concentration analysis
Position Analytics API
getPositionPnL(positionId, timeRange?): Get single position PnL analysisgetPositionTimeseries(positionId, timeRange?): Get single position timeseries datagetUserPositions(owner): Get positions for a specific ownergetSessionPnL(owner, lbPair, timeRange?): Get session PnL for all positions of owner/lb_pairgetSessionTimeseries(owner, lbPair, timeRange?): Get session timeseries for all positions
Direct Database Client
For server-side applications with direct database access:
import { AnalyticsClient } from '@builderz/maiker-analytics-sdk';
const client = new AnalyticsClient({
connectionString: 'postgresql://user:pass@host:port/db',
ssl: true,
});
// Use the various analytics modules
const positionAnalytics = await client.positions.getAnalytics('position_id');
const pairAnalytics = await client.pairs.getAnalytics('lb_pair');Types
All TypeScript types are exported for use in your applications:
import {
TokenPair,
LBPair,
TimeseriesDataPoint,
PositionPnLResult,
PositionTimeseriesResult,
TokenMapsResponse,
TimeRange,
TimeGranularity,
} from '@builderz/maiker-analytics-sdk';Environment Configuration
The HTTP API client automatically detects environment:
// For local development
process.env.NEXT_PUBLIC_LOCAL_API = 'true'; // Uses http://localhost:3000
// For production (default)
// Uses https://api.maiker.funError Handling
All clients include comprehensive error handling:
try {
const data = await client.getPairTokenMaps();
} catch (error) {
console.error('API Error:', error.message);
// Handle error appropriately
}API Reference
Time Ranges
interface TimeRange {
start_timestamp?: number; // Unix timestamp in seconds
end_timestamp?: number; // Unix timestamp in seconds
}Time Granularities
- TimeGranularity:
'15m' | '1h' | '4h' | '12h' | '24h'
Contributing
- Fork the repository
- Create your feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
