@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.
@@ -4,7 +4,7 @@
4
4
  /**
5
5
  * Supported event types
6
6
  */
7
- export type EventType = 'price' | 'orderbook' | 'time' | 'trade' | 'fill' | 'liquidation' | 'custom';
7
+ export type EventType = 'price' | 'orderbook' | 'time' | 'trade' | 'fill' | 'liquidation' | 'wallet' | 'opportunity' | 'custom';
8
8
  /**
9
9
  * Conditions for filtering events
10
10
  */
@@ -25,22 +25,241 @@ export interface EventConditions {
25
25
  spreadBelow?: number;
26
26
  /** Trigger when volume exceeds this value */
27
27
  volumeAbove?: number;
28
+ /** Minimum smart score for wallet events */
29
+ minSmartScore?: number;
30
+ /** Minimum win rate for wallet events */
31
+ minWinRate?: number;
32
+ /** Minimum trade count for wallet events */
33
+ minTradeCount?: number;
34
+ /** Minimum conviction rate for wallet events */
35
+ minConvictionRate?: number;
36
+ /** Minimum opportunity score */
37
+ minScore?: number;
38
+ /** Filter by strategy type */
39
+ strategyType?: string;
40
+ /** Filter by status */
41
+ status?: 'active' | 'dismissed';
28
42
  [key: string]: any;
29
43
  }
30
44
  /**
31
- * Event subscription configuration
32
- * Defines what events a strategy wants to receive
45
+ * Event source type - determines which WebSocket server to connect to
33
46
  */
34
- export interface EventSubscription {
35
- /** Type of event to subscribe to */
36
- type: EventType;
37
- /** Market/asset identifier (e.g., token ID, trading pair like "BTC-USD") */
38
- market?: string;
47
+ export type EventSourceType = 'osiris' | 'polymarket';
48
+ /**
49
+ * Base subscription properties shared by all subscription types
50
+ */
51
+ interface BaseSubscription {
52
+ /** Event source type (default: 'osiris') */
53
+ eventSource?: EventSourceType;
39
54
  /** Optional filter conditions */
40
55
  conditions?: EventConditions;
41
- /** Optional custom channel name for the event source */
42
- channel?: string;
43
56
  }
57
+ /**
58
+ * Market subscription for price, orderbook, trade, and fill events
59
+ * Maps to Osiris topic: market:{market}
60
+ * Maps to Polymarket RTDS topics: crypto_prices, trades, orders
61
+ */
62
+ export interface MarketSubscription extends BaseSubscription {
63
+ /** Type of market event to subscribe to */
64
+ type: 'price' | 'orderbook' | 'trade' | 'fill';
65
+ /** Market/asset identifier (e.g., market slug, token ID, trading pair like "BTC-USD") */
66
+ market: string;
67
+ }
68
+ /**
69
+ * Wallet subscription for wallet analysis events (Osiris only)
70
+ * Maps to Osiris topic: wallet:{wallet}
71
+ * Not supported by Polymarket RTDS
72
+ */
73
+ export interface WalletSubscription extends BaseSubscription {
74
+ /** Wallet subscription type */
75
+ type: 'wallet';
76
+ /** Wallet address to subscribe to */
77
+ wallet: string;
78
+ }
79
+ /**
80
+ * Opportunity subscription for trading opportunity events (Osiris only)
81
+ * Maps to Osiris topic: opps:{filter}
82
+ * Not supported by Polymarket RTDS
83
+ */
84
+ export interface OpportunitySubscription extends BaseSubscription {
85
+ /** Opportunity subscription type */
86
+ type: 'opportunity';
87
+ /**
88
+ * Optional filter for opportunities:
89
+ * - 'all' - All opportunities (default)
90
+ * - Strategy type (e.g., 'wide_spread_markets', 'closing_soon')
91
+ * - Market slug for specific market opportunities
92
+ */
93
+ filter?: string;
94
+ }
95
+ /**
96
+ * Custom subscription for user-defined event topics
97
+ * Allows direct topic specification for advanced use cases
98
+ */
99
+ export interface CustomSubscription extends BaseSubscription {
100
+ /** Custom subscription type */
101
+ type: 'custom';
102
+ /** Full topic string (e.g., 'custom:my-topic' or any valid topic) */
103
+ topic: string;
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
+ }
238
+ /**
239
+ * Event subscription configuration (discriminated union)
240
+ * Defines what events a strategy wants to receive
241
+ *
242
+ * @example Market subscription
243
+ * ```typescript
244
+ * { type: 'price', market: 'BTC-USD' }
245
+ * ```
246
+ *
247
+ * @example Wallet subscription (Osiris only)
248
+ * ```typescript
249
+ * { type: 'wallet', wallet: '0x123...', conditions: { minWinRate: 60 } }
250
+ * ```
251
+ *
252
+ * @example Opportunity subscription (Osiris only)
253
+ * ```typescript
254
+ * { type: 'opportunity', filter: 'wide_spread_markets' }
255
+ * ```
256
+ *
257
+ * @example CLOB Market subscription (Polymarket only)
258
+ * ```typescript
259
+ * { type: 'clob_market', marketId: 'condition-id', messageType: 'agg_orderbook' }
260
+ * ```
261
+ */
262
+ export type EventSubscription = MarketSubscription | WalletSubscription | OpportunitySubscription | CustomSubscription | ClobMarketSubscription | ClobUserSubscription | ActivitySubscription | CommentsSubscription | CryptoPricesSubscription | RfqSubscription;
44
263
  /**
45
264
  * Data payload for strategy events
46
265
  */
@@ -82,8 +301,10 @@ export interface StrategyEvent {
82
301
  type: EventType;
83
302
  /** Timestamp when event occurred (Unix milliseconds) */
84
303
  timestamp: number;
85
- /** Market/asset this event relates to */
304
+ /** Market/asset this event relates to (for market events) */
86
305
  market?: string;
306
+ /** Wallet address this event relates to (for wallet events) */
307
+ wallet?: string;
87
308
  /** Event-specific data payload */
88
309
  data: EventData;
89
310
  }
@@ -99,4 +320,53 @@ export interface EventSourceUnsubscribeMessage {
99
320
  subscriptions: EventSubscription[];
100
321
  }
101
322
  export type EventSourceMessage = EventSourceSubscribeMessage | EventSourceUnsubscribeMessage;
323
+ /**
324
+ * Check if subscription is a MarketSubscription
325
+ */
326
+ export declare function isMarketSubscription(sub: EventSubscription): sub is MarketSubscription;
327
+ /**
328
+ * Check if subscription is a WalletSubscription
329
+ */
330
+ export declare function isWalletSubscription(sub: EventSubscription): sub is WalletSubscription;
331
+ /**
332
+ * Check if subscription is an OpportunitySubscription
333
+ */
334
+ export declare function isOpportunitySubscription(sub: EventSubscription): sub is OpportunitySubscription;
335
+ /**
336
+ * Check if subscription is a CustomSubscription
337
+ */
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;
371
+ export {};
102
372
  //# sourceMappingURL=event-types.d.ts.map
@@ -0,0 +1,135 @@
1
+ export interface GammaMarket {
2
+ id: string;
3
+ conditionId: string;
4
+ slug: string;
5
+ question: string;
6
+ description: string;
7
+ category: string;
8
+ image: string;
9
+ icon: string;
10
+ twitterCardImage: string;
11
+ active: boolean;
12
+ closed: boolean;
13
+ archived: boolean;
14
+ ready: boolean;
15
+ restricted: boolean;
16
+ endDate: string;
17
+ endDateIso: string;
18
+ createdAt: string;
19
+ updatedAt: string;
20
+ closedTime?: string;
21
+ hasReviewedDates: boolean;
22
+ readyForCron: boolean;
23
+ marketType: string;
24
+ liquidity: string;
25
+ volume: string;
26
+ volumeNum: number;
27
+ liquidityNum: number;
28
+ volume24hr: number;
29
+ volume1wk: number;
30
+ volume1mo: number;
31
+ volume1yr: number;
32
+ bestBid: number;
33
+ bestAsk: number;
34
+ lastTradePrice: number;
35
+ spread: number;
36
+ oneDayPriceChange: number;
37
+ oneHourPriceChange: number;
38
+ oneWeekPriceChange: number;
39
+ oneMonthPriceChange: number;
40
+ oneYearPriceChange: number;
41
+ outcomes: string;
42
+ outcomePrices: string;
43
+ clobTokenIds: string;
44
+ umaResolutionStatuses: string;
45
+ marketMakerAddress: string;
46
+ updatedBy: number;
47
+ mailchimpTag?: string;
48
+ fpmmLive: boolean;
49
+ creator: string;
50
+ funded: boolean;
51
+ cyom: boolean;
52
+ competitive: number;
53
+ pagerDutyNotificationEnabled: boolean;
54
+ approved: boolean;
55
+ rewardsMinSize: number;
56
+ rewardsMaxSpread: number;
57
+ clearBookOnStart: boolean;
58
+ manualActivation: boolean;
59
+ negRiskOther: boolean;
60
+ pendingDeployment: boolean;
61
+ deploying: boolean;
62
+ rfqEnabled: boolean;
63
+ holdingRewardsEnabled: boolean;
64
+ feesEnabled: boolean;
65
+ requiresTranslation: boolean;
66
+ volume1wkAmm: number;
67
+ volume1moAmm: number;
68
+ volume1yrAmm: number;
69
+ volume1wkClob: number;
70
+ volume1moClob: number;
71
+ volume1yrClob: number;
72
+ events: any[];
73
+ }
74
+ export interface Event {
75
+ id?: string;
76
+ slug?: string;
77
+ title?: string;
78
+ description?: string;
79
+ start_date?: string;
80
+ end_date?: string;
81
+ image?: string;
82
+ icon?: string;
83
+ created_at?: string;
84
+ updated_at?: string;
85
+ archived?: boolean;
86
+ active?: boolean;
87
+ closed?: boolean;
88
+ restricted?: boolean;
89
+ liquidity?: number;
90
+ volume?: string;
91
+ markets?: GammaMarket[];
92
+ tags?: Tag[];
93
+ categories?: Category[];
94
+ series?: Series[];
95
+ comment_count?: number;
96
+ enable_comment?: boolean;
97
+ ticker?: string;
98
+ }
99
+ export interface Series {
100
+ id?: string;
101
+ slug?: string;
102
+ title?: string;
103
+ description?: string;
104
+ image?: string;
105
+ created_at?: string;
106
+ updated_at?: string;
107
+ events?: Event[];
108
+ categories?: Category[];
109
+ }
110
+ export interface Category {
111
+ id?: string;
112
+ label?: string;
113
+ slug?: string;
114
+ }
115
+ export interface Tag {
116
+ id?: string;
117
+ label?: string;
118
+ slug?: string;
119
+ description?: string;
120
+ event_count?: number;
121
+ market_count?: number;
122
+ parent_id?: string;
123
+ children?: Tag[];
124
+ }
125
+ export interface ClobReward {
126
+ id?: string;
127
+ market_id?: string;
128
+ event_id?: string;
129
+ reward_epoch?: number;
130
+ asset_address?: string;
131
+ reward_amount?: string;
132
+ start_date?: string;
133
+ end_date?: string;
134
+ }
135
+ //# sourceMappingURL=gamma.d.ts.map
@@ -1,5 +1,5 @@
1
- import type { OHLCV, TAParams } from "@vesper85/technical-indicators";
2
- import type { GammaMarket, Event as GammaEvent, Tag, Team, Sport, Series, Comment as GammaComment, SearchResults, PaginatedResponse, MarketFilters, EventFilters, EventPaginationFilters, PaginationParams, SearchParams } from "polymarket-gamma";
1
+ import type { OHLCV, TAParams } from "@osiris-ai/technical-indicators";
2
+ import type { Event as GammaEvent, Tag, Team, Sport, Series, Comment as GammaComment, SearchResults, PaginatedResponse, MarketFilters, EventFilters, EventPaginationFilters, PaginationParams, SearchParams, GammaMarket } from "polymarket-gamma";
3
3
  import type { ClearinghouseState, SpotMeta, SpotClearinghouseState, SpotMetaAndAssetCtxs, Meta, MetaAndAssetCtxs, UserFunding, UserNonFundingLedgerUpdates, FundingHistory, PredictedFundings, PerpsAtOpenInterestCap, PerpDexLimits, AllMids, UserOpenOrders, FrontendOpenOrders, UserFills, UserRateLimit, OrderStatus, L2Book, CandleSnapshot, HistoricalOrder, TwapSliceFill, SubAccount, VaultDetails, VaultEquity, UserRole, Delegation, DelegatorSummary, DelegatorHistoryEntry, DelegatorReward, ValidatorSummary, VaultSummary, UserFees, PortfolioPeriods, PreTransferCheck, Referral, ExtraAgent, LegalCheck, TwapHistory, MultiSigSigners, BuilderFeeApproval, UserOrderHistory } from "hyperliquid";
4
4
  export interface OsirisState {
5
5
  get(key: string): Promise<any>;
@@ -128,10 +128,7 @@ export interface PolymarketClientOptions {
128
128
  mcpUrl?: string;
129
129
  /**
130
130
  * MCP OAuth access token for authenticated MCP calls.
131
- * IMPORTANT: This must be an MCP-specific token obtained through the Osiris Hub
132
- * OAuth flow for MCP packages (via /hub/authorize endpoint with MCP scopes).
133
- * This is NOT the same as the general backend access token.
134
- * Required scopes: osiris:auth, osiris:auth:action
131
+ * Required when using MCP mode for order placement.
135
132
  */
136
133
  mcpAccessToken?: string;
137
134
  /**
@@ -278,50 +275,16 @@ export interface PolymarketAPI {
278
275
  * @returns Order book data
279
276
  */
280
277
  getOrderBook(tokenId: string): Promise<PolymarketOrderBook>;
281
- /**
282
- * Place a limit buy order
283
- * @param tokenId Token ID of the outcome
284
- * @param price Price per share (0-1 range)
285
- * @param size Number of shares to buy
286
- * @returns Order response
287
- */
288
- buyLimit(tokenId: string, price: number, size: number): Promise<PolymarketOrderResponse>;
289
- /**
290
- * Place a limit sell order
291
- * @param tokenId Token ID of the outcome
292
- * @param price Price per share (0-1 range)
293
- * @param size Number of shares to sell
294
- * @returns Order response
295
- */
296
- sellLimit(tokenId: string, price: number, size: number): Promise<PolymarketOrderResponse>;
297
- /**
298
- * Place a market buy order (executes immediately at best price)
299
- * @param tokenId Token ID of the outcome
300
- * @param amount Amount in USDC to spend
301
- * @param slippage Slippage tolerance as decimal (e.g., 0.05 for 5%). Default: 0.05
302
- * @returns Order response
303
- */
304
- buyMarket(tokenId: string, amount: number, slippage?: number): Promise<PolymarketOrderResponse>;
305
- /**
306
- * Place a market sell order (executes immediately at best price)
307
- * @param tokenId Token ID of the outcome
308
- * @param size Number of shares to sell
309
- * @param slippage Slippage tolerance as decimal (e.g., 0.05 for 5%). Default: 0.05
310
- * @returns Order response
311
- */
312
- sellMarket(tokenId: string, size: number, slippage?: number): Promise<PolymarketOrderResponse>;
313
278
  /**
314
279
  * Buy shares of an outcome token (uses market order)
315
280
  * @param tokenId Token ID of the outcome
316
281
  * @param size Amount in USDC to spend
317
- * @deprecated Use buyMarket() instead
318
282
  */
319
283
  buy(tokenId: string, size: number): Promise<void>;
320
284
  /**
321
285
  * Sell shares of an outcome token (uses market order)
322
286
  * @param tokenId Token ID of the outcome
323
287
  * @param size Number of shares to sell
324
- * @deprecated Use sellMarket() instead
325
288
  */
326
289
  sell(tokenId: string, size: number): Promise<void>;
327
290
  }
@@ -0,0 +1,3 @@
1
+ import { GammaMarket } from "polymarket-gamma";
2
+ export declare function mapToGammaMarket(raw: any): GammaMarket;
3
+ //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesper85/strategy-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "description": "SDK for writing and running trading strategies with Polymarket and Hyperliquid integrations",
6
6
  "keywords": [
@@ -15,8 +15,9 @@
15
15
  "types": "./dist/index.d.ts",
16
16
  "exports": {
17
17
  ".": {
18
+ "types": "./dist/index.d.ts",
18
19
  "import": "./dist/index.js",
19
- "types": "./dist/index.d.ts"
20
+ "default": "./dist/index.js"
20
21
  },
21
22
  "./package.json": "./package.json"
22
23
  },
@@ -43,8 +44,9 @@
43
44
  "release": "npm run build && changeset publish"
44
45
  },
45
46
  "dependencies": {
46
- "@vesper85/technical-indicators": "^0.1.0",
47
47
  "@polymarket/clob-client": "^4.6.0",
48
+ "@polymarket/real-time-data-client": "^1.0.0",
49
+ "@vesper85/technical-indicators": "^0.1.0",
48
50
  "axios": "^1.7.9",
49
51
  "ethers": "^6.13.4",
50
52
  "hyperliquid": "^1.7.7",
@@ -73,4 +75,4 @@
73
75
  "url": "https://github.com/FetcchX/legion-sdk/issues"
74
76
  },
75
77
  "homepage": "https://github.com/FetcchX/legion-sdk#readme"
76
- }
78
+ }