infofinance-sdk
v0.0.3
Published
Infofinance SDK for GraphQL API
Downloads
8
Readme
Polynance SDK
A TypeScript SDK for interacting with the Polynance GraphQL API, providing easy access to prediction market data across multiple protocols.
Installation
npm install @polynance/sdkQuick Start
import { createClient, Protocol } from '@polynance/sdk';
const client = createClient({
endpoint: 'http://localhost:4000/graphql',
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
});
// Fetch events
const events = await client.getEvents({
protocols: [Protocol.POLYMARKET],
active: true
});
// Execute custom queries
const result = await client.query(`
query {
stats {
totalEvents
totalMarkets
totalVolume
}
}
`);Features
- Type-safe GraphQL client
- Support for all Polynance API endpoints
- Built-in query methods for common operations
- Custom query execution support
- Full TypeScript support with shared types
- Schema introspection and discovery
API Reference
Creating a Client
const client = createClient({
endpoint: string,
headers?: Record<string, string>
});Available Methods
Data Fetching
getEvents(filter?, orderBy?, pagination?)- Fetch eventsgetEvent(id)- Fetch a single eventgetMarkets(filter?, orderBy?, pagination?)- Fetch marketsgetMarket(id)- Fetch a single marketgetStats()- Fetch aggregated statisticsgetTrader(protocol, wallet)- Fetch trader informationgetTraderPositions(protocol, wallet)- Fetch trader positionsgetTraderActivity(protocol, wallet)- Fetch trader activityquery(query, variables?)- Execute custom GraphQL queries
Schema Access
getSchema()- Returns the GraphQL schema as a stringgetSchemaIntrospection()- Get the complete GraphQL schema via introspectiongetAvailableQueries()- List all available queries with their argumentsgetTypeDetails(typeName)- Get detailed information about a specific typegenerateQueryExample(queryName)- Generate an example query for a given query name
Schema Access
The SDK provides the complete GraphQL schema as a string for easy sharing and tooling integration:
// Get schema from client
const schema = client.getSchema();
console.log(schema);
// Or use the exported constant directly
import { GRAPHQL_SCHEMA } from '@polynance/sdk';
fs.writeFileSync('schema.graphql', GRAPHQL_SCHEMA);Dynamic Schema Discovery
For runtime schema exploration:
// Discover available queries
const queries = await client.getAvailableQueries();
queries.forEach(q => console.log(`${q.name}: ${q.description}`));
// Get type information
const eventType = await client.getTypeDetails('Event');
console.log(`Event type has ${eventType.fields.length} fields`);
// Generate example query
const example = await client.generateQueryExample('events');
console.log(example);Examples
See the examples directory for more usage examples.
