@vesper85/strategy-sdk 0.1.0 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * RTDS Services
3
+ *
4
+ * Real-time data subscription services for Polymarket and Osiris.
5
+ */
6
+ export * from './unified-rtds.service';
7
+ export * from './polymarket-rtds.service';
8
+ export * from './osiris-rtds.service';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,134 @@
1
+ import type { Logger } from '../utils/logger';
2
+ import type { EventSubscription, StrategyEvent } from '../types/event-types';
3
+ /**
4
+ * Default Osiris Pub/Sub server URL
5
+ */
6
+ export declare const DEFAULT_OSIRIS_RTDS_URL = "wss://rtds.osirislabs.xyz";
7
+ /**
8
+ * Configuration for the OsirisRTDSService
9
+ */
10
+ export interface OsirisRTDSConfig {
11
+ /** Logger instance */
12
+ logger: Logger;
13
+ /** Callback for received events */
14
+ onEvent: (event: StrategyEvent) => void;
15
+ /** Callback for errors */
16
+ onError?: (error: Error) => void;
17
+ /** Callback when connected */
18
+ onConnect?: () => void;
19
+ /** Callback when disconnected */
20
+ onDisconnect?: () => void;
21
+ /** WebSocket URL (defaults to DEFAULT_OSIRIS_RTDS_URL) */
22
+ url?: string;
23
+ /** Reconnection settings */
24
+ reconnect?: {
25
+ /** Maximum number of reconnection attempts (default: 10) */
26
+ maxAttempts?: number;
27
+ /** Base delay between reconnection attempts in ms (default: 1000) */
28
+ delayMs?: number;
29
+ /** Maximum delay between reconnection attempts in ms (default: 30000) */
30
+ maxDelayMs?: number;
31
+ };
32
+ /** Ping interval in ms (default: 30000) */
33
+ pingIntervalMs?: number;
34
+ }
35
+ /**
36
+ * Osiris Real-Time Data Service
37
+ *
38
+ * Connects to Osiris Pub/Sub WebSocket for:
39
+ * - Market analysis events (smart scores, conviction rates, liquidity)
40
+ * - Wallet analysis events (trading metrics, PnL)
41
+ * - Trading opportunity events
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const service = new OsirisRTDSService({
46
+ * logger: createConsoleLogger(),
47
+ * onEvent: (event) => console.log('Event:', event),
48
+ * url: 'wss://rtds.osirislabs.xyz'
49
+ * });
50
+ *
51
+ * service.connect();
52
+ * service.subscribe([
53
+ * { type: 'wallet', wallet: '0x123...' },
54
+ * { type: 'opportunity', filter: 'wide_spread_markets' }
55
+ * ]);
56
+ * ```
57
+ */
58
+ export declare class OsirisRTDSService {
59
+ private ws;
60
+ private config;
61
+ private isConnected;
62
+ private reconnectAttempts;
63
+ private reconnectTimeout;
64
+ private pingInterval;
65
+ private isIntentionallyClosed;
66
+ private activeTopics;
67
+ private readonly maxReconnectAttempts;
68
+ private readonly baseReconnectDelay;
69
+ private readonly maxReconnectDelay;
70
+ private readonly pingIntervalMs;
71
+ private readonly url;
72
+ constructor(config: OsirisRTDSConfig);
73
+ /**
74
+ * Connect to the Osiris Pub/Sub WebSocket
75
+ */
76
+ connect(): void;
77
+ /**
78
+ * Disconnect from the Osiris Pub/Sub WebSocket
79
+ */
80
+ disconnect(): void;
81
+ /**
82
+ * Check if connected
83
+ */
84
+ isActive(): boolean;
85
+ /**
86
+ * Subscribe to events
87
+ */
88
+ subscribe(subscriptions: EventSubscription[]): void;
89
+ /**
90
+ * Unsubscribe from topics
91
+ */
92
+ unsubscribe(subscriptions: EventSubscription[]): void;
93
+ /**
94
+ * Unsubscribe from topics by name
95
+ */
96
+ private unsubscribeFromTopics;
97
+ /**
98
+ * Send ping to keep connection alive
99
+ */
100
+ ping(): void;
101
+ /**
102
+ * Map SDK subscriptions to Osiris Pub/Sub format
103
+ */
104
+ private mapToOsirisSubscriptions;
105
+ /**
106
+ * Map SDK subscription to Osiris topic string
107
+ */
108
+ private mapSubscriptionToTopic;
109
+ /**
110
+ * Start ping interval
111
+ */
112
+ private startPingInterval;
113
+ /**
114
+ * Stop ping interval
115
+ */
116
+ private stopPingInterval;
117
+ /**
118
+ * Attempt reconnection with exponential backoff
119
+ */
120
+ private attemptReconnect;
121
+ /**
122
+ * Handle incoming WebSocket messages
123
+ */
124
+ private handleMessage;
125
+ /**
126
+ * Convert Osiris message to StrategyEvent
127
+ */
128
+ private convertToStrategyEvent;
129
+ }
130
+ /**
131
+ * Create an OsirisRTDSService instance
132
+ */
133
+ export declare function createOsirisRTDSService(config: OsirisRTDSConfig): OsirisRTDSService;
134
+ //# sourceMappingURL=osiris-rtds.service.d.ts.map
@@ -0,0 +1,117 @@
1
+ import type { Logger } from '../utils/logger';
2
+ import type { EventSubscription, StrategyEvent } from '../types/event-types';
3
+ /**
4
+ * CLOB API key credentials for authenticated subscriptions
5
+ */
6
+ export interface ClobApiKeyCreds {
7
+ key: string;
8
+ secret: string;
9
+ passphrase: string;
10
+ }
11
+ /**
12
+ * Configuration for the PolymarketRTDSService
13
+ */
14
+ export interface PolymarketRTDSConfig {
15
+ /** Logger instance */
16
+ logger: Logger;
17
+ /** Callback for received events */
18
+ onEvent: (event: StrategyEvent) => void;
19
+ /** Callback for errors */
20
+ onError?: (error: Error) => void;
21
+ /** Callback when connected */
22
+ onConnect?: () => void;
23
+ /** Callback when disconnected */
24
+ onDisconnect?: () => void;
25
+ /** CLOB API credentials for authenticated subscriptions (clob_user topic) */
26
+ clobAuth?: ClobApiKeyCreds;
27
+ /** Ping interval in ms (default: 5000) */
28
+ pingIntervalMs?: number;
29
+ /** Auto-reconnect on disconnect (default: true) */
30
+ autoReconnect?: boolean;
31
+ }
32
+ /**
33
+ * Polymarket Real-Time Data Service
34
+ *
35
+ * A wrapper around @polymarket/real-time-data-client that handles:
36
+ * - Connection lifecycle management
37
+ * - Subscription mapping from SDK types to RTDS format
38
+ * - Message normalization to StrategyEvent format
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const service = new PolymarketRTDSService({
43
+ * logger: createConsoleLogger(),
44
+ * onEvent: (event) => console.log('Event:', event),
45
+ * clobAuth: { key: '...', secret: '...', passphrase: '...' }
46
+ * });
47
+ *
48
+ * service.connect();
49
+ * service.subscribe([
50
+ * { type: 'clob_market', marketId: 'condition-id', messageType: 'agg_orderbook' }
51
+ * ]);
52
+ * ```
53
+ */
54
+ export declare class PolymarketRTDSService {
55
+ private client;
56
+ private config;
57
+ private isConnected;
58
+ private activeSubscriptions;
59
+ constructor(config: PolymarketRTDSConfig);
60
+ /**
61
+ * Connect to the Polymarket RTDS WebSocket
62
+ */
63
+ connect(): void;
64
+ /**
65
+ * Disconnect from the Polymarket RTDS WebSocket
66
+ */
67
+ disconnect(): void;
68
+ /**
69
+ * Check if connected
70
+ */
71
+ isActive(): boolean;
72
+ /**
73
+ * Subscribe to events
74
+ * Converts SDK EventSubscription types to RTDS Subscription format
75
+ */
76
+ subscribe(subscriptions: EventSubscription[]): void;
77
+ /**
78
+ * Unsubscribe from events
79
+ */
80
+ unsubscribe(subscriptions: EventSubscription[]): void;
81
+ /**
82
+ * Map SDK EventSubscription to RTDS Subscription format
83
+ */
84
+ private mapToRTDSSubscriptions;
85
+ /**
86
+ * Map a single SDK EventSubscription to RTDS Subscription
87
+ */
88
+ private mapSubscription;
89
+ private mapClobMarketSubscription;
90
+ private mapClobUserSubscription;
91
+ private mapActivitySubscription;
92
+ private mapCommentsSubscription;
93
+ private mapCryptoPricesSubscription;
94
+ private mapRfqSubscription;
95
+ private mapMarketSubscription;
96
+ /**
97
+ * Handle incoming RTDS messages
98
+ */
99
+ private handleMessage;
100
+ /**
101
+ * Convert RTDS Message to StrategyEvent
102
+ */
103
+ private convertToStrategyEvent;
104
+ /**
105
+ * Map RTDS topic/type to SDK EventType
106
+ */
107
+ private mapTopicToEventType;
108
+ /**
109
+ * Extract event data from RTDS message payload
110
+ */
111
+ private extractEventData;
112
+ }
113
+ /**
114
+ * Create a PolymarketRTDSService instance
115
+ */
116
+ export declare function createPolymarketRTDSService(config: PolymarketRTDSConfig): PolymarketRTDSService;
117
+ //# sourceMappingURL=polymarket-rtds.service.d.ts.map
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Unified RTDS Service
3
+ *
4
+ * Provides a unified interface for subscribing to real-time events
5
+ * from both Polymarket RTDS and Osiris Pub/Sub services.
6
+ */
7
+ import type { Logger } from '../utils/logger';
8
+ import type { EventSubscription, StrategyEvent } from '../types/event-types';
9
+ import { type ClobApiKeyCreds } from './polymarket-rtds.service';
10
+ /**
11
+ * Configuration for the UnifiedRTDSService
12
+ */
13
+ export interface UnifiedRTDSConfig {
14
+ /** Logger instance */
15
+ logger: Logger;
16
+ /** Callback for received events */
17
+ onEvent: (event: StrategyEvent) => void;
18
+ /** Callback for errors */
19
+ onError?: (error: Error) => void;
20
+ /** Callback when connected */
21
+ onConnect?: () => void;
22
+ /** Callback when disconnected */
23
+ onDisconnect?: () => void;
24
+ /** Polymarket-specific configuration */
25
+ polymarket?: {
26
+ /** Enable Polymarket RTDS connection */
27
+ enabled?: boolean;
28
+ /** CLOB API credentials for authenticated subscriptions */
29
+ clobAuth?: ClobApiKeyCreds;
30
+ };
31
+ /** Osiris-specific configuration */
32
+ osiris?: {
33
+ /** Enable Osiris Pub/Sub connection */
34
+ enabled?: boolean;
35
+ /** WebSocket URL (defaults to DEFAULT_OSIRIS_RTDS_URL) */
36
+ url?: string;
37
+ /** Ping interval in ms */
38
+ pingIntervalMs?: number;
39
+ };
40
+ /** Reconnection settings (applied to both services) */
41
+ reconnect?: {
42
+ maxAttempts?: number;
43
+ delayMs?: number;
44
+ maxDelayMs?: number;
45
+ };
46
+ }
47
+ /**
48
+ * Unified Real-Time Data Service
49
+ *
50
+ * Manages connections to both Polymarket RTDS and Osiris Pub/Sub,
51
+ * automatically routing subscriptions to the appropriate backend.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const service = new UnifiedRTDSService({
56
+ * logger: createConsoleLogger(),
57
+ * onEvent: (event) => console.log('Event:', event),
58
+ * polymarket: {
59
+ * enabled: true,
60
+ * clobAuth: { key: '...', secret: '...', passphrase: '...' }
61
+ * },
62
+ * osiris: {
63
+ * enabled: true,
64
+ * url: 'wss://rtds.osirislabs.xyz'
65
+ * }
66
+ * });
67
+ *
68
+ * service.connect();
69
+ *
70
+ * // Subscriptions are automatically routed
71
+ * service.subscribe([
72
+ * // Goes to Polymarket
73
+ * { type: 'clob_market', marketId: 'cond-id', messageType: 'agg_orderbook' },
74
+ * // Goes to Osiris
75
+ * { type: 'wallet', wallet: '0x123...' },
76
+ * { type: 'opportunity', filter: 'wide_spread_markets' }
77
+ * ]);
78
+ * ```
79
+ */
80
+ export declare class UnifiedRTDSService {
81
+ private config;
82
+ private polymarketService;
83
+ private osirisService;
84
+ private polymarketConnected;
85
+ private osirisConnected;
86
+ constructor(config: UnifiedRTDSConfig);
87
+ /**
88
+ * Initialize the underlying services based on configuration
89
+ */
90
+ private initializeServices;
91
+ /**
92
+ * Connect to all enabled services
93
+ */
94
+ connect(): void;
95
+ /**
96
+ * Disconnect from all services
97
+ */
98
+ disconnect(): void;
99
+ /**
100
+ * Check if connected to at least one service
101
+ */
102
+ isActive(): boolean;
103
+ /**
104
+ * Get connection status for each service
105
+ */
106
+ getStatus(): {
107
+ polymarket: {
108
+ enabled: boolean;
109
+ connected: boolean;
110
+ };
111
+ osiris: {
112
+ enabled: boolean;
113
+ connected: boolean;
114
+ };
115
+ };
116
+ /**
117
+ * Subscribe to events
118
+ * Automatically routes subscriptions to the appropriate backend
119
+ */
120
+ subscribe(subscriptions: EventSubscription[]): void;
121
+ /**
122
+ * Unsubscribe from events
123
+ */
124
+ unsubscribe(subscriptions: EventSubscription[]): void;
125
+ /**
126
+ * Route subscriptions to appropriate backends based on type and eventSource
127
+ */
128
+ private routeSubscriptions;
129
+ /**
130
+ * Check if all enabled services are connected
131
+ */
132
+ private checkAllConnected;
133
+ /**
134
+ * Check if any service disconnected
135
+ */
136
+ private checkAnyDisconnected;
137
+ }
138
+ /**
139
+ * Create a UnifiedRTDSService instance
140
+ */
141
+ export declare function createUnifiedRTDSService(config: UnifiedRTDSConfig): UnifiedRTDSService;
142
+ export { PolymarketRTDSService, createPolymarketRTDSService } from './polymarket-rtds.service';
143
+ export { OsirisRTDSService, createOsirisRTDSService, DEFAULT_OSIRIS_RTDS_URL } from './osiris-rtds.service';
144
+ export type { ClobApiKeyCreds, PolymarketRTDSConfig } from './polymarket-rtds.service';
145
+ export type { OsirisRTDSConfig } from './osiris-rtds.service';
146
+ //# sourceMappingURL=unified-rtds.service.d.ts.map