python-proxy-scraper-client
Version:
A TypeScript client for interacting with a Python proxy scraper service
138 lines (137 loc) • 5.99 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.GeckoTerminalClient = void 0;
const base_client_1 = require("../../shared/base-client");
class GeckoTerminalClient extends base_client_1.BaseClient {
constructor(config = { baseUrl: 'http://localhost:8000' }) {
super(config);
}
async search(query) {
const endpoint = `/geckoterminal/search?query=${encodeURIComponent(query)}`;
return this.get(endpoint);
}
/**
* Get detailed information about a specific pool
* @param chain The blockchain network (e.g., 'solana', 'ethereum')
* @param poolAddress The address of the pool
* @returns Pool information and related data
*/
async getPoolInfo(network, poolAddress) {
const endpoint = `/geckoterminal/${network}/pools/${poolAddress}`;
return this.get(endpoint);
}
/**
* Get trending pools for a specific network
* @param network The blockchain network (e.g., 'solana', 'ethereum')
* @param include Optional array of related data to include in the response
* @returns List of trending pools and related data
*/
async getTrendingPools(network, include) {
const params = new URLSearchParams();
if (include?.length) {
params.append('include', include.join(','));
}
const queryString = params.toString();
const endpoint = `/geckoterminal/${network}/trending-pools${queryString ? `?${queryString}` : ''}`;
return this.get(endpoint);
}
/**
* Get token info snapshots for a specific pool
* @param network The blockchain network (e.g., 'solana', 'ethereum')
* @param poolAddress The address of the pool
* @returns Token info snapshots for the pool
*/
async getTokenInfoSnapshots(network, poolAddress) {
const endpoint = `/geckoterminal/${network}/pools/${poolAddress}/token_info_snapshots`;
return this.get(endpoint);
}
async getTokenDetails(network, tokenAddress) {
const searchResult = await this.search(tokenAddress);
const poolsSortedByByLiquidity = searchResult.attributes.pools.sort((a, b) => b.liquidity - a.liquidity);
const topPool = poolsSortedByByLiquidity[0];
if (!topPool) {
throw new Error('No pool found');
}
const [poolInfo, tokenInfoSnapshots] = await Promise.all([
this.getPoolInfo(network, topPool.address),
this.getTokenInfoSnapshots(network, topPool.address)
]);
return {
tokenAddress,
searchResult,
poolInfo,
tokenInfoSnapshots: tokenInfoSnapshots.data
};
}
/**
* Get candlestick data for a specific pool
* @param networkId The network ID (e.g., '168087677')
* @param pairId The pair ID (e.g., '5668054')
* @param resolution Candlestick resolution in minutes (default: 1)
* @param fromTimestamp Start timestamp in seconds (optional)
* @param toTimestamp End timestamp in seconds (optional)
* @param forUpdate Whether this is for an update (default: false)
* @param countBack Number of candlesticks to get (optional)
* @param currency Currency for price data (default: 'usd')
* @param isInverted Whether the price is inverted (default: false)
* @returns Candlestick data for the pool
*/
async getCandlesticks(networkId, pairId, resolution = 1, fromTimestamp, toTimestamp, forUpdate = false, countBack, currency = 'usd', isInverted = false) {
const params = new URLSearchParams({
resolution: resolution.toString(),
for_update: forUpdate.toString(),
currency,
is_inverted: isInverted.toString()
});
if (fromTimestamp) {
params.append('from_timestamp', fromTimestamp.toString());
}
if (toTimestamp) {
params.append('to_timestamp', toTimestamp.toString());
}
if (countBack) {
params.append('count_back', countBack.toString());
}
const endpoint = `/geckoterminal/candlesticks/${networkId}/${pairId}?${params.toString()}`;
return this.get(endpoint);
}
/**
* Get detailed information about a specific pool with specific includes
* @param network The blockchain network (e.g., 'solana', 'ethereum')
* @param poolAddress The address of the pool
* @param include Optional array of related data to include in the response
* @param baseToken Base token index (default: 0)
* @returns Pool information and related data
*/
async getPoolInfoWithIncludes(network, poolAddress, include, baseToken = 0) {
const params = new URLSearchParams({
base_token: baseToken.toString()
});
if (include?.length) {
params.append('include', include.join(','));
}
const endpoint = `/geckoterminal/${network}/pools/${poolAddress}?${params.toString()}`;
return this.get(endpoint);
}
/**
* Get list of networks with specific fields and sidebar visibility
* @param fields Optional array of fields to include for networks (default: ['name', 'identifier', 'image_url', 'is_new'])
* @param showForSidebar Whether to show networks in sidebar (default: true)
* @returns List of networks with specified fields
*/
async getNetworks() {
const endpoint = `/geckoterminal/networks`;
return this.get(endpoint);
}
/**
* Get top holders for a specific token
* @param network The blockchain network (e.g., 'solana', 'ethereum')
* @param tokenAddress The address of the token
* @returns List of top holders for the token
*/
async getTopHolders(network, tokenAddress) {
const endpoint = `/geckoterminal/${network}/tokens/${tokenAddress}/top_holders`;
return this.get(endpoint);
}
}
exports.GeckoTerminalClient = GeckoTerminalClient;
;