pmxtjs 1.5.6 → 1.6.0
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/dist/esm/generated/src/models/CreateOrderParams.d.ts +6 -0
- package/dist/esm/generated/src/models/CreateOrderParams.js +2 -0
- package/dist/esm/generated/src/models/MarketOutcome.d.ts +8 -1
- package/dist/esm/generated/src/models/MarketOutcome.js +2 -0
- package/dist/esm/generated/src/models/UnifiedMarket.d.ts +8 -1
- package/dist/esm/generated/src/models/UnifiedMarket.js +2 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/pmxt/client.d.ts +46 -1
- package/dist/esm/pmxt/client.js +245 -0
- package/dist/esm/pmxt/models.d.ts +84 -0
- package/dist/esm/pmxt/server-manager.d.ts +8 -0
- package/dist/esm/pmxt/server-manager.js +13 -0
- package/dist/generated/src/models/CreateOrderParams.d.ts +6 -0
- package/dist/generated/src/models/CreateOrderParams.js +2 -0
- package/dist/generated/src/models/MarketOutcome.d.ts +8 -1
- package/dist/generated/src/models/MarketOutcome.js +2 -0
- package/dist/generated/src/models/UnifiedMarket.d.ts +8 -1
- package/dist/generated/src/models/UnifiedMarket.js +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +9 -0
- package/dist/pmxt/client.d.ts +46 -1
- package/dist/pmxt/client.js +245 -0
- package/dist/pmxt/models.d.ts +84 -0
- package/dist/pmxt/server-manager.d.ts +8 -0
- package/dist/pmxt/server-manager.js +13 -0
- package/generated/docs/CreateOrderParams.md +2 -0
- package/generated/docs/MarketOutcome.md +2 -0
- package/generated/docs/UnifiedMarket.md +2 -0
- package/generated/package.json +1 -1
- package/generated/src/models/CreateOrderParams.ts +8 -0
- package/generated/src/models/MarketOutcome.ts +10 -1
- package/generated/src/models/UnifiedMarket.ts +10 -1
- package/index.ts +12 -0
- package/package.json +2 -2
- package/pmxt/client.ts +289 -0
- package/pmxt/models.ts +91 -1
- package/pmxt/server-manager.ts +15 -0
|
@@ -55,6 +55,7 @@ export function CreateOrderParamsFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
55
55
|
'type': json['type'],
|
|
56
56
|
'amount': json['amount'],
|
|
57
57
|
'price': json['price'] == null ? undefined : json['price'],
|
|
58
|
+
'fee': json['fee'] == null ? undefined : json['fee'],
|
|
58
59
|
};
|
|
59
60
|
}
|
|
60
61
|
export function CreateOrderParamsToJSON(json) {
|
|
@@ -71,5 +72,6 @@ export function CreateOrderParamsToJSONTyped(value, ignoreDiscriminator = false)
|
|
|
71
72
|
'type': value['type'],
|
|
72
73
|
'amount': value['amount'],
|
|
73
74
|
'price': value['price'],
|
|
75
|
+
'fee': value['fee'],
|
|
74
76
|
};
|
|
75
77
|
}
|
|
@@ -16,11 +16,18 @@
|
|
|
16
16
|
*/
|
|
17
17
|
export interface MarketOutcome {
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* DEPRECATED: Use outcomeId instead. Will be removed in v2.0
|
|
20
20
|
* @type {string}
|
|
21
21
|
* @memberof MarketOutcome
|
|
22
|
+
* @deprecated
|
|
22
23
|
*/
|
|
23
24
|
id?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Outcome ID for trading operations (CLOB Token ID for Polymarket, Market Ticker for Kalshi)
|
|
27
|
+
* @type {string}
|
|
28
|
+
* @memberof MarketOutcome
|
|
29
|
+
*/
|
|
30
|
+
outcomeId?: string;
|
|
24
31
|
/**
|
|
25
32
|
*
|
|
26
33
|
* @type {string}
|
|
@@ -26,6 +26,7 @@ export function MarketOutcomeFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
26
26
|
}
|
|
27
27
|
return {
|
|
28
28
|
'id': json['id'] == null ? undefined : json['id'],
|
|
29
|
+
'outcomeId': json['outcomeId'] == null ? undefined : json['outcomeId'],
|
|
29
30
|
'label': json['label'] == null ? undefined : json['label'],
|
|
30
31
|
'price': json['price'] == null ? undefined : json['price'],
|
|
31
32
|
'priceChange24h': json['priceChange24h'] == null ? undefined : json['priceChange24h'],
|
|
@@ -41,6 +42,7 @@ export function MarketOutcomeToJSONTyped(value, ignoreDiscriminator = false) {
|
|
|
41
42
|
}
|
|
42
43
|
return {
|
|
43
44
|
'id': value['id'],
|
|
45
|
+
'outcomeId': value['outcomeId'],
|
|
44
46
|
'label': value['label'],
|
|
45
47
|
'price': value['price'],
|
|
46
48
|
'priceChange24h': value['priceChange24h'],
|
|
@@ -17,11 +17,18 @@ import type { MarketOutcome } from './MarketOutcome.js';
|
|
|
17
17
|
*/
|
|
18
18
|
export interface UnifiedMarket {
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* DEPRECATED: Use marketId instead. Will be removed in v2.0
|
|
21
21
|
* @type {string}
|
|
22
22
|
* @memberof UnifiedMarket
|
|
23
|
+
* @deprecated
|
|
23
24
|
*/
|
|
24
25
|
id?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The unique identifier for this market
|
|
28
|
+
* @type {string}
|
|
29
|
+
* @memberof UnifiedMarket
|
|
30
|
+
*/
|
|
31
|
+
marketId?: string;
|
|
25
32
|
/**
|
|
26
33
|
*
|
|
27
34
|
* @type {string}
|
|
@@ -27,6 +27,7 @@ export function UnifiedMarketFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
27
27
|
}
|
|
28
28
|
return {
|
|
29
29
|
'id': json['id'] == null ? undefined : json['id'],
|
|
30
|
+
'marketId': json['marketId'] == null ? undefined : json['marketId'],
|
|
30
31
|
'title': json['title'] == null ? undefined : json['title'],
|
|
31
32
|
'description': json['description'] == null ? undefined : json['description'],
|
|
32
33
|
'outcomes': json['outcomes'] == null ? undefined : (json['outcomes'].map(MarketOutcomeFromJSON)),
|
|
@@ -54,6 +55,7 @@ export function UnifiedMarketToJSONTyped(value, ignoreDiscriminator = false) {
|
|
|
54
55
|
}
|
|
55
56
|
return {
|
|
56
57
|
'id': value['id'],
|
|
58
|
+
'marketId': value['marketId'],
|
|
57
59
|
'title': value['title'],
|
|
58
60
|
'description': value['description'],
|
|
59
61
|
'outcomes': value['outcomes'] == null ? undefined : (value['outcomes'].map(MarketOutcomeToJSON)),
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -22,11 +22,15 @@ import { ServerManager } from "./pmxt/server-manager.js";
|
|
|
22
22
|
export { Exchange, Polymarket, Kalshi, Limitless } from "./pmxt/client.js";
|
|
23
23
|
export { ServerManager } from "./pmxt/server-manager.js";
|
|
24
24
|
export type * from "./pmxt/models.js";
|
|
25
|
+
declare function stopServer(): Promise<void>;
|
|
26
|
+
declare function restartServer(): Promise<void>;
|
|
25
27
|
declare const pmxt: {
|
|
26
28
|
Exchange: typeof Exchange;
|
|
27
29
|
Polymarket: typeof Polymarket;
|
|
28
30
|
Kalshi: typeof Kalshi;
|
|
29
31
|
Limitless: typeof Limitless;
|
|
30
32
|
ServerManager: typeof ServerManager;
|
|
33
|
+
stopServer: typeof stopServer;
|
|
34
|
+
restartServer: typeof restartServer;
|
|
31
35
|
};
|
|
32
36
|
export default pmxt;
|
package/dist/esm/index.js
CHANGED
|
@@ -22,12 +22,21 @@ import { ServerManager } from "./pmxt/server-manager.js";
|
|
|
22
22
|
import * as models from "./pmxt/models.js";
|
|
23
23
|
export { Exchange, Polymarket, Kalshi, Limitless } from "./pmxt/client.js";
|
|
24
24
|
export { ServerManager } from "./pmxt/server-manager.js";
|
|
25
|
+
const defaultManager = new ServerManager();
|
|
26
|
+
async function stopServer() {
|
|
27
|
+
await defaultManager.stop();
|
|
28
|
+
}
|
|
29
|
+
async function restartServer() {
|
|
30
|
+
await defaultManager.restart();
|
|
31
|
+
}
|
|
25
32
|
const pmxt = {
|
|
26
33
|
Exchange,
|
|
27
34
|
Polymarket,
|
|
28
35
|
Kalshi,
|
|
29
36
|
Limitless,
|
|
30
37
|
ServerManager,
|
|
38
|
+
stopServer,
|
|
39
|
+
restartServer,
|
|
31
40
|
...models
|
|
32
41
|
};
|
|
33
42
|
export default pmxt;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* OpenAPI client, matching the Python API exactly.
|
|
6
6
|
*/
|
|
7
7
|
import { DefaultApi, Configuration, ExchangeCredentials } from "../generated/src/index.js";
|
|
8
|
-
import { UnifiedMarket, PriceCandle, OrderBook, Trade, Order, Position, Balance, MarketFilterParams, HistoryFilterParams, CreateOrderParams, UnifiedEvent, ExecutionPriceResult } from "./models.js";
|
|
8
|
+
import { UnifiedMarket, PriceCandle, OrderBook, Trade, Order, Position, Balance, MarketFilterParams, HistoryFilterParams, CreateOrderParams, UnifiedEvent, ExecutionPriceResult, MarketFilterCriteria, MarketFilterFunction, EventFilterCriteria, EventFilterFunction } from "./models.js";
|
|
9
9
|
import { ServerManager } from "./server-manager.js";
|
|
10
10
|
/**
|
|
11
11
|
* Base exchange client options.
|
|
@@ -254,6 +254,51 @@ export declare abstract class Exchange {
|
|
|
254
254
|
* @returns Detailed execution result
|
|
255
255
|
*/
|
|
256
256
|
getExecutionPriceDetailed(orderBook: OrderBook, side: 'buy' | 'sell', amount: number): Promise<ExecutionPriceResult>;
|
|
257
|
+
/**
|
|
258
|
+
* Filter markets based on criteria or custom function.
|
|
259
|
+
*
|
|
260
|
+
* @param markets - Array of markets to filter
|
|
261
|
+
* @param criteria - Filter criteria object, string (simple text search), or predicate function
|
|
262
|
+
* @returns Filtered array of markets
|
|
263
|
+
*
|
|
264
|
+
* @example Simple text search
|
|
265
|
+
* api.filterMarkets(markets, 'Trump')
|
|
266
|
+
*
|
|
267
|
+
* @example Advanced filtering
|
|
268
|
+
* api.filterMarkets(markets, {
|
|
269
|
+
* text: 'Trump',
|
|
270
|
+
* searchIn: ['title', 'tags'],
|
|
271
|
+
* volume24h: { min: 10000 },
|
|
272
|
+
* category: 'Politics',
|
|
273
|
+
* price: { outcome: 'yes', max: 0.5 }
|
|
274
|
+
* })
|
|
275
|
+
*
|
|
276
|
+
* @example Custom predicate
|
|
277
|
+
* api.filterMarkets(markets, m => m.liquidity > 5000 && m.yes?.price < 0.3)
|
|
278
|
+
*/
|
|
279
|
+
filterMarkets(markets: UnifiedMarket[], criteria: string | MarketFilterCriteria | MarketFilterFunction): UnifiedMarket[];
|
|
280
|
+
/**
|
|
281
|
+
* Filter events based on criteria or custom function.
|
|
282
|
+
*
|
|
283
|
+
* @param events - Array of events to filter
|
|
284
|
+
* @param criteria - Filter criteria object, string (simple text search), or predicate function
|
|
285
|
+
* @returns Filtered array of events
|
|
286
|
+
*
|
|
287
|
+
* @example Simple text search
|
|
288
|
+
* api.filterEvents(events, 'Trump')
|
|
289
|
+
*
|
|
290
|
+
* @example Advanced filtering
|
|
291
|
+
* api.filterEvents(events, {
|
|
292
|
+
* text: 'Election',
|
|
293
|
+
* searchIn: ['title', 'tags'],
|
|
294
|
+
* category: 'Politics',
|
|
295
|
+
* marketCount: { min: 5 }
|
|
296
|
+
* })
|
|
297
|
+
*
|
|
298
|
+
* @example Custom predicate
|
|
299
|
+
* api.filterEvents(events, e => e.markets.length > 10)
|
|
300
|
+
*/
|
|
301
|
+
filterEvents(events: UnifiedEvent[], criteria: string | EventFilterCriteria | EventFilterFunction): UnifiedEvent[];
|
|
257
302
|
}
|
|
258
303
|
/**
|
|
259
304
|
* Polymarket exchange client.
|
package/dist/esm/pmxt/client.js
CHANGED
|
@@ -594,6 +594,9 @@ export class Exchange {
|
|
|
594
594
|
if (params.price !== undefined) {
|
|
595
595
|
paramsDict.price = params.price;
|
|
596
596
|
}
|
|
597
|
+
if (params.fee !== undefined) {
|
|
598
|
+
paramsDict.fee = params.fee;
|
|
599
|
+
}
|
|
597
600
|
const requestBody = {
|
|
598
601
|
args: [paramsDict],
|
|
599
602
|
credentials: this.getCredentials()
|
|
@@ -784,6 +787,248 @@ export class Exchange {
|
|
|
784
787
|
throw new Error(`Failed to get execution price: ${error}`);
|
|
785
788
|
}
|
|
786
789
|
}
|
|
790
|
+
// ----------------------------------------------------------------------------
|
|
791
|
+
// Filtering Methods
|
|
792
|
+
// ----------------------------------------------------------------------------
|
|
793
|
+
/**
|
|
794
|
+
* Filter markets based on criteria or custom function.
|
|
795
|
+
*
|
|
796
|
+
* @param markets - Array of markets to filter
|
|
797
|
+
* @param criteria - Filter criteria object, string (simple text search), or predicate function
|
|
798
|
+
* @returns Filtered array of markets
|
|
799
|
+
*
|
|
800
|
+
* @example Simple text search
|
|
801
|
+
* api.filterMarkets(markets, 'Trump')
|
|
802
|
+
*
|
|
803
|
+
* @example Advanced filtering
|
|
804
|
+
* api.filterMarkets(markets, {
|
|
805
|
+
* text: 'Trump',
|
|
806
|
+
* searchIn: ['title', 'tags'],
|
|
807
|
+
* volume24h: { min: 10000 },
|
|
808
|
+
* category: 'Politics',
|
|
809
|
+
* price: { outcome: 'yes', max: 0.5 }
|
|
810
|
+
* })
|
|
811
|
+
*
|
|
812
|
+
* @example Custom predicate
|
|
813
|
+
* api.filterMarkets(markets, m => m.liquidity > 5000 && m.yes?.price < 0.3)
|
|
814
|
+
*/
|
|
815
|
+
filterMarkets(markets, criteria) {
|
|
816
|
+
// Handle predicate function
|
|
817
|
+
if (typeof criteria === 'function') {
|
|
818
|
+
return markets.filter(criteria);
|
|
819
|
+
}
|
|
820
|
+
// Handle simple string search
|
|
821
|
+
if (typeof criteria === 'string') {
|
|
822
|
+
const lowerQuery = criteria.toLowerCase();
|
|
823
|
+
return markets.filter(m => m.title.toLowerCase().includes(lowerQuery));
|
|
824
|
+
}
|
|
825
|
+
// Handle criteria object
|
|
826
|
+
return markets.filter(market => {
|
|
827
|
+
// Text search
|
|
828
|
+
if (criteria.text) {
|
|
829
|
+
const lowerQuery = criteria.text.toLowerCase();
|
|
830
|
+
const searchIn = criteria.searchIn || ['title'];
|
|
831
|
+
let textMatch = false;
|
|
832
|
+
for (const field of searchIn) {
|
|
833
|
+
if (field === 'title' && market.title?.toLowerCase().includes(lowerQuery)) {
|
|
834
|
+
textMatch = true;
|
|
835
|
+
break;
|
|
836
|
+
}
|
|
837
|
+
if (field === 'description' && market.description?.toLowerCase().includes(lowerQuery)) {
|
|
838
|
+
textMatch = true;
|
|
839
|
+
break;
|
|
840
|
+
}
|
|
841
|
+
if (field === 'category' && market.category?.toLowerCase().includes(lowerQuery)) {
|
|
842
|
+
textMatch = true;
|
|
843
|
+
break;
|
|
844
|
+
}
|
|
845
|
+
if (field === 'tags' && market.tags?.some(tag => tag.toLowerCase().includes(lowerQuery))) {
|
|
846
|
+
textMatch = true;
|
|
847
|
+
break;
|
|
848
|
+
}
|
|
849
|
+
if (field === 'outcomes' && market.outcomes?.some(o => o.label.toLowerCase().includes(lowerQuery))) {
|
|
850
|
+
textMatch = true;
|
|
851
|
+
break;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
if (!textMatch)
|
|
855
|
+
return false;
|
|
856
|
+
}
|
|
857
|
+
// Category filter
|
|
858
|
+
if (criteria.category && market.category !== criteria.category) {
|
|
859
|
+
return false;
|
|
860
|
+
}
|
|
861
|
+
// Tags filter (match ANY of the provided tags)
|
|
862
|
+
if (criteria.tags && criteria.tags.length > 0) {
|
|
863
|
+
const hasMatchingTag = criteria.tags.some(tag => market.tags?.some(marketTag => marketTag.toLowerCase() === tag.toLowerCase()));
|
|
864
|
+
if (!hasMatchingTag)
|
|
865
|
+
return false;
|
|
866
|
+
}
|
|
867
|
+
// Volume24h filter
|
|
868
|
+
if (criteria.volume24h) {
|
|
869
|
+
if (criteria.volume24h.min !== undefined && market.volume24h < criteria.volume24h.min) {
|
|
870
|
+
return false;
|
|
871
|
+
}
|
|
872
|
+
if (criteria.volume24h.max !== undefined && market.volume24h > criteria.volume24h.max) {
|
|
873
|
+
return false;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
// Volume filter
|
|
877
|
+
if (criteria.volume) {
|
|
878
|
+
if (criteria.volume.min !== undefined && (market.volume || 0) < criteria.volume.min) {
|
|
879
|
+
return false;
|
|
880
|
+
}
|
|
881
|
+
if (criteria.volume.max !== undefined && (market.volume || 0) > criteria.volume.max) {
|
|
882
|
+
return false;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
// Liquidity filter
|
|
886
|
+
if (criteria.liquidity) {
|
|
887
|
+
if (criteria.liquidity.min !== undefined && market.liquidity < criteria.liquidity.min) {
|
|
888
|
+
return false;
|
|
889
|
+
}
|
|
890
|
+
if (criteria.liquidity.max !== undefined && market.liquidity > criteria.liquidity.max) {
|
|
891
|
+
return false;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
// OpenInterest filter
|
|
895
|
+
if (criteria.openInterest) {
|
|
896
|
+
if (criteria.openInterest.min !== undefined && (market.openInterest || 0) < criteria.openInterest.min) {
|
|
897
|
+
return false;
|
|
898
|
+
}
|
|
899
|
+
if (criteria.openInterest.max !== undefined && (market.openInterest || 0) > criteria.openInterest.max) {
|
|
900
|
+
return false;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
// ResolutionDate filter
|
|
904
|
+
if (criteria.resolutionDate && market.resolutionDate) {
|
|
905
|
+
const resDate = market.resolutionDate;
|
|
906
|
+
if (criteria.resolutionDate.before && resDate >= criteria.resolutionDate.before) {
|
|
907
|
+
return false;
|
|
908
|
+
}
|
|
909
|
+
if (criteria.resolutionDate.after && resDate <= criteria.resolutionDate.after) {
|
|
910
|
+
return false;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
// Price filter (for binary markets)
|
|
914
|
+
if (criteria.price) {
|
|
915
|
+
const outcome = market[criteria.price.outcome];
|
|
916
|
+
if (!outcome)
|
|
917
|
+
return false;
|
|
918
|
+
if (criteria.price.min !== undefined && outcome.price < criteria.price.min) {
|
|
919
|
+
return false;
|
|
920
|
+
}
|
|
921
|
+
if (criteria.price.max !== undefined && outcome.price > criteria.price.max) {
|
|
922
|
+
return false;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
// Price change filter
|
|
926
|
+
if (criteria.priceChange24h) {
|
|
927
|
+
const outcome = market[criteria.priceChange24h.outcome];
|
|
928
|
+
if (!outcome || outcome.priceChange24h === undefined)
|
|
929
|
+
return false;
|
|
930
|
+
if (criteria.priceChange24h.min !== undefined && outcome.priceChange24h < criteria.priceChange24h.min) {
|
|
931
|
+
return false;
|
|
932
|
+
}
|
|
933
|
+
if (criteria.priceChange24h.max !== undefined && outcome.priceChange24h > criteria.priceChange24h.max) {
|
|
934
|
+
return false;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
return true;
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* Filter events based on criteria or custom function.
|
|
942
|
+
*
|
|
943
|
+
* @param events - Array of events to filter
|
|
944
|
+
* @param criteria - Filter criteria object, string (simple text search), or predicate function
|
|
945
|
+
* @returns Filtered array of events
|
|
946
|
+
*
|
|
947
|
+
* @example Simple text search
|
|
948
|
+
* api.filterEvents(events, 'Trump')
|
|
949
|
+
*
|
|
950
|
+
* @example Advanced filtering
|
|
951
|
+
* api.filterEvents(events, {
|
|
952
|
+
* text: 'Election',
|
|
953
|
+
* searchIn: ['title', 'tags'],
|
|
954
|
+
* category: 'Politics',
|
|
955
|
+
* marketCount: { min: 5 }
|
|
956
|
+
* })
|
|
957
|
+
*
|
|
958
|
+
* @example Custom predicate
|
|
959
|
+
* api.filterEvents(events, e => e.markets.length > 10)
|
|
960
|
+
*/
|
|
961
|
+
filterEvents(events, criteria) {
|
|
962
|
+
// Handle predicate function
|
|
963
|
+
if (typeof criteria === 'function') {
|
|
964
|
+
return events.filter(criteria);
|
|
965
|
+
}
|
|
966
|
+
// Handle simple string search
|
|
967
|
+
if (typeof criteria === 'string') {
|
|
968
|
+
const lowerQuery = criteria.toLowerCase();
|
|
969
|
+
return events.filter(e => e.title.toLowerCase().includes(lowerQuery));
|
|
970
|
+
}
|
|
971
|
+
// Handle criteria object
|
|
972
|
+
return events.filter(event => {
|
|
973
|
+
// Text search
|
|
974
|
+
if (criteria.text) {
|
|
975
|
+
const lowerQuery = criteria.text.toLowerCase();
|
|
976
|
+
const searchIn = criteria.searchIn || ['title'];
|
|
977
|
+
let textMatch = false;
|
|
978
|
+
for (const field of searchIn) {
|
|
979
|
+
if (field === 'title' && event.title?.toLowerCase().includes(lowerQuery)) {
|
|
980
|
+
textMatch = true;
|
|
981
|
+
break;
|
|
982
|
+
}
|
|
983
|
+
if (field === 'description' && event.description?.toLowerCase().includes(lowerQuery)) {
|
|
984
|
+
textMatch = true;
|
|
985
|
+
break;
|
|
986
|
+
}
|
|
987
|
+
if (field === 'category' && event.category?.toLowerCase().includes(lowerQuery)) {
|
|
988
|
+
textMatch = true;
|
|
989
|
+
break;
|
|
990
|
+
}
|
|
991
|
+
if (field === 'tags' && event.tags?.some(tag => tag.toLowerCase().includes(lowerQuery))) {
|
|
992
|
+
textMatch = true;
|
|
993
|
+
break;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
if (!textMatch)
|
|
997
|
+
return false;
|
|
998
|
+
}
|
|
999
|
+
// Category filter
|
|
1000
|
+
if (criteria.category && event.category !== criteria.category) {
|
|
1001
|
+
return false;
|
|
1002
|
+
}
|
|
1003
|
+
// Tags filter (match ANY of the provided tags)
|
|
1004
|
+
if (criteria.tags && criteria.tags.length > 0) {
|
|
1005
|
+
const hasMatchingTag = criteria.tags.some(tag => event.tags?.some(eventTag => eventTag.toLowerCase() === tag.toLowerCase()));
|
|
1006
|
+
if (!hasMatchingTag)
|
|
1007
|
+
return false;
|
|
1008
|
+
}
|
|
1009
|
+
// Market count filter
|
|
1010
|
+
if (criteria.marketCount) {
|
|
1011
|
+
const count = event.markets.length;
|
|
1012
|
+
if (criteria.marketCount.min !== undefined && count < criteria.marketCount.min) {
|
|
1013
|
+
return false;
|
|
1014
|
+
}
|
|
1015
|
+
if (criteria.marketCount.max !== undefined && count > criteria.marketCount.max) {
|
|
1016
|
+
return false;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
// Total volume filter
|
|
1020
|
+
if (criteria.totalVolume) {
|
|
1021
|
+
const totalVolume = event.markets.reduce((sum, m) => sum + m.volume24h, 0);
|
|
1022
|
+
if (criteria.totalVolume.min !== undefined && totalVolume < criteria.totalVolume.min) {
|
|
1023
|
+
return false;
|
|
1024
|
+
}
|
|
1025
|
+
if (criteria.totalVolume.max !== undefined && totalVolume > criteria.totalVolume.max) {
|
|
1026
|
+
return false;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
return true;
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
787
1032
|
}
|
|
788
1033
|
/**
|
|
789
1034
|
* Polymarket exchange client.
|
|
@@ -234,6 +234,8 @@ export interface CreateOrderParams {
|
|
|
234
234
|
amount: number;
|
|
235
235
|
/** Limit price (required for limit orders, 0.0-1.0) */
|
|
236
236
|
price?: number;
|
|
237
|
+
/** Optional fee rate (e.g., 1000 for 0.1%) */
|
|
238
|
+
fee?: number;
|
|
237
239
|
}
|
|
238
240
|
/**
|
|
239
241
|
* A grouped collection of related markets (e.g., "Who will be Fed Chair?" contains multiple candidate markets)
|
|
@@ -266,3 +268,85 @@ export interface UnifiedEvent {
|
|
|
266
268
|
*/
|
|
267
269
|
searchMarkets(query: string, searchIn?: SearchIn): UnifiedMarket[];
|
|
268
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Advanced criteria for filtering markets.
|
|
273
|
+
* Supports text search, numeric ranges, dates, categories, and price filters.
|
|
274
|
+
*/
|
|
275
|
+
export interface MarketFilterCriteria {
|
|
276
|
+
/** Text search query */
|
|
277
|
+
text?: string;
|
|
278
|
+
/** Fields to search in (default: ['title']) */
|
|
279
|
+
searchIn?: ('title' | 'description' | 'category' | 'tags' | 'outcomes')[];
|
|
280
|
+
/** Filter by 24-hour volume */
|
|
281
|
+
volume24h?: {
|
|
282
|
+
min?: number;
|
|
283
|
+
max?: number;
|
|
284
|
+
};
|
|
285
|
+
/** Filter by total volume */
|
|
286
|
+
volume?: {
|
|
287
|
+
min?: number;
|
|
288
|
+
max?: number;
|
|
289
|
+
};
|
|
290
|
+
/** Filter by liquidity */
|
|
291
|
+
liquidity?: {
|
|
292
|
+
min?: number;
|
|
293
|
+
max?: number;
|
|
294
|
+
};
|
|
295
|
+
/** Filter by open interest */
|
|
296
|
+
openInterest?: {
|
|
297
|
+
min?: number;
|
|
298
|
+
max?: number;
|
|
299
|
+
};
|
|
300
|
+
/** Filter by resolution date */
|
|
301
|
+
resolutionDate?: {
|
|
302
|
+
before?: Date;
|
|
303
|
+
after?: Date;
|
|
304
|
+
};
|
|
305
|
+
/** Filter by category */
|
|
306
|
+
category?: string;
|
|
307
|
+
/** Filter by tags (matches if market has ANY of these) */
|
|
308
|
+
tags?: string[];
|
|
309
|
+
/** Filter by outcome price (for binary markets) */
|
|
310
|
+
price?: {
|
|
311
|
+
outcome: 'yes' | 'no' | 'up' | 'down';
|
|
312
|
+
min?: number;
|
|
313
|
+
max?: number;
|
|
314
|
+
};
|
|
315
|
+
/** Filter by 24-hour price change */
|
|
316
|
+
priceChange24h?: {
|
|
317
|
+
outcome: 'yes' | 'no' | 'up' | 'down';
|
|
318
|
+
min?: number;
|
|
319
|
+
max?: number;
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Function type for custom market filtering logic.
|
|
324
|
+
*/
|
|
325
|
+
export type MarketFilterFunction = (market: UnifiedMarket) => boolean;
|
|
326
|
+
/**
|
|
327
|
+
* Advanced criteria for filtering events.
|
|
328
|
+
*/
|
|
329
|
+
export interface EventFilterCriteria {
|
|
330
|
+
/** Text search query */
|
|
331
|
+
text?: string;
|
|
332
|
+
/** Fields to search in (default: ['title']) */
|
|
333
|
+
searchIn?: ('title' | 'description' | 'category' | 'tags')[];
|
|
334
|
+
/** Filter by category */
|
|
335
|
+
category?: string;
|
|
336
|
+
/** Filter by tags (matches if event has ANY of these) */
|
|
337
|
+
tags?: string[];
|
|
338
|
+
/** Filter by number of markets in the event */
|
|
339
|
+
marketCount?: {
|
|
340
|
+
min?: number;
|
|
341
|
+
max?: number;
|
|
342
|
+
};
|
|
343
|
+
/** Filter by total volume across all markets */
|
|
344
|
+
totalVolume?: {
|
|
345
|
+
min?: number;
|
|
346
|
+
max?: number;
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Function type for custom event filtering logic.
|
|
351
|
+
*/
|
|
352
|
+
export type EventFilterFunction = (event: UnifiedEvent) => boolean;
|
|
@@ -44,5 +44,13 @@ export declare class ServerManager {
|
|
|
44
44
|
*/
|
|
45
45
|
ensureServerRunning(): Promise<void>;
|
|
46
46
|
private isVersionMismatch;
|
|
47
|
+
/**
|
|
48
|
+
* Stop the currently running server.
|
|
49
|
+
*/
|
|
50
|
+
stop(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Restart the server.
|
|
53
|
+
*/
|
|
54
|
+
restart(): Promise<void>;
|
|
47
55
|
private killOldServer;
|
|
48
56
|
}
|
|
@@ -170,6 +170,19 @@ export class ServerManager {
|
|
|
170
170
|
}
|
|
171
171
|
return false;
|
|
172
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Stop the currently running server.
|
|
175
|
+
*/
|
|
176
|
+
async stop() {
|
|
177
|
+
await this.killOldServer();
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Restart the server.
|
|
181
|
+
*/
|
|
182
|
+
async restart() {
|
|
183
|
+
await this.stop();
|
|
184
|
+
await this.ensureServerRunning();
|
|
185
|
+
}
|
|
173
186
|
async killOldServer() {
|
|
174
187
|
const info = this.getServerInfo();
|
|
175
188
|
if (info && info.pid) {
|
|
@@ -63,6 +63,7 @@ function CreateOrderParamsFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
63
63
|
'type': json['type'],
|
|
64
64
|
'amount': json['amount'],
|
|
65
65
|
'price': json['price'] == null ? undefined : json['price'],
|
|
66
|
+
'fee': json['fee'] == null ? undefined : json['fee'],
|
|
66
67
|
};
|
|
67
68
|
}
|
|
68
69
|
function CreateOrderParamsToJSON(json) {
|
|
@@ -79,5 +80,6 @@ function CreateOrderParamsToJSONTyped(value, ignoreDiscriminator = false) {
|
|
|
79
80
|
'type': value['type'],
|
|
80
81
|
'amount': value['amount'],
|
|
81
82
|
'price': value['price'],
|
|
83
|
+
'fee': value['fee'],
|
|
82
84
|
};
|
|
83
85
|
}
|
|
@@ -16,11 +16,18 @@
|
|
|
16
16
|
*/
|
|
17
17
|
export interface MarketOutcome {
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* DEPRECATED: Use outcomeId instead. Will be removed in v2.0
|
|
20
20
|
* @type {string}
|
|
21
21
|
* @memberof MarketOutcome
|
|
22
|
+
* @deprecated
|
|
22
23
|
*/
|
|
23
24
|
id?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Outcome ID for trading operations (CLOB Token ID for Polymarket, Market Ticker for Kalshi)
|
|
27
|
+
* @type {string}
|
|
28
|
+
* @memberof MarketOutcome
|
|
29
|
+
*/
|
|
30
|
+
outcomeId?: string;
|
|
24
31
|
/**
|
|
25
32
|
*
|
|
26
33
|
* @type {string}
|
|
@@ -33,6 +33,7 @@ function MarketOutcomeFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
33
33
|
}
|
|
34
34
|
return {
|
|
35
35
|
'id': json['id'] == null ? undefined : json['id'],
|
|
36
|
+
'outcomeId': json['outcomeId'] == null ? undefined : json['outcomeId'],
|
|
36
37
|
'label': json['label'] == null ? undefined : json['label'],
|
|
37
38
|
'price': json['price'] == null ? undefined : json['price'],
|
|
38
39
|
'priceChange24h': json['priceChange24h'] == null ? undefined : json['priceChange24h'],
|
|
@@ -48,6 +49,7 @@ function MarketOutcomeToJSONTyped(value, ignoreDiscriminator = false) {
|
|
|
48
49
|
}
|
|
49
50
|
return {
|
|
50
51
|
'id': value['id'],
|
|
52
|
+
'outcomeId': value['outcomeId'],
|
|
51
53
|
'label': value['label'],
|
|
52
54
|
'price': value['price'],
|
|
53
55
|
'priceChange24h': value['priceChange24h'],
|
|
@@ -17,11 +17,18 @@ import type { MarketOutcome } from './MarketOutcome';
|
|
|
17
17
|
*/
|
|
18
18
|
export interface UnifiedMarket {
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* DEPRECATED: Use marketId instead. Will be removed in v2.0
|
|
21
21
|
* @type {string}
|
|
22
22
|
* @memberof UnifiedMarket
|
|
23
|
+
* @deprecated
|
|
23
24
|
*/
|
|
24
25
|
id?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The unique identifier for this market
|
|
28
|
+
* @type {string}
|
|
29
|
+
* @memberof UnifiedMarket
|
|
30
|
+
*/
|
|
31
|
+
marketId?: string;
|
|
25
32
|
/**
|
|
26
33
|
*
|
|
27
34
|
* @type {string}
|