pmxt-core 2.8.0 → 2.9.1
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/BaseExchange.d.ts +48 -0
- package/dist/BaseExchange.js +116 -0
- package/dist/exchanges/kalshi/api.d.ts +1763 -0
- package/dist/exchanges/kalshi/api.js +2554 -0
- package/dist/exchanges/kalshi/fetchEvents.d.ts +3 -2
- package/dist/exchanges/kalshi/fetchEvents.js +9 -16
- package/dist/exchanges/kalshi/fetchMarkets.d.ts +3 -2
- package/dist/exchanges/kalshi/fetchMarkets.js +24 -32
- package/dist/exchanges/kalshi/fetchOHLCV.d.ts +1 -2
- package/dist/exchanges/kalshi/fetchOHLCV.js +9 -11
- package/dist/exchanges/kalshi/index.d.ts +2 -1
- package/dist/exchanges/kalshi/index.js +161 -183
- package/dist/exchanges/kalshi/kalshi.test.js +51 -31
- package/dist/exchanges/limitless/api.d.ts +555 -0
- package/dist/exchanges/limitless/api.js +863 -0
- package/dist/exchanges/limitless/fetchEvents.d.ts +1 -2
- package/dist/exchanges/limitless/fetchEvents.js +9 -15
- package/dist/exchanges/limitless/fetchMarkets.d.ts +1 -2
- package/dist/exchanges/limitless/fetchMarkets.js +9 -16
- package/dist/exchanges/limitless/fetchOHLCV.d.ts +1 -2
- package/dist/exchanges/limitless/fetchOHLCV.js +2 -11
- package/dist/exchanges/limitless/fetchOrderBook.d.ts +1 -2
- package/dist/exchanges/limitless/fetchOrderBook.js +2 -11
- package/dist/exchanges/limitless/index.d.ts +1 -0
- package/dist/exchanges/limitless/index.js +28 -7
- package/dist/exchanges/limitless/websocket.d.ts +2 -1
- package/dist/exchanges/limitless/websocket.js +6 -4
- package/dist/exchanges/myriad/api.d.ts +294 -0
- package/dist/exchanges/myriad/api.js +690 -0
- package/dist/exchanges/myriad/fetchOHLCV.d.ts +1 -2
- package/dist/exchanges/myriad/fetchOHLCV.js +3 -11
- package/dist/exchanges/myriad/fetchOrderBook.d.ts +1 -2
- package/dist/exchanges/myriad/fetchOrderBook.js +3 -11
- package/dist/exchanges/myriad/index.d.ts +2 -0
- package/dist/exchanges/myriad/index.js +116 -103
- package/dist/exchanges/myriad/websocket.d.ts +2 -2
- package/dist/exchanges/myriad/websocket.js +28 -6
- package/dist/exchanges/polymarket/api-clob.d.ts +346 -0
- package/dist/exchanges/polymarket/api-clob.js +517 -0
- package/dist/exchanges/polymarket/api-data.d.ts +789 -0
- package/dist/exchanges/polymarket/api-data.js +860 -0
- package/dist/exchanges/polymarket/api-gamma.d.ts +556 -0
- package/dist/exchanges/polymarket/api-gamma.js +1161 -0
- package/dist/exchanges/polymarket/fetchEvents.js +0 -68
- package/dist/exchanges/polymarket/fetchOHLCV.d.ts +1 -2
- package/dist/exchanges/polymarket/fetchOHLCV.js +4 -10
- package/dist/exchanges/polymarket/fetchOrderBook.d.ts +1 -2
- package/dist/exchanges/polymarket/fetchOrderBook.js +2 -10
- package/dist/exchanges/polymarket/fetchTrades.d.ts +1 -2
- package/dist/exchanges/polymarket/fetchTrades.js +2 -11
- package/dist/exchanges/polymarket/index.d.ts +10 -0
- package/dist/exchanges/polymarket/index.js +110 -5
- package/dist/exchanges/probable/api.d.ts +605 -0
- package/dist/exchanges/probable/api.js +887 -0
- package/dist/exchanges/probable/fetchEvents.d.ts +3 -3
- package/dist/exchanges/probable/fetchEvents.js +28 -25
- package/dist/exchanges/probable/fetchMarkets.d.ts +1 -1
- package/dist/exchanges/probable/fetchMarkets.js +25 -21
- package/dist/exchanges/probable/index.d.ts +1 -0
- package/dist/exchanges/probable/index.js +92 -10
- package/dist/exchanges/probable/utils.d.ts +1 -2
- package/dist/exchanges/probable/utils.js +4 -11
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/utils/openapi.d.ts +9 -0
- package/dist/utils/openapi.js +59 -0
- package/package.json +4 -3
- package/dist/exchanges/kalshi/fetchOrderBook.d.ts +0 -3
- package/dist/exchanges/kalshi/fetchOrderBook.js +0 -59
- package/dist/exchanges/kalshi/fetchTrades.d.ts +0 -4
- package/dist/exchanges/kalshi/fetchTrades.js +0 -31
- package/dist/exchanges/limitless/fetchPositions.d.ts +0 -2
- package/dist/exchanges/limitless/fetchPositions.js +0 -34
- package/dist/exchanges/myriad/fetchTrades.d.ts +0 -4
- package/dist/exchanges/myriad/fetchTrades.js +0 -62
- package/dist/exchanges/polymarket/fetchPositions.d.ts +0 -2
- package/dist/exchanges/polymarket/fetchPositions.js +0 -34
- package/dist/exchanges/probable/fetchOHLCV.d.ts +0 -4
- package/dist/exchanges/probable/fetchOHLCV.js +0 -83
- package/dist/exchanges/probable/fetchOrderBook.d.ts +0 -3
- package/dist/exchanges/probable/fetchOrderBook.js +0 -37
- package/dist/exchanges/probable/fetchPositions.d.ts +0 -2
- package/dist/exchanges/probable/fetchPositions.js +0 -33
package/dist/BaseExchange.d.ts
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import { UnifiedMarket, UnifiedEvent, PriceCandle, CandleInterval, OrderBook, Trade, Order, Position, Balance, CreateOrderParams } from './types';
|
|
2
2
|
import { ExecutionPriceResult } from './utils/math';
|
|
3
3
|
import { AxiosInstance } from 'axios';
|
|
4
|
+
export interface ApiEndpoint {
|
|
5
|
+
method: string;
|
|
6
|
+
path: string;
|
|
7
|
+
isPrivate?: boolean;
|
|
8
|
+
operationId?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ApiDescriptor {
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
endpoints: Record<string, ApiEndpoint>;
|
|
13
|
+
}
|
|
14
|
+
export interface ImplicitApiMethodInfo {
|
|
15
|
+
name: string;
|
|
16
|
+
method: string;
|
|
17
|
+
path: string;
|
|
18
|
+
isPrivate: boolean;
|
|
19
|
+
}
|
|
4
20
|
export interface MarketFilterParams {
|
|
5
21
|
limit?: number;
|
|
6
22
|
offset?: number;
|
|
@@ -120,12 +136,15 @@ export interface ExchangeCredentials {
|
|
|
120
136
|
funderAddress?: string;
|
|
121
137
|
}
|
|
122
138
|
export declare abstract class PredictionMarketExchange {
|
|
139
|
+
[key: string]: any;
|
|
123
140
|
protected credentials?: ExchangeCredentials;
|
|
124
141
|
verbose: boolean;
|
|
125
142
|
http: AxiosInstance;
|
|
126
143
|
markets: Record<string, UnifiedMarket>;
|
|
127
144
|
marketsBySlug: Record<string, UnifiedMarket>;
|
|
128
145
|
loadedMarkets: boolean;
|
|
146
|
+
protected apiDescriptor?: ApiDescriptor;
|
|
147
|
+
private apiDescriptors;
|
|
129
148
|
readonly has: ExchangeHas;
|
|
130
149
|
constructor(credentials?: ExchangeCredentials);
|
|
131
150
|
abstract get name(): string;
|
|
@@ -595,4 +614,33 @@ export declare abstract class PredictionMarketExchange {
|
|
|
595
614
|
* exchange.close()
|
|
596
615
|
*/
|
|
597
616
|
close(): Promise<void>;
|
|
617
|
+
/**
|
|
618
|
+
* Call an implicit API method by its operationId (or auto-generated name).
|
|
619
|
+
* Provides a typed entry point so unified methods can delegate to the implicit API
|
|
620
|
+
* without casting to `any` everywhere.
|
|
621
|
+
*/
|
|
622
|
+
protected callApi(operationId: string, params?: Record<string, any>): Promise<any>;
|
|
623
|
+
/**
|
|
624
|
+
* Parse an API descriptor and generate callable methods on this instance.
|
|
625
|
+
* Existing methods (unified API) are never overwritten.
|
|
626
|
+
*/
|
|
627
|
+
protected defineImplicitApi(descriptor: ApiDescriptor): void;
|
|
628
|
+
/**
|
|
629
|
+
* Creates an async function for an implicit API endpoint.
|
|
630
|
+
*/
|
|
631
|
+
private createImplicitMethod;
|
|
632
|
+
/**
|
|
633
|
+
* Returns auth headers for a private API call.
|
|
634
|
+
* Exchanges should override this to provide authentication.
|
|
635
|
+
*/
|
|
636
|
+
protected sign(_method: string, _path: string, _params: Record<string, any>): Record<string, string>;
|
|
637
|
+
/**
|
|
638
|
+
* Maps errors from implicit API calls through the exchange's error mapper.
|
|
639
|
+
* Exchanges should override this to use their specific error mapper.
|
|
640
|
+
*/
|
|
641
|
+
protected mapImplicitApiError(error: any): any;
|
|
642
|
+
/**
|
|
643
|
+
* Introspection getter: returns info about all implicit API methods.
|
|
644
|
+
*/
|
|
645
|
+
get implicitApi(): ImplicitApiMethodInfo[];
|
|
598
646
|
}
|
package/dist/BaseExchange.js
CHANGED
|
@@ -18,6 +18,9 @@ class PredictionMarketExchange {
|
|
|
18
18
|
markets = {};
|
|
19
19
|
marketsBySlug = {};
|
|
20
20
|
loadedMarkets = false;
|
|
21
|
+
// Implicit API (merged across multiple defineImplicitApi calls)
|
|
22
|
+
apiDescriptor;
|
|
23
|
+
apiDescriptors = [];
|
|
21
24
|
has = {
|
|
22
25
|
fetchMarkets: false,
|
|
23
26
|
fetchEvents: false,
|
|
@@ -825,5 +828,118 @@ class PredictionMarketExchange {
|
|
|
825
828
|
// Default implementation: no-op
|
|
826
829
|
// Exchanges with WebSocket support should override this
|
|
827
830
|
}
|
|
831
|
+
// ----------------------------------------------------------------------------
|
|
832
|
+
// Implicit API (OpenAPI-driven method generation)
|
|
833
|
+
// ----------------------------------------------------------------------------
|
|
834
|
+
/**
|
|
835
|
+
* Call an implicit API method by its operationId (or auto-generated name).
|
|
836
|
+
* Provides a typed entry point so unified methods can delegate to the implicit API
|
|
837
|
+
* without casting to `any` everywhere.
|
|
838
|
+
*/
|
|
839
|
+
async callApi(operationId, params) {
|
|
840
|
+
const method = this[operationId];
|
|
841
|
+
if (typeof method !== 'function') {
|
|
842
|
+
throw new Error(`Implicit API method "${operationId}" not found on ${this.name}`);
|
|
843
|
+
}
|
|
844
|
+
return method.call(this, params);
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* Parse an API descriptor and generate callable methods on this instance.
|
|
848
|
+
* Existing methods (unified API) are never overwritten.
|
|
849
|
+
*/
|
|
850
|
+
defineImplicitApi(descriptor) {
|
|
851
|
+
this.apiDescriptors.push(descriptor);
|
|
852
|
+
// Merge into a single apiDescriptor for the implicitApi getter
|
|
853
|
+
if (!this.apiDescriptor) {
|
|
854
|
+
this.apiDescriptor = { baseUrl: descriptor.baseUrl, endpoints: { ...descriptor.endpoints } };
|
|
855
|
+
}
|
|
856
|
+
else {
|
|
857
|
+
Object.assign(this.apiDescriptor.endpoints, descriptor.endpoints);
|
|
858
|
+
}
|
|
859
|
+
for (const [name, endpoint] of Object.entries(descriptor.endpoints)) {
|
|
860
|
+
// Never overwrite existing methods (unified API wins)
|
|
861
|
+
if (name in this) {
|
|
862
|
+
continue;
|
|
863
|
+
}
|
|
864
|
+
this[name] = this.createImplicitMethod(name, endpoint, descriptor.baseUrl);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Creates an async function for an implicit API endpoint.
|
|
869
|
+
*/
|
|
870
|
+
createImplicitMethod(name, endpoint, baseUrl) {
|
|
871
|
+
return async (params) => {
|
|
872
|
+
const allParams = { ...(params || {}) };
|
|
873
|
+
// Substitute path parameters like {ticker} from params
|
|
874
|
+
let resolvedPath = endpoint.path.replace(/\{([^}]+)\}/g, (_match, key) => {
|
|
875
|
+
const value = allParams[key];
|
|
876
|
+
if (value === undefined) {
|
|
877
|
+
throw new Error(`Missing required path parameter "${key}" for ${name}(). ` +
|
|
878
|
+
`Path: ${endpoint.path}`);
|
|
879
|
+
}
|
|
880
|
+
delete allParams[key];
|
|
881
|
+
return encodeURIComponent(String(value));
|
|
882
|
+
});
|
|
883
|
+
// Get auth headers for private endpoints
|
|
884
|
+
let headers = {};
|
|
885
|
+
if (endpoint.isPrivate) {
|
|
886
|
+
headers = this.sign(endpoint.method, resolvedPath, allParams);
|
|
887
|
+
}
|
|
888
|
+
const url = `${baseUrl}${resolvedPath}`;
|
|
889
|
+
const method = endpoint.method.toUpperCase();
|
|
890
|
+
try {
|
|
891
|
+
let response;
|
|
892
|
+
if (method === 'GET' || method === 'DELETE') {
|
|
893
|
+
// Remaining params go to query string
|
|
894
|
+
response = await this.http.request({
|
|
895
|
+
method: method,
|
|
896
|
+
url,
|
|
897
|
+
params: Object.keys(allParams).length > 0 ? allParams : undefined,
|
|
898
|
+
headers,
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
else {
|
|
902
|
+
// POST/PUT/PATCH: remaining params go to JSON body
|
|
903
|
+
response = await this.http.request({
|
|
904
|
+
method: method,
|
|
905
|
+
url,
|
|
906
|
+
data: Object.keys(allParams).length > 0 ? allParams : undefined,
|
|
907
|
+
headers: { 'Content-Type': 'application/json', ...headers },
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
return response.data;
|
|
911
|
+
}
|
|
912
|
+
catch (error) {
|
|
913
|
+
throw this.mapImplicitApiError(error);
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Returns auth headers for a private API call.
|
|
919
|
+
* Exchanges should override this to provide authentication.
|
|
920
|
+
*/
|
|
921
|
+
sign(_method, _path, _params) {
|
|
922
|
+
return {};
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Maps errors from implicit API calls through the exchange's error mapper.
|
|
926
|
+
* Exchanges should override this to use their specific error mapper.
|
|
927
|
+
*/
|
|
928
|
+
mapImplicitApiError(error) {
|
|
929
|
+
throw error;
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Introspection getter: returns info about all implicit API methods.
|
|
933
|
+
*/
|
|
934
|
+
get implicitApi() {
|
|
935
|
+
if (!this.apiDescriptor)
|
|
936
|
+
return [];
|
|
937
|
+
return Object.entries(this.apiDescriptor.endpoints).map(([name, endpoint]) => ({
|
|
938
|
+
name,
|
|
939
|
+
method: endpoint.method,
|
|
940
|
+
path: endpoint.path,
|
|
941
|
+
isPrivate: !!endpoint.isPrivate,
|
|
942
|
+
}));
|
|
943
|
+
}
|
|
828
944
|
}
|
|
829
945
|
exports.PredictionMarketExchange = PredictionMarketExchange;
|