skewtape 0.1.5 → 0.1.7
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 +4 -13
- package/dist/cjs/client.d.ts +37 -6
- package/dist/cjs/client.js +42 -13
- package/dist/cjs/fees.d.ts +4 -2
- package/dist/cjs/fees.js +48 -8
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +2 -5
- package/dist/cjs/kalshi.d.ts +3 -3
- package/dist/cjs/kalshi.js +4 -4
- package/dist/cjs/paginated.d.ts +1 -1
- package/dist/cjs/paginated.js +1 -1
- package/dist/cjs/quote-math.js +4 -1
- package/dist/cjs/quote.d.ts +1 -12
- package/dist/cjs/quote.js +1 -16
- package/dist/cjs/route.d.ts +6 -65
- package/dist/cjs/route.js +3 -120
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/client.d.ts +37 -6
- package/dist/esm/client.js +42 -13
- package/dist/esm/fees.d.ts +4 -2
- package/dist/esm/fees.js +48 -8
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/kalshi.d.ts +3 -3
- package/dist/esm/kalshi.js +4 -4
- package/dist/esm/paginated.d.ts +1 -1
- package/dist/esm/paginated.js +1 -1
- package/dist/esm/quote-math.js +4 -1
- package/dist/esm/quote.d.ts +1 -12
- package/dist/esm/quote.js +0 -14
- package/dist/esm/route.d.ts +6 -65
- package/dist/esm/route.js +2 -117
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
- package/src/client.ts +72 -21
- package/src/fees.ts +47 -7
- package/src/generated/schema.d.ts +388 -34
- package/src/index.ts +0 -4
- package/src/kalshi.ts +4 -4
- package/src/paginated.ts +1 -1
- package/src/quote-math.ts +3 -1
- package/src/quote.ts +1 -16
- package/src/route.ts +7 -147
- package/src/version.ts +1 -1
package/dist/cjs/route.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* route() builds and checks an order, and stops there: it never signs, never
|
|
7
7
|
* sends, never takes a private key, and needs no Skewtape key. Every code and
|
|
8
|
-
* fee it carries is the developer's own: the Polymarket builder code
|
|
9
|
-
*
|
|
8
|
+
* fee it carries is the developer's own: the Polymarket builder code and the
|
|
9
|
+
* Hyperliquid builder fee. Omitting them sends none, and no Skewtape value
|
|
10
10
|
* exists in this package (a test scans it). The developer is responsible for
|
|
11
11
|
* their users: who may trade where, and under which terms (sk.geoblock helps
|
|
12
12
|
* with Polymarket's).
|
|
@@ -20,10 +20,9 @@
|
|
|
20
20
|
* const body = order.postBody(signature, yourClobApiKeyId);
|
|
21
21
|
*/
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.
|
|
23
|
+
exports.ROUTE_FIELDS = exports.PolymarketOrder = exports.ZERO_BYTES32 = exports.MAX_SAFE_SALT = exports.POLYMARKET_GTD_MIN_SECONDS = exports.POLYMARKET_MAX_SIZE = exports.POLYMARKET_DECIMALS = exports.POLYMARKET_TICKS = exports.POLYMARKET_SIGNATURE_TYPES = exports.POLYMARKET_SIDES = exports.POLYMARKET_EXCHANGES = exports.POLYGON_CHAIN_ID = exports.POLYMARKET_DOMAIN_NAME = exports.EIP712_DOMAIN_TYPE = exports.POLYMARKET_ORDER_TYPE = exports.RouteError = void 0;
|
|
24
24
|
exports.polymarketAmounts = polymarketAmounts;
|
|
25
25
|
exports.polymarketOrder = polymarketOrder;
|
|
26
|
-
exports.dflowOrder = dflowOrder;
|
|
27
26
|
exports.route = route;
|
|
28
27
|
const errors_js_1 = require("./errors.js");
|
|
29
28
|
Object.defineProperty(exports, "RouteError", { enumerable: true, get: function () { return errors_js_1.RouteError; } });
|
|
@@ -295,10 +294,6 @@ exports.ROUTE_FIELDS = {
|
|
|
295
294
|
"venue", "exchange", "tokenId", "side", "price", "tickSize", "maker", "size", "amount", "orderType",
|
|
296
295
|
"signatureType", "signer", "builder", "metadata", "expiration", "salt", "timestampMs",
|
|
297
296
|
],
|
|
298
|
-
kalshi_dflow: [
|
|
299
|
-
"venue", "inputMint", "outputMint", "amount", "userPublicKey", "slippageBps", "predictionMarketSlippageBps",
|
|
300
|
-
"platformFeeScale", "platformFeeBps", "platformFeeMode", "feeAccount", "baseUrl",
|
|
301
|
-
],
|
|
302
297
|
hyperliquid: route_hyperliquid_js_1.HYPERLIQUID_FIELDS,
|
|
303
298
|
};
|
|
304
299
|
function onlyFields(venue, input) {
|
|
@@ -395,121 +390,9 @@ function polymarketOrder(input) {
|
|
|
395
390
|
},
|
|
396
391
|
}, orderType, expiration, side);
|
|
397
392
|
}
|
|
398
|
-
// --- DFlow --------------------------------------------------------------------
|
|
399
|
-
/**
|
|
400
|
-
* The Trading API that returns the unsigned transaction: GET /order on
|
|
401
|
-
* https://quote-api.dflow.net (pond.dflow.net/get-started/endpoints.md), with
|
|
402
|
-
* the developer's own key in the x-api-key header ("All calls to the
|
|
403
|
-
* production endpoints must use an API key", pond.dflow.net/get-started/api-key.md).
|
|
404
|
-
*/
|
|
405
|
-
exports.DFLOW_TRADING_API = "https://quote-api.dflow.net";
|
|
406
|
-
exports.DFLOW_API_KEY_HEADER = "x-api-key";
|
|
407
|
-
/**
|
|
408
|
-
* platformFeeScale: "Optional platform fee scale for World prediction market
|
|
409
|
-
* swaps and async prediction market swaps, with 3 decimals ... Must be >= 0 and
|
|
410
|
-
* < 1000. For example, a value of 50 means 0.050." platformFeeBps: a fixed fee
|
|
411
|
-
* in basis points, for spot trades (pond.dflow.net/spot/trading/platform-fees.md).
|
|
412
|
-
*/
|
|
413
|
-
exports.DFLOW_FEE_SCALE_MAX = 999;
|
|
414
|
-
exports.DFLOW_FEE_BPS_MAX = 10_000;
|
|
415
|
-
const DFLOW_FEE_MODES = ["outputMint", "inputMint"];
|
|
416
|
-
const BASE58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
417
|
-
function solanaAddress(name, value) {
|
|
418
|
-
if (typeof value !== "string" || value.length < 32 || value.length > 44 || [...value].some((c) => !BASE58.includes(c))) {
|
|
419
|
-
throw new errors_js_1.RouteError(`${name}: ${JSON.stringify(value)} is not a base58 Solana address`);
|
|
420
|
-
}
|
|
421
|
-
let n = 0n;
|
|
422
|
-
for (const c of value)
|
|
423
|
-
n = n * 58n + BigInt(BASE58.indexOf(c));
|
|
424
|
-
let bytes = n === 0n ? 0 : Math.ceil(n.toString(16).length / 2);
|
|
425
|
-
bytes += value.length - value.replace(/^1+/, "").length;
|
|
426
|
-
if (bytes !== 32)
|
|
427
|
-
throw new errors_js_1.RouteError(`${name}: ${JSON.stringify(value)} does not decode to 32 bytes`);
|
|
428
|
-
return value;
|
|
429
|
-
}
|
|
430
|
-
/**
|
|
431
|
-
* The request that returns an unsigned DFlow transaction: GET `url` with
|
|
432
|
-
* `params` and your own DFlow key in the x-api-key header. The response's
|
|
433
|
-
* `transaction` (base64) is for your user to sign and submit. Nothing was
|
|
434
|
-
* sent: route() never calls DFlow.
|
|
435
|
-
*/
|
|
436
|
-
class DFlowOrderRequest {
|
|
437
|
-
url;
|
|
438
|
-
params;
|
|
439
|
-
venue = "kalshi_dflow";
|
|
440
|
-
apiKeyHeader = exports.DFLOW_API_KEY_HEADER;
|
|
441
|
-
constructor(url, params) {
|
|
442
|
-
this.url = url;
|
|
443
|
-
this.params = params;
|
|
444
|
-
}
|
|
445
|
-
get fullUrl() {
|
|
446
|
-
return `${this.url}?${new URLSearchParams(this.params).toString()}`;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
exports.DFlowOrderRequest = DFlowOrderRequest;
|
|
450
|
-
function intIn(name, value, max) {
|
|
451
|
-
if (typeof value !== "number" || !Number.isInteger(value) || value < 0 || value > max) {
|
|
452
|
-
throw new errors_js_1.RouteError(`${name}: an integer from 0 to ${max}`);
|
|
453
|
-
}
|
|
454
|
-
return value;
|
|
455
|
-
}
|
|
456
|
-
function dflowOrder(input) {
|
|
457
|
-
onlyFields("kalshi_dflow", input);
|
|
458
|
-
const params = {
|
|
459
|
-
inputMint: solanaAddress("inputMint", input.inputMint),
|
|
460
|
-
outputMint: solanaAddress("outputMint", input.outputMint),
|
|
461
|
-
};
|
|
462
|
-
const amount = input.amount;
|
|
463
|
-
if (!(typeof amount === "bigint" ? amount > 0n : Number.isSafeInteger(amount) && amount > 0)) {
|
|
464
|
-
throw new errors_js_1.RouteError("amount: a positive integer, in the input mint's base units");
|
|
465
|
-
}
|
|
466
|
-
params.amount = amount.toString();
|
|
467
|
-
params.userPublicKey = solanaAddress("userPublicKey", input.userPublicKey);
|
|
468
|
-
if (input.slippageBps !== undefined) {
|
|
469
|
-
if (input.slippageBps !== "auto")
|
|
470
|
-
intIn('slippageBps (or "auto")', input.slippageBps, 65535);
|
|
471
|
-
params.slippageBps = String(input.slippageBps);
|
|
472
|
-
}
|
|
473
|
-
if (input.predictionMarketSlippageBps !== undefined) {
|
|
474
|
-
params.predictionMarketSlippageBps = String(intIn("predictionMarketSlippageBps", input.predictionMarketSlippageBps, 65535));
|
|
475
|
-
}
|
|
476
|
-
if (input.platformFeeScale !== undefined && input.platformFeeBps !== undefined) {
|
|
477
|
-
throw new errors_js_1.RouteError("platformFeeScale (a prediction market swap) or platformFeeBps (spot), not both");
|
|
478
|
-
}
|
|
479
|
-
let fee = 0;
|
|
480
|
-
if (input.platformFeeScale !== undefined) {
|
|
481
|
-
fee = intIn("platformFeeScale (in thousandths, 50 is 0.050)", input.platformFeeScale, exports.DFLOW_FEE_SCALE_MAX);
|
|
482
|
-
if (fee)
|
|
483
|
-
params.platformFeeScale = String(fee);
|
|
484
|
-
}
|
|
485
|
-
if (input.platformFeeBps !== undefined) {
|
|
486
|
-
fee = intIn("platformFeeBps", input.platformFeeBps, exports.DFLOW_FEE_BPS_MAX);
|
|
487
|
-
if (fee)
|
|
488
|
-
params.platformFeeBps = String(fee);
|
|
489
|
-
}
|
|
490
|
-
if (fee && input.feeAccount === undefined) {
|
|
491
|
-
throw new errors_js_1.RouteError("feeAccount: your token account for the fee mint; DFlow requires it with a fee");
|
|
492
|
-
}
|
|
493
|
-
if (!fee && input.feeAccount !== undefined) {
|
|
494
|
-
throw new errors_js_1.RouteError("feeAccount without a fee: DFlow collects nothing, so send neither");
|
|
495
|
-
}
|
|
496
|
-
if (input.feeAccount !== undefined)
|
|
497
|
-
params.feeAccount = solanaAddress("feeAccount", input.feeAccount);
|
|
498
|
-
if (input.platformFeeMode !== undefined) {
|
|
499
|
-
if (!DFLOW_FEE_MODES.includes(input.platformFeeMode))
|
|
500
|
-
throw new errors_js_1.RouteError(`platformFeeMode: one of ${DFLOW_FEE_MODES.join(", ")}`);
|
|
501
|
-
params.platformFeeMode = input.platformFeeMode;
|
|
502
|
-
}
|
|
503
|
-
const base = input.baseUrl ?? exports.DFLOW_TRADING_API;
|
|
504
|
-
if (typeof base !== "string" || !base.startsWith("https://"))
|
|
505
|
-
throw new errors_js_1.RouteError("baseUrl: an https URL of DFlow's Trading API");
|
|
506
|
-
return new DFlowOrderRequest(`${base.replace(/\/+$/, "")}/order`, params);
|
|
507
|
-
}
|
|
508
393
|
function route(order) {
|
|
509
394
|
if (order.venue === "polymarket")
|
|
510
395
|
return polymarketOrder(order);
|
|
511
|
-
if (order.venue === "kalshi_dflow")
|
|
512
|
-
return dflowOrder(order);
|
|
513
396
|
if (order.venue === "hyperliquid")
|
|
514
397
|
return (0, route_hyperliquid_js_1.hyperliquidOrder)(order);
|
|
515
398
|
throw new errors_js_1.RouteError(`venue: one of ${Object.keys(exports.ROUTE_FIELDS).join(", ")}`);
|
package/dist/cjs/version.d.ts
CHANGED
package/dist/cjs/version.js
CHANGED
package/dist/esm/client.d.ts
CHANGED
|
@@ -61,11 +61,26 @@ export interface MarketsOptions {
|
|
|
61
61
|
venue?: string;
|
|
62
62
|
marketId?: string[];
|
|
63
63
|
updatedSince?: Date | string;
|
|
64
|
+
/** Only markets in one of these statuses. */
|
|
65
|
+
status?: Array<"open" | "closed" | "resolved" | "voided">;
|
|
66
|
+
/** Only markets whose category label is exactly one of these (at most 20). */
|
|
67
|
+
category?: string[];
|
|
68
|
+
/** Only the markets of this venue event; needs venue, since event ids are per venue. */
|
|
69
|
+
venueEventId?: string;
|
|
70
|
+
/** Only markets whose close_at is at or after this time. */
|
|
71
|
+
closeAfter?: Date | string;
|
|
72
|
+
/** Only markets whose close_at is before this time. */
|
|
73
|
+
closeBefore?: Date | string;
|
|
74
|
+
/** Keyword search on the question, 1 to 100 characters. */
|
|
75
|
+
q?: string;
|
|
76
|
+
/** venue (the default), close_at, updated_at or first_seen_at. */
|
|
77
|
+
sort?: "venue" | "close_at" | "updated_at" | "first_seen_at";
|
|
78
|
+
/** asc (the default) or desc. */
|
|
79
|
+
order?: "asc" | "desc";
|
|
64
80
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* or
|
|
68
|
-
* /v1/markets would make it one request per page of results.
|
|
81
|
+
* true is status ["resolved"], false the three others (open, closed,
|
|
82
|
+
* voided): filtered on the server like status, so one request per page of
|
|
83
|
+
* results. Pass resolved or status, not both (a ConfigurationError).
|
|
69
84
|
*/
|
|
70
85
|
resolved?: boolean;
|
|
71
86
|
limit?: number;
|
|
@@ -75,6 +90,10 @@ export interface EventsOptions {
|
|
|
75
90
|
resolutionEqual?: boolean;
|
|
76
91
|
venue?: string;
|
|
77
92
|
status?: "approved" | "needs_rereview" | "retired";
|
|
93
|
+
/** event_id (the default) or published_at. */
|
|
94
|
+
sort?: "event_id" | "published_at";
|
|
95
|
+
/** asc (the default) or desc. */
|
|
96
|
+
order?: "asc" | "desc";
|
|
78
97
|
limit?: number;
|
|
79
98
|
}
|
|
80
99
|
export interface FillsOptions {
|
|
@@ -102,6 +121,14 @@ export interface ResolutionsOptions {
|
|
|
102
121
|
/** Up to 100 market ids. */
|
|
103
122
|
marketId?: string[];
|
|
104
123
|
createdSince?: Date | string;
|
|
124
|
+
/** Only events whose resolved_at is at or after this time. */
|
|
125
|
+
resolvedAfter?: Date | string;
|
|
126
|
+
/** Only events whose resolved_at is before this time. */
|
|
127
|
+
resolvedBefore?: Date | string;
|
|
128
|
+
/** venue (the default) or resolved_at. */
|
|
129
|
+
sort?: "venue" | "resolved_at";
|
|
130
|
+
/** asc (the default) or desc. */
|
|
131
|
+
order?: "asc" | "desc";
|
|
105
132
|
limit?: number;
|
|
106
133
|
}
|
|
107
134
|
export interface FeesOptions {
|
|
@@ -148,7 +175,11 @@ export declare class Skewtape {
|
|
|
148
175
|
* error envelope. A request past the timeout is a SkewtapeError.
|
|
149
176
|
*/
|
|
150
177
|
private call;
|
|
151
|
-
/**
|
|
178
|
+
/**
|
|
179
|
+
* sk.markets({venue, status, q}) lists markets; sk.markets.get(venue,
|
|
180
|
+
* marketId) reads one. Every filter is the API's, resolved included (true
|
|
181
|
+
* is status ["resolved"], false the three others), so one request per page.
|
|
182
|
+
*/
|
|
152
183
|
readonly markets: ((options?: MarketsOptions) => Paginated<Market>) & {
|
|
153
184
|
get: (venue: string, marketId: string) => Promise<Market>;
|
|
154
185
|
};
|
|
@@ -165,7 +196,7 @@ export declare class Skewtape {
|
|
|
165
196
|
fills(options: FillsOptions): Paginated<Fill>;
|
|
166
197
|
/** sk.candles({res, since}) lists candles of one size from since to until. */
|
|
167
198
|
candles(options: CandlesOptions): Paginated<Candle>;
|
|
168
|
-
/** sk.resolutions({venue, marketId, createdSince}) lists resolution events, of up to 100 markets when marketId is given. */
|
|
199
|
+
/** sk.resolutions({venue, marketId, createdSince, resolvedAfter, resolvedBefore}) lists resolution events, of up to 100 markets when marketId is given. */
|
|
169
200
|
resolutions(options?: ResolutionsOptions): Paginated<Resolution>;
|
|
170
201
|
/** sk.fees({venue}) lists the fee schedule rows. */
|
|
171
202
|
fees(options?: FeesOptions): Paginated<Fee>;
|
package/dist/esm/client.js
CHANGED
|
@@ -51,6 +51,14 @@ function dateOf(micros) {
|
|
|
51
51
|
function iso(v) {
|
|
52
52
|
return v instanceof Date ? v.toISOString() : v;
|
|
53
53
|
}
|
|
54
|
+
/** The status filter sk.markets sends: status as given, or resolved's (true is resolved, false the three others). */
|
|
55
|
+
function marketStatus(options) {
|
|
56
|
+
if (options.resolved === undefined)
|
|
57
|
+
return options.status;
|
|
58
|
+
if (options.status !== undefined)
|
|
59
|
+
throw new ConfigurationError('pass resolved or status, not both: resolved true is status ["resolved"], false the three others');
|
|
60
|
+
return options.resolved ? ["resolved"] : ["open", "closed", "voided"];
|
|
61
|
+
}
|
|
54
62
|
function defaultSleep(seconds) {
|
|
55
63
|
return new Promise((resolve) => setTimeout(resolve, seconds * 1000));
|
|
56
64
|
}
|
|
@@ -131,18 +139,33 @@ export class Skewtape {
|
|
|
131
139
|
throw errorFromResponse(response.status, response.headers, error);
|
|
132
140
|
}
|
|
133
141
|
}
|
|
134
|
-
/**
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
/**
|
|
143
|
+
* sk.markets({venue, status, q}) lists markets; sk.markets.get(venue,
|
|
144
|
+
* marketId) reads one. Every filter is the API's, resolved included (true
|
|
145
|
+
* is status ["resolved"], false the three others), so one request per page.
|
|
146
|
+
*/
|
|
147
|
+
markets = Object.assign((options = {}) => {
|
|
148
|
+
const status = marketStatus(options);
|
|
149
|
+
return new Paginated(async (cursor) => {
|
|
150
|
+
const query = {
|
|
151
|
+
venue: options.venue,
|
|
152
|
+
market_id: options.marketId,
|
|
153
|
+
updated_since: iso(options.updatedSince),
|
|
154
|
+
status,
|
|
155
|
+
category: options.category,
|
|
156
|
+
venue_event_id: options.venueEventId,
|
|
157
|
+
close_after: iso(options.closeAfter),
|
|
158
|
+
close_before: iso(options.closeBefore),
|
|
159
|
+
q: options.q,
|
|
160
|
+
sort: options.sort,
|
|
161
|
+
order: options.order,
|
|
162
|
+
limit: options.limit ?? 100,
|
|
163
|
+
cursor,
|
|
164
|
+
};
|
|
165
|
+
const data = await this.call(() => this.api.GET("/v1/markets", { params: { query } }));
|
|
166
|
+
return { items: data.data, nextCursor: data.next_cursor ?? null };
|
|
167
|
+
});
|
|
168
|
+
}, {
|
|
146
169
|
get: (venue, marketId) => this.call(() => this.api.GET("/v1/markets/{venue}/{market_id}", { params: { path: { venue, market_id: marketId } } })),
|
|
147
170
|
});
|
|
148
171
|
/** sk.events({minConfidence, resolutionEqual}) lists matched events; sk.events.get(eventId) reads one. */
|
|
@@ -166,6 +189,8 @@ export class Skewtape {
|
|
|
166
189
|
resolution_equal: options.resolutionEqual,
|
|
167
190
|
venue: options.venue,
|
|
168
191
|
status: options.status,
|
|
192
|
+
sort: options.sort,
|
|
193
|
+
order: options.order,
|
|
169
194
|
limit: options.limit ?? 100,
|
|
170
195
|
cursor,
|
|
171
196
|
};
|
|
@@ -209,13 +234,17 @@ export class Skewtape {
|
|
|
209
234
|
return { items: data.data, nextCursor: data.next_cursor ?? null };
|
|
210
235
|
});
|
|
211
236
|
}
|
|
212
|
-
/** sk.resolutions({venue, marketId, createdSince}) lists resolution events, of up to 100 markets when marketId is given. */
|
|
237
|
+
/** sk.resolutions({venue, marketId, createdSince, resolvedAfter, resolvedBefore}) lists resolution events, of up to 100 markets when marketId is given. */
|
|
213
238
|
resolutions(options = {}) {
|
|
214
239
|
return new Paginated(async (cursor) => {
|
|
215
240
|
const query = {
|
|
216
241
|
venue: options.venue,
|
|
217
242
|
market_id: options.marketId,
|
|
218
243
|
created_since: iso(options.createdSince),
|
|
244
|
+
resolved_after: iso(options.resolvedAfter),
|
|
245
|
+
resolved_before: iso(options.resolvedBefore),
|
|
246
|
+
sort: options.sort,
|
|
247
|
+
order: options.order,
|
|
219
248
|
limit: options.limit ?? 100,
|
|
220
249
|
cursor,
|
|
221
250
|
};
|
package/dist/esm/fees.d.ts
CHANGED
|
@@ -62,7 +62,9 @@ export declare function makerFeeRaw(row: FeeRowInput, sizeRaw: bigint, notionalR
|
|
|
62
62
|
/**
|
|
63
63
|
* The row in force for a fill of venue at time at (microseconds, a Date or
|
|
64
64
|
* an ISO string): the market's fee_category if a row has it, else the row
|
|
65
|
-
* with category *; of several, the latest effective_from.
|
|
66
|
-
*
|
|
65
|
+
* with category *; of several, the latest effective_from. A Polymarket
|
|
66
|
+
* fee_category that joins names ("finance|mentions") gives the terms its rows
|
|
67
|
+
* share, under the joined name, while every one of them is in force and
|
|
68
|
+
* charges alike, and never the * row. Undefined when no row applies.
|
|
67
69
|
*/
|
|
68
70
|
export declare function selectFeeRow(rows: Iterable<FeeRowInput>, venue: string, category: string | null | undefined, at: bigint | Date | string): FeeRow | undefined;
|
package/dist/esm/fees.js
CHANGED
|
@@ -10,6 +10,13 @@ import { SkewtapeError } from "./errors.js";
|
|
|
10
10
|
import { Rat, parseInt64, parseMicros } from "./exact.js";
|
|
11
11
|
export const COLLATERAL_MICROS_DECIMALS = 6;
|
|
12
12
|
export const FALLBACK_CATEGORY = "*";
|
|
13
|
+
/**
|
|
14
|
+
* A Polymarket fee_category joins several rows' names ("finance|mentions")
|
|
15
|
+
* when those rows charge alike and the venue's data does not say which is the
|
|
16
|
+
* market's.
|
|
17
|
+
*/
|
|
18
|
+
const JOINED_VENUE = "polymarket";
|
|
19
|
+
const JOINED_SEPARATOR = "|";
|
|
13
20
|
const MICROS_PER_UNIT = 1000000n;
|
|
14
21
|
/** A fee that cannot be computed: an unknown formula or rounding, a missing parameter, a size out of range. */
|
|
15
22
|
export class FeeError extends SkewtapeError {
|
|
@@ -165,21 +172,54 @@ function inForce(r, at) {
|
|
|
165
172
|
/**
|
|
166
173
|
* The row in force for a fill of venue at time at (microseconds, a Date or
|
|
167
174
|
* an ISO string): the market's fee_category if a row has it, else the row
|
|
168
|
-
* with category *; of several, the latest effective_from.
|
|
169
|
-
*
|
|
175
|
+
* with category *; of several, the latest effective_from. A Polymarket
|
|
176
|
+
* fee_category that joins names ("finance|mentions") gives the terms its rows
|
|
177
|
+
* share, under the joined name, while every one of them is in force and
|
|
178
|
+
* charges alike, and never the * row. Undefined when no row applies.
|
|
170
179
|
*/
|
|
171
180
|
export function selectFeeRow(rows, venue, category, at) {
|
|
172
181
|
const t = typeof at === "bigint" ? at : parseMicros(at, "at");
|
|
173
|
-
const all = [...rows].map(feeRowOf);
|
|
182
|
+
const all = [...rows].map(feeRowOf).filter((r) => r.venue === venue);
|
|
183
|
+
if (venue === JOINED_VENUE && category && category.includes(JOINED_SEPARATOR))
|
|
184
|
+
return joinedRow(all, category, t);
|
|
174
185
|
const wanted = category && category !== FALLBACK_CATEGORY ? [category, FALLBACK_CATEGORY] : [FALLBACK_CATEGORY];
|
|
175
186
|
for (const cat of wanted) {
|
|
176
|
-
|
|
177
|
-
for (const r of all) {
|
|
178
|
-
if (r.venue === venue && r.category === cat && inForce(r, t) && (best === undefined || r.effectiveFrom > best.effectiveFrom))
|
|
179
|
-
best = r;
|
|
180
|
-
}
|
|
187
|
+
const best = rowInForce(all, cat, t);
|
|
181
188
|
if (best)
|
|
182
189
|
return best;
|
|
183
190
|
}
|
|
184
191
|
return undefined;
|
|
185
192
|
}
|
|
193
|
+
function rowInForce(rows, category, at) {
|
|
194
|
+
let best;
|
|
195
|
+
for (const r of rows) {
|
|
196
|
+
if (r.category === category && inForce(r, at) && (best === undefined || r.effectiveFrom > best.effectiveFrom))
|
|
197
|
+
best = r;
|
|
198
|
+
}
|
|
199
|
+
return best;
|
|
200
|
+
}
|
|
201
|
+
function joinedRow(rows, key, at) {
|
|
202
|
+
let out;
|
|
203
|
+
for (const name of key.split(JOINED_SEPARATOR)) {
|
|
204
|
+
const r = rowInForce(rows, name, at);
|
|
205
|
+
if (r === undefined || (out !== undefined && !sameTerms(out, r)))
|
|
206
|
+
return undefined;
|
|
207
|
+
if (out === undefined) {
|
|
208
|
+
out = { ...r, category: key };
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (r.effectiveFrom > out.effectiveFrom)
|
|
212
|
+
out.effectiveFrom = r.effectiveFrom;
|
|
213
|
+
if (r.effectiveTo !== null && (out.effectiveTo === null || r.effectiveTo < out.effectiveTo))
|
|
214
|
+
out.effectiveTo = r.effectiveTo;
|
|
215
|
+
}
|
|
216
|
+
return out;
|
|
217
|
+
}
|
|
218
|
+
/** Whether two rows charge alike: everything but the name, period and source. */
|
|
219
|
+
function sameTerms(a, b) {
|
|
220
|
+
return a.formula === b.formula && a.rounding === b.rounding && a.minFeeMicros === b.minFeeMicros && sameParams(a.takerParams, b.takerParams) && sameParams(a.makerRebateParams, b.makerRebateParams);
|
|
221
|
+
}
|
|
222
|
+
function sameParams(a, b) {
|
|
223
|
+
const keys = Object.keys(a);
|
|
224
|
+
return keys.length === Object.keys(b).length && keys.every((k) => a[k] === b[k]);
|
|
225
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -20,10 +20,10 @@ export { downloadFile, verifyChecksums, type DownloadOptions } from "./download.
|
|
|
20
20
|
export { Rat, fractionStr, roundHalfUp } from "./exact.js";
|
|
21
21
|
export { FeeError, feeRowOf, makerFeeRaw, microsToRaw, selectFeeRow, takerFeeRaw, type FeeRow, type FeeRowInput } from "./fees.js";
|
|
22
22
|
export { DEFAULT_KALSHI_BASE_URL, KALSHI_VENUES, Kalshi, KalshiError, PERIODS, kalshiTickers, seriesTickerOf, type KalshiCandlestick, type KalshiCandlesticksOptions, type KalshiEventLike, type KalshiLevel, type KalshiMarket, type KalshiMarketsOptions, type KalshiOHLC, type KalshiOptions, type KalshiOrderbook, type KalshiPeriod, type KalshiTrade, type KalshiTradesOptions, } from "./kalshi.js";
|
|
23
|
-
export { BookUnavailable, DEFAULT_BOOK_READERS, KALSHI_FRACTION_MICRO, quoteFromContext, readKalshiBook,
|
|
23
|
+
export { BookUnavailable, DEFAULT_BOOK_READERS, KALSHI_FRACTION_MICRO, quoteFromContext, readKalshiBook, readPolymarketBook, type BookReader, type BookRequest, type QuoteContext, type QuoteContextMember, type QuoteOptions, } from "./quote.js";
|
|
24
24
|
export { InvalidQuoteInputError, QuoteError, RuleMismatchError, VenueUnreachableError, computeQuote, type Book, type Leg, type Level, type QuoteInput, type QuoteResult, type Skip, type VenueQuote, } from "./quote-math.js";
|
|
25
25
|
export { AuthenticationError, BlockedError, ChecksumError, ConfigurationError, ForbiddenPlanError, InvalidRequestError, NotFoundError, QuotaExceededError, RateLimitError, ServerError, SkewtapeError, } from "./errors.js";
|
|
26
|
-
export {
|
|
26
|
+
export { POLYMARKET_EXCHANGES, PolymarketOrder, RouteError, route, type PolymarketRoute, type PolymarketTypedData, type RouteInput, } from "./route.js";
|
|
27
27
|
export { HYPERLIQUID_EXCHANGE_URL, HYPERLIQUID_TESTNET_EXCHANGE_URL, HyperliquidApproveBuilderFee, HyperliquidOrder, hyperliquidApproveBuilderFee, type HyperliquidRoute, } from "./route-hyperliquid.js";
|
|
28
28
|
export { geoblock, type GeoblockResult, type GeoblockOptions } from "./geoblock.js";
|
|
29
29
|
export { Stream, feedUrl, type FeedMessage, type FeedSocket, type FeedSocketConstructor, type StreamOptions } from "./stream.js";
|
package/dist/esm/index.js
CHANGED
|
@@ -20,10 +20,10 @@ export { downloadFile, verifyChecksums } from "./download.js";
|
|
|
20
20
|
export { Rat, fractionStr, roundHalfUp } from "./exact.js";
|
|
21
21
|
export { FeeError, feeRowOf, makerFeeRaw, microsToRaw, selectFeeRow, takerFeeRaw } from "./fees.js";
|
|
22
22
|
export { DEFAULT_KALSHI_BASE_URL, KALSHI_VENUES, Kalshi, KalshiError, PERIODS, kalshiTickers, seriesTickerOf, } from "./kalshi.js";
|
|
23
|
-
export { BookUnavailable, DEFAULT_BOOK_READERS, KALSHI_FRACTION_MICRO, quoteFromContext, readKalshiBook,
|
|
23
|
+
export { BookUnavailable, DEFAULT_BOOK_READERS, KALSHI_FRACTION_MICRO, quoteFromContext, readKalshiBook, readPolymarketBook, } from "./quote.js";
|
|
24
24
|
export { InvalidQuoteInputError, QuoteError, RuleMismatchError, VenueUnreachableError, computeQuote, } from "./quote-math.js";
|
|
25
25
|
export { AuthenticationError, BlockedError, ChecksumError, ConfigurationError, ForbiddenPlanError, InvalidRequestError, NotFoundError, QuotaExceededError, RateLimitError, ServerError, SkewtapeError, } from "./errors.js";
|
|
26
|
-
export {
|
|
26
|
+
export { POLYMARKET_EXCHANGES, PolymarketOrder, RouteError, route, } from "./route.js";
|
|
27
27
|
export { HYPERLIQUID_EXCHANGE_URL, HYPERLIQUID_TESTNET_EXCHANGE_URL, HyperliquidApproveBuilderFee, HyperliquidOrder, hyperliquidApproveBuilderFee, } from "./route-hyperliquid.js";
|
|
28
28
|
export { geoblock } from "./geoblock.js";
|
|
29
29
|
export { Stream, feedUrl } from "./stream.js";
|
package/dist/esm/kalshi.d.ts
CHANGED
|
@@ -159,8 +159,8 @@ export interface KalshiEventLike {
|
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
161
|
* The Kalshi tickers of a matched event: the market_id of its members on
|
|
162
|
-
* kalshi
|
|
163
|
-
*
|
|
162
|
+
* kalshi (the ticker is the id), active ones unless includeInactive, in
|
|
163
|
+
* member order, each once.
|
|
164
164
|
*/
|
|
165
165
|
export declare function kalshiTickers(event: KalshiEventLike, includeInactive?: boolean): string[];
|
|
166
166
|
export interface KalshiOptions {
|
|
@@ -250,7 +250,7 @@ export declare class Kalshi {
|
|
|
250
250
|
* periods a request and a 1d stick is a New York day.
|
|
251
251
|
*/
|
|
252
252
|
candlesticks(ticker: string, options: KalshiCandlesticksOptions): Promise<KalshiCandlestick[]>;
|
|
253
|
-
/** The Kalshi tickers of a Skewtape matched event: the market_id of its kalshi
|
|
253
|
+
/** The Kalshi tickers of a Skewtape matched event: the market_id of its kalshi members, active ones unless includeInactive. */
|
|
254
254
|
tickers(event: KalshiEventLike, options?: {
|
|
255
255
|
includeInactive?: boolean;
|
|
256
256
|
}): string[];
|
package/dist/esm/kalshi.js
CHANGED
|
@@ -33,7 +33,7 @@ import { VERSION } from "./version.js";
|
|
|
33
33
|
/** The production Trade API host Kalshi's docs prefer (api.elections.kalshi.com stays supported; pass baseUrl for it or for the demo host). */
|
|
34
34
|
export const DEFAULT_KALSHI_BASE_URL = "https://external-api.kalshi.com/trade-api/v2";
|
|
35
35
|
/** The matched-event member venues whose market_id is a Kalshi ticker. */
|
|
36
|
-
export const KALSHI_VENUES = new Set(["kalshi"
|
|
36
|
+
export const KALSHI_VENUES = new Set(["kalshi"]);
|
|
37
37
|
/** Candlestick sizes, as sk.candles names them, to Kalshi's period_interval minutes. */
|
|
38
38
|
export const PERIODS = { "1m": 1, "1h": 60, "1d": 1440 };
|
|
39
39
|
/**
|
|
@@ -217,8 +217,8 @@ class Signer {
|
|
|
217
217
|
}
|
|
218
218
|
/**
|
|
219
219
|
* The Kalshi tickers of a matched event: the market_id of its members on
|
|
220
|
-
* kalshi
|
|
221
|
-
*
|
|
220
|
+
* kalshi (the ticker is the id), active ones unless includeInactive, in
|
|
221
|
+
* member order, each once.
|
|
222
222
|
*/
|
|
223
223
|
export function kalshiTickers(event, includeInactive = false) {
|
|
224
224
|
const out = [];
|
|
@@ -387,7 +387,7 @@ export class Kalshi {
|
|
|
387
387
|
const rows = Array.isArray(body.candlesticks) ? body.candlesticks : [];
|
|
388
388
|
return rows.map((s) => candlestickFromRaw(record(s), minutes));
|
|
389
389
|
}
|
|
390
|
-
/** The Kalshi tickers of a Skewtape matched event: the market_id of its kalshi
|
|
390
|
+
/** The Kalshi tickers of a Skewtape matched event: the market_id of its kalshi members, active ones unless includeInactive. */
|
|
391
391
|
tickers(event, options = {}) {
|
|
392
392
|
return kalshiTickers(event, options.includeInactive ?? false);
|
|
393
393
|
}
|
package/dist/esm/paginated.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare class Paginated<T> implements AsyncIterable<T> {
|
|
|
16
16
|
private readonly fetchPage;
|
|
17
17
|
private readonly keep?;
|
|
18
18
|
constructor(fetchPage: (cursor?: string) => Promise<Page<T>>, keep?: ((item: T) => boolean) | undefined);
|
|
19
|
-
/** The pages as the API returns them; a client-side filter (
|
|
19
|
+
/** The pages as the API returns them; a client-side filter (sk.pairs: the matched events of two active members) applies to each. */
|
|
20
20
|
pages(): AsyncGenerator<Page<T>, void, undefined>;
|
|
21
21
|
[Symbol.asyncIterator](): AsyncGenerator<T, void, undefined>;
|
|
22
22
|
/** The first item, or undefined when there is none. */
|
package/dist/esm/paginated.js
CHANGED
|
@@ -14,7 +14,7 @@ export class Paginated {
|
|
|
14
14
|
this.fetchPage = fetchPage;
|
|
15
15
|
this.keep = keep;
|
|
16
16
|
}
|
|
17
|
-
/** The pages as the API returns them; a client-side filter (
|
|
17
|
+
/** The pages as the API returns them; a client-side filter (sk.pairs: the matched events of two active members) applies to each. */
|
|
18
18
|
async *pages() {
|
|
19
19
|
let cursor;
|
|
20
20
|
for (;;) {
|
package/dist/esm/quote-math.js
CHANGED
|
@@ -392,7 +392,10 @@ export function computeQuote(q) {
|
|
|
392
392
|
res.venues.push({ depth_micro: safe(m.depth, "depth"), ...legOut(leg, q.side) });
|
|
393
393
|
if (m.fee === null && feeKnown) {
|
|
394
394
|
res.warnings.push(`fee_unknown: ${m.m.venue} (${m.m.fee_status}): its fee is unknown, so it is left out of the plan; venues shows it alone, before fees`);
|
|
395
|
-
|
|
395
|
+
// The partial line names the venues left out only when one of them
|
|
396
|
+
// could have filled some of the size.
|
|
397
|
+
if (alloc > 0n)
|
|
398
|
+
leftOut = true;
|
|
396
399
|
continue;
|
|
397
400
|
}
|
|
398
401
|
if (m.fee === null)
|
package/dist/esm/quote.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export interface QuoteOptions {
|
|
|
38
38
|
size: number | string;
|
|
39
39
|
/** Quote members that do not resolve alike, with a warning; refused by default. */
|
|
40
40
|
allowRuleMismatch?: boolean;
|
|
41
|
-
/** Readers by venue, used before the defaults (Polymarket's CLOB; Kalshi's public orderbook
|
|
41
|
+
/** Readers by venue, used before the defaults (Polymarket's CLOB; Kalshi's public orderbook). */
|
|
42
42
|
bookReaders?: Record<string, BookReader>;
|
|
43
43
|
/** The fetch the books are read with; the global one by default. It must not carry the Skewtape key. */
|
|
44
44
|
venueFetch?: typeof fetch;
|
|
@@ -84,17 +84,6 @@ export declare const readPolymarketBook: BookReader;
|
|
|
84
84
|
* may refuse. Kalshi documents no minimum order beyond that.
|
|
85
85
|
*/
|
|
86
86
|
export declare const readKalshiBook: BookReader;
|
|
87
|
-
/**
|
|
88
|
-
* A kalshi_dflow member trades through DFlow (ADR-0016), whose orderbook
|
|
89
|
-
* needs DFlow access, not set up yet, so the member is left out with that
|
|
90
|
-
* reason, plainly; nothing reads the book another way. (A kalshi member is
|
|
91
|
-
* read from Kalshi's own book: readKalshiBook.)
|
|
92
|
-
*
|
|
93
|
-
* TODO(decision): DFlow's orderbook endpoint, its shape and the key it needs
|
|
94
|
-
* (production access is by request). Until then a caller can pass its own
|
|
95
|
-
* reader in bookReaders.
|
|
96
|
-
*/
|
|
97
|
-
export declare const readKalshiBookThroughDflow: BookReader;
|
|
98
87
|
export declare const DEFAULT_BOOK_READERS: Readonly<Record<string, BookReader>>;
|
|
99
88
|
/** The event's outcome names a quote can take, as the members' outcome maps name them. */
|
|
100
89
|
export declare function outcomesOf(context: QuoteContext): string[];
|
package/dist/esm/quote.js
CHANGED
|
@@ -189,23 +189,9 @@ export const readKalshiBook = async (request, fetchImpl) => {
|
|
|
189
189
|
throw new BookUnavailable(`Kalshi sent a book this version cannot read (${err instanceof Error ? err.message : String(err)})`);
|
|
190
190
|
}
|
|
191
191
|
};
|
|
192
|
-
/**
|
|
193
|
-
* A kalshi_dflow member trades through DFlow (ADR-0016), whose orderbook
|
|
194
|
-
* needs DFlow access, not set up yet, so the member is left out with that
|
|
195
|
-
* reason, plainly; nothing reads the book another way. (A kalshi member is
|
|
196
|
-
* read from Kalshi's own book: readKalshiBook.)
|
|
197
|
-
*
|
|
198
|
-
* TODO(decision): DFlow's orderbook endpoint, its shape and the key it needs
|
|
199
|
-
* (production access is by request). Until then a caller can pass its own
|
|
200
|
-
* reader in bookReaders.
|
|
201
|
-
*/
|
|
202
|
-
export const readKalshiBookThroughDflow = async () => {
|
|
203
|
-
throw new BookUnavailable("kalshi_dflow's book is read through DFlow's orderbook, and DFlow access is not set up yet");
|
|
204
|
-
};
|
|
205
192
|
export const DEFAULT_BOOK_READERS = {
|
|
206
193
|
polymarket: readPolymarketBook,
|
|
207
194
|
kalshi: readKalshiBook,
|
|
208
|
-
kalshi_dflow: readKalshiBookThroughDflow,
|
|
209
195
|
};
|
|
210
196
|
/** Each outcome's name (its label, or its token id when the market gives two outcomes the same label) to its token id. */
|
|
211
197
|
function names(member) {
|