@vesper85/strategy-sdk 0.1.2 → 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.
package/README.md CHANGED
@@ -232,41 +232,182 @@ const runner = createEventRunner(strategy, {
232
232
 
233
233
  ### Polymarket RTDS
234
234
 
235
- Connect directly to Polymarket's Real-Time Data Socket:
235
+ Connect directly to Polymarket's Real-Time Data Socket for live market data.
236
+
237
+ #### Strategy-Based Usage
238
+
239
+ Set `eventSource: 'polymarket'` in your subscriptions:
236
240
 
237
241
  ```typescript
238
- // Set eventSource: 'polymarket' in subscriptions
239
- subscriptions: EventSubscription[] = [
240
- {
241
- type: 'price',
242
- eventSource: 'polymarket',
243
- market: 'ETH',
242
+ import type {
243
+ CodeStrategy,
244
+ EventSubscription,
245
+ StrategyEvent,
246
+ CryptoPricesSubscription,
247
+ ActivitySubscription,
248
+ ClobMarketSubscription,
249
+ CommentsSubscription
250
+ } from '@osiris-ai/strategy-sdk';
251
+
252
+ class MyPolymarketStrategy implements CodeStrategy {
253
+ subscriptions: EventSubscription[] = [
254
+ // Crypto price updates
255
+ { type: 'crypto_prices', symbol: 'btcusdt', eventSource: 'polymarket' },
256
+
257
+ // Trade activity feed
258
+ { type: 'activity', messageType: '*', eventSource: 'polymarket' },
259
+
260
+ // CLOB orderbook data (requires market condition ID)
261
+ { type: 'clob_market', marketId: 'condition-id', messageType: 'agg_orderbook', eventSource: 'polymarket' },
262
+
263
+ // Comments and reactions
264
+ { type: 'comments', messageType: '*', eventSource: 'polymarket' },
265
+ ];
266
+
267
+ async onEvent(event: StrategyEvent, osiris: OsirisContext): Promise<void> {
268
+ const topic = event.data.raw?.topic;
269
+
270
+ if (topic === 'crypto_prices') {
271
+ console.log(`BTC: $${event.data.price}`);
272
+ } else if (topic === 'activity') {
273
+ console.log(`Trade: ${event.data.side} ${event.data.size} @ ${event.data.price}`);
274
+ }
244
275
  }
245
- ];
276
+ }
246
277
 
247
278
  const runner = createEventRunner(strategy, {
248
279
  logger,
249
280
  polymarket: {
250
281
  walletAddress: '0x...',
251
- // clobAuth: { ... } for private subscriptions
282
+ // clobAuth: { key, secret, passphrase } for clob_user subscriptions
252
283
  },
253
284
  }, context);
254
285
  ```
255
286
 
287
+ #### Polymarket Subscription Types
288
+
289
+ | Type | Description | Auth Required |
290
+ |------|-------------|---------------|
291
+ | `crypto_prices` | Real-time BTC/ETH/etc prices | No |
292
+ | `activity` | Global trade activity feed | No |
293
+ | `clob_market` | Orderbook, price changes for specific market | No |
294
+ | `comments` | Comments and reactions | No |
295
+ | `rfq` | Request for Quote events | No |
296
+ | `clob_user` | Your orders and trades | Yes (clobAuth) |
297
+
298
+ #### CryptoPricesSubscription
299
+
300
+ ```typescript
301
+ {
302
+ type: 'crypto_prices',
303
+ symbol: 'btcusdt', // or 'ethusdt', etc.
304
+ eventSource: 'polymarket'
305
+ }
306
+ ```
307
+
308
+ #### ActivitySubscription
309
+
310
+ ```typescript
311
+ {
312
+ type: 'activity',
313
+ eventSlug: 'will-bitcoin-hit-100k', // optional filter
314
+ marketSlug: 'market-slug', // optional filter
315
+ messageType: '*', // 'trades', 'positions', or '*'
316
+ eventSource: 'polymarket'
317
+ }
318
+ ```
319
+
320
+ #### ClobMarketSubscription
321
+
322
+ ```typescript
323
+ {
324
+ type: 'clob_market',
325
+ marketId: '0x1234...condition-id', // Market condition ID
326
+ messageType: 'agg_orderbook', // 'price_change', 'last_trade_price', 'tick_size_change', '*'
327
+ eventSource: 'polymarket'
328
+ }
329
+ ```
330
+
331
+ #### ClobUserSubscription (Requires Auth)
332
+
333
+ ```typescript
334
+ {
335
+ type: 'clob_user',
336
+ messageType: '*', // 'order', 'trade', or '*'
337
+ eventSource: 'polymarket'
338
+ }
339
+
340
+ // Config with clobAuth:
341
+ const runner = createEventRunner(strategy, {
342
+ logger,
343
+ polymarket: {
344
+ clobAuth: {
345
+ key: process.env.POLYMARKET_API_KEY!,
346
+ secret: process.env.POLYMARKET_API_SECRET!,
347
+ passphrase: process.env.POLYMARKET_PASSPHRASE!,
348
+ }
349
+ }
350
+ }, context);
351
+ ```
352
+
353
+ #### CommentsSubscription
354
+
355
+ ```typescript
356
+ {
357
+ type: 'comments',
358
+ parentEntityId: 'market-id', // optional filter
359
+ parentEntityType: 'market', // optional filter
360
+ messageType: '*', // 'comment_created', 'reaction_created', '*'
361
+ eventSource: 'polymarket'
362
+ }
363
+ ```
364
+
365
+ #### RfqSubscription
366
+
367
+ ```typescript
368
+ {
369
+ type: 'rfq',
370
+ messageType: '*',
371
+ eventSource: 'polymarket'
372
+ }
373
+
256
374
  ## Type Guards
257
375
 
258
376
  Use type guards for runtime type checking:
259
377
 
260
378
  ```typescript
261
379
  import {
380
+ // Generic subscription types
262
381
  isMarketSubscription,
263
382
  isWalletSubscription,
264
383
  isOpportunitySubscription,
265
- isCustomSubscription
384
+ isCustomSubscription,
385
+
386
+ // Polymarket RTDS subscription types
387
+ isClobMarketSubscription,
388
+ isClobUserSubscription,
389
+ isActivitySubscription,
390
+ isCommentsSubscription,
391
+ isCryptoPricesSubscription,
392
+ isRfqSubscription,
393
+
394
+ // Source routing helpers
395
+ isPolymarketSubscription,
396
+ isOsirisSubscription
266
397
  } from '@osiris-ai/strategy-sdk';
267
398
 
268
- if (isWalletSubscription(subscription)) {
269
- console.log(subscription.wallet); // TypeScript knows this is WalletSubscription
399
+ // Check if subscription is for Polymarket
400
+ if (isPolymarketSubscription(subscription)) {
401
+ // Subscription will be routed to Polymarket RTDS
402
+ }
403
+
404
+ // Check specific Polymarket types
405
+ if (isClobMarketSubscription(subscription)) {
406
+ console.log(subscription.marketId); // TypeScript knows this is ClobMarketSubscription
407
+ }
408
+
409
+ if (isCryptoPricesSubscription(subscription)) {
410
+ console.log(subscription.symbol); // TypeScript knows this is CryptoPricesSubscription
270
411
  }
271
412
  ```
272
413
 
@@ -1,4 +1,4 @@
1
- import { type GammaMarket, type Event as GammaEvent, type Tag, type Team, type Sport, type Series, type Comment as GammaComment, type SearchResults, type PaginatedResponse, type MarketFilters, type EventFilters, type EventPaginationFilters, type PaginationParams, type SearchParams } from "polymarket-gamma";
1
+ import { GammaMarket, type Event as GammaEvent, type Tag, type Team, type Sport, type Series, type Comment as GammaComment, type SearchResults, type PaginatedResponse, type MarketFilters, type EventFilters, type EventPaginationFilters, type PaginationParams, type SearchParams } from "polymarket-gamma";
2
2
  import type { PolymarketAPI, PolymarketClientOptions, PolymarketLimitOrderParams, PolymarketMarketOrderParams, PolymarketOrderResponse, PolymarketOpenOrder, PolymarketCancelResponse, PolymarketOrderBook, PolymarketApprovalResult, SignerAPI } from "../types/osiris";
3
3
  import type { Logger } from "../utils/logger";
4
4
  export declare class PolymarketClient implements PolymarketAPI {
@@ -16,7 +16,6 @@ export declare class PolymarketClient implements PolymarketAPI {
16
16
  constructor(logger: Logger, signer: SignerAPI, userAddress: string, options?: PolymarketClientOptions);
17
17
  initializeTradingClient(): Promise<void>;
18
18
  isTradingClientInitialized(): boolean;
19
- private getPrivateKeyFromSigner;
20
19
  private ensureTradingClient;
21
20
  private ensureMcpInstance;
22
21
  /**
@@ -132,6 +132,9 @@ export declare class PolymarketEventRunner {
132
132
  /**
133
133
  * Get the message type for a given RTDS topic
134
134
  * Each topic has specific message types as per the Polymarket RTDS documentation
135
+ *
136
+ * Note: Only 'crypto_prices' and 'comments' are documented RTDS topics.
137
+ * 'trades' and 'orders' subscriptions require the CLOB WebSocket API, not RTDS.
135
138
  */
136
139
  private getMessageTypeForTopic;
137
140
  /**
@@ -1,11 +1,10 @@
1
1
  import type { CodeStrategy } from "../types/strategy";
2
2
  import type { OsirisContext } from "../types/osiris";
3
- import type { Logger } from "../utils/logger";
3
+ import { type Logger } from "../utils/logger";
4
4
  export interface StrategyRunnerConfig {
5
- /** Logger instance for logging */
6
- logger: Logger;
7
5
  /** Optional strategy ID for logging (defaults to 'unnamed-strategy') */
8
6
  strategyId?: string;
7
+ logger?: Logger;
9
8
  }
10
9
  export interface StrategyEngineConfig extends StrategyRunnerConfig {
11
10
  /** Interval between ticks in milliseconds (default: 60000) */
@@ -22,7 +21,7 @@ export declare function runStrategy(strategy: CodeStrategy, config: StrategyRunn
22
21
  * Create a strategy engine that runs a strategy on a tick interval
23
22
  * Returns a controller object to start/stop the engine
24
23
  */
25
- export declare function createStrategyEngine(strategy: CodeStrategy, config: StrategyEngineConfig, context: OsirisContext): StrategyEngine;
24
+ export declare function createStrategyEngine(strategy: CodeStrategy, context: OsirisContext, config: StrategyEngineConfig): StrategyEngine;
26
25
  /**
27
26
  * Strategy Engine that runs a strategy on a tick interval
28
27
  */
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export type { CodeStrategy, } from './types/strategy';
2
2
  export type { OsirisContext, OsirisState, PolymarketAPI, HyperliquidAPI, TechnicalAnalysisAPI, SignerAPI, PolymarketOrderSide, PolymarketLimitOrderParams, PolymarketMarketOrderParams, PolymarketOrderResponse, PolymarketOpenOrder, PolymarketCancelResponse, PolymarketOrderBook, PolymarketOrderBookEntry, PolymarketApprovalResult, PolymarketClientOptions, } from './types/osiris';
3
- export type { EventType, EventSourceType, EventSubscription, EventConditions, StrategyEvent, EventData, EventSourceSubscribeMessage, EventSourceUnsubscribeMessage, EventSourceMessage, MarketSubscription, WalletSubscription, OpportunitySubscription, CustomSubscription, } from './types/event-types';
4
- export { isMarketSubscription, isWalletSubscription, isOpportunitySubscription, isCustomSubscription, } from './types/event-types';
3
+ export type { EventType, EventSourceType, EventSubscription, EventConditions, StrategyEvent, EventData, EventSourceSubscribeMessage, EventSourceUnsubscribeMessage, EventSourceMessage, MarketSubscription, WalletSubscription, OpportunitySubscription, CustomSubscription, ClobMarketSubscription, ClobUserSubscription, ActivitySubscription, CommentsSubscription, CryptoPricesSubscription, RfqSubscription, } from './types/event-types';
4
+ export { isMarketSubscription, isWalletSubscription, isOpportunitySubscription, isCustomSubscription, isClobMarketSubscription, isClobUserSubscription, isActivitySubscription, isCommentsSubscription, isCryptoPricesSubscription, isRfqSubscription, isPolymarketSubscription, isOsirisSubscription, } from './types/event-types';
5
5
  export { PolymarketClient, } from './clients/polymarket-client';
6
6
  export { HyperliquidClient, } from './clients/hyperliquid-client';
7
7
  export { MemoryStateManager, } from './state/memory-state';
@@ -10,6 +10,7 @@ export { createOsirisContext, type OsirisContextConfig, } from './context/osiris
10
10
  export { runStrategy, createStrategyEngine, StrategyEngine, isEventBasedStrategy, isTickBasedStrategy, validateStrategy, type StrategyRunnerConfig, type StrategyEngineConfig, } from './engine/strategy-runner';
11
11
  export { OsirisEventRunner, createEventRunner, type EventRunner, type EventRunnerConfig, } from './engine/event-runner';
12
12
  export { PolymarketEventRunner, createPolymarketEventRunner, type PolymarketEventRunnerConfig, type PolymarketClobAuth, type PolymarketGammaAuth, type PolymarketRTDSSubscription, type PolymarketRTDSTopic, } from './engine/polymarket-event-runner';
13
+ export { UnifiedRTDSService, createUnifiedRTDSService, PolymarketRTDSService, createPolymarketRTDSService, OsirisRTDSService, createOsirisRTDSService, DEFAULT_OSIRIS_RTDS_URL, type UnifiedRTDSConfig, type PolymarketRTDSConfig, type OsirisRTDSConfig, type ClobApiKeyCreds, } from './rtds';
13
14
  export { createConsoleLogger, type Logger, } from './utils/logger';
14
15
  export { Signer, OsirisSigner, PrivateKeySigner, type ISigner, type SignerConfig, type OsirisSignerConfig, type PrivateKeySignerConfig, } from './signer';
15
16
  //# sourceMappingURL=index.d.ts.map