pmxt-core 2.1.2 → 2.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.
|
@@ -20,12 +20,13 @@ export declare class PolymarketExchange extends PredictionMarketExchange {
|
|
|
20
20
|
* Ensure authentication is initialized before trading operations.
|
|
21
21
|
*/
|
|
22
22
|
private ensureAuth;
|
|
23
|
-
createOrder(params: CreateOrderParams): Promise<Order>;
|
|
24
23
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
24
|
+
* Pre-warm the SDK's internal caches for a token by fetching tick size,
|
|
25
|
+
* fee rate, and neg-risk in parallel. Call this when you start watching
|
|
26
|
+
* a market so that subsequent createOrder calls hit only POST /order.
|
|
27
27
|
*/
|
|
28
|
-
|
|
28
|
+
preWarmMarket(outcomeId: string): Promise<void>;
|
|
29
|
+
createOrder(params: CreateOrderParams): Promise<Order>;
|
|
29
30
|
cancelOrder(orderId: string): Promise<Order>;
|
|
30
31
|
fetchOrder(orderId: string): Promise<Order>;
|
|
31
32
|
fetchOpenOrders(marketId?: string): Promise<Order[]>;
|
|
@@ -73,6 +73,20 @@ class PolymarketExchange extends BaseExchange_1.PredictionMarketExchange {
|
|
|
73
73
|
}
|
|
74
74
|
return this.auth;
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Pre-warm the SDK's internal caches for a token by fetching tick size,
|
|
78
|
+
* fee rate, and neg-risk in parallel. Call this when you start watching
|
|
79
|
+
* a market so that subsequent createOrder calls hit only POST /order.
|
|
80
|
+
*/
|
|
81
|
+
async preWarmMarket(outcomeId) {
|
|
82
|
+
const auth = this.ensureAuth();
|
|
83
|
+
const client = await auth.getClobClient();
|
|
84
|
+
await Promise.all([
|
|
85
|
+
client.getTickSize(outcomeId),
|
|
86
|
+
client.getFeeRateBps(outcomeId),
|
|
87
|
+
client.getNegRisk(outcomeId),
|
|
88
|
+
]);
|
|
89
|
+
}
|
|
76
90
|
async createOrder(params) {
|
|
77
91
|
try {
|
|
78
92
|
const auth = this.ensureAuth();
|
|
@@ -85,22 +99,8 @@ class PolymarketExchange extends BaseExchange_1.PredictionMarketExchange {
|
|
|
85
99
|
}
|
|
86
100
|
// For market orders, use max slippage: 0.99 for BUY (willing to pay up to 99%), 0.01 for SELL (willing to accept down to 1%)
|
|
87
101
|
const price = params.price || (side === clob_client_1.Side.BUY ? 0.99 : 0.01);
|
|
88
|
-
//
|
|
89
|
-
|
|
90
|
-
if (params.tickSize) {
|
|
91
|
-
tickSize = params.tickSize.toString();
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
// Fetch the order book to infer tick size from price levels
|
|
95
|
-
try {
|
|
96
|
-
const orderBook = await this.fetchOrderBook(params.outcomeId);
|
|
97
|
-
tickSize = this.inferTickSize(orderBook);
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
// Fallback to 0.01 if order book fetch fails (standard for Polymarket)
|
|
101
|
-
tickSize = "0.01";
|
|
102
|
-
}
|
|
103
|
-
}
|
|
102
|
+
// Use provided tickSize, or let the SDK resolve it from its own cache / API
|
|
103
|
+
const tickSize = params.tickSize ? params.tickSize.toString() : undefined;
|
|
104
104
|
const orderArgs = {
|
|
105
105
|
tokenID: params.outcomeId,
|
|
106
106
|
price: price,
|
|
@@ -110,10 +110,14 @@ class PolymarketExchange extends BaseExchange_1.PredictionMarketExchange {
|
|
|
110
110
|
if (params.fee !== undefined && params.fee !== null) {
|
|
111
111
|
orderArgs.feeRateBps = params.fee;
|
|
112
112
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
tickSize
|
|
116
|
-
}
|
|
113
|
+
const options = {};
|
|
114
|
+
if (tickSize) {
|
|
115
|
+
options.tickSize = tickSize;
|
|
116
|
+
}
|
|
117
|
+
if (params.negRisk !== undefined) {
|
|
118
|
+
options.negRisk = params.negRisk;
|
|
119
|
+
}
|
|
120
|
+
const response = await client.createAndPostOrder(orderArgs, options);
|
|
117
121
|
if (!response || !response.success) {
|
|
118
122
|
throw new Error(`${response?.errorMsg || 'Order placement failed'} (Response: ${JSON.stringify(response)})`);
|
|
119
123
|
}
|
|
@@ -136,40 +140,6 @@ class PolymarketExchange extends BaseExchange_1.PredictionMarketExchange {
|
|
|
136
140
|
throw errors_1.polymarketErrorMapper.mapError(error);
|
|
137
141
|
}
|
|
138
142
|
}
|
|
139
|
-
/**
|
|
140
|
-
* Infer the tick size from order book price levels.
|
|
141
|
-
* Analyzes the decimal precision of existing orders to determine the market's tick size.
|
|
142
|
-
*/
|
|
143
|
-
inferTickSize(orderBook) {
|
|
144
|
-
const allPrices = [
|
|
145
|
-
...orderBook.bids.map(b => b.price),
|
|
146
|
-
...orderBook.asks.map(a => a.price)
|
|
147
|
-
];
|
|
148
|
-
if (allPrices.length === 0) {
|
|
149
|
-
return "0.01"; // Default fallback for Polymarket
|
|
150
|
-
}
|
|
151
|
-
// Find the smallest non-zero decimal increment
|
|
152
|
-
let minIncrement = 1;
|
|
153
|
-
for (const price of allPrices) {
|
|
154
|
-
const priceStr = price.toString();
|
|
155
|
-
const decimalPart = priceStr.split('.')[1];
|
|
156
|
-
if (decimalPart) {
|
|
157
|
-
const decimals = decimalPart.length;
|
|
158
|
-
const increment = Math.pow(10, -decimals);
|
|
159
|
-
if (increment < minIncrement) {
|
|
160
|
-
minIncrement = increment;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
// Map to valid tick sizes: 0.1, 0.01, 0.001, 0.0001
|
|
165
|
-
if (minIncrement >= 0.1)
|
|
166
|
-
return "0.1";
|
|
167
|
-
if (minIncrement >= 0.01)
|
|
168
|
-
return "0.01";
|
|
169
|
-
if (minIncrement >= 0.001)
|
|
170
|
-
return "0.001";
|
|
171
|
-
return "0.0001";
|
|
172
|
-
}
|
|
173
143
|
async cancelOrder(orderId) {
|
|
174
144
|
try {
|
|
175
145
|
const auth = this.ensureAuth();
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmxt-core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "pmxt is a unified prediction market data API. The ccxt for prediction markets.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"test": "jest -c jest.config.js",
|
|
30
30
|
"server": "tsx watch src/server/index.ts",
|
|
31
31
|
"server:prod": "node dist/server/index.js",
|
|
32
|
-
"generate:sdk:python": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g python -o ../sdks/python/generated --package-name pmxt_internal --additional-properties=projectName=pmxt-internal,packageVersion=2.1.
|
|
33
|
-
"generate:sdk:typescript": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g typescript-fetch -o ../sdks/typescript/generated --additional-properties=npmName=pmxtjs,npmVersion=2.1.
|
|
32
|
+
"generate:sdk:python": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g python -o ../sdks/python/generated --package-name pmxt_internal --additional-properties=projectName=pmxt-internal,packageVersion=2.1.3,library=urllib3",
|
|
33
|
+
"generate:sdk:typescript": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g typescript-fetch -o ../sdks/typescript/generated --additional-properties=npmName=pmxtjs,npmVersion=2.1.3,supportsES6=true,typescriptThreePlus=true && node ../sdks/typescript/scripts/fix-generated.js",
|
|
34
34
|
"extract:jsdoc": "node ../scripts/extract-jsdoc.js",
|
|
35
35
|
"generate:docs": "npm run extract:jsdoc && node ../scripts/generate-api-docs.js",
|
|
36
36
|
"generate:sdk:all": "npm run generate:sdk:python && npm run generate:sdk:typescript && npm run generate:docs"
|