DFlowClient

Configure and initialize the DFlow SDK client

DFlowClient

The DFlowClient is the main entry point for all SDK operations. It provides access to all APIs through a single unified interface.

Basic Usage

import { DFlowClient } from 'dflow-sdk';
 
// Development (default) - no API key required
// Uses dev-*.dflow.net endpoints for testing with real capital
const dflow = new DFlowClient();
 
// Production - API key required
// Uses *.dflow.net endpoints for production deployments
const prodClient = new DFlowClient({
  environment: 'production',
  apiKey: 'your-api-key',
});

Configuration Options

import { DFlowClient } from 'dflow-sdk';
 
const dflow = new DFlowClient({
  environment: 'development', // or 'production'
  apiKey: 'your-api-key',
  metadataBaseUrl: 'https://custom-api.example.com/api/v1', // Optional override
  tradeBaseUrl: 'https://custom-trade.example.com', // Optional override
  wsOptions: {
    reconnect: true,
    reconnectInterval: 5000,
    maxReconnectAttempts: 10,
  },
});

Options

PropertyTypeDefaultDescription
environment'development' | 'production''development'Environment to use. Development requires no API key.
apiKeystring-API key for authenticated endpoints (required for production)
metadataBaseUrlstringBased on environmentCustom base URL for Metadata API (overrides environment)
tradeBaseUrlstringBased on environmentCustom base URL for Trade API (overrides environment)
wsOptionsWebSocketOptionsSee belowWebSocket configuration

Environment Details

EnvironmentAPI KeyEndpointsUse Case
developmentNot requireddev-*.dflow.netTesting with real capital against Kalshi
productionRequired*.dflow.netProduction deployments

WebSocket Options

PropertyTypeDefaultDescription
urlstringBased on environmentWebSocket server URL
reconnectbooleantrueAuto-reconnect on disconnect
reconnectIntervalnumber5000Milliseconds between reconnect attempts
maxReconnectAttemptsnumber10Maximum reconnection attempts

Available APIs

Once initialized, the client provides access to all APIs:

Metadata APIs

dflow.events      // EventsAPI - Event discovery and details
dflow.markets     // MarketsAPI - Market data and batch queries
dflow.orderbook   // OrderbookAPI - Order book snapshots
dflow.trades      // TradesAPI - Trade history
dflow.liveData    // LiveDataAPI - Real-time data feeds
dflow.series      // SeriesAPI - Series information
dflow.tags        // TagsAPI - Tags and categories
dflow.sports      // SportsAPI - Sports filters
dflow.search      // SearchAPI - Search functionality

Trade APIs

dflow.orders           // OrdersAPI - Order management
dflow.swap             // SwapAPI - Imperative swaps
dflow.intent           // IntentAPI - Declarative/intent swaps
dflow.predictionMarket // PredictionMarketAPI - Market initialization
dflow.tokens           // TokensAPI - Token information
dflow.venues           // VenuesAPI - Trading venues

WebSocket

dflow.ws  // DFlowWebSocket - Real-time subscriptions

Setting API Key Later

const dflow = new DFlowClient();
 
// Set API key after initialization
dflow.setApiKey('your-api-key');

Environment Selection

The SDK defaults to development environment, which is ideal for testing:

import { DFlowClient } from 'dflow-sdk';
 
// Development (default) - no API key required
const devClient = new DFlowClient();
 
// Equivalent to:
const devClient2 = new DFlowClient({ environment: 'development' });
 
// Production - requires API key
const prodClient = new DFlowClient({
  environment: 'production',
  apiKey: 'your-api-key',
});

Development environment uses dev-*.dflow.net endpoints and allows testing with real capital against Kalshi without an API key. Production environment uses *.dflow.net endpoints and requires an API key.

Type Exports

The SDK exports all types for TypeScript users:

import type {
  DFlowClientOptions,
  WebSocketOptions,
  Event,
  Market,
  SwapQuote,
  // ... and more
} from 'dflow-sdk';

On this page