@vesper85/strategy-sdk 0.1.0 → 0.1.2
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 +202 -213
- package/dist/clients/polymarket-client.d.ts +0 -16
- package/dist/engine/event-runner.d.ts +33 -3
- package/dist/engine/polymarket-event-runner.d.ts +202 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +661 -176
- package/dist/types/event-types.d.ts +111 -11
- package/dist/types/osiris.d.ts +2 -39
- package/package.json +3 -2
|
@@ -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,103 @@ 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
|
|
32
|
-
* Defines what events a strategy wants to receive
|
|
45
|
+
* Event source type - determines which WebSocket server to connect to
|
|
33
46
|
*/
|
|
34
|
-
export
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
+
* Event subscription configuration (discriminated union)
|
|
107
|
+
* Defines what events a strategy wants to receive
|
|
108
|
+
*
|
|
109
|
+
* @example Market subscription
|
|
110
|
+
* ```typescript
|
|
111
|
+
* { type: 'price', market: 'BTC-USD' }
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @example Wallet subscription
|
|
115
|
+
* ```typescript
|
|
116
|
+
* { type: 'wallet', wallet: '0x123...', conditions: { minWinRate: 60 } }
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @example Opportunity subscription
|
|
120
|
+
* ```typescript
|
|
121
|
+
* { type: 'opportunity', filter: 'wide_spread_markets' }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export type EventSubscription = MarketSubscription | WalletSubscription | OpportunitySubscription | CustomSubscription;
|
|
44
125
|
/**
|
|
45
126
|
* Data payload for strategy events
|
|
46
127
|
*/
|
|
@@ -82,8 +163,10 @@ export interface StrategyEvent {
|
|
|
82
163
|
type: EventType;
|
|
83
164
|
/** Timestamp when event occurred (Unix milliseconds) */
|
|
84
165
|
timestamp: number;
|
|
85
|
-
/** Market/asset this event relates to */
|
|
166
|
+
/** Market/asset this event relates to (for market events) */
|
|
86
167
|
market?: string;
|
|
168
|
+
/** Wallet address this event relates to (for wallet events) */
|
|
169
|
+
wallet?: string;
|
|
87
170
|
/** Event-specific data payload */
|
|
88
171
|
data: EventData;
|
|
89
172
|
}
|
|
@@ -99,4 +182,21 @@ export interface EventSourceUnsubscribeMessage {
|
|
|
99
182
|
subscriptions: EventSubscription[];
|
|
100
183
|
}
|
|
101
184
|
export type EventSourceMessage = EventSourceSubscribeMessage | EventSourceUnsubscribeMessage;
|
|
185
|
+
/**
|
|
186
|
+
* Check if subscription is a MarketSubscription
|
|
187
|
+
*/
|
|
188
|
+
export declare function isMarketSubscription(sub: EventSubscription): sub is MarketSubscription;
|
|
189
|
+
/**
|
|
190
|
+
* Check if subscription is a WalletSubscription
|
|
191
|
+
*/
|
|
192
|
+
export declare function isWalletSubscription(sub: EventSubscription): sub is WalletSubscription;
|
|
193
|
+
/**
|
|
194
|
+
* Check if subscription is an OpportunitySubscription
|
|
195
|
+
*/
|
|
196
|
+
export declare function isOpportunitySubscription(sub: EventSubscription): sub is OpportunitySubscription;
|
|
197
|
+
/**
|
|
198
|
+
* Check if subscription is a CustomSubscription
|
|
199
|
+
*/
|
|
200
|
+
export declare function isCustomSubscription(sub: EventSubscription): sub is CustomSubscription;
|
|
201
|
+
export {};
|
|
102
202
|
//# sourceMappingURL=event-types.d.ts.map
|
package/dist/types/osiris.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { OHLCV, TAParams } from "@
|
|
1
|
+
import type { OHLCV, TAParams } from "@osiris-ai/technical-indicators";
|
|
2
2
|
import type { GammaMarket, Event as GammaEvent, Tag, Team, Sport, Series, Comment as GammaComment, SearchResults, PaginatedResponse, MarketFilters, EventFilters, EventPaginationFilters, PaginationParams, SearchParams } 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 {
|
|
@@ -128,10 +128,7 @@ export interface PolymarketClientOptions {
|
|
|
128
128
|
mcpUrl?: string;
|
|
129
129
|
/**
|
|
130
130
|
* MCP OAuth access token for authenticated MCP calls.
|
|
131
|
-
*
|
|
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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vesper85/strategy-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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
|
-
"
|
|
20
|
+
"default": "./dist/index.js"
|
|
20
21
|
},
|
|
21
22
|
"./package.json": "./package.json"
|
|
22
23
|
},
|