@vesper85/strategy-sdk 0.1.20 → 0.1.21

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
@@ -22,6 +22,8 @@ pnpm add @vesper85/strategy-sdk
22
22
  yarn add @vesper85/strategy-sdk
23
23
  ```
24
24
 
25
+ **Note:** This package supports both ESM and CommonJS. You can use it in either type of project without needing to add `"type": "module"` to your `package.json`.
26
+
25
27
  ## Quick Start
26
28
 
27
29
  ### 1. Create a Tick-Based Strategy
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=polymarket-client.integration.test.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=polymarket-client.test.d.ts.map
@@ -1,4 +1,4 @@
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 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 EventPaginationFilters, type PaginationParams, type SearchParams } from '../gamma';
2
2
  import { ethers } from 'ethers';
3
3
  import type { PolymarketAPI, PolymarketClientOptions, PolymarketLimitOrderParams, PolymarketMarketOrderParams, PolymarketOrderResponse, PolymarketOpenOrder, PolymarketCancelResponse, PolymarketOrderBook, PolymarketApprovalResult, PolymarketMergeParams, PolymarketMergeResponse, PolymarketRedeemParams, PolymarketRedeemResponse, SignerAPI, ExtendedEventFilters } from '../types/osiris';
4
4
  import type { Logger } from '../utils/logger';
@@ -179,10 +179,12 @@ export declare class PolymarketClient implements PolymarketAPI {
179
179
  /**
180
180
  * Create limit order via Safe wallet using relay client
181
181
  * Orders are still submitted to CLOB, but approvals and execution use Safe
182
+ * Automatically ensures required approvals are in place before placing the order
182
183
  */
183
184
  private createLimitOrderViaSafe;
184
185
  /**
185
186
  * Create market order via Safe wallet using relay client
187
+ * Automatically ensures required approvals are in place before placing the order
186
188
  */
187
189
  private createMarketOrderViaSafe;
188
190
  /**
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Polymarket Gamma API Client
3
+ * TypeScript client for accessing Polymarket's prediction markets and events
4
+ */
5
+ import type { Comment, Event, EventFilters, EventPaginationFilters, GammaMarket, MarketFilters, PaginatedResponse, PaginationParams, SearchParams, SearchResults, Series, Sport, Tag, Team } from './types';
6
+ /**
7
+ * Configuration options for the Gamma client
8
+ */
9
+ export interface GammaClientConfig {
10
+ baseUrl?: string;
11
+ timeout?: number;
12
+ fetch?: typeof fetch;
13
+ headers?: Record<string, string>;
14
+ enableCache?: boolean;
15
+ }
16
+ /**
17
+ * Polymarket Gamma API Client
18
+ * Provides methods to access prediction markets, events, tags, and related data
19
+ */
20
+ export declare class PolymarketGammaClient {
21
+ private readonly baseUrl;
22
+ private readonly timeout;
23
+ private readonly fetchFn;
24
+ private readonly customHeaders;
25
+ private readonly enableCache;
26
+ private readonly requestCache;
27
+ /**
28
+ * Creates a new Polymarket Gamma API client
29
+ * @param config - Optional configuration
30
+ */
31
+ constructor(config?: GammaClientConfig);
32
+ /**
33
+ * Parse JSON string fields that the API returns as strings instead of arrays/objects
34
+ */
35
+ private parseJsonFields;
36
+ /**
37
+ * Validate API response to ensure it's a valid object
38
+ */
39
+ private validateResponse;
40
+ /**
41
+ * Internal method to make HTTP requests with deduplication
42
+ */
43
+ private request;
44
+ /**
45
+ * Perform the actual HTTP request
46
+ */
47
+ private doRequest;
48
+ /**
49
+ * Internal method to make POST requests
50
+ */
51
+ private post;
52
+ /**
53
+ * Search across events, tags, and profiles
54
+ * @param params - Search parameters
55
+ * @returns Search results
56
+ */
57
+ search(params: SearchParams): Promise<SearchResults>;
58
+ /**
59
+ * Get a market by ID or slug
60
+ * @param idOrSlug - Market ID or slug
61
+ * @returns Market details
62
+ */
63
+ getMarket(idOrSlug: string): Promise<GammaMarket>;
64
+ /**
65
+ * Get markets with optional filtering and pagination
66
+ * @param filters - Filter and pagination parameters
67
+ * @returns Array of markets
68
+ */
69
+ getMarkets(filters?: MarketFilters): Promise<GammaMarket[]>;
70
+ /**
71
+ * Get tags for a specific market
72
+ * @param marketId - Market ID
73
+ * @returns Array of tags
74
+ */
75
+ getMarketTags(marketId: string): Promise<Tag[]>;
76
+ /**
77
+ * Get an event by ID or slug
78
+ * @param idOrSlug - Event ID or slug
79
+ * @returns Event details
80
+ */
81
+ getEvent(idOrSlug: string): Promise<Event>;
82
+ /**
83
+ * Get events with optional filtering and pagination
84
+ * @param filters - Filter and pagination parameters
85
+ * @returns Array of events
86
+ */
87
+ getEvents(filters?: EventFilters): Promise<Event[]>;
88
+ /**
89
+ * Get tags for a specific event
90
+ * @param eventId - Event ID
91
+ * @returns Array of tags
92
+ */
93
+ getEventTags(eventId: string): Promise<Tag[]>;
94
+ /**
95
+ * Get events with pagination metadata
96
+ * @param filters - Filter and pagination parameters
97
+ * @returns Paginated response with events and metadata
98
+ */
99
+ getEventsPaginated(filters?: EventPaginationFilters): Promise<PaginatedResponse<Event>>;
100
+ /**
101
+ * Get all tags
102
+ * @param params - Optional pagination parameters
103
+ * @returns Array of tags
104
+ */
105
+ getTags(params?: PaginationParams): Promise<Tag[]>;
106
+ /**
107
+ * Get a specific tag by ID or slug
108
+ * @param idOrSlug - Tag ID or slug
109
+ * @returns Tag details
110
+ */
111
+ getTag(idOrSlug: string): Promise<Tag>;
112
+ /**
113
+ * Get related tags for a specific tag
114
+ * @param idOrSlug - Tag ID or slug
115
+ * @returns Array of related tags
116
+ */
117
+ getRelatedTags(idOrSlug: string): Promise<Tag[]>;
118
+ /**
119
+ * Get all tags related to a specific tag
120
+ * @param idOrSlug - Tag ID or slug
121
+ * @returns Array of tags
122
+ */
123
+ getRelatedTagsTags(idOrSlug: string): Promise<Tag[]>;
124
+ /**
125
+ * Get all teams
126
+ * @param params - Optional pagination parameters
127
+ * @returns Array of teams
128
+ */
129
+ getTeams(params?: PaginationParams): Promise<Team[]>;
130
+ /**
131
+ * Get all sports
132
+ * @param params - Optional pagination parameters
133
+ * @returns Array of sports
134
+ */
135
+ getSports(params?: PaginationParams): Promise<Sport[]>;
136
+ /**
137
+ * Get all series
138
+ * @param params - Optional pagination parameters
139
+ * @returns Array of series
140
+ */
141
+ getSeries(params?: PaginationParams): Promise<Series[]>;
142
+ /**
143
+ * Get a specific series by ID
144
+ * @param seriesId - Series ID
145
+ * @returns Series details
146
+ */
147
+ getSeriesById(seriesId: string): Promise<Series>;
148
+ /**
149
+ * Get comments with optional filtering
150
+ * @param params - Optional pagination and filter parameters
151
+ * @returns Array of comments
152
+ */
153
+ getComments(params?: PaginationParams): Promise<Comment[]>;
154
+ /**
155
+ * Get a specific comment by ID
156
+ * @param commentId - Comment ID
157
+ * @returns Comment details
158
+ */
159
+ getComment(commentId: string): Promise<Comment>;
160
+ /**
161
+ * Get comments by user address
162
+ * @param userAddress - User's Ethereum address
163
+ * @param params - Optional pagination parameters
164
+ * @returns Array of comments
165
+ */
166
+ getCommentsByUser(userAddress: string, params?: PaginationParams): Promise<Comment[]>;
167
+ /**
168
+ * Get Grok AI-powered event summary
169
+ * @param eventSlug - Event slug
170
+ * @returns Event summary text
171
+ */
172
+ grokEventSummary(eventSlug: string): Promise<string>;
173
+ /**
174
+ * Get Grok AI-powered election market explanation
175
+ * @param marketSlug - Market slug
176
+ * @returns Market explanation text
177
+ */
178
+ grokElectionMarketExplanation(marketSlug: string): Promise<string>;
179
+ }
180
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,3 @@
1
+ export * from './client';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,339 @@
1
+ /**
2
+ * TypeScript type definitions for Polymarket Gamma API
3
+ * Based on the Python Pydantic models from polymarket-apis
4
+ */
5
+ /**
6
+ * Represents a prediction market on Polymarket
7
+ */
8
+ export interface GammaMarket {
9
+ id?: string;
10
+ condition_id?: string;
11
+ question_id?: string;
12
+ slug?: string;
13
+ question?: string;
14
+ twitter_card_image?: string;
15
+ resolution_source?: string;
16
+ end_date?: string;
17
+ category?: string;
18
+ amm_type?: string;
19
+ liquidity?: number;
20
+ sponsor_name?: string;
21
+ sponsor_image?: string;
22
+ start_date?: string;
23
+ x_axis_value?: string;
24
+ y_axis_value?: string;
25
+ denomination_token?: string;
26
+ fee?: string;
27
+ image?: string;
28
+ icon?: string;
29
+ lower_bound?: string;
30
+ upper_bound?: string;
31
+ description?: string;
32
+ outcomes?: string[];
33
+ outcome_prices?: string[];
34
+ outcomePrices?: string[];
35
+ volume?: string;
36
+ active?: boolean;
37
+ market_type?: string;
38
+ format_type?: string;
39
+ lower_bound_date?: string;
40
+ upper_bound_date?: string;
41
+ closed?: boolean;
42
+ market_maker_address?: string;
43
+ created_by?: number;
44
+ updated_by?: number;
45
+ created_at?: string;
46
+ updated_at?: string;
47
+ closed_time?: string;
48
+ wide_format?: boolean;
49
+ new?: boolean;
50
+ mailchimp_tag?: string;
51
+ featured?: boolean;
52
+ archived?: boolean;
53
+ resolved_by?: string;
54
+ restricted?: boolean;
55
+ market_group?: number;
56
+ group_item_title?: string;
57
+ group_item_threshold?: string;
58
+ uma_end_date?: string;
59
+ seconds_delay?: number;
60
+ notification_policy?: number;
61
+ pager_duty_notification_enabled?: boolean;
62
+ reward_pool?: number;
63
+ reward_epoch?: number;
64
+ reward_multiplier?: number;
65
+ reward_min_size?: number;
66
+ reward_max_spread?: number;
67
+ ready?: boolean;
68
+ enable_order_book?: boolean;
69
+ notification_type?: string;
70
+ uma_reward?: string;
71
+ uma_resolution_statuses?: string[];
72
+ umaResolutionStatuses?: string[];
73
+ question_title?: string;
74
+ enable_ask?: boolean;
75
+ notifications?: number[];
76
+ events?: Event[];
77
+ markets?: GammaMarket[];
78
+ clob_token_ids?: string[];
79
+ clobTokenIds?: string[];
80
+ clobRewards?: ClobReward[];
81
+ tags?: Tag[];
82
+ cyom?: boolean;
83
+ competitive?: number;
84
+ neg_risk?: boolean;
85
+ neg_risk_market_id?: string;
86
+ neg_risk_request_id?: string;
87
+ accepting_orders?: boolean;
88
+ accepting_order_timestamp?: string;
89
+ minimum_order_size?: number;
90
+ minimum_tick_size?: number;
91
+ taker_fee_bps?: number;
92
+ maker_fee_bps?: number;
93
+ minimum_tick_size_usd?: number;
94
+ maker_base_fee?: number;
95
+ taker_base_fee?: number;
96
+ best_bid?: string;
97
+ best_ask?: string;
98
+ spread?: number;
99
+ spread_percent?: number;
100
+ volume_24hr?: string;
101
+ volume_num_trades_24hr?: number;
102
+ last_trade_price?: string;
103
+ last_trade_time?: string;
104
+ open_interest?: string;
105
+ rewards_daily_rate?: number;
106
+ rewards_min_size?: number;
107
+ rewards_max_spread?: number;
108
+ seconds_delay_requested?: number;
109
+ auto_update_schema?: boolean;
110
+ active_trading_prompt?: boolean;
111
+ }
112
+ /**
113
+ * Represents an event that contains one or more markets
114
+ */
115
+ export interface Event {
116
+ id?: string;
117
+ slug?: string;
118
+ title?: string;
119
+ description?: string;
120
+ start_date?: string;
121
+ end_date?: string;
122
+ image?: string;
123
+ icon?: string;
124
+ created_at?: string;
125
+ updated_at?: string;
126
+ archived?: boolean;
127
+ active?: boolean;
128
+ closed?: boolean;
129
+ restricted?: boolean;
130
+ liquidity?: number;
131
+ volume?: string;
132
+ markets?: GammaMarket[];
133
+ tags?: Tag[];
134
+ categories?: Category[];
135
+ series?: Series[];
136
+ comment_count?: number;
137
+ enable_comment?: boolean;
138
+ ticker?: string;
139
+ }
140
+ /**
141
+ * Represents a series or tournament of related events
142
+ */
143
+ export interface Series {
144
+ id?: string;
145
+ slug?: string;
146
+ title?: string;
147
+ description?: string;
148
+ image?: string;
149
+ created_at?: string;
150
+ updated_at?: string;
151
+ events?: Event[];
152
+ categories?: Category[];
153
+ }
154
+ /**
155
+ * Represents a category for organizing markets and events
156
+ */
157
+ export interface Category {
158
+ id?: string;
159
+ label?: string;
160
+ slug?: string;
161
+ }
162
+ /**
163
+ * Represents a tag for organizing and filtering content
164
+ */
165
+ export interface Tag {
166
+ id?: string;
167
+ label?: string;
168
+ slug?: string;
169
+ description?: string;
170
+ event_count?: number;
171
+ market_count?: number;
172
+ parent_id?: string;
173
+ children?: Tag[];
174
+ }
175
+ /**
176
+ * Represents a user profile
177
+ */
178
+ export interface Profile {
179
+ id?: string;
180
+ name?: string;
181
+ username?: string;
182
+ avatar_url?: string;
183
+ bio?: string;
184
+ }
185
+ /**
186
+ * Represents a comment on a market or event
187
+ */
188
+ export interface Comment {
189
+ id?: string;
190
+ market_id?: string;
191
+ event_id?: string;
192
+ user?: Profile;
193
+ content?: string;
194
+ created_at?: string;
195
+ updated_at?: string;
196
+ parent_id?: string;
197
+ reactions?: Reaction[];
198
+ reply_count?: number;
199
+ }
200
+ /**
201
+ * Represents a reaction to a comment
202
+ */
203
+ export interface Reaction {
204
+ id?: string;
205
+ comment_id?: string;
206
+ user?: Profile;
207
+ type?: string;
208
+ created_at?: string;
209
+ }
210
+ /**
211
+ * Represents a sports team
212
+ */
213
+ export interface Team {
214
+ id?: string;
215
+ name?: string;
216
+ short_name?: string;
217
+ abbreviation?: string;
218
+ logo?: string;
219
+ sport_id?: string;
220
+ sport?: Sport;
221
+ }
222
+ /**
223
+ * Represents a sport
224
+ */
225
+ export interface Sport {
226
+ id?: string;
227
+ name?: string;
228
+ slug?: string;
229
+ }
230
+ /**
231
+ * Represents a CLOB (Central Limit Order Book) reward
232
+ */
233
+ export interface ClobReward {
234
+ id?: string;
235
+ market_id?: string;
236
+ event_id?: string;
237
+ reward_epoch?: number;
238
+ asset_address?: string;
239
+ reward_amount?: string;
240
+ start_date?: string;
241
+ end_date?: string;
242
+ }
243
+ /**
244
+ * Represents a collection of markets
245
+ */
246
+ export interface Collection {
247
+ id?: string;
248
+ title?: string;
249
+ slug?: string;
250
+ description?: string;
251
+ markets?: GammaMarket[];
252
+ }
253
+ /**
254
+ * Represents a market creator
255
+ */
256
+ export interface Creator {
257
+ id?: string;
258
+ name?: string;
259
+ avatar_url?: string;
260
+ }
261
+ /**
262
+ * Search results wrapper
263
+ */
264
+ export interface SearchResults {
265
+ events?: Event[];
266
+ tags?: Tag[];
267
+ profiles?: Profile[];
268
+ }
269
+ /**
270
+ * Pagination parameters for list queries
271
+ */
272
+ export interface PaginationParams {
273
+ limit?: number;
274
+ offset?: number;
275
+ [key: string]: unknown;
276
+ }
277
+ /**
278
+ * Filter parameters for markets
279
+ */
280
+ export interface MarketFilters extends PaginationParams {
281
+ active?: boolean;
282
+ closed?: boolean;
283
+ archived?: boolean;
284
+ featured?: boolean;
285
+ restricted?: boolean;
286
+ tags?: string[];
287
+ category?: string;
288
+ event_id?: string;
289
+ order_by?: string;
290
+ ascending?: boolean;
291
+ }
292
+ /**
293
+ * Filter parameters for events
294
+ */
295
+ export interface EventFilters extends PaginationParams {
296
+ active?: boolean;
297
+ closed?: boolean;
298
+ archived?: boolean;
299
+ restricted?: boolean;
300
+ tags?: string[];
301
+ category?: string;
302
+ series_id?: string;
303
+ order_by?: string;
304
+ ascending?: boolean;
305
+ }
306
+ /**
307
+ * Search parameters
308
+ */
309
+ export interface SearchParams {
310
+ query: string;
311
+ limit?: number;
312
+ offset?: number;
313
+ [key: string]: unknown;
314
+ }
315
+ /**
316
+ * Pagination metadata
317
+ */
318
+ export interface PaginationMetadata {
319
+ hasMore: boolean;
320
+ totalResults: number;
321
+ }
322
+ /**
323
+ * Paginated response wrapper
324
+ */
325
+ export interface PaginatedResponse<T> {
326
+ data: T[];
327
+ pagination: PaginationMetadata;
328
+ }
329
+ /**
330
+ * Pagination filter parameters for events
331
+ */
332
+ export interface EventPaginationFilters extends PaginationParams {
333
+ active?: boolean;
334
+ closed?: boolean;
335
+ archived?: boolean;
336
+ order?: string;
337
+ ascending?: boolean;
338
+ }
339
+ //# sourceMappingURL=types.d.ts.map