@vesper85/strategy-sdk 0.1.2 → 0.1.4

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
@@ -102,6 +102,139 @@ export interface CustomSubscription extends BaseSubscription {
102
102
  /** Full topic string (e.g., 'custom:my-topic' or any valid topic) */
103
103
  topic: string;
104
104
  }
105
+ /**
106
+ * CLOB Market subscription for Polymarket-specific market events
107
+ * Connects to the clob_market topic for real-time orderbook and price data
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * { type: 'clob_market', marketId: 'condition-id', messageType: 'agg_orderbook' }
112
+ * ```
113
+ */
114
+ export interface ClobMarketSubscription extends BaseSubscription {
115
+ /** CLOB market subscription type */
116
+ type: 'clob_market';
117
+ /** Token ID or condition ID for CLOB market events */
118
+ marketId: string;
119
+ /**
120
+ * Specific message types:
121
+ * - 'price_change' - Price changes for the market
122
+ * - 'agg_orderbook' - Aggregated orderbook updates
123
+ * - 'last_trade_price' - Last trade price updates
124
+ * - 'tick_size_change' - Tick size changes
125
+ * - 'market_created' - New market creation events
126
+ * - 'market_resolved' - Market resolution events
127
+ * - '*' - All message types (default)
128
+ */
129
+ messageType?: 'price_change' | 'agg_orderbook' | 'last_trade_price' | 'tick_size_change' | 'market_created' | 'market_resolved' | '*';
130
+ }
131
+ /**
132
+ * CLOB User subscription for authenticated user-specific events
133
+ * Requires CLOB API credentials for authentication
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * { type: 'clob_user', messageType: 'order' }
138
+ * ```
139
+ */
140
+ export interface ClobUserSubscription extends BaseSubscription {
141
+ /** CLOB user subscription type */
142
+ type: 'clob_user';
143
+ /**
144
+ * Specific message types:
145
+ * - 'order' - Order updates (placement, cancellation, fill)
146
+ * - 'trade' - Trade execution events
147
+ * - '*' - All message types (default)
148
+ */
149
+ messageType?: 'order' | 'trade' | '*';
150
+ }
151
+ /**
152
+ * Activity subscription for trade activity feed events
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * { type: 'activity', eventSlug: 'will-bitcoin-hit-100k' }
157
+ * ```
158
+ */
159
+ export interface ActivitySubscription extends BaseSubscription {
160
+ /** Activity subscription type */
161
+ type: 'activity';
162
+ /** Event slug to filter trades (optional) */
163
+ eventSlug?: string;
164
+ /** Market slug to filter trades (optional) */
165
+ marketSlug?: string;
166
+ /**
167
+ * Specific message types:
168
+ * - 'trades' - Trade events
169
+ * - 'orders_matched' - Order match events
170
+ * - '*' - All message types (default)
171
+ */
172
+ messageType?: 'trades' | 'orders_matched' | '*';
173
+ }
174
+ /**
175
+ * Comments subscription for comment and reaction events
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * { type: 'comments', parentEntityId: 100, parentEntityType: 'Event' }
180
+ * ```
181
+ */
182
+ export interface CommentsSubscription extends BaseSubscription {
183
+ /** Comments subscription type */
184
+ type: 'comments';
185
+ /** Parent entity ID to filter comments */
186
+ parentEntityId?: number;
187
+ /** Parent entity type */
188
+ parentEntityType?: 'Event' | 'Series';
189
+ /**
190
+ * Specific message types:
191
+ * - 'comment_created' - New comment events
192
+ * - 'comment_removed' - Comment removal events
193
+ * - 'reaction_created' - Reaction added events
194
+ * - 'reaction_removed' - Reaction removed events
195
+ * - '*' - All message types (default)
196
+ */
197
+ messageType?: 'comment_created' | 'comment_removed' | 'reaction_created' | 'reaction_removed' | '*';
198
+ }
199
+ /**
200
+ * Crypto prices subscription for real-time cryptocurrency price updates
201
+ *
202
+ * @example
203
+ * ```typescript
204
+ * { type: 'crypto_prices', symbol: 'btcusdt' }
205
+ * ```
206
+ */
207
+ export interface CryptoPricesSubscription extends BaseSubscription {
208
+ /** Crypto prices subscription type */
209
+ type: 'crypto_prices';
210
+ /** Symbol to filter (e.g., 'btcusdt', 'ethusdt') */
211
+ symbol?: string;
212
+ }
213
+ /**
214
+ * RFQ subscription for Request for Quote events
215
+ *
216
+ * @example
217
+ * ```typescript
218
+ * { type: 'rfq', messageType: 'request_created' }
219
+ * ```
220
+ */
221
+ export interface RfqSubscription extends BaseSubscription {
222
+ /** RFQ subscription type */
223
+ type: 'rfq';
224
+ /**
225
+ * Specific message types:
226
+ * - 'request_created' - New RFQ request
227
+ * - 'request_edited' - RFQ request edited
228
+ * - 'request_canceled' - RFQ request canceled
229
+ * - 'request_expired' - RFQ request expired
230
+ * - 'quote_created' - New quote
231
+ * - 'quote_edited' - Quote edited
232
+ * - 'quote_canceled' - Quote canceled
233
+ * - 'quote_expired' - Quote expired
234
+ * - '*' - All message types (default)
235
+ */
236
+ messageType?: 'request_created' | 'request_edited' | 'request_canceled' | 'request_expired' | 'quote_created' | 'quote_edited' | 'quote_canceled' | 'quote_expired' | '*';
237
+ }
105
238
  /**
106
239
  * Event subscription configuration (discriminated union)
107
240
  * Defines what events a strategy wants to receive
@@ -111,17 +244,22 @@ export interface CustomSubscription extends BaseSubscription {
111
244
  * { type: 'price', market: 'BTC-USD' }
112
245
  * ```
113
246
  *
114
- * @example Wallet subscription
247
+ * @example Wallet subscription (Osiris only)
115
248
  * ```typescript
116
249
  * { type: 'wallet', wallet: '0x123...', conditions: { minWinRate: 60 } }
117
250
  * ```
118
251
  *
119
- * @example Opportunity subscription
252
+ * @example Opportunity subscription (Osiris only)
120
253
  * ```typescript
121
254
  * { type: 'opportunity', filter: 'wide_spread_markets' }
122
255
  * ```
256
+ *
257
+ * @example CLOB Market subscription (Polymarket only)
258
+ * ```typescript
259
+ * { type: 'clob_market', marketId: 'condition-id', messageType: 'agg_orderbook' }
260
+ * ```
123
261
  */
124
- export type EventSubscription = MarketSubscription | WalletSubscription | OpportunitySubscription | CustomSubscription;
262
+ export type EventSubscription = MarketSubscription | WalletSubscription | OpportunitySubscription | CustomSubscription | ClobMarketSubscription | ClobUserSubscription | ActivitySubscription | CommentsSubscription | CryptoPricesSubscription | RfqSubscription;
125
263
  /**
126
264
  * Data payload for strategy events
127
265
  */
@@ -198,5 +336,37 @@ export declare function isOpportunitySubscription(sub: EventSubscription): sub i
198
336
  * Check if subscription is a CustomSubscription
199
337
  */
200
338
  export declare function isCustomSubscription(sub: EventSubscription): sub is CustomSubscription;
339
+ /**
340
+ * Check if subscription is a ClobMarketSubscription
341
+ */
342
+ export declare function isClobMarketSubscription(sub: EventSubscription): sub is ClobMarketSubscription;
343
+ /**
344
+ * Check if subscription is a ClobUserSubscription
345
+ */
346
+ export declare function isClobUserSubscription(sub: EventSubscription): sub is ClobUserSubscription;
347
+ /**
348
+ * Check if subscription is an ActivitySubscription
349
+ */
350
+ export declare function isActivitySubscription(sub: EventSubscription): sub is ActivitySubscription;
351
+ /**
352
+ * Check if subscription is a CommentsSubscription
353
+ */
354
+ export declare function isCommentsSubscription(sub: EventSubscription): sub is CommentsSubscription;
355
+ /**
356
+ * Check if subscription is a CryptoPricesSubscription
357
+ */
358
+ export declare function isCryptoPricesSubscription(sub: EventSubscription): sub is CryptoPricesSubscription;
359
+ /**
360
+ * Check if subscription is an RfqSubscription
361
+ */
362
+ export declare function isRfqSubscription(sub: EventSubscription): sub is RfqSubscription;
363
+ /**
364
+ * Check if subscription is a Polymarket-specific subscription
365
+ */
366
+ export declare function isPolymarketSubscription(sub: EventSubscription): boolean;
367
+ /**
368
+ * Check if subscription is an Osiris-specific subscription
369
+ */
370
+ export declare function isOsirisSubscription(sub: EventSubscription): boolean;
201
371
  export {};
202
372
  //# sourceMappingURL=event-types.d.ts.map